mob.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. //This is the distance at which @autoloot works,
  13. //if the item drops farther from the player than this,
  14. //it will not be autolooted. [Skotlex]
  15. //Note: The range is unlimited unless this define is set.
  16. //#define AUTOLOOT_DISTANCE AREA_SIZE
  17. //The number of drops all mobs have and the max drop-slot that the steal skill will attempt to steal from.
  18. #define MAX_MOB_DROP 10
  19. #define MAX_MVP_DROP 3
  20. #define MAX_MOB_DROP_ADD 5
  21. #define MAX_MVP_DROP_ADD 2
  22. #define MAX_MOB_DROP_TOTAL (MAX_MOB_DROP+MAX_MOB_DROP_ADD)
  23. #define MAX_MVP_DROP_TOTAL (MAX_MVP_DROP+MAX_MVP_DROP_ADD)
  24. //Min time between AI executions
  25. const t_tick MIN_MOBTHINKTIME = 100;
  26. //Min time before mobs do a check to call nearby friends for help (or for slaves to support their master)
  27. const t_tick MIN_MOBLINKTIME = 1000;
  28. //Min time between random walks
  29. const t_tick MIN_RANDOMWALKTIME = 4000;
  30. //Distance that slaves should keep from their master.
  31. #define MOB_SLAVEDISTANCE 2
  32. //Used to determine default enemy type of mobs (for use in eachinrange calls)
  33. #define DEFAULT_ENEMY_TYPE(md) (md->special_state.ai?BL_CHAR:BL_MOB|BL_PC|BL_HOM|BL_MER)
  34. /**
  35. * Mob constants
  36. * Added definitions for WoE:SE objects and other [L0ne_W0lf], [aleos]
  37. */
  38. enum MOBID {
  39. MOBID_PORING = 1002,
  40. MOBID_RED_PLANT = 1078,
  41. MOBID_BLUE_PLANT,
  42. MOBID_GREEN_PLANT,
  43. MOBID_YELLOW_PLANT,
  44. MOBID_WHITE_PLANT,
  45. MOBID_SHINING_PLANT,
  46. MOBID_BLACK_MUSHROOM = 1084,
  47. MOBID_MARINE_SPHERE = 1142,
  48. MOBID_EMPERIUM = 1288,
  49. MOBID_G_PARASITE = 1555,
  50. MOBID_G_FLORA = 1575,
  51. MOBID_G_HYDRA = 1579,
  52. MOBID_G_MANDRAGORA = 1589,
  53. MOBID_G_GEOGRAPHER = 1590,
  54. MOBID_GUARDIAN_STONE1 = 1907,
  55. MOBID_GUARDIAN_STONE2,
  56. MOBID_SILVERSNIPER = 2042,
  57. MOBID_MAGICDECOY_FIRE,
  58. MOBID_MAGICDECOY_WATER,
  59. MOBID_MAGICDECOY_EARTH,
  60. MOBID_MAGICDECOY_WIND,
  61. MOBID_ZANZOU = 2308,
  62. MOBID_S_HORNET = 2158,
  63. MOBID_S_GIANT_HORNET,
  64. MOBID_S_LUCIOLA_VESPA,
  65. MOBID_GUILD_SKILL_FLAG = 20269,
  66. };
  67. ///Mob skill states.
  68. enum MobSkillState {
  69. MSS_ANY = -1,
  70. MSS_IDLE,
  71. MSS_WALK,
  72. MSS_LOOT,
  73. MSS_DEAD,
  74. MSS_BERSERK, //Aggressive mob attacking
  75. MSS_ANGRY, //Mob retaliating from being attacked.
  76. MSS_RUSH, //Mob following a player after being attacked.
  77. MSS_FOLLOW, //Mob following a player without being attacked.
  78. MSS_ANYTARGET,
  79. };
  80. enum MobDamageLogFlag
  81. {
  82. MDLF_NORMAL = 0,
  83. MDLF_HOMUN,
  84. MDLF_PET,
  85. MDLF_SELF
  86. };
  87. enum e_size : uint8 {
  88. SZ_SMALL = 0,
  89. SZ_MEDIUM,
  90. SZ_BIG,
  91. SZ_ALL,
  92. SZ_MAX
  93. };
  94. /// Random Monster Groups
  95. enum e_random_monster : uint16 {
  96. MOBG_BRANCH_OF_DEAD_TREE = 0,
  97. MOBG_PORING_BOX,
  98. MOBG_BLOODY_DEAD_BRANCH,
  99. MOBG_RED_POUCH_OF_SURPRISE,
  100. MOBG_CLASSCHANGE,
  101. MOBG_TAEKWON_MISSION,
  102. MOBG_MAX,
  103. };
  104. /// Random Monster Group Flags
  105. enum e_random_monster_flags {
  106. RMF_NONE = 0x00, ///< Apply no flags
  107. RMF_DB_RATE = 0x01, ///< Apply the summon success chance found in the list (otherwise get any monster from the db)
  108. RMF_CHECK_MOB_LV = 0x02, ///< Apply a monster level check
  109. RMF_MOB_NOT_BOSS = 0x04, ///< Selected monster should not be a Boss type (except those from MOBG_BLOODY_DEAD_BRANCH)
  110. RMF_MOB_NOT_SPAWN = 0x08, ///< Selected monster must have normal spawn
  111. RMF_MOB_NOT_PLANT = 0x10, ///< Selected monster should not be a Plant type
  112. RMF_ALL = 0xFF, ///< Apply all flags
  113. };
  114. enum e_mob_bosstype : uint8{
  115. BOSSTYPE_NONE,
  116. BOSSTYPE_MINIBOSS,
  117. BOSSTYPE_MVP
  118. };
  119. /// Monster Aegis AI types
  120. enum e_aegis_monstertype : uint16 {
  121. MONSTER_TYPE_01 = 0x81,
  122. MONSTER_TYPE_02 = 0x83,
  123. MONSTER_TYPE_03 = 0x1089,
  124. MONSTER_TYPE_04 = 0x3885,
  125. MONSTER_TYPE_05 = 0x2085,
  126. MONSTER_TYPE_06 = 0,
  127. MONSTER_TYPE_07 = 0x108B,
  128. MONSTER_TYPE_08 = 0x7085,
  129. MONSTER_TYPE_09 = 0x3095,
  130. MONSTER_TYPE_10 = 0x84,
  131. MONSTER_TYPE_11 = 0x84,
  132. MONSTER_TYPE_12 = 0x2085,
  133. MONSTER_TYPE_13 = 0x308D,
  134. //MONSTER_TYPE_14
  135. //MONSTER_TYPE_15
  136. //MONSTER_TYPE_16
  137. MONSTER_TYPE_17 = 0x91,
  138. //MONSTER_TYPE_18
  139. MONSTER_TYPE_19 = 0x3095,
  140. MONSTER_TYPE_20 = 0x3295,
  141. MONSTER_TYPE_21 = 0x3695,
  142. //MONSTER_TYPE_22
  143. //MONSTER_TYPE_23
  144. MONSTER_TYPE_24 = 0xA1,
  145. MONSTER_TYPE_25 = 0x1,
  146. MONSTER_TYPE_26 = 0xB695,
  147. MONSTER_TYPE_27 = 0x8084,
  148. };
  149. /// Aegis monster class types
  150. enum e_aegis_monsterclass : int8 {
  151. CLASS_NONE = -1,
  152. CLASS_NORMAL = 0,
  153. CLASS_BOSS,
  154. CLASS_GUARDIAN,
  155. CLASS_BATTLEFIELD = 4,
  156. CLASS_EVENT,
  157. CLASS_ALL,
  158. CLASS_MAX,
  159. };
  160. struct s_mob_skill {
  161. enum MobSkillState state;
  162. uint16 skill_id,skill_lv;
  163. short permillage;
  164. int casttime,delay;
  165. short cancel;
  166. short cond1,cond2;
  167. short target;
  168. int val[5];
  169. short emotion;
  170. unsigned short msg_id;
  171. };
  172. struct s_mob_chat {
  173. uint16 msg_id;
  174. uint32 color;
  175. std::string msg;
  176. };
  177. class MobChatDatabase : public TypesafeYamlDatabase<uint16, s_mob_chat> {
  178. public:
  179. MobChatDatabase() : TypesafeYamlDatabase("MOB_CHAT_DB", 1) {
  180. }
  181. const std::string getDefaultLocation();
  182. uint64 parseBodyNode(const YAML::Node &node);
  183. };
  184. struct s_mob_item_drop_ratio {
  185. t_itemid nameid;
  186. uint16 drop_ratio;
  187. std::vector<uint16> mob_ids;
  188. };
  189. class MobItemRatioDatabase : public TypesafeYamlDatabase<t_itemid, s_mob_item_drop_ratio> {
  190. public:
  191. MobItemRatioDatabase() : TypesafeYamlDatabase("MOB_ITEM_RATIO_DB", 1) {
  192. }
  193. const std::string getDefaultLocation();
  194. uint64 parseBodyNode(const YAML::Node &node);
  195. };
  196. struct spawn_info {
  197. unsigned short mapindex;
  198. unsigned short qty;
  199. };
  200. /// Loooitem struct
  201. struct s_mob_lootitem {
  202. struct item item; ///< Item info
  203. unsigned short mob_id; ///< ID of monster that dropped the item
  204. };
  205. /// Struct for monster's drop item
  206. struct s_mob_drop {
  207. t_itemid nameid;
  208. uint32 rate;
  209. uint16 randomopt_group;
  210. bool steal_protected;
  211. };
  212. struct s_mob_db {
  213. uint32 id;
  214. std::string sprite, name, jname;
  215. t_exp base_exp;
  216. t_exp job_exp;
  217. t_exp mexp;
  218. uint16 range2, range3;
  219. std::vector<e_race2> race2; // celest
  220. uint16 lv;
  221. s_mob_drop dropitem[MAX_MOB_DROP_TOTAL], mvpitem[MAX_MVP_DROP_TOTAL];
  222. status_data status;
  223. view_data vd;
  224. uint32 option;
  225. std::vector<std::shared_ptr<s_mob_skill>> skill;
  226. uint16 damagetaken;
  227. e_mob_bosstype get_bosstype();
  228. };
  229. class MobDatabase : public TypesafeCachedYamlDatabase <uint32, s_mob_db> {
  230. private:
  231. bool parseDropNode(std::string nodeName, YAML::Node node, uint8 max, s_mob_drop *drops);
  232. public:
  233. MobDatabase() : TypesafeCachedYamlDatabase("MOB_DB", 2, 1) {
  234. }
  235. const std::string getDefaultLocation();
  236. uint64 parseBodyNode(const YAML::Node &node);
  237. void loadingFinished();
  238. };
  239. extern MobDatabase mob_db;
  240. struct mob_data {
  241. struct block_list bl;
  242. struct unit_data ud;
  243. struct view_data *vd;
  244. bool vd_changed;
  245. struct status_data status, *base_status; //Second one is in case of leveling up mobs, or tiny/large mobs.
  246. struct status_change sc;
  247. std::shared_ptr<s_mob_db> db; //For quick data access (saves doing mob_db(md->mob_id) all the time) [Skotlex]
  248. char name[NAME_LENGTH];
  249. struct s_specialState {
  250. unsigned int size : 2; //Small/Big monsters.
  251. enum mob_ai ai; //Special ai for summoned monsters.
  252. unsigned int clone : 1;/* is clone? 1:0 */
  253. } special_state; //Special mob information that does not needs to be zero'ed on mob respawn.
  254. struct s_MobState {
  255. unsigned int aggressive : 1; //Signals whether the mob AI is in aggressive mode or reactive mode. [Skotlex]
  256. unsigned int steal_coin_flag : 1;
  257. unsigned int soul_change_flag : 1; // Celest
  258. unsigned int alchemist: 1;
  259. unsigned int npc_killmonster: 1; //for new killmonster behavior
  260. unsigned int rebirth: 1; // NPC_Rebirth used
  261. unsigned int boss : 1;
  262. unsigned int copy_master_mode : 1; ///< Whether the spawned monster should copy the master's mode.
  263. enum MobSkillState skillstate;
  264. unsigned char steal_flag; //number of steal tries (to prevent steal exploit on mobs with few items) [Lupus]
  265. unsigned char attacked_count; //For rude attacked.
  266. int provoke_flag; // Celest
  267. } state;
  268. struct guardian_data* guardian_data;
  269. struct s_dmglog {
  270. int id; //char id
  271. unsigned int dmg;
  272. unsigned int flag : 2; //0: Normal. 1: Homunc exp. 2: Pet exp
  273. } dmglog[DAMAGELOG_SIZE];
  274. uint32 spotted_log[DAMAGELOG_SIZE];
  275. struct spawn_data *spawn; //Spawn data.
  276. int spawn_timer; //Required for Convex Mirror
  277. struct s_mob_lootitem *lootitems;
  278. short mob_id;
  279. unsigned int tdmg; //Stores total damage given to the mob, for exp calculations. [Skotlex]
  280. int level;
  281. int target_id,attacked_id,norm_attacked_id;
  282. int areanpc_id; //Required in OnTouchNPC (to avoid multiple area touchs)
  283. int bg_id; // BattleGround System
  284. t_tick next_walktime,last_thinktime,last_linktime,last_pcneartime,dmgtick;
  285. short move_fail_count;
  286. short lootitem_count;
  287. short min_chase;
  288. unsigned char walktoxy_fail_count; //Pathfinding succeeds but the actual walking failed (e.g. Icewall lock)
  289. int deletetimer;
  290. int master_id,master_dist;
  291. int8 skill_idx; // Index of last used skill from db->skill[]
  292. t_tick skilldelay[MAX_MOBSKILL];
  293. char npc_event[EVENT_NAME_LENGTH];
  294. /**
  295. * Did this monster summon something?
  296. * Used to flag summon deletions, saves a worth amount of memory
  297. **/
  298. bool can_summon;
  299. /**
  300. * MvP Tombstone NPC ID
  301. **/
  302. int tomb_nid;
  303. e_mob_bosstype get_bosstype();
  304. };
  305. class MobAvailDatabase : public YamlDatabase {
  306. public:
  307. MobAvailDatabase() : YamlDatabase("MOB_AVAIL_DB", 1) {
  308. }
  309. void clear() { };
  310. const std::string getDefaultLocation();
  311. uint64 parseBodyNode(const YAML::Node& node);
  312. };
  313. struct s_randomsummon_entry {
  314. uint16 mob_id;
  315. uint32 rate;
  316. };
  317. struct s_randomsummon_group {
  318. uint16 random_id;
  319. uint16 default_mob_id;
  320. std::unordered_map<uint16, std::shared_ptr<s_randomsummon_entry>> list;
  321. };
  322. class MobSummonDatabase : public TypesafeYamlDatabase<uint16, s_randomsummon_group> {
  323. public:
  324. MobSummonDatabase() : TypesafeYamlDatabase("MOB_SUMMONABLE_DB", 1) {
  325. }
  326. const std::string getDefaultLocation();
  327. uint64 parseBodyNode(const YAML::Node &node);
  328. };
  329. enum e_mob_skill_target {
  330. MST_TARGET = 0,
  331. MST_RANDOM, //Random Target!
  332. MST_SELF,
  333. MST_FRIEND,
  334. MST_MASTER,
  335. MST_AROUND5,
  336. MST_AROUND6,
  337. MST_AROUND7,
  338. MST_AROUND8,
  339. MST_AROUND1,
  340. MST_AROUND2,
  341. MST_AROUND3,
  342. MST_AROUND4,
  343. MST_AROUND = MST_AROUND4,
  344. };
  345. enum e_mob_skill_condition {
  346. MSC_ALWAYS = 0x0000,
  347. MSC_MYHPLTMAXRATE,
  348. MSC_MYHPINRATE,
  349. MSC_FRIENDHPLTMAXRATE,
  350. MSC_FRIENDHPINRATE,
  351. MSC_MYSTATUSON,
  352. MSC_MYSTATUSOFF,
  353. MSC_FRIENDSTATUSON,
  354. MSC_FRIENDSTATUSOFF,
  355. MSC_ATTACKPCGT,
  356. MSC_ATTACKPCGE,
  357. MSC_SLAVELT,
  358. MSC_SLAVELE,
  359. MSC_CLOSEDATTACKED,
  360. MSC_LONGRANGEATTACKED,
  361. MSC_AFTERSKILL,
  362. MSC_SKILLUSED,
  363. MSC_CASTTARGETED,
  364. MSC_RUDEATTACKED,
  365. MSC_MASTERHPLTMAXRATE,
  366. MSC_MASTERATTACKED,
  367. MSC_ALCHEMIST,
  368. MSC_SPAWN,
  369. };
  370. // The data structures for storing delayed item drops
  371. struct item_drop {
  372. struct item item_data;
  373. unsigned short mob_id;
  374. enum bl_type src_type;
  375. struct item_drop* next;
  376. };
  377. struct item_drop_list {
  378. int16 m, x, y; // coordinates
  379. int first_charid, second_charid, third_charid; // charid's of players with higher pickup priority
  380. struct item_drop* item; // linked list of drops
  381. };
  382. uint16 mobdb_searchname(const char * const str);
  383. std::shared_ptr<s_mob_db> mobdb_search_aegisname( const char* str );
  384. int mobdb_searchname_array(const char *str, uint16 * out, int size);
  385. int mobdb_checkid(const int id);
  386. struct view_data* mob_get_viewdata(int mob_id);
  387. void mob_set_dynamic_viewdata( struct mob_data* md );
  388. void mob_free_dynamic_viewdata( struct mob_data* md );
  389. 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);
  390. int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y,
  391. const char* mobname, int mob_id, int amount, const char* event, unsigned int size, enum mob_ai ai);
  392. int mob_once_spawn_area(struct map_session_data* sd, int16 m,
  393. 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);
  394. bool mob_ksprotected (struct block_list *src, struct block_list *target);
  395. 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]
  396. int mob_spawn_bg(const char* mapname, int16 x, int16 y, const char* mobname, int mob_id, const char* event, unsigned int bg_id);
  397. int mob_guardian_guildchange(struct mob_data *md); //Change Guardian's ownership. [Skotlex]
  398. int mob_randomwalk(struct mob_data *md,t_tick tick);
  399. int mob_warpchase(struct mob_data *md, struct block_list *target);
  400. int mob_target(struct mob_data *md,struct block_list *bl,int dist);
  401. int mob_unlocktarget(struct mob_data *md, t_tick tick);
  402. struct mob_data* mob_spawn_dataset(struct spawn_data *data);
  403. int mob_spawn(struct mob_data *md);
  404. TIMER_FUNC(mob_delayspawn);
  405. int mob_setdelayspawn(struct mob_data *md);
  406. int mob_parse_dataset(struct spawn_data *data);
  407. void mob_log_damage(struct mob_data *md, struct block_list *src, int damage);
  408. void mob_damage(struct mob_data *md, struct block_list *src, int damage);
  409. int mob_dead(struct mob_data *md, struct block_list *src, int type);
  410. void mob_revive(struct mob_data *md, unsigned int hp);
  411. void mob_heal(struct mob_data *md,unsigned int heal);
  412. #define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type)
  413. #define mob_stop_attack(md) unit_stop_attack(&(md)->bl)
  414. void mob_clear_spawninfo();
  415. void do_init_mob(void);
  416. void do_final_mob(bool is_reload);
  417. TIMER_FUNC(mob_timer_delete);
  418. int mob_deleteslave(struct mob_data *md);
  419. int mob_random_class (int *value, size_t count);
  420. int mob_get_random_id(int type, enum e_random_monster_flags flag, int lv);
  421. int mob_class_change(struct mob_data *md,int mob_id);
  422. int mob_warpslave(struct block_list *bl, int range);
  423. int mob_linksearch(struct block_list *bl,va_list ap);
  424. int mobskill_use(struct mob_data *md,t_tick tick,int event);
  425. int mobskill_event(struct mob_data *md,struct block_list *src,t_tick tick, int flag);
  426. int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id);
  427. int mob_countslave(struct block_list *bl);
  428. int mob_count_sub(struct block_list *bl, va_list ap);
  429. int mob_is_clone(int mob_id);
  430. 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);
  431. int mob_clone_delete(struct mob_data *md);
  432. void mob_reload_itemmob_data(void);
  433. void mob_reload(void);
  434. void mob_add_spawn(uint16 mob_id, const struct spawn_info& new_spawn);
  435. const std::vector<spawn_info> mob_get_spawns(uint16 mob_id);
  436. bool mob_has_spawn(uint16 mob_id);
  437. // MvP Tomb System
  438. int mvptomb_setdelayspawn(struct npc_data *nd);
  439. TIMER_FUNC(mvptomb_delayspawn);
  440. void mvptomb_create(struct mob_data *md, char *killer, time_t time);
  441. void mvptomb_destroy(struct mob_data *md);
  442. void mob_setdropitem_option(struct item *itm, struct s_mob_drop *mobdrop);
  443. #define CHK_MOBSIZE(size) ((size) >= SZ_SMALL && (size) < SZ_MAX) /// Check valid Monster Size
  444. #endif /* MOB_HPP */