mob.h 11 KB

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