mob.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef MOB_HPP
  4. #define MOB_HPP
  5. #include <vector>
  6. #include "../common/database.hpp"
  7. #include "../common/mmo.hpp" // struct item
  8. #include "../common/timer.hpp"
  9. #include "status.hpp" // struct status data, struct status_change
  10. #include "unit.hpp" // unit_stop_walking(), unit_stop_attack()
  11. struct guardian_data;
  12. //The number of drops all mobs have and the max drop-slot that the steal skill will attempt to steal from.
  13. #define MAX_MOB_DROP 10
  14. #define MAX_MVP_DROP 3
  15. #define MAX_MOB_DROP_ADD 5
  16. #define MAX_MVP_DROP_ADD 2
  17. #define MAX_MOB_DROP_TOTAL (MAX_MOB_DROP+MAX_MOB_DROP_ADD)
  18. #define MAX_MVP_DROP_TOTAL (MAX_MVP_DROP+MAX_MVP_DROP_ADD)
  19. #define MAX_STEAL_DROP 7
  20. #define MAX_RACE2_MOBS 100
  21. //Min time between AI executions
  22. const t_tick MIN_MOBTHINKTIME = 100;
  23. //Min time before mobs do a check to call nearby friends for help (or for slaves to support their master)
  24. const t_tick MIN_MOBLINKTIME = 1000;
  25. //Min time between random walks
  26. const t_tick MIN_RANDOMWALKTIME = 4000;
  27. //Distance that slaves should keep from their master.
  28. #define MOB_SLAVEDISTANCE 2
  29. //Used to determine default enemy type of mobs (for use in eachinrange calls)
  30. #define DEFAULT_ENEMY_TYPE(md) (md->special_state.ai?BL_CHAR:BL_MOB|BL_PC|BL_HOM|BL_MER)
  31. /**
  32. * Mob constants
  33. * Added definitions for WoE:SE objects and other [L0ne_W0lf], [aleos]
  34. */
  35. enum MOBID {
  36. MOBID_PORING = 1002,
  37. MOBID_RED_PLANT = 1078,
  38. MOBID_BLUE_PLANT,
  39. MOBID_GREEN_PLANT,
  40. MOBID_YELLOW_PLANT,
  41. MOBID_WHITE_PLANT,
  42. MOBID_SHINING_PLANT,
  43. MOBID_BLACK_MUSHROOM = 1084,
  44. MOBID_MARINE_SPHERE = 1142,
  45. MOBID_EMPERIUM = 1288,
  46. MOBID_G_PARASITE = 1555,
  47. MOBID_G_FLORA = 1575,
  48. MOBID_G_HYDRA = 1579,
  49. MOBID_G_MANDRAGORA = 1589,
  50. MOBID_G_GEOGRAPHER = 1590,
  51. MOBID_GUARDIAN_STONE1 = 1907,
  52. MOBID_GUARDIAN_STONE2,
  53. MOBID_SILVERSNIPER = 2042,
  54. MOBID_MAGICDECOY_FIRE,
  55. MOBID_MAGICDECOY_WATER,
  56. MOBID_MAGICDECOY_EARTH,
  57. MOBID_MAGICDECOY_WIND,
  58. MOBID_ZANZOU = 2308,
  59. MOBID_S_HORNET = 2158,
  60. MOBID_S_GIANT_HORNET,
  61. MOBID_S_LUCIOLA_VESPA,
  62. };
  63. ///Mob skill states.
  64. enum MobSkillState {
  65. MSS_ANY = -1,
  66. MSS_IDLE,
  67. MSS_WALK,
  68. MSS_LOOT,
  69. MSS_DEAD,
  70. MSS_BERSERK, //Aggressive mob attacking
  71. MSS_ANGRY, //Mob retaliating from being attacked.
  72. MSS_RUSH, //Mob following a player after being attacked.
  73. MSS_FOLLOW, //Mob following a player without being attacked.
  74. MSS_ANYTARGET,
  75. };
  76. enum MobDamageLogFlag
  77. {
  78. MDLF_NORMAL = 0,
  79. MDLF_HOMUN,
  80. MDLF_PET,
  81. MDLF_SELF
  82. };
  83. enum e_size : uint8 {
  84. SZ_SMALL = 0,
  85. SZ_MEDIUM,
  86. SZ_BIG,
  87. SZ_ALL,
  88. SZ_MAX
  89. };
  90. /// Random Monster Groups
  91. enum e_random_monster : uint16 {
  92. MOBG_Branch_Of_Dead_Tree = 0,
  93. MOBG_Poring_Box,
  94. MOBG_Bloody_Dead_Branch,
  95. MOBG_Red_Pouch_Of_Surprise,
  96. MOBG_ClassChange,
  97. MOBG_Taekwon_Mission,
  98. };
  99. /// Random Monster Group Flags
  100. enum e_random_monster_flags {
  101. RMF_NONE = 0x00, ///< Apply no flags
  102. RMF_DB_RATE = 0x01, ///< Apply the summon success chance found in the list (otherwise get any monster from the db)
  103. RMF_CHECK_MOB_LV = 0x02, ///< Apply a monster level check
  104. RMF_MOB_NOT_BOSS = 0x04, ///< Selected monster should not be a Boss type (except those from MOBG_Bloody_Dead_Branch)
  105. RMF_MOB_NOT_SPAWN = 0x08, ///< Selected monster must have normal spawn
  106. RMF_MOB_NOT_PLANT = 0x10, ///< Selected monster should not be a Plant type
  107. RMF_ALL = 0xFF, ///< Apply all flags
  108. };
  109. struct mob_skill {
  110. enum MobSkillState state;
  111. uint16 skill_id,skill_lv;
  112. short permillage;
  113. int casttime,delay;
  114. short cancel;
  115. short cond1,cond2;
  116. short target;
  117. int val[5];
  118. short emotion;
  119. unsigned short msg_id;
  120. };
  121. struct mob_chat {
  122. unsigned short msg_id;
  123. unsigned long color;
  124. char msg[CHAT_SIZE_MAX];
  125. };
  126. struct spawn_info {
  127. unsigned short mapindex;
  128. unsigned short qty;
  129. };
  130. /// Loooitem struct
  131. struct s_mob_lootitem {
  132. struct item item; ///< Item info
  133. unsigned short mob_id; ///< ID of monster that dropped the item
  134. };
  135. /// Struct for monster's drop item
  136. struct s_mob_drop {
  137. t_itemid nameid;
  138. int p;
  139. uint8 randomopt_group;
  140. unsigned steal_protected : 1;
  141. };
  142. struct mob_db {
  143. char sprite[NAME_LENGTH],name[NAME_LENGTH],jname[NAME_LENGTH];
  144. unsigned int base_exp,job_exp;
  145. unsigned int mexp;
  146. short range2,range3;
  147. enum e_race2 race2; // celest
  148. unsigned short lv;
  149. struct s_mob_drop dropitem[MAX_MOB_DROP_TOTAL], mvpitem[MAX_MVP_DROP_TOTAL];
  150. struct status_data status;
  151. struct view_data vd;
  152. unsigned int option;
  153. int maxskill;
  154. struct mob_skill skill[MAX_MOBSKILL];
  155. };
  156. struct mob_data {
  157. struct block_list bl;
  158. struct unit_data ud;
  159. struct view_data *vd;
  160. bool vd_changed;
  161. struct status_data status, *base_status; //Second one is in case of leveling up mobs, or tiny/large mobs.
  162. struct status_change sc;
  163. struct mob_db *db; //For quick data access (saves doing mob_db(md->mob_id) all the time) [Skotlex]
  164. char name[NAME_LENGTH];
  165. struct s_specialState {
  166. unsigned int size : 2; //Small/Big monsters.
  167. enum mob_ai ai; //Special ai for summoned monsters.
  168. unsigned int clone : 1;/* is clone? 1:0 */
  169. } special_state; //Special mob information that does not needs to be zero'ed on mob respawn.
  170. struct s_MobState {
  171. unsigned int aggressive : 1; //Signals whether the mob AI is in aggressive mode or reactive mode. [Skotlex]
  172. unsigned int steal_coin_flag : 1;
  173. unsigned int soul_change_flag : 1; // Celest
  174. unsigned int alchemist: 1;
  175. unsigned int npc_killmonster: 1; //for new killmonster behavior
  176. unsigned int rebirth: 1; // NPC_Rebirth used
  177. unsigned int boss : 1;
  178. unsigned int copy_master_mode : 1; ///< Whether the spawned monster should copy the master's mode.
  179. enum MobSkillState skillstate;
  180. unsigned char steal_flag; //number of steal tries (to prevent steal exploit on mobs with few items) [Lupus]
  181. unsigned char attacked_count; //For rude attacked.
  182. int provoke_flag; // Celest
  183. } state;
  184. struct guardian_data* guardian_data;
  185. struct s_dmglog {
  186. int id; //char id
  187. unsigned int dmg;
  188. unsigned int flag : 2; //0: Normal. 1: Homunc exp. 2: Pet exp
  189. } dmglog[DAMAGELOG_SIZE];
  190. uint32 spotted_log[DAMAGELOG_SIZE];
  191. struct spawn_data *spawn; //Spawn data.
  192. int spawn_timer; //Required for Convex Mirror
  193. struct s_mob_lootitem *lootitems;
  194. short mob_id;
  195. unsigned int tdmg; //Stores total damage given to the mob, for exp calculations. [Skotlex]
  196. int level;
  197. int target_id,attacked_id,norm_attacked_id;
  198. int areanpc_id; //Required in OnTouchNPC (to avoid multiple area touchs)
  199. int bg_id; // BattleGround System
  200. t_tick next_walktime,last_thinktime,last_linktime,last_pcneartime,dmgtick;
  201. short move_fail_count;
  202. short lootitem_count;
  203. short min_chase;
  204. unsigned char walktoxy_fail_count; //Pathfinding succeeds but the actual walking failed (e.g. Icewall lock)
  205. int deletetimer;
  206. int master_id,master_dist;
  207. int8 skill_idx; // Index of last used skill from db->skill[]
  208. t_tick skilldelay[MAX_MOBSKILL];
  209. char npc_event[EVENT_NAME_LENGTH];
  210. /**
  211. * Did this monster summon something?
  212. * Used to flag summon deletions, saves a worth amount of memory
  213. **/
  214. bool can_summon;
  215. /**
  216. * MvP Tombstone NPC ID
  217. **/
  218. int tomb_nid;
  219. };
  220. class MobAvailDatabase : public YamlDatabase {
  221. public:
  222. MobAvailDatabase() : YamlDatabase("MOB_AVAIL_DB", 1) {
  223. }
  224. void clear() { };
  225. const std::string getDefaultLocation();
  226. uint64 parseBodyNode(const YAML::Node& node);
  227. };
  228. enum e_mob_skill_target {
  229. MST_TARGET = 0,
  230. MST_RANDOM, //Random Target!
  231. MST_SELF,
  232. MST_FRIEND,
  233. MST_MASTER,
  234. MST_AROUND5,
  235. MST_AROUND6,
  236. MST_AROUND7,
  237. MST_AROUND8,
  238. MST_AROUND1,
  239. MST_AROUND2,
  240. MST_AROUND3,
  241. MST_AROUND4,
  242. MST_AROUND = MST_AROUND4,
  243. };
  244. enum e_mob_skill_condition {
  245. MSC_ALWAYS = 0x0000,
  246. MSC_MYHPLTMAXRATE,
  247. MSC_MYHPINRATE,
  248. MSC_FRIENDHPLTMAXRATE,
  249. MSC_FRIENDHPINRATE,
  250. MSC_MYSTATUSON,
  251. MSC_MYSTATUSOFF,
  252. MSC_FRIENDSTATUSON,
  253. MSC_FRIENDSTATUSOFF,
  254. MSC_ATTACKPCGT,
  255. MSC_ATTACKPCGE,
  256. MSC_SLAVELT,
  257. MSC_SLAVELE,
  258. MSC_CLOSEDATTACKED,
  259. MSC_LONGRANGEATTACKED,
  260. MSC_AFTERSKILL,
  261. MSC_SKILLUSED,
  262. MSC_CASTTARGETED,
  263. MSC_RUDEATTACKED,
  264. MSC_MASTERHPLTMAXRATE,
  265. MSC_MASTERATTACKED,
  266. MSC_ALCHEMIST,
  267. MSC_SPAWN,
  268. };
  269. // The data structures for storing delayed item drops
  270. struct item_drop {
  271. struct item item_data;
  272. unsigned short mob_id;
  273. enum bl_type src_type;
  274. struct item_drop* next;
  275. };
  276. struct item_drop_list {
  277. int16 m, x, y; // coordinates
  278. int first_charid, second_charid, third_charid; // charid's of players with higher pickup priority
  279. struct item_drop* item; // linked list of drops
  280. };
  281. struct mob_db *mob_db(int mob_id);
  282. uint16 mobdb_searchname(const char * const str);
  283. struct mob_db* mobdb_search_aegisname( const char* str );
  284. int mobdb_searchname_array(const char *str, uint16 * out, int size);
  285. int mobdb_checkid(const int id);
  286. struct view_data* mob_get_viewdata(int mob_id);
  287. void mob_set_dynamic_viewdata( struct mob_data* md );
  288. void mob_free_dynamic_viewdata( struct mob_data* md );
  289. struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int mob_id, const char *event, unsigned int size, enum mob_ai ai);
  290. int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y,
  291. const char* mobname, int mob_id, int amount, const char* event, unsigned int size, enum mob_ai ai);
  292. int mob_once_spawn_area(struct map_session_data* sd, int16 m,
  293. int16 x0, int16 y0, int16 x1, int16 y1, const char* mobname, int mob_id, int amount, const char* event, unsigned int size, enum mob_ai ai);
  294. bool mob_ksprotected (struct block_list *src, struct block_list *target);
  295. int mob_spawn_guardian(const char* mapname, int16 x, int16 y, const char* mobname, int mob_id, const char* event, int guardian, bool has_index); // Spawning Guardians [Valaris]
  296. int mob_spawn_bg(const char* mapname, int16 x, int16 y, const char* mobname, int mob_id, const char* event, unsigned int bg_id);
  297. int mob_guardian_guildchange(struct mob_data *md); //Change Guardian's ownership. [Skotlex]
  298. int mob_randomwalk(struct mob_data *md,t_tick tick);
  299. int mob_warpchase(struct mob_data *md, struct block_list *target);
  300. int mob_target(struct mob_data *md,struct block_list *bl,int dist);
  301. int mob_unlocktarget(struct mob_data *md, t_tick tick);
  302. struct mob_data* mob_spawn_dataset(struct spawn_data *data);
  303. int mob_spawn(struct mob_data *md);
  304. TIMER_FUNC(mob_delayspawn);
  305. int mob_setdelayspawn(struct mob_data *md);
  306. int mob_parse_dataset(struct spawn_data *data);
  307. void mob_log_damage(struct mob_data *md, struct block_list *src, int damage);
  308. void mob_damage(struct mob_data *md, struct block_list *src, int damage);
  309. int mob_dead(struct mob_data *md, struct block_list *src, int type);
  310. void mob_revive(struct mob_data *md, unsigned int hp);
  311. void mob_heal(struct mob_data *md,unsigned int heal);
  312. #define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type)
  313. #define mob_stop_attack(md) unit_stop_attack(&(md)->bl)
  314. void mob_clear_spawninfo();
  315. void do_init_mob(void);
  316. void do_final_mob(bool is_reload);
  317. TIMER_FUNC(mob_timer_delete);
  318. int mob_deleteslave(struct mob_data *md);
  319. int mob_random_class (int *value, size_t count);
  320. int mob_get_random_id(int type, enum e_random_monster_flags flag, int lv);
  321. int mob_class_change(struct mob_data *md,int mob_id);
  322. int mob_warpslave(struct block_list *bl, int range);
  323. int mob_linksearch(struct block_list *bl,va_list ap);
  324. int mobskill_use(struct mob_data *md,t_tick tick,int event);
  325. int mobskill_event(struct mob_data *md,struct block_list *src,t_tick tick, int flag);
  326. int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id);
  327. int mob_countslave(struct block_list *bl);
  328. int mob_count_sub(struct block_list *bl, va_list ap);
  329. int mob_is_clone(int mob_id);
  330. int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, enum e_mode mode, int flag, unsigned int duration);
  331. int mob_clone_delete(struct mob_data *md);
  332. void mob_reload_itemmob_data(void);
  333. void mob_reload(void);
  334. void mob_add_spawn(uint16 mob_id, const struct spawn_info& new_spawn);
  335. const std::vector<spawn_info> mob_get_spawns(uint16 mob_id);
  336. bool mob_has_spawn(uint16 mob_id);
  337. // MvP Tomb System
  338. int mvptomb_setdelayspawn(struct npc_data *nd);
  339. TIMER_FUNC(mvptomb_delayspawn);
  340. void mvptomb_create(struct mob_data *md, char *killer, time_t time);
  341. void mvptomb_destroy(struct mob_data *md);
  342. void mob_setdropitem_option(struct item *itm, struct s_mob_drop *mobdrop);
  343. #define CHK_MOBSIZE(size) ((size) >= SZ_SMALL && (size) < SZ_MAX) /// Check valid Monster Size
  344. #endif /* MOB_HPP */