pet.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef PET_HPP
  4. #define PET_HPP
  5. #include <common/cbasetypes.hpp>
  6. #include <common/database.hpp>
  7. #include <common/mmo.hpp>
  8. #include <common/timer.hpp>
  9. #include "battle.hpp"
  10. #include "mob.hpp"
  11. #include "pc.hpp"
  12. #include "script.hpp"
  13. #include "status.hpp"
  14. #include "unit.hpp"
  15. #include <unordered_map>
  16. #define MAX_PETLOOT_SIZE 30
  17. struct s_pet_evo_data {
  18. uint16 target_mob_id;
  19. std::unordered_map<t_itemid, uint16> requirements;
  20. };
  21. /// Pet DB
  22. struct s_pet_db {
  23. uint16 class_; ///< Monster ID
  24. t_itemid itemID; ///< Lure ID
  25. t_itemid EggID; ///< Egg ID
  26. t_itemid AcceID; ///< Accessory ID
  27. t_itemid FoodID; ///< Food ID
  28. uint16 fullness; ///< Amount of hunger decresed each hungry_delay interval
  29. uint32 hungry_delay; ///< Hunger value decrease each x seconds
  30. int32 hunger_increase; ///< Hunger increased every time the pet is fed.
  31. int32 r_hungry; ///< Intimacy increased after feeding
  32. int32 r_full; ///< Intimacy increased when over-fed
  33. uint32 intimate; ///< Initial intimacy value
  34. int32 die; ///< Intimacy increased when die
  35. int32 hungry_intimacy_dec; ///< Intimacy increased when hungry
  36. uint16 capture; ///< Capture success rate 10000 = 100%
  37. bool s_perfor; ///< Special performance
  38. uint16 attack_rate; ///< Rate of which the pet will attack (requires at least pet_support_min_friendly intimacy).
  39. uint16 defence_attack_rate; ///< Rate of which the pet will retaliate when master is being attacked (requires at least pet_support_min_friendly intimacy).
  40. uint16 change_target_rate; ///< Rate of which the pet will change its attack target.
  41. bool allow_autofeed; ///< Can this pet use auto feeding mechanic.
  42. std::unordered_map<uint16, std::shared_ptr<s_pet_evo_data>> evolution_data; ///< Data for evolving the pet.
  43. struct script_code
  44. *pet_support_script, ///< Script since pet hatched. For pet* script commands only.
  45. *pet_bonus_script; ///< Bonus script for this pet.
  46. ~s_pet_db()
  47. {
  48. if( this->pet_support_script ){
  49. script_free_code(this->pet_support_script);
  50. }
  51. if( this->pet_bonus_script ){
  52. script_free_code(this->pet_bonus_script);
  53. }
  54. }
  55. };
  56. enum e_pet_itemtype : uint8 { PET_CATCH,PET_EGG,PET_EQUIP,PET_FOOD };
  57. enum e_pet_catch_flag : uint8 {
  58. PET_CATCH_NORMAL = 0,
  59. PET_CATCH_UNIVERSAL_NO_BOSS, // The catch attempt is universal (ignoring MD_STATUS_IMMUNE/Boss)
  60. PET_CATCH_UNIVERSAL_ALL,
  61. PET_CATCH_MAX
  62. };
  63. enum e_pet_intimate_level : uint16 {
  64. PET_INTIMATE_NONE = 0,
  65. PET_INTIMATE_AWKWARD = 1,
  66. PET_INTIMATE_SHY = 100,
  67. PET_INTIMATE_NEUTRAL = 250,
  68. PET_INTIMATE_CORDIAL = 750,
  69. PET_INTIMATE_LOYAL = 910,
  70. PET_INTIMATE_MAX = 1000
  71. };
  72. enum e_pet_hungry : uint16 {
  73. PET_HUNGRY_NONE = 0,
  74. PET_HUNGRY_VERY_HUNGRY = 10,
  75. PET_HUNGRY_HUNGRY = 25,
  76. PET_HUNGRY_NEUTRAL = 75,
  77. PET_HUNGRY_SATISFIED = 90,
  78. PET_HUNGRY_STUFFED = 100
  79. };
  80. struct pet_recovery { //Stat recovery
  81. enum sc_type type; //Status Change id
  82. uint16 delay; //How long before curing (secs).
  83. int32 timer;
  84. };
  85. struct pet_bonus {
  86. uint16 type; //bStr, bVit?
  87. uint16 val; //value
  88. uint16 duration; //in seconds
  89. uint16 delay; //Time before re-effect the bonus in seconds
  90. int32 timer;
  91. };
  92. struct pet_skill_attack { //Attack Skill
  93. uint16 id;
  94. uint16 lv; // Skill level
  95. uint16 damage; // Fixed damage value of petskillattack2
  96. uint16 div_; //0 = Normal skill. >0 = Fixed damage (lv), fixed div_.
  97. uint16 rate; //Base chance of skill ocurrance (10 = 10% of attacks)
  98. uint16 bonusrate; //How being 100% loyal affects cast rate (10 = At 1000 intimacy->rate+10%
  99. };
  100. struct pet_skill_support { //Support Skill
  101. uint16 id;
  102. uint16 lv;
  103. uint16 hp; //Max HP% for skill to trigger (50 -> 50% for Magnificat)
  104. uint16 sp; //Max SP% for skill to trigger (100 = no check)
  105. uint16 delay; //Time (secs) between being able to recast.
  106. int32 timer;
  107. };
  108. struct pet_loot {
  109. struct item *item;
  110. uint16 count;
  111. uint16 weight;
  112. uint16 max;
  113. };
  114. class PetDatabase : public TypesafeYamlDatabase<uint16,s_pet_db>{
  115. public:
  116. PetDatabase() : TypesafeYamlDatabase( "PET_DB", 1 ){
  117. }
  118. const std::string getDefaultLocation() override;
  119. uint64 parseBodyNode( const ryml::NodeRef& node ) override;
  120. // Additional
  121. bool reload();
  122. };
  123. extern PetDatabase pet_db;
  124. TIMER_FUNC(pet_endautobonus);
  125. /// Pet AutoBonus bonus struct
  126. struct s_petautobonus {
  127. int16 rate;
  128. uint16 atk_type;
  129. std::string bonus_script, other_script;
  130. t_tick duration;
  131. int32 timer;
  132. ~s_petautobonus() {
  133. if (this->timer != INVALID_TIMER) {
  134. delete_timer(this->timer, pet_endautobonus);
  135. this->timer = INVALID_TIMER;
  136. }
  137. this->bonus_script.clear();
  138. this->other_script.clear();
  139. }
  140. };
  141. /// Pet Autobonus database wrapper
  142. struct s_pet_autobonus_wrapper {
  143. script_code *script;
  144. ~s_pet_autobonus_wrapper() {
  145. if (this->script != nullptr) {
  146. script_free_code(this->script);
  147. this->script = nullptr;
  148. }
  149. }
  150. };
  151. extern std::unordered_map<std::string, std::shared_ptr<s_pet_autobonus_wrapper>> pet_autobonuses;
  152. struct pet_data {
  153. struct block_list bl;
  154. struct unit_data ud;
  155. struct view_data vd;
  156. struct s_pet pet;
  157. struct status_data status;
  158. std::shared_ptr<s_mob_db> db;
  159. int32 pet_hungry_timer;
  160. int32 target_id;
  161. struct {
  162. unsigned skillbonus : 1;
  163. } state;
  164. int32 move_fail_count;
  165. t_tick next_walktime,last_thinktime;
  166. uint16 rate_fix; //Support rate as modified by intimacy (1000 = 100%) [Skotlex]
  167. struct pet_recovery* recovery;
  168. struct pet_bonus* bonus;
  169. struct pet_skill_attack* a_skill;
  170. struct pet_skill_support* s_skill;
  171. struct pet_loot* loot;
  172. std::vector<std::shared_ptr<s_petautobonus>> autobonus, autobonus2, autobonus3;
  173. int32 masterteleport_timer;
  174. map_session_data *master;
  175. std::shared_ptr<s_pet_db> get_pet_db() {
  176. return pet_db.find(this->pet.class_);
  177. }
  178. int32 get_pet_walk_speed() {
  179. switch (battle_config.pet_walk_speed) {
  180. default:
  181. case 1: // Master
  182. return this->master->battle_status.speed;
  183. case 2: // DEFAULT_WALK_SPEED
  184. return DEFAULT_WALK_SPEED;
  185. case 3: // Mob database
  186. return this->db->status.speed;
  187. }
  188. }
  189. };
  190. bool pet_create_egg(map_session_data *sd, t_itemid item_id);
  191. int32 pet_hungry_val(struct pet_data *pd);
  192. void pet_set_intimate(struct pet_data *pd, int32 value);
  193. int32 pet_target_check(struct pet_data *pd,struct block_list *bl,int32 type);
  194. void pet_unlocktarget(struct pet_data *pd);
  195. int32 pet_sc_check(map_session_data *sd, int32 type); //Skotlex
  196. std::shared_ptr<s_pet_db> pet_db_search(int32 key, enum e_pet_itemtype type);
  197. int32 pet_hungry_timer_delete(struct pet_data *pd);
  198. bool pet_data_init(map_session_data *sd, struct s_pet *pet);
  199. bool pet_return_egg( map_session_data *sd, struct pet_data *pd );
  200. int32 pet_birth_process(map_session_data *sd, struct s_pet *pet);
  201. int32 pet_recv_petdata(uint32 account_id,struct s_pet *p,int32 flag);
  202. int32 pet_select_egg(map_session_data *sd,int16 egg_index);
  203. void pet_catch_process_start( map_session_data& sd, t_itemid item_id, e_pet_catch_flag flag );
  204. void pet_catch_process_end( map_session_data& sd, int32 target_id );
  205. bool pet_get_egg(uint32 account_id, int16 pet_class, int32 pet_id);
  206. int32 pet_menu(map_session_data *sd,int32 menunum);
  207. int32 pet_change_name(map_session_data *sd,char *name);
  208. int32 pet_change_name_ack(map_session_data *sd, char* name, int32 flag);
  209. int32 pet_equipitem(map_session_data *sd,int32 index);
  210. void pet_lootitem_drop( pet_data& pd, map_session_data* sd );
  211. int32 pet_attackskill(struct pet_data *pd, int32 target_id);
  212. TIMER_FUNC(pet_skill_support_timer); // [Skotlex]
  213. TIMER_FUNC(pet_skill_bonus_timer); // [Valaris]
  214. TIMER_FUNC(pet_recovery_timer); // [Valaris]
  215. TIMER_FUNC(pet_heal_timer); // [Valaris]
  216. int32 pet_egg_search(map_session_data *sd, int32 pet_id);
  217. void pet_evolution(map_session_data *sd, int16 pet_id);
  218. int32 pet_food(map_session_data *sd, struct pet_data *pd);
  219. void pet_clear_support_bonuses(map_session_data *sd);
  220. bool pet_addautobonus(std::vector<std::shared_ptr<s_petautobonus>> &bonus, const std::string &script, int16 rate, uint32 dur, uint16 atk_type, const std::string &other_script, bool onskill);
  221. void pet_exeautobonus(map_session_data &sd, std::vector<std::shared_ptr<s_petautobonus>> *bonus, std::shared_ptr<s_petautobonus> &autobonus);
  222. void pet_delautobonus(map_session_data &sd, std::vector<std::shared_ptr<s_petautobonus>> &bonus, bool restore);
  223. void do_init_pet(void);
  224. void do_final_pet(void);
  225. #endif /* PET_HPP */