Guest User

Untitled

a guest
Oct 15th, 2019
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright (c) Hercules Dev Team, licensed under GNU GPL.
  2. // See the LICENSE file
  3. // Sample Hercules Plugin
  4.  
  5. #include "common/hercules.h"
  6. #include "common/memmgr.h"
  7. #include "common/mmo.h"
  8. #include "common/socket.h"
  9. #include "map/map.h"
  10. #include "map/pc.h"
  11. #include "map/script.h"
  12. #include "map/skill.h"
  13. #include "map/status.h"
  14.  
  15. #include "plugins/HPMHooking.h"
  16. #include "common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. /* works like bDelayRate */
  23. /* example: cooldown is 10000 (10s) */
  24. /* 'bonus bCoolDownRate,50;' = 15000 (15s) (+50%) */
  25. /* 'bonus bCoolDownRate,-50;' = 5000 (5s) (-50%) */
  26.  
  27. HPExport struct hplugin_info pinfo = {
  28. "bCoolDownRate", // Plugin name
  29. SERVER_TYPE_MAP, // Which server types this plugin works with?
  30. "0.1", // Plugin version
  31. HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
  32. };
  33.  
  34. int bCoolDownRateID = -1;
  35.  
  36. struct s_cooldown_rate {
  37. int rate;
  38. };
  39.  
  40. /* to check for the bonus */
  41. int skill_blockpc_start_preHook(struct map_session_data **sd, uint16 *skill_id, int *tick)
  42. {
  43. const struct s_cooldown_rate *data;
  44.  
  45. if (*tick > 1 && sd != NULL && (data = getFromMSD(*sd, 0)) != NULL) {
  46. if (data->rate != 100)
  47. *tick = *tick * data->rate / 100;
  48. }
  49. return 1;/* doesn't matter */
  50. }
  51.  
  52. /* to set the bonus */
  53. int pc_bonus_preHook(struct map_session_data **sd, int *type, int *val)
  54. {
  55. if (*type == bCoolDownRateID) {
  56. struct s_cooldown_rate *data;
  57.  
  58. if ((data = getFromMSD(*sd, 0)) == NULL) {/* don't have, create */
  59. CREATE(data, struct s_cooldown_rate, 1);/* alloc */
  60. data->rate = 100;/* 100% -- default */
  61. addToMSD(*sd, data, 0, true);/* link to sd */
  62. }
  63. data->rate += *val;
  64.  
  65. hookStop();/* don't need to run the original */
  66. }
  67.  
  68. return 0;
  69. }
  70. /* to reset the bonus on recalc */
  71. int status_calc_pc_preHook(struct map_session_data **sd, enum e_status_calc_opt *opt)
  72. {
  73. struct s_cooldown_rate *data;
  74.  
  75. if ((data = getFromMSD(*sd,0)) != NULL) {
  76. data->rate = 100;//100% -- default
  77. }
  78. return 1;/* doesn't matter */
  79. }
  80.  
  81. HPExport void plugin_init(void)
  82. {
  83. /* grab a unique bonus ID for us */
  84. bCoolDownRateID = map->get_new_bonus_id();
  85. /* set constant 'bCoolDownRate', and set value to bCoolDownRateID */
  86. script->set_constant("bCoolDownRate", bCoolDownRateID, false, false);
  87.  
  88. /* hook */
  89. addHookPre(skill, blockpc_start, skill_blockpc_start_preHook);
  90. addHookPre(pc, bonus, pc_bonus_preHook);
  91. addHookPre(status, calc_pc_, status_calc_pc_preHook);
  92. }
RAW Paste Data