mob.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. #define MAX_RANDOMMONSTER 5
  12. // Change this to increase the table size in your mob_db to accomodate a larger mob database.
  13. // Be sure to note that IDs 4001 to 4048 are reserved for advanced/baby/expanded classes.
  14. // Notice that the last 1000 entries are used for player clones, so always set this to desired value +1000
  15. #define MAX_MOB_DB 5000
  16. //The number of drops all mobs have and the max drop-slot that the steal skill will attempt to steal from.
  17. #define MAX_MOB_DROP 10
  18. #define MAX_MVP_DROP 3
  19. #define MAX_STEAL_DROP 7
  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. //Externals for the status effects. [Epoque]
  34. extern const int mob_manuk[8];
  35. extern const int mob_splendide[5];
  36. ///Mob skill states.
  37. enum MobSkillState {
  38. MSS_ANY = -1,
  39. MSS_IDLE,
  40. MSS_WALK,
  41. MSS_LOOT,
  42. MSS_DEAD,
  43. MSS_BERSERK, //Aggressive mob attacking
  44. MSS_ANGRY, //Mob retaliating from being attacked.
  45. MSS_RUSH, //Mob following a player after being attacked.
  46. MSS_FOLLOW, //Mob following a player without being attacked.
  47. MSS_ANYTARGET,
  48. };
  49. enum MobDamageLogFlag
  50. {
  51. MDLF_NORMAL = 0,
  52. MDLF_HOMUN,
  53. MDLF_PET,
  54. };
  55. enum size {
  56. SZ_SMALL = 0,
  57. SZ_MEDIUM,
  58. SZ_BIG,
  59. SZ_ALL,
  60. SZ_MAX
  61. };
  62. struct mob_skill {
  63. enum MobSkillState state;
  64. uint16 skill_id,skill_lv;
  65. short permillage;
  66. int casttime,delay;
  67. short cancel;
  68. short cond1,cond2;
  69. short target;
  70. int val[5];
  71. short emotion;
  72. unsigned short msg_id;
  73. };
  74. struct mob_chat {
  75. unsigned short msg_id;
  76. unsigned long color;
  77. char msg[CHAT_SIZE_MAX];
  78. };
  79. struct spawn_info {
  80. unsigned short mapindex;
  81. unsigned short qty;
  82. };
  83. struct mob_db {
  84. char sprite[NAME_LENGTH],name[NAME_LENGTH],jname[NAME_LENGTH];
  85. unsigned int base_exp,job_exp;
  86. unsigned int mexp;
  87. short range2,range3;
  88. short race2; // celest
  89. unsigned short lv;
  90. struct {
  91. unsigned short nameid;
  92. int p;
  93. } dropitem[MAX_MOB_DROP];
  94. struct {
  95. unsigned short nameid;
  96. int p;
  97. } mvpitem[MAX_MVP_DROP];
  98. struct status_data status;
  99. struct view_data vd;
  100. unsigned int option;
  101. int summonper[MAX_RANDOMMONSTER];
  102. int maxskill;
  103. struct mob_skill skill[MAX_MOBSKILL];
  104. struct spawn_info spawn[10];
  105. };
  106. struct mob_data {
  107. struct block_list bl;
  108. struct unit_data ud;
  109. struct view_data *vd;
  110. struct status_data status, *base_status; //Second one is in case of leveling up mobs, or tiny/large mobs.
  111. struct status_change sc;
  112. struct mob_db *db; //For quick data access (saves doing mob_db(md->mob_id) all the time) [Skotlex]
  113. char name[NAME_LENGTH];
  114. struct {
  115. unsigned int size : 2; //Small/Big monsters.
  116. enum mob_ai ai; //Special ai for summoned monsters.
  117. unsigned int clone : 1;/* is clone? 1:0 */
  118. } special_state; //Special mob information that does not needs to be zero'ed on mob respawn.
  119. struct {
  120. unsigned int aggressive : 1; //Signals whether the mob AI is in aggressive mode or reactive mode. [Skotlex]
  121. unsigned int steal_coin_flag : 1;
  122. unsigned int soul_change_flag : 1; // Celest
  123. unsigned int alchemist: 1;
  124. unsigned int spotted: 1;
  125. unsigned int npc_killmonster: 1; //for new killmonster behavior
  126. unsigned int rebirth: 1; // NPC_Rebirth used
  127. unsigned int boss : 1;
  128. enum MobSkillState skillstate;
  129. unsigned char steal_flag; //number of steal tries (to prevent steal exploit on mobs with few items) [Lupus]
  130. unsigned char attacked_count; //For rude attacked.
  131. int provoke_flag; // Celest
  132. } state;
  133. struct guardian_data* guardian_data;
  134. struct s_dmglog {
  135. int id; //char id
  136. unsigned int dmg;
  137. unsigned int flag : 2; //0: Normal. 1: Homunc exp. 2: Pet exp
  138. } dmglog[DAMAGELOG_SIZE];
  139. struct spawn_data *spawn; //Spawn data.
  140. int spawn_timer; //Required for Convex Mirror
  141. struct item *lootitem;
  142. short mob_id;
  143. unsigned int tdmg; //Stores total damage given to the mob, for exp calculations. [Skotlex]
  144. int level;
  145. int target_id,attacked_id;
  146. int areanpc_id; //Required in OnTouchNPC (to avoid multiple area touchs)
  147. unsigned int bg_id; // BattleGround System
  148. unsigned int next_walktime,last_thinktime,last_linktime,last_pcneartime,dmgtick;
  149. short move_fail_count;
  150. short lootitem_count;
  151. short min_chase;
  152. unsigned char walktoxy_fail_count; //Pathfinding succeeds but the actual walking failed (e.g. Icewall lock)
  153. int deletetimer;
  154. int master_id,master_dist;
  155. int8 skill_idx;// key of array
  156. unsigned int skilldelay[MAX_MOBSKILL];
  157. char npc_event[EVENT_NAME_LENGTH];
  158. /**
  159. * Did this monster summon something?
  160. * Used to flag summon deletions, saves a worth amount of memory
  161. **/
  162. bool can_summon;
  163. /**
  164. * MvP Tombstone NPC ID
  165. **/
  166. int tomb_nid;
  167. };
  168. enum {
  169. MST_TARGET = 0,
  170. MST_RANDOM, //Random Target!
  171. MST_SELF,
  172. MST_FRIEND,
  173. MST_MASTER,
  174. MST_AROUND5,
  175. MST_AROUND6,
  176. MST_AROUND7,
  177. MST_AROUND8,
  178. MST_AROUND1,
  179. MST_AROUND2,
  180. MST_AROUND3,
  181. MST_AROUND4,
  182. MST_AROUND = MST_AROUND4,
  183. MSC_ALWAYS = 0x0000,
  184. MSC_MYHPLTMAXRATE,
  185. MSC_MYHPINRATE,
  186. MSC_FRIENDHPLTMAXRATE,
  187. MSC_FRIENDHPINRATE,
  188. MSC_MYSTATUSON,
  189. MSC_MYSTATUSOFF,
  190. MSC_FRIENDSTATUSON,
  191. MSC_FRIENDSTATUSOFF,
  192. MSC_ATTACKPCGT,
  193. MSC_ATTACKPCGE,
  194. MSC_SLAVELT,
  195. MSC_SLAVELE,
  196. MSC_CLOSEDATTACKED,
  197. MSC_LONGRANGEATTACKED,
  198. MSC_AFTERSKILL,
  199. MSC_SKILLUSED,
  200. MSC_CASTTARGETED,
  201. MSC_RUDEATTACKED,
  202. MSC_MASTERHPLTMAXRATE,
  203. MSC_MASTERATTACKED,
  204. MSC_ALCHEMIST,
  205. MSC_SPAWN,
  206. };
  207. // The data structures for storing delayed item drops
  208. struct item_drop {
  209. struct item item_data;
  210. struct item_drop* next;
  211. };
  212. struct item_drop_list {
  213. int16 m, x, y; // coordinates
  214. int first_charid, second_charid, third_charid; // charid's of players with higher pickup priority
  215. struct item_drop* item; // linked list of drops
  216. };
  217. struct mob_db* mob_db(int mob_id);
  218. int mobdb_searchname(const char *str);
  219. int mobdb_searchname_array(struct mob_db** data, int size, const char *str);
  220. int mobdb_checkid(const int id);
  221. struct view_data* mob_get_viewdata(int mob_id);
  222. struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m,
  223. short x, short y, const char *mobname, int mob_id, const char *event, unsigned int size, unsigned int ai);
  224. int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y,
  225. const char* mobname, int mob_id, int amount, const char* event, unsigned int size, unsigned int ai);
  226. int mob_once_spawn_area(struct map_session_data* sd, int16 m,
  227. 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);
  228. bool mob_ksprotected (struct block_list *src, struct block_list *target);
  229. 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]
  230. int mob_spawn_bg(const char* mapname, int16 x, int16 y, const char* mobname, int mob_id, const char* event, unsigned int bg_id);
  231. int mob_guardian_guildchange(struct mob_data *md); //Change Guardian's ownership. [Skotlex]
  232. int mob_randomwalk(struct mob_data *md,unsigned int tick);
  233. int mob_warpchase(struct mob_data *md, struct block_list *target);
  234. int mob_target(struct mob_data *md,struct block_list *bl,int dist);
  235. int mob_unlocktarget(struct mob_data *md, unsigned int tick);
  236. struct mob_data* mob_spawn_dataset(struct spawn_data *data);
  237. int mob_spawn(struct mob_data *md);
  238. int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data);
  239. int mob_setdelayspawn(struct mob_data *md);
  240. int mob_parse_dataset(struct spawn_data *data);
  241. void mob_log_damage(struct mob_data *md, struct block_list *src, int damage);
  242. void mob_damage(struct mob_data *md, struct block_list *src, int damage);
  243. int mob_dead(struct mob_data *md, struct block_list *src, int type);
  244. void mob_revive(struct mob_data *md, unsigned int hp);
  245. void mob_heal(struct mob_data *md,unsigned int heal);
  246. #define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type)
  247. #define mob_stop_attack(md) unit_stop_attack(&(md)->bl)
  248. #define mob_is_battleground(md) ( map[(md)->bl.m].flag.battleground && ((md)->mob_id == MOBID_BARRICADE2 || ((md)->mob_id >= MOBID_FOOD_STOR && (md)->mob_id <= MOBID_PINK_CRYST)) )
  249. #define mob_is_gvg(md) (map[(md)->bl.m].flag.gvg_castle && ( (md)->mob_id == MOBID_EMPERIUM || (md)->mob_id == MOBID_BARRICADE1 || (md)->mob_id == MOBID_GUARIDAN_STONE1 || (md)->mob_id == MOBID_GUARIDAN_STONE2) )
  250. #define mob_is_treasure(md) (((md)->mob_id >= MOBID_TREAS01 && (md)->mob_id <= MOBID_TREAS40) || ((md)->mob_id >= MOBID_TREAS41 && (md)->mob_id <= MOBID_TREAS49))
  251. #define mob_is_guardian(mob_id) ((mob_id >= MOBID_A_GUARDIAN && mob_id <= MOBID_S_GUARDIAN) || mob_id == MOBID_S_GUARDIAN_ || mob_id == MOBID_A_GUARDIAN_)
  252. #define mob_is_goblin(md, mid) (((md)->mob_id >= MOBID_GOBLIN_1 && (md)->mob_id <= MOBID_GOBLIN_5) && (mid >= MOBID_GOBLIN_1 && mid <= MOBID_GOBLIN_5))
  253. #define mob_is_samename(md, mid) (strcmp(mob_db((md)->mob_id)->jname, mob_db(mid)->jname) == 0)
  254. void mob_clear_spawninfo();
  255. void do_init_mob(void);
  256. void do_final_mob(void);
  257. int mob_timer_delete(int tid, unsigned int tick, int id, intptr_t data);
  258. int mob_deleteslave(struct mob_data *md);
  259. int mob_random_class (int *value, size_t count);
  260. int mob_get_random_id(int type, int flag, int lv);
  261. int mob_class_change(struct mob_data *md,int mob_id);
  262. int mob_warpslave(struct block_list *bl, int range);
  263. int mob_linksearch(struct block_list *bl,va_list ap);
  264. int mobskill_use(struct mob_data *md,unsigned int tick,int event);
  265. int mobskill_event(struct mob_data *md,struct block_list *src,unsigned int tick, int flag);
  266. int mobskill_castend_id( int tid, unsigned int tick, int id,int data );
  267. int mobskill_castend_pos( int tid, unsigned int tick, int id,int data );
  268. int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id);
  269. int mob_countslave(struct block_list *bl);
  270. int mob_count_sub(struct block_list *bl, va_list ap);
  271. int mob_is_clone(int mob_id);
  272. int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration);
  273. int mob_clone_delete(struct mob_data *md);
  274. void mob_reload(void);
  275. // MvP Tomb System
  276. void mvptomb_create(struct mob_data *md, char *killer, time_t time);
  277. void mvptomb_destroy(struct mob_data *md);
  278. #define CHK_MOBSIZE(size) ((size) >= SZ_SMALL && (size) < SZ_MAX) /// Check valid Monster Size
  279. #endif /* _MOB_H_ */