mob.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 4
  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 4000
  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. //Distance that slaves should keep from their master.
  25. #define MOB_SLAVEDISTANCE 2
  26. // These define the range of available IDs for clones. [Valaris]
  27. #define MOB_CLONE_START (MAX_MOB_DB-999)
  28. #define MOB_CLONE_END MAX_MOB_DB
  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_PC|BL_HOM|BL_MER)
  31. //Externals for the status effects. [Epoque]
  32. extern const int mob_manuk[8];
  33. extern const int mob_splendide[5];
  34. //Mob skill states.
  35. enum MobSkillState {
  36. MSS_ANY = -1,
  37. MSS_IDLE,
  38. MSS_WALK,
  39. MSS_LOOT,
  40. MSS_DEAD,
  41. MSS_BERSERK, //Aggressive mob attacking
  42. MSS_ANGRY, //Mob retaliating from being attacked.
  43. MSS_RUSH, //Mob following a player after being attacked.
  44. MSS_FOLLOW, //Mob following a player without being attacked.
  45. MSS_ANYTARGET,
  46. };
  47. enum MobDamageLogFlag
  48. {
  49. MDLF_NORMAL = 0,
  50. MDLF_HOMUN,
  51. MDLF_PET,
  52. };
  53. enum size {
  54. SZ_SMALL = 0,
  55. SZ_MEDIUM,
  56. SZ_BIG,
  57. };
  58. struct mob_skill {
  59. enum MobSkillState state;
  60. short skill_id,skill_lv;
  61. short permillage;
  62. int casttime,delay;
  63. short cancel;
  64. short cond1,cond2;
  65. short target;
  66. int val[5];
  67. short emotion;
  68. unsigned short msg_id;
  69. };
  70. struct mob_chat {
  71. unsigned short msg_id;
  72. unsigned long color;
  73. char msg[CHAT_SIZE_MAX];
  74. };
  75. struct spawn_info {
  76. unsigned short mapindex;
  77. unsigned short qty;
  78. };
  79. struct mob_db {
  80. char sprite[NAME_LENGTH],name[NAME_LENGTH],jname[NAME_LENGTH];
  81. unsigned int base_exp,job_exp;
  82. unsigned int mexp;
  83. short range2,range3;
  84. short race2; // celest
  85. unsigned short lv;
  86. struct { int nameid,p; } dropitem[MAX_MOB_DROP];
  87. struct { int nameid,p; } mvpitem[MAX_MVP_DROP];
  88. struct status_data status;
  89. struct view_data vd;
  90. unsigned int option;
  91. int summonper[MAX_RANDOMMONSTER];
  92. int maxskill;
  93. struct mob_skill skill[MAX_MOBSKILL];
  94. struct spawn_info spawn[10];
  95. };
  96. struct mob_data {
  97. struct block_list bl;
  98. struct unit_data ud;
  99. struct view_data *vd;
  100. struct status_data status, *base_status; //Second one is in case of leveling up mobs, or tiny/large mobs.
  101. struct status_change sc;
  102. struct mob_db *db; //For quick data access (saves doing mob_db(md->class_) all the time) [Skotlex]
  103. char name[NAME_LENGTH];
  104. struct {
  105. unsigned int size : 2; //Small/Big monsters.
  106. unsigned int ai : 2; //Special ai for summoned monsters.
  107. //0: Normal mob.
  108. //1: Standard summon, attacks mobs.
  109. //2: Alchemist Marine Sphere
  110. //3: Alchemist Summon Flora
  111. unsigned int clone : 1;/* is clone? 1:0 */
  112. } special_state; //Special mob information that does not needs to be zero'ed on mob respawn.
  113. struct {
  114. unsigned int aggressive : 1; //Signals whether the mob AI is in aggressive mode or reactive mode. [Skotlex]
  115. unsigned int steal_coin_flag : 1;
  116. unsigned int soul_change_flag : 1; // Celest
  117. unsigned int alchemist: 1;
  118. unsigned int spotted: 1;
  119. unsigned int npc_killmonster: 1; //for new killmonster behavior
  120. unsigned int rebirth: 1; // NPC_Rebirth used
  121. unsigned int boss : 1;
  122. enum MobSkillState skillstate;
  123. unsigned char steal_flag; //number of steal tries (to prevent steal exploit on mobs with few items) [Lupus]
  124. unsigned char attacked_count; //For rude attacked.
  125. int provoke_flag; // Celest
  126. } state;
  127. struct guardian_data* guardian_data;
  128. struct {
  129. int id;
  130. unsigned int dmg;
  131. unsigned int flag : 2; //0: Normal. 1: Homunc exp. 2: Pet exp
  132. } dmglog[DAMAGELOG_SIZE];
  133. struct spawn_data *spawn; //Spawn data.
  134. int spawn_timer; //Required for Convex Mirror
  135. struct item *lootitem;
  136. short class_;
  137. unsigned int tdmg; //Stores total damage given to the mob, for exp calculations. [Skotlex]
  138. int level;
  139. int target_id,attacked_id;
  140. int areanpc_id; //Required in OnTouchNPC (to avoid multiple area touchs)
  141. unsigned int bg_id; // BattleGround System
  142. unsigned int next_walktime,last_thinktime,last_linktime,last_pcneartime,dmgtick;
  143. short move_fail_count;
  144. short lootitem_count;
  145. short min_chase;
  146. int deletetimer;
  147. int master_id,master_dist;
  148. short skillidx;
  149. unsigned int skilldelay[MAX_MOBSKILL];
  150. char npc_event[EVENT_NAME_LENGTH];
  151. /**
  152. * Did this monster summon something?
  153. * Used to flag summon deletions, saves a worth amount of memory
  154. **/
  155. bool can_summon : 1;
  156. struct npc_data *tomb_npc;
  157. };
  158. enum {
  159. MST_TARGET = 0,
  160. MST_RANDOM, //Random Target!
  161. MST_SELF,
  162. MST_FRIEND,
  163. MST_MASTER,
  164. MST_AROUND5,
  165. MST_AROUND6,
  166. MST_AROUND7,
  167. MST_AROUND8,
  168. MST_AROUND1,
  169. MST_AROUND2,
  170. MST_AROUND3,
  171. MST_AROUND4,
  172. MST_AROUND = MST_AROUND4,
  173. MSC_ALWAYS = 0x0000,
  174. MSC_MYHPLTMAXRATE,
  175. MSC_MYHPINRATE,
  176. MSC_FRIENDHPLTMAXRATE,
  177. MSC_FRIENDHPINRATE,
  178. MSC_MYSTATUSON,
  179. MSC_MYSTATUSOFF,
  180. MSC_FRIENDSTATUSON,
  181. MSC_FRIENDSTATUSOFF,
  182. MSC_ATTACKPCGT,
  183. MSC_ATTACKPCGE,
  184. MSC_SLAVELT,
  185. MSC_SLAVELE,
  186. MSC_CLOSEDATTACKED,
  187. MSC_LONGRANGEATTACKED,
  188. MSC_AFTERSKILL,
  189. MSC_SKILLUSED ,
  190. MSC_CASTTARGETED,
  191. MSC_RUDEATTACKED,
  192. MSC_MASTERHPLTMAXRATE,
  193. MSC_MASTERATTACKED,
  194. MSC_ALCHEMIST,
  195. MSC_SPAWN,
  196. };
  197. // The data structures for storing delayed item drops
  198. struct item_drop {
  199. struct item item_data;
  200. struct item_drop* next;
  201. };
  202. struct item_drop_list {
  203. int m, x, y; // coordinates
  204. int first_charid, second_charid, third_charid; // charid's of players with higher pickup priority
  205. struct item_drop* item; // linked list of drops
  206. };
  207. struct mob_db* mob_db(int class_);
  208. int mobdb_searchname(const char *str);
  209. int mobdb_searchname_array(struct mob_db** data, int size, const char *str);
  210. int mobdb_checkid(const int id);
  211. struct view_data* mob_get_viewdata(int class_);
  212. struct mob_data *mob_once_spawn_sub(struct block_list *bl, int m,
  213. short x, short y, const char *mobname, int class_, const char *event);
  214. int mob_once_spawn(struct map_session_data* sd,int m,short x,short y,const char* mobname,int class_,int amount,const char* event);
  215. int mob_once_spawn_area(struct map_session_data* sd,int m,int x0,int y0,int x1,int y1,const char* mobname,int class_,int amount,const char* event);
  216. bool mob_ksprotected (struct block_list *src, struct block_list *target);
  217. int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobname, int class_, const char* event, int guardian, bool has_index); // Spawning Guardians [Valaris]
  218. int mob_spawn_bg(const char* mapname, short x, short y, const char* mobname, int class_, const char* event, unsigned int bg_id);
  219. int mob_guardian_guildchange(struct mob_data *md); //Change Guardian's ownership. [Skotlex]
  220. int mob_randomwalk(struct mob_data *md,unsigned int tick);
  221. int mob_warpchase(struct mob_data *md, struct block_list *target);
  222. int mob_target(struct mob_data *md,struct block_list *bl,int dist);
  223. int mob_unlocktarget(struct mob_data *md, unsigned int tick);
  224. struct mob_data* mob_spawn_dataset(struct spawn_data *data);
  225. int mob_spawn(struct mob_data *md);
  226. int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data);
  227. int mob_setdelayspawn(struct mob_data *md);
  228. int mob_parse_dataset(struct spawn_data *data);
  229. void mob_log_damage(struct mob_data *md, struct block_list *src, int damage);
  230. void mob_damage(struct mob_data *md, struct block_list *src, int damage);
  231. int mob_dead(struct mob_data *md, struct block_list *src, int type);
  232. void mob_revive(struct mob_data *md, unsigned int hp);
  233. void mob_heal(struct mob_data *md,unsigned int heal);
  234. #define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type)
  235. #define mob_stop_attack(md) unit_stop_attack(&(md)->bl)
  236. #define mob_is_battleground(md) ( map[(md)->bl.m].flag.battleground && ((md)->class_ == 1906 || ((md)->class_ >= 1909 && (md)->class_ <= 1915)) )
  237. void mob_clear_spawninfo();
  238. int do_init_mob(void);
  239. int do_final_mob(void);
  240. int mob_timer_delete(int tid, unsigned int tick, int id, intptr_t data);
  241. int mob_deleteslave(struct mob_data *md);
  242. int mob_random_class (int *value, size_t count);
  243. int mob_get_random_id(int type, int flag, int lv);
  244. int mob_class_change(struct mob_data *md,int class_);
  245. int mob_warpslave(struct block_list *bl, int range);
  246. int mob_linksearch(struct block_list *bl,va_list ap);
  247. int mobskill_use(struct mob_data *md,unsigned int tick,int event);
  248. int mobskill_event(struct mob_data *md,struct block_list *src,unsigned int tick, int flag);
  249. int mobskill_castend_id( int tid, unsigned int tick, int id,int data );
  250. int mobskill_castend_pos( int tid, unsigned int tick, int id,int data );
  251. int mob_summonslave(struct mob_data *md2,int *value,int amount,int skill_id);
  252. int mob_countslave(struct block_list *bl);
  253. int mob_is_clone(int class_);
  254. int mob_clone_spawn(struct map_session_data *sd, int m, int x, int y, const char *event, int master_id, int mode, int flag, unsigned int duration);
  255. int mob_clone_delete(struct mob_data *md);
  256. void mob_reload(void);
  257. // MvP Tomb System
  258. void mvptomb_create(struct mob_data *md, char *killer, time_t time);
  259. void mvptomb_destroy(struct mob_data *md);
  260. #endif /* _MOB_H_ */