1 | // Copyright (c) Athena Dev Teams - Licensed under GNU GPL |
---|
2 | // For more information, see LICENCE in the main folder |
---|
3 | |
---|
4 | #ifndef _MOB_H_ |
---|
5 | #define _MOB_H_ |
---|
6 | |
---|
7 | #include "../common/mmo.h" // struct item |
---|
8 | #include "guild.h" // struct guardian_data |
---|
9 | #include "map.h" // struct status_data, struct view_data, struct mob_skill |
---|
10 | #include "status.h" // struct status data, struct status_change |
---|
11 | #include "unit.h" // unit_stop_walking(), unit_stop_attack() |
---|
12 | |
---|
13 | |
---|
14 | #define MAX_RANDOMMONSTER 5 |
---|
15 | #define MAX_MOB_RACE_DB 6 |
---|
16 | |
---|
17 | // Change this to increase the table size in your mob_db to accomodate a larger mob database. |
---|
18 | // Be sure to note that IDs 4001 to 4048 are reserved for advanced/baby/expanded classes. |
---|
19 | // Notice that the last 1000 entries are used for player clones, so always set this to desired value +1000 |
---|
20 | #define MAX_MOB_DB 7000 |
---|
21 | |
---|
22 | //The number of drops all mobs have and the max drop-slot that the steal skill will attempt to steal from. |
---|
23 | #define MAX_MOB_DROP 10 |
---|
24 | #define MAX_STEAL_DROP 7 |
---|
25 | |
---|
26 | //Min time between AI executions |
---|
27 | #define MIN_MOBTHINKTIME 100 |
---|
28 | //Min time before mobs do a check to call nearby friends for help (or for slaves to support their master) |
---|
29 | #define MIN_MOBLINKTIME 1000 |
---|
30 | |
---|
31 | //Distance that slaves should keep from their master. |
---|
32 | #define MOB_SLAVEDISTANCE 2 |
---|
33 | |
---|
34 | // These define the range of available IDs for clones. [Valaris] |
---|
35 | #define MOB_CLONE_START (MAX_MOB_DB-999) |
---|
36 | #define MOB_CLONE_END MAX_MOB_DB |
---|
37 | |
---|
38 | // Scripted Mob AI Constants |
---|
39 | #define CALLBACK_NPCCLICK 0x100 |
---|
40 | #define CALLBACK_ATTACK 0x80 |
---|
41 | #define CALLBACK_DETECT 0x40 |
---|
42 | #define CALLBACK_DEAD 0x20 |
---|
43 | #define CALLBACK_ASSIST 0x10 |
---|
44 | #define CALLBACK_KILL 0x08 |
---|
45 | #define CALLBACK_UNLOCK 0x04 |
---|
46 | #define CALLBACK_WALKACK 0x02 |
---|
47 | #define CALLBACK_WARPACK 0x01 |
---|
48 | |
---|
49 | int mob_script_callback(struct mob_data *md, struct block_list *target, short action_type); |
---|
50 | |
---|
51 | struct mob_skill { |
---|
52 | short state; |
---|
53 | short skill_id,skill_lv; |
---|
54 | short permillage; |
---|
55 | int casttime,delay; |
---|
56 | short cancel; |
---|
57 | short cond1,cond2; |
---|
58 | short target; |
---|
59 | int val[5]; |
---|
60 | short emotion; |
---|
61 | }; |
---|
62 | |
---|
63 | struct spawn_info { |
---|
64 | unsigned short mapindex; |
---|
65 | unsigned short qty; |
---|
66 | }; |
---|
67 | |
---|
68 | struct mob_db { |
---|
69 | char sprite[NAME_LENGTH],name[NAME_LENGTH],jname[NAME_LENGTH]; |
---|
70 | unsigned int base_exp,job_exp; |
---|
71 | unsigned int mexp,mexpper; |
---|
72 | short range2,range3; |
---|
73 | short race2; // celest |
---|
74 | unsigned short lv; |
---|
75 | struct { int nameid,p; } dropitem[MAX_MOB_DROP]; |
---|
76 | struct { int nameid,p; } mvpitem[3]; |
---|
77 | struct status_data status; |
---|
78 | struct view_data vd; |
---|
79 | short option; |
---|
80 | int summonper[MAX_RANDOMMONSTER]; |
---|
81 | int maxskill; |
---|
82 | struct mob_skill skill[MAX_MOBSKILL]; |
---|
83 | struct spawn_info spawn[10]; |
---|
84 | }; |
---|
85 | |
---|
86 | struct mob_data { |
---|
87 | struct block_list bl; |
---|
88 | struct unit_data ud; |
---|
89 | struct view_data *vd; |
---|
90 | struct status_data status, *base_status; //Second one is in case of leveling up mobs, or tiny/large mobs. |
---|
91 | struct status_change sc; |
---|
92 | struct mob_db *db; //For quick data access (saves doing mob_db(md->class_) all the time) [Skotlex] |
---|
93 | struct barricade_data *barricade; |
---|
94 | char name[NAME_LENGTH]; |
---|
95 | struct { |
---|
96 | unsigned size : 2; //Small/Big monsters. |
---|
97 | unsigned ai : 2; //Special ai for summoned monsters. |
---|
98 | //0: Normal mob. |
---|
99 | //1: Standard summon, attacks mobs. |
---|
100 | //2: Alchemist Marine Sphere |
---|
101 | //3: Alchemist Summon Flora |
---|
102 | } special_state; //Special mob information that does not needs to be zero'ed on mob respawn. |
---|
103 | struct { |
---|
104 | unsigned skillstate : 8; |
---|
105 | unsigned aggressive : 1; //Signals whether the mob AI is in aggressive mode or reactive mode. [Skotlex] |
---|
106 | unsigned char steal_flag; //number of steal tries (to prevent steal exploit on mobs with few items) [Lupus] |
---|
107 | unsigned steal_coin_flag : 1; |
---|
108 | unsigned soul_change_flag : 1; // Celest |
---|
109 | unsigned alchemist: 1; |
---|
110 | unsigned no_random_walk: 1; |
---|
111 | unsigned killer: 1; |
---|
112 | unsigned spotted: 1; |
---|
113 | unsigned char attacked_count; //For rude attacked. |
---|
114 | int provoke_flag; // Celest |
---|
115 | } state; |
---|
116 | struct guardian_data* guardian_data; |
---|
117 | struct { |
---|
118 | int id; |
---|
119 | unsigned int dmg; |
---|
120 | unsigned flag : 1; //0: Normal. 1: Homunc exp |
---|
121 | } dmglog[DAMAGELOG_SIZE]; |
---|
122 | struct spawn_data *spawn; //Spawn data. |
---|
123 | struct item *lootitem; |
---|
124 | short class_; |
---|
125 | unsigned int tdmg; //Stores total damage given to the mob, for exp calculations. [Skotlex] |
---|
126 | int level; |
---|
127 | int target_id,attacked_id; |
---|
128 | int areanpc_id; //Required in OnTouchNPC (to avoid multiple area touchs) |
---|
129 | |
---|
130 | unsigned int next_walktime,last_thinktime,last_linktime,last_pcneartime; |
---|
131 | short move_fail_count; |
---|
132 | short lootitem_count; |
---|
133 | short min_chase; |
---|
134 | |
---|
135 | int deletetimer; |
---|
136 | int master_id,master_dist; |
---|
137 | |
---|
138 | struct npc_data *nd; |
---|
139 | unsigned short callback_flag; |
---|
140 | |
---|
141 | short skillidx; |
---|
142 | unsigned int skilldelay[MAX_MOBSKILL]; |
---|
143 | char npc_event[50]; |
---|
144 | int npc_killmonster; //for new killmonster behavior |
---|
145 | }; |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | enum { |
---|
150 | MST_TARGET = 0, |
---|
151 | MST_RANDOM, //Random Target! |
---|
152 | MST_SELF, |
---|
153 | MST_FRIEND, |
---|
154 | MST_MASTER, |
---|
155 | MST_AROUND5, |
---|
156 | MST_AROUND6, |
---|
157 | MST_AROUND7, |
---|
158 | MST_AROUND8, |
---|
159 | MST_AROUND1, |
---|
160 | MST_AROUND2, |
---|
161 | MST_AROUND3, |
---|
162 | MST_AROUND4, |
---|
163 | MST_AROUND = MST_AROUND4, |
---|
164 | |
---|
165 | MSC_ALWAYS = 0x0000, |
---|
166 | MSC_MYHPLTMAXRATE, |
---|
167 | MSC_MYHPINRATE, |
---|
168 | MSC_FRIENDHPLTMAXRATE, |
---|
169 | MSC_FRIENDHPINRATE, |
---|
170 | MSC_MYSTATUSON, |
---|
171 | MSC_MYSTATUSOFF, |
---|
172 | MSC_FRIENDSTATUSON, |
---|
173 | MSC_FRIENDSTATUSOFF, |
---|
174 | MSC_ATTACKPCGT, |
---|
175 | MSC_ATTACKPCGE, |
---|
176 | MSC_SLAVELT, |
---|
177 | MSC_SLAVELE, |
---|
178 | MSC_CLOSEDATTACKED, |
---|
179 | MSC_LONGRANGEATTACKED, |
---|
180 | MSC_AFTERSKILL, |
---|
181 | MSC_SKILLUSED , |
---|
182 | MSC_CASTTARGETED, |
---|
183 | MSC_RUDEATTACKED, |
---|
184 | MSC_MASTERHPLTMAXRATE, |
---|
185 | MSC_MASTERATTACKED, |
---|
186 | MSC_ALCHEMIST, |
---|
187 | MSC_SPAWN, |
---|
188 | }; |
---|
189 | |
---|
190 | //Mob skill states. |
---|
191 | enum { |
---|
192 | MSS_ANY = -1, |
---|
193 | MSS_IDLE, |
---|
194 | MSS_WALK, |
---|
195 | MSS_LOOT, |
---|
196 | MSS_DEAD, |
---|
197 | MSS_BERSERK, //Aggressive mob attacking |
---|
198 | MSS_ANGRY, //Mob retaliating from being attacked. |
---|
199 | MSS_RUSH, //Mob following a player after being attacked. |
---|
200 | MSS_FOLLOW, //Mob following a player without being attacked. |
---|
201 | MSS_ANYTARGET, |
---|
202 | }; |
---|
203 | |
---|
204 | |
---|
205 | // The data structures for storing delayed item drops |
---|
206 | struct item_drop { |
---|
207 | struct item item_data; |
---|
208 | struct item_drop* next; |
---|
209 | }; |
---|
210 | struct item_drop_list { |
---|
211 | int m, x, y; // coordinates |
---|
212 | int first_charid, second_charid, third_charid; // charid's of players with higher pickup priority |
---|
213 | struct item_drop* item; // linked list of drops |
---|
214 | }; |
---|
215 | |
---|
216 | struct mob_db* mob_db(int class_); |
---|
217 | int mobdb_searchname(const char *str); |
---|
218 | int mobdb_searchname_array(struct mob_db** data, int size, const char *str); |
---|
219 | int mobdb_checkid(const int id); |
---|
220 | struct view_data* mob_get_viewdata(int class_); |
---|
221 | struct mob_data *mob_once_spawn_sub(struct block_list *bl, int m, |
---|
222 | short x, short y, const char *mobname, int class_, const char *event); |
---|
223 | 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); |
---|
224 | 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); |
---|
225 | |
---|
226 | bool mob_ksprotected (struct block_list *src, struct block_list *target); |
---|
227 | short mob_barricade_build(short m, short x, short y, const char* mobname, short count, short dir, bool killable, bool walkable, bool shootable, bool odd, const char* event); |
---|
228 | void mob_barricade_destroy(short m, const char *event); |
---|
229 | void mob_barricade_get(struct map_session_data *sd); |
---|
230 | void mod_barricade_clearall(void); |
---|
231 | |
---|
232 | 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] |
---|
233 | int mob_guardian_guildchange(struct block_list *bl,va_list ap); //Change Guardian's ownership. [Skotlex] |
---|
234 | |
---|
235 | int mob_randomwalk(struct mob_data *md,unsigned int tick); |
---|
236 | int mob_warpchase(struct mob_data *md, struct block_list *target); |
---|
237 | int mob_target(struct mob_data *md,struct block_list *bl,int dist); |
---|
238 | int mob_unlocktarget(struct mob_data *md, unsigned int tick); |
---|
239 | struct mob_data* mob_spawn_dataset(struct spawn_data *data); |
---|
240 | int mob_spawn(struct mob_data *md); |
---|
241 | int mob_setdelayspawn(struct mob_data *md); |
---|
242 | int mob_parse_dataset(struct spawn_data *data); |
---|
243 | void mob_log_damage(struct mob_data *md, struct block_list *src, int damage); |
---|
244 | void mob_damage(struct mob_data *md, struct block_list *src, int damage); |
---|
245 | int mob_dead(struct mob_data *md, struct block_list *src, int type); |
---|
246 | void mob_revive(struct mob_data *md, unsigned int hp); |
---|
247 | void mob_heal(struct mob_data *md,unsigned int heal); |
---|
248 | |
---|
249 | #define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type) |
---|
250 | #define mob_stop_attack(md) unit_stop_attack(&(md)->bl) |
---|
251 | |
---|
252 | void mob_clear_spawninfo(); |
---|
253 | int do_init_mob(void); |
---|
254 | int do_final_mob(void); |
---|
255 | |
---|
256 | int mob_timer_delete(int tid, unsigned int tick, int id, intptr data); |
---|
257 | int mob_deleteslave(struct mob_data *md); |
---|
258 | |
---|
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 class_); |
---|
262 | int mob_warpslave(struct block_list *bl, int range); |
---|
263 | int mob_linksearch(struct block_list *bl,va_list ap); |
---|
264 | |
---|
265 | int mobskill_use(struct mob_data *md,unsigned int tick,int event); |
---|
266 | int mobskill_event(struct mob_data *md,struct block_list *src,unsigned int tick, int flag); |
---|
267 | int mobskill_castend_id( int tid, unsigned int tick, int id,int data ); |
---|
268 | int mobskill_castend_pos( int tid, unsigned int tick, int id,int data ); |
---|
269 | int mob_summonslave(struct mob_data *md2,int *value,int amount,int skill_id); |
---|
270 | int mob_countslave(struct block_list *bl); |
---|
271 | int mob_convertslave(struct mob_data *md); |
---|
272 | int mob_countslave_class(struct block_list* bl, int count, short* classes); // By FlavioJS [Brain] |
---|
273 | |
---|
274 | |
---|
275 | int mob_is_clone(int class_); |
---|
276 | |
---|
277 | 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); |
---|
278 | int mob_clone_delete(int class_); |
---|
279 | |
---|
280 | void mob_reload(void); |
---|
281 | |
---|
282 | #endif /* _MOB_H_ */ |
---|