Spawn.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __EQ2_SPAWN__
  17. #define __EQ2_SPAWN__
  18. #include "../common/types.h"
  19. #include "../common/EQPacket.h"
  20. #include "../common/EQ2_Common_Structs.h"
  21. #include "../common/MiscFunctions.h"
  22. #include "../common/opcodemgr.h"
  23. #include "../common/timer.h"
  24. #include "Commands/Commands.h"
  25. #include "Zone/position.h"
  26. #include "SpawnLists.h"
  27. #include <vector>
  28. #include "../common/ConfigReader.h"
  29. #include "Items/Items.h"
  30. #include "Zone/map.h"
  31. #include "../common/Mutex.h"
  32. #include "MutexList.h"
  33. #include <deque>
  34. #include <memory> // needed for LS to compile properly on linux
  35. #define DAMAGE_PACKET_TYPE_SIPHON_SPELL 0x41
  36. #define DAMAGE_PACKET_TYPE_SIPHON_SPELL2 0x49
  37. #define DAMAGE_PACKET_TYPE_MULTIPLE_DAMAGE 0x80
  38. #define DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE 0xC0
  39. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE 0xC1
  40. #define DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG 0xC4
  41. #define DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG 0xC5
  42. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE2 0xC8
  43. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE3 0xC9
  44. #define DAMAGE_PACKET_TYPE_RANGE_DAMAGE 0xE2
  45. #define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG 0xE3
  46. #define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG2 0xEA
  47. #define DAMAGE_PACKET_RESULT_NO_DAMAGE 0
  48. #define DAMAGE_PACKET_RESULT_SUCCESSFUL 1
  49. #define DAMAGE_PACKET_RESULT_MISS 4
  50. #define DAMAGE_PACKET_RESULT_DODGE 8
  51. #define DAMAGE_PACKET_RESULT_PARRY 12
  52. #define DAMAGE_PACKET_RESULT_RIPOSTE 16
  53. #define DAMAGE_PACKET_RESULT_BLOCK 20
  54. #define DAMAGE_PACKET_RESULT_DEATH_BLOW 24
  55. #define DAMAGE_PACKET_RESULT_INVULNERABLE 28
  56. #define DAMAGE_PACKET_RESULT_RESIST 36
  57. #define DAMAGE_PACKET_RESULT_REFLECT 40
  58. #define DAMAGE_PACKET_RESULT_IMMUNE 44
  59. #define DAMAGE_PACKET_RESULT_DEFLECT 48
  60. #define DAMAGE_PACKET_RESULT_COUNTER 52
  61. #define DAMAGE_PACKET_RESULT_COUNTER_STRIKE 60
  62. #define DAMAGE_PACKET_RESULT_BASH 64
  63. #define DAMAGE_PACKET_DAMAGE_TYPE_SLASH 0
  64. #define DAMAGE_PACKET_DAMAGE_TYPE_CRUSH 1
  65. #define DAMAGE_PACKET_DAMAGE_TYPE_PIERCE 2
  66. #define DAMAGE_PACKET_DAMAGE_TYPE_HEAT 3
  67. #define DAMAGE_PACKET_DAMAGE_TYPE_COLD 4
  68. #define DAMAGE_PACKET_DAMAGE_TYPE_MAGIC 5
  69. #define DAMAGE_PACKET_DAMAGE_TYPE_MENTAL 6
  70. #define DAMAGE_PACKET_DAMAGE_TYPE_DIVINE 7
  71. #define DAMAGE_PACKET_DAMAGE_TYPE_DISEASE 8
  72. #define DAMAGE_PACKET_DAMAGE_TYPE_POISON 9
  73. #define DAMAGE_PACKET_DAMAGE_TYPE_DROWN 10
  74. #define DAMAGE_PACKET_DAMAGE_TYPE_FALLING 11
  75. #define DAMAGE_PACKET_DAMAGE_TYPE_PAIN 12
  76. #define HEAL_PACKET_TYPE_SIMPLE_HEAL 0
  77. #define HEAL_PACKET_TYPE_CRIT_HEAL 1
  78. #define HEAL_PACKET_TYPE_ABSORB 2
  79. #define HEAL_PACKET_TYPE_REGEN_ABSORB 4
  80. #define HEAL_PACKET_TYPE_SIMPLE_MANA 8
  81. #define HEAL_PACKET_TYPE_CRIT_MANA 9
  82. #define HEAL_PACKET_TYPE_SAVAGERY 16
  83. #define HEAL_PACKET_TYPE_CRIT_SAVAGERY 17
  84. #define HEAL_PACKET_TYPE_REPAIR 64
  85. #define HEAL_PACKET_TYPE_CRIT_REPAIR 65
  86. #define ARROW_COLOR_GRAY 0 // 3
  87. #define ARROW_COLOR_GREEN 1 // 1
  88. #define ARROW_COLOR_BLUE 2
  89. #define ARROW_COLOR_WHITE 3 // 3
  90. #define ARROW_COLOR_YELLOW 4 // 4
  91. #define ARROW_COLOR_ORANGE 5 // 5
  92. #define ARROW_COLOR_RED 6
  93. #define ACTIVITY_STATUS_ROLEPLAYING 1
  94. #define ACTIVITY_STATUS_ANONYMOUS 2
  95. #define ACTIVITY_STATUS_LINKDEAD 4
  96. #define ACTIVITY_STATUS_CAMPING 8
  97. #define ACTIVITY_STATUS_LFG 16
  98. #define ACTIVITY_STATUS_LFW 32
  99. #define ACTIVITY_STATUS_SOLID 64 //used by zone objects to remain solid
  100. #define ACTIVITY_STATUS_IMMUNITY_GAINED 8192
  101. #define ACTIVITY_STATUS_IMMUNITY_REMAINING 16384
  102. // WE ARE UNSURE OF THESE OLD CLIENT VALUES USED AS TEMP PLACEHOLDERS FOR NEWER CLIENTS
  103. #define ACTIVITY_STATUS_AFK 32768 // whats the real one?
  104. #define ACTIVITY_STATUS_MERCENARY_1188 1<<2
  105. #define ACTIVITY_STATUS_STATICOBJECT_1188 1<<3
  106. #define ACTIVITY_STATUS_MERCHANT_1188 1<<4
  107. #define ACTIVITY_STATUS_HIDEICON_1188 1<<9
  108. #define ACTIVITY_STATUS_INTERACTABLE_1188 1<<10
  109. #define ACTIVITY_STATUS_NOTARGET_1188 1<<11
  110. #define ACTIVITY_STATUS_ISTRANSPORT_1188 1<<12
  111. #define ACTIVITY_STATUS_SHOWHOUSEICON_1188 1<<13
  112. #define ACTIVITY_STATUS_LOOTABLE_1188 1<<14
  113. #define ACTIVITY_STATUS_INCOMBAT_1188 1<<15
  114. #define ACTIVITY_STATUS_AFK_1188 1<<16
  115. #define ACTIVITY_STATUS_ROLEPLAYING_1188 1<<17
  116. #define ACTIVITY_STATUS_ANONYMOUS_1188 1<<18
  117. #define ACTIVITY_STATUS_LINKDEAD_1188 1<<19
  118. #define ACTIVITY_STATUS_CAMPING_1188 1<<20
  119. #define ACTIVITY_STATUS_LFG_1188 1<<21
  120. #define ACTIVITY_STATUS_LFW_1188 1<<22
  121. #define ACTIVITY_STATUS_SOLID_1188 1<<23 //used by zone objects to remain solid
  122. #define ACTIVITY_STATUS_MENTORING_1188 1<<28
  123. #define ACTIVITY_STATUS_IMMUNITY_GAINED_1188 1<<30
  124. #define ACTIVITY_STATUS_IMMUNITY_REMAINING_1188 1<<31
  125. #define POS_STATE_KNEELING 64
  126. #define POS_STATE_SOLID 128 //used by most mobs to remaind solid (cant walk through them)
  127. #define POS_STATE_NOTARGET_CURSOR 256 //cant target and no cursor is displayed
  128. #define POS_STATE_CROUCHING 512
  129. #define MERCHANT_TYPE_NO_BUY 1
  130. #define MERCHANT_TYPE_NO_BUY_BACK 2
  131. #define MERCHANT_TYPE_SPELLS 4
  132. #define MERCHANT_TYPE_CRAFTING 8
  133. #define MERCHANT_TYPE_REPAIR 16
  134. #define MERCHANT_TYPE_LOTTO 32
  135. #define INFO_VIS_FLAG_INVIS 1
  136. #define INFO_VIS_FLAG_HIDE_HOOD 2
  137. #define INFO_VIS_FLAG_MOUNTED 4
  138. #define INFO_VIS_FLAG_CROUCH 8
  139. using namespace std;
  140. class Spell;
  141. class ZoneServer;
  142. class Quest;
  143. struct LUAHistory;
  144. struct Cell;
  145. struct CellInfo {
  146. Cell* CurrentCell;
  147. int CellListIndex;
  148. };
  149. struct MovementData{
  150. float x;
  151. float y;
  152. float z;
  153. float speed;
  154. int32 delay;
  155. string lua_function;
  156. };
  157. struct BasicInfoStruct{
  158. sint32 cur_hp;
  159. sint32 max_hp;
  160. sint32 hp_base;
  161. sint32 cur_power;
  162. sint32 max_power;
  163. sint32 power_base;
  164. sint32 cur_savagery;
  165. sint32 max_savagery;
  166. sint32 savagery_base;
  167. sint32 cur_dissonance;
  168. sint32 max_dissonance;
  169. sint32 dissonance_base;
  170. sint16 assigned_aa;
  171. sint16 unassigned_aa;
  172. sint16 tradeskill_aa;
  173. sint16 unassigned_tradeskill_aa;
  174. sint16 prestige_aa;
  175. sint16 unassigned_prestige_aa;
  176. sint16 tradeskill_prestige_aa;
  177. sint16 unassigned_tradeskill_prestige_aa;
  178. };
  179. struct MovementLocation{
  180. float x;
  181. float y;
  182. float z;
  183. float speed;
  184. //int32 start_time;
  185. //int32 end_time;
  186. bool attackable;
  187. string lua_function;
  188. bool mapped;
  189. int32 gridid;
  190. };
  191. struct SpawnUpdate {
  192. int32 spawn_id;
  193. bool info_changed;
  194. bool vis_changed;
  195. bool pos_changed;
  196. shared_ptr<Client> client;
  197. };
  198. struct SpawnData {
  199. Spawn* spawn;
  200. uchar* data;
  201. int32 size;
  202. };
  203. class Spawn {
  204. public:
  205. Spawn();
  206. virtual ~Spawn();
  207. template <class Field, class Value> void Set(Field* field, Value value, bool setUpdateFlags = true){
  208. if (setUpdateFlags) {
  209. changed = true;
  210. AddChangedZoneSpawn();
  211. }
  212. *field = value;
  213. }
  214. template <class Field> void Set(Field* field, const char* value, bool setUpdateFlags = true){
  215. if (setUpdateFlags) {
  216. changed = true;
  217. AddChangedZoneSpawn();
  218. }
  219. strcpy(field, value);
  220. }
  221. template <class Field, class Value> void SetPos(Field* field, Value value, bool setUpdateFlags = true){
  222. if(setUpdateFlags){
  223. position_changed = true;
  224. }
  225. Set(field, value, setUpdateFlags);
  226. }
  227. template <class Field, class Value> void SetInfo(Field* field, Value value, bool setUpdateFlags = true){
  228. if(setUpdateFlags){
  229. info_changed = true;
  230. }
  231. Set(field, value);
  232. }
  233. template <class Field, class Value> void SetVis(Field* field, Value value, bool setUpdateFlags = true){
  234. if(setUpdateFlags)
  235. vis_changed = true;
  236. Set(field, value);
  237. }
  238. template <class Field> void SetPos(Field* field, char* value, bool setUpdateFlags = true){
  239. if(setUpdateFlags){
  240. position_changed = true;
  241. }
  242. Set(field, value, setUpdateFlags);
  243. }
  244. template <class Field> void SetInfo(Field* field, char* value, bool setUpdateFlags = true){
  245. if(setUpdateFlags){
  246. info_changed = true;
  247. }
  248. Set(field, value);
  249. }
  250. EntityCommand* CreateEntityCommand(EntityCommand* old_command){
  251. EntityCommand* entity_command = new EntityCommand;
  252. entity_command->name = old_command->name;
  253. entity_command->distance = old_command->distance;
  254. entity_command->command = old_command->command;
  255. entity_command->error_text = old_command->error_text;
  256. entity_command->cast_time = old_command->cast_time;
  257. entity_command->spell_visual = old_command->spell_visual;
  258. entity_command->default_allow_list = old_command->default_allow_list;
  259. return entity_command;
  260. }
  261. EntityCommand* CreateEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual, bool default_allow_list=true){
  262. EntityCommand* entity_command = new EntityCommand;
  263. entity_command->name = name;
  264. entity_command->distance = distance;
  265. entity_command->command = command;
  266. entity_command->error_text = error_text;
  267. entity_command->cast_time = cast_time;
  268. entity_command->spell_visual = spell_visual;
  269. entity_command->default_allow_list = default_allow_list;
  270. return entity_command;
  271. }
  272. void AddChangedZoneSpawn();
  273. void AddPrimaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual, bool defaultDenyList = false, Player* player = NULL);
  274. void RemovePrimaryEntityCommand(const char* command);
  275. bool SetPermissionToEntityCommand(EntityCommand* command, Player* player, bool permissionValue);
  276. void AddSecondaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  277. secondary_command_list.push_back(CreateEntityCommand(name, distance, command, error_text, cast_time, spell_visual));
  278. }
  279. int8 GetLockedNoLoot(){
  280. return appearance.locked_no_loot;
  281. }
  282. int16 GetEmoteState(){
  283. return appearance.emote_state;
  284. }
  285. int8 GetHideHood(){
  286. return appearance.hide_hood;
  287. }
  288. void SetLockedNoLoot(int8 new_val, bool updateFlags = true){
  289. SetVis(&appearance.locked_no_loot, new_val, updateFlags);
  290. }
  291. void SetHandFlag(int8 new_val, bool updateFlags = true){
  292. SetVis(&appearance.display_hand_icon, new_val, updateFlags);
  293. }
  294. void SetHideHood(int8 new_val, bool updateFlags = true){
  295. SetInfo(&appearance.hide_hood, new_val, updateFlags);
  296. }
  297. void SetEmoteState(int8 new_val, bool updateFlags = true){
  298. SetInfo(&appearance.emote_state, new_val, updateFlags);
  299. }
  300. void SetName(const char* new_name, bool updateFlags = true){
  301. SetInfo(appearance.name, new_name, updateFlags);
  302. }
  303. void SetPrefixTitle(const char* new_prefix_title, bool updateFlags = true) {
  304. SetInfo(appearance.prefix_title, new_prefix_title, updateFlags);
  305. }
  306. void SetSuffixTitle(const char* new_suffix_title, bool updateFlags = true) {
  307. SetInfo(appearance.suffix_title, new_suffix_title, updateFlags);
  308. }
  309. void SetSubTitle(const char* new_sub_title, bool updateFlags = true) {
  310. SetInfo(appearance.sub_title, new_sub_title, updateFlags);
  311. }
  312. void SetLastName(const char* new_last_name, bool updateFlags = true) {
  313. SetInfo(appearance.last_name, new_last_name, updateFlags);
  314. }
  315. void SetAdventureClass(int8 new_class, bool updateFlags = true) {
  316. SetInfo(&appearance.adventure_class, new_class, updateFlags);
  317. }
  318. void SetTradeskillClass(int8 new_class, bool updateFlags = true) {
  319. SetInfo(&appearance.tradeskill_class, new_class, updateFlags);
  320. }
  321. void SetSize(int16 new_size, bool updateFlags = true) {
  322. SetPos(&size, new_size, updateFlags);
  323. }
  324. void SetSpeedX(float speed_x, bool updateFlags = true) {
  325. SetPos(&appearance.pos.SpeedX, speed_x, updateFlags);
  326. }
  327. void SetSpeedY(float speed_y, bool updateFlags = true) {
  328. SetPos(&appearance.pos.SpeedY, speed_y, updateFlags);
  329. }
  330. void SetSpeedZ(float speed_z, bool updateFlags = true) {
  331. SetPos(&appearance.pos.SpeedZ, speed_z, updateFlags);
  332. }
  333. void SetX(float x, bool updateFlags = true){
  334. SetPos(&appearance.pos.X, x, updateFlags);
  335. }
  336. void SetY(float y, bool updateFlags = true, bool disableYMapFix = false);
  337. void SetZ(float z, bool updateFlags = true){
  338. SetPos(&appearance.pos.Z, z, updateFlags);
  339. }
  340. void SetHeading(sint16 dir1, sint16 dir2, bool updateFlags = true){
  341. SetPos(&appearance.pos.Dir1, dir1, updateFlags);
  342. SetPos(&appearance.pos.Dir2, dir2, updateFlags);
  343. }
  344. void SetHeading(float heading, bool updateFlags = true){
  345. last_heading_angle = heading;
  346. if (heading != 180)
  347. heading = (heading - 180) * 64;
  348. SetHeading((sint16)heading, (sint16)heading, updateFlags);
  349. }
  350. void SetPitch(sint16 pitch1, sint16 pitch2, bool updateFlags = true){
  351. SetPos(&appearance.pos.Pitch1, (sint16)pitch1, updateFlags);
  352. SetPos(&appearance.pos.Pitch2, (sint16)pitch2, updateFlags);
  353. }
  354. void SetPitch(float pitch, bool updateFlags = true){
  355. if (pitch == 0){
  356. SetPos(&appearance.pos.Pitch1, (sint16)0, updateFlags);
  357. SetPos(&appearance.pos.Pitch2, (sint16)0, updateFlags);
  358. return;
  359. }
  360. if (pitch != 180)
  361. pitch = (pitch - 180) * 64;
  362. SetPos(&appearance.pos.Pitch1, (sint16)pitch, updateFlags);
  363. SetPos(&appearance.pos.Pitch2, (sint16)pitch, updateFlags);
  364. }
  365. void SetRoll(float roll, bool updateFlags = true){
  366. if (roll == 0){
  367. SetPos(&appearance.pos.Roll, (sint16)0, updateFlags);
  368. return;
  369. }
  370. else if (roll != 180)
  371. roll = (roll - 180) * 64;
  372. SetPos(&appearance.pos.Roll, (sint16)roll, updateFlags);
  373. }
  374. void SetVisualState(int16 state, bool updateFlags = true){
  375. SetInfo(&appearance.visual_state, state, updateFlags);
  376. }
  377. void SetActionState(int16 state, bool updateFlags = true){
  378. SetInfo(&appearance.action_state, state, updateFlags);
  379. }
  380. void SetMoodState(int16 state, bool updateFlags = true){
  381. SetInfo(&appearance.mood_state, state, updateFlags);
  382. }
  383. void SetInitialState(int16 state, bool updateFlags = true){
  384. SetPos(&appearance.pos.state, state, updateFlags);
  385. }
  386. void SetActivityStatus(int16 state, bool updateFlags = true){
  387. SetInfo(&appearance.activity_status, state, updateFlags);
  388. }
  389. void SetCollisionRadius(int32 radius, bool updateFlags = true){
  390. SetPos(&appearance.pos.collision_radius, radius, updateFlags);
  391. }
  392. int16 GetCollisionRadius(){
  393. return appearance.pos.collision_radius;
  394. }
  395. int16 GetVisualState(){
  396. return appearance.visual_state;
  397. }
  398. int16 GetActionState(){
  399. return appearance.action_state;
  400. }
  401. int16 GetMoodState(){
  402. return appearance.mood_state;
  403. }
  404. int16 GetInitialState(){
  405. return appearance.pos.state;
  406. }
  407. int16 GetActivityStatus(){
  408. return appearance.activity_status;
  409. }
  410. int32 GetPrimaryCommandListID(){
  411. return primary_command_list_id;
  412. }
  413. int32 GetSecondaryCommandListID(){
  414. return secondary_command_list_id;
  415. }
  416. void SetID(int32 in_id){
  417. Set(&id, in_id);
  418. }
  419. void SetEncounterLevel(int8 enc_level, bool setUpdateFlags = true){
  420. SetInfo(&appearance.encounter_level, enc_level, setUpdateFlags);
  421. }
  422. void SetLevel(int16 level, bool setUpdateFlags = true){
  423. SetInfo(&appearance.level, level, setUpdateFlags);
  424. }
  425. void SetTSLevel(int16 tradeskill_level, bool setUpdateFlags = true){
  426. SetInfo(&appearance.tradeskill_level, tradeskill_level, setUpdateFlags);
  427. }
  428. void SetGender(int8 gender, bool setUpdateFlags = true){
  429. SetInfo(&appearance.gender, gender, setUpdateFlags);
  430. }
  431. void SetShowName(int8 new_val, bool setUpdateFlags = true){
  432. SetVis(&appearance.display_name, new_val, setUpdateFlags);
  433. }
  434. void SetShowLevel(int8 new_val, bool setUpdateFlags = true){
  435. SetVis(&appearance.show_level, new_val, setUpdateFlags);
  436. }
  437. void SetHeroic(int8 new_val, bool setUpdateFlags = true){
  438. SetInfo(&appearance.heroic_flag, new_val, setUpdateFlags);
  439. }
  440. void SetTargetable(int8 new_val, bool setUpdateFlags = true){
  441. SetVis(&appearance.targetable, new_val, setUpdateFlags);
  442. }
  443. void SetShowCommandIcon(int8 new_val, bool setUpdateFlags = true){
  444. SetVis(&appearance.show_command_icon, new_val, setUpdateFlags);
  445. }
  446. void SetShowHandIcon(int8 new_val, bool setUpdateFlags = true){
  447. SetVis(&appearance.display_hand_icon, new_val, setUpdateFlags);
  448. }
  449. void SetAttackable(int8 new_val, bool setUpdateFlags = true){
  450. SetInfo(&appearance.attackable, new_val, setUpdateFlags);
  451. }
  452. void SetLocation(int32 id, bool setUpdateFlags = true){
  453. SetPos(&appearance.pos.grid_id, id, setUpdateFlags);
  454. }
  455. void SetRace(int8 race, bool setUpdateFlags = true){
  456. SetInfo(&appearance.race, race, setUpdateFlags);
  457. }
  458. void SetIcon(int8 icon, bool setUpdateFlags = true){
  459. SetInfo(&appearance.icon, icon, setUpdateFlags);
  460. }
  461. void AddIconValue(int8 val){
  462. if(!(appearance.icon & val))
  463. SetIcon(appearance.icon+val);
  464. }
  465. void RemoveIconValue(int8 val){
  466. if((appearance.icon & val))
  467. SetIcon(appearance.icon-val);
  468. }
  469. int8 GetIconValue(){
  470. return appearance.icon;
  471. }
  472. virtual void SetSpeed(float speed){
  473. SetPos(&appearance.pos.Speed1, (int8)speed);
  474. }
  475. virtual float GetSpeed(){
  476. return (float)appearance.pos.Speed1;
  477. }
  478. virtual float GetBaseSpeed(){
  479. return (float)appearance.pos.Speed1;
  480. }
  481. void SetSpawnType(int8 new_type){
  482. SetInfo(&spawn_type, new_type);
  483. }
  484. int8 GetSpawnType(){
  485. return spawn_type;
  486. }
  487. void SetDatabaseID(int32 new_id){
  488. database_id = new_id;
  489. }
  490. int32 GetDatabaseID(){
  491. return database_id;
  492. }
  493. int8 GetShowHandIcon(){
  494. return appearance.display_hand_icon;
  495. }
  496. int32 GetLocation(){
  497. return appearance.pos.grid_id;
  498. }
  499. int8 GetAttackable(){
  500. return appearance.attackable;
  501. }
  502. int8 GetShowName(){
  503. return appearance.display_name;
  504. }
  505. int8 GetShowLevel(){
  506. return appearance.show_level;
  507. }
  508. int8 GetHeroic(){
  509. return appearance.heroic_flag;
  510. }
  511. int8 GetTargetable(){
  512. return appearance.targetable;
  513. }
  514. int8 GetShowCommandIcon(){
  515. return appearance.show_command_icon;
  516. }
  517. char* GetName(){
  518. return appearance.name;
  519. }
  520. char* GetPrefixTitle(){
  521. return appearance.prefix_title;
  522. }
  523. char* GetSuffixTitle(){
  524. return appearance.suffix_title;
  525. }
  526. char* GetSubTitle() {
  527. return appearance.sub_title;
  528. }
  529. char* GetLastName() {
  530. return appearance.last_name;
  531. }
  532. int8 GetAdventureClass() {
  533. return appearance.adventure_class;
  534. }
  535. int8 GetTradeskillClass() {
  536. return appearance.tradeskill_class;
  537. }
  538. float GetDestinationX(){
  539. return appearance.pos.X2;
  540. }
  541. float GetX() {
  542. return appearance.pos.X;
  543. }
  544. float GetSpeedX() {
  545. return appearance.pos.SpeedX;
  546. }
  547. float GetSpeedY() {
  548. return appearance.pos.SpeedY;
  549. }
  550. float GetSpeedZ() {
  551. return appearance.pos.SpeedZ;
  552. }
  553. float GetDestinationY(){
  554. return appearance.pos.Y2;
  555. }
  556. float GetY(){
  557. return appearance.pos.Y;
  558. }
  559. float GetDestinationZ(){
  560. return appearance.pos.Z2;
  561. }
  562. float GetZ(){
  563. return appearance.pos.Z;
  564. }
  565. float GetHeading(){
  566. float heading = 0;
  567. if(appearance.pos.Dir1 != 0){
  568. heading = ((float)appearance.pos.Dir1)/((float)64);
  569. if(heading >= 180)
  570. heading -= 180;
  571. else
  572. heading += 180;
  573. }
  574. return heading;
  575. }
  576. float GetPitch(){
  577. float pitch = 0;
  578. if(appearance.pos.Pitch1 != 0){
  579. pitch = ((float)appearance.pos.Pitch1)/((float)64);
  580. if(pitch >= 180)
  581. pitch -= 180;
  582. else
  583. pitch += 180;
  584. }
  585. return pitch;
  586. }
  587. float GetRoll(){
  588. float roll = 0;
  589. if(appearance.pos.Roll != 0){
  590. roll = ((float)appearance.pos.Roll)/((float)64);
  591. if(roll >= 180)
  592. roll -= 180;
  593. else
  594. roll += 180;
  595. }
  596. return roll;
  597. }
  598. int32 GetID(){
  599. return id;
  600. }
  601. float GetDistance(float x1, float y1, float z1, float x2, float y2, float z2);
  602. float GetDistance(float x, float y, float z, float radius, bool ignore_y = false);
  603. float GetDistance(float x, float y, float z, bool ignore_y = false);
  604. float GetDistance(Spawn* spawn, bool ignore_y = false, bool includeRadius=true);
  605. float GetDistance(Spawn* spawn, float x1, float y1, float z1, bool includeRadius=true);
  606. float CalculateRadius(Spawn* target);
  607. int8 GetEncounterLevel(){
  608. return appearance.encounter_level;
  609. }
  610. sint32 GetTotalPower();
  611. sint32 GetPower();
  612. sint32 GetTotalHP();
  613. sint32 GetHP();
  614. sint32 GetTotalHPBase();
  615. sint32 GetTotalPowerBase();
  616. sint32 GetTotalSavagery();
  617. sint32 GetSavagery();
  618. sint32 GetTotalDissonance();
  619. sint32 GetDissonance();
  620. sint32 GetTotalSavageryBase();
  621. sint32 GetTotalDissonanceBase();
  622. sint16 GetAssignedAA();
  623. sint16 GetUnassignedAA();
  624. sint16 GetTradeskillAA();
  625. sint16 GetUnassignedTradeskillAA();
  626. sint16 GetPrestigeAA();
  627. sint16 GetUnassignedPretigeAA();
  628. sint16 GetTradeskillPrestigeAA();
  629. sint16 GetUnassignedTradeskillPrestigeAA();
  630. void SetTotalPower(sint32 new_val);
  631. void SetTotalHP(sint32 new_val);
  632. void SetTotalSavagery(sint32 new_val);
  633. void SetTotalDissonance(sint32 new_val);
  634. void SetTotalPowerBase(sint32 new_val);
  635. void SetTotalHPBase(sint32 new_val);
  636. void SetTotalSavageryBase(sint32 new_val);
  637. void SetTotalDissonanceBase(sint32 new_val);
  638. void SetPower(sint32 power, bool setUpdateFlags = true);
  639. void SetHP(sint32 new_val, bool setUpdateFlags = true);
  640. void SetSavagery(sint32 savagery, bool setUpdateFlags = true);
  641. void SetDissonance(sint32 dissonance, bool setUpdateFlags = true);
  642. void SetAssignedAA(sint16 new_val);
  643. void SetUnassignedAA(sint16 new_val);
  644. void SetTradeskillAA(sint16 new_val);
  645. void SetUnassignedTradeskillAA(sint16 new_val);
  646. void SetPrestigeAA(sint16 new_val);
  647. void SetUnassignedPrestigeAA(sint16 new_val);
  648. void SetTradeskillPrestigeAA(sint16 new_val);
  649. void SetUnassignedTradeskillPrestigeAA(sint16 new_val);
  650. void SetPrivateQuestSpawn(bool val) {req_quests_private = val;}
  651. void SetQuestsRequiredOverride(int16 val) {req_quests_override = val;}
  652. void SetQuestsRequiredContinuedAccess(bool val) {req_quests_continued_access = val;}
  653. bool GetPrivateQuestSpawn() {return req_quests_private;}
  654. int16 GetQuestsRequiredOverride() {return req_quests_override;}
  655. bool GetQuestsRequiredContinuedAccess() {return req_quests_continued_access;}
  656. bool Alive(){ return GetHP() > 0; }
  657. int16 GetLevel(){
  658. return appearance.level;
  659. }
  660. int16 GetTSLevel(){
  661. return appearance.tradeskill_level;
  662. }
  663. int8 GetGender(){
  664. return appearance.gender;
  665. }
  666. int8 GetRace(){
  667. return appearance.race;
  668. }
  669. int8 GetLuaRaceId() {
  670. return appearance.lua_race_id;
  671. }
  672. int32 GetSize(){
  673. return size;
  674. }
  675. int32 GetDeviation(){
  676. return deviation;
  677. }
  678. void SetDeviation(int32 in_dev){
  679. deviation = in_dev;
  680. }
  681. float GetSpawnOrigHeading(){
  682. return appearance.pos.SpawnOrigHeading;
  683. }
  684. void SetSpawnOrigHeading(float val){
  685. appearance.pos.SpawnOrigHeading = val;
  686. }
  687. float GetSpawnOrigX(){
  688. return appearance.pos.SpawnOrigX;
  689. }
  690. float GetSpawnOrigY(){
  691. return appearance.pos.SpawnOrigY;
  692. }
  693. float GetSpawnOrigZ(){
  694. return appearance.pos.SpawnOrigZ;
  695. }
  696. float GetSpawnOrigPitch(){
  697. return appearance.pos.SpawnOrigPitch;
  698. }
  699. float GetSpawnOrigRoll(){
  700. return appearance.pos.SpawnOrigRoll;
  701. }
  702. void SetSpawnOrigX(float val){
  703. appearance.pos.SpawnOrigX = val;
  704. }
  705. void SetSpawnOrigY(float val){
  706. appearance.pos.SpawnOrigY = val;
  707. }
  708. void SetSpawnOrigZ(float val){
  709. appearance.pos.SpawnOrigZ = val;
  710. }
  711. void SetSpawnOrigRoll(float val){
  712. appearance.pos.SpawnOrigRoll = val;
  713. }
  714. void SetSpawnOrigPitch(float val){
  715. appearance.pos.SpawnOrigPitch = val;
  716. }
  717. void SetSogaModelType(int16 new_val, bool setUpdateFlags = true){
  718. SetInfo(&appearance.soga_model_type, new_val, setUpdateFlags);
  719. }
  720. void SetModelType(int16 model_type, bool setUpdateFlags = true){
  721. SetInfo(&appearance.model_type, model_type, setUpdateFlags);
  722. SetInfo(&appearance.soga_model_type, model_type, setUpdateFlags);
  723. }
  724. int16 GetSogaModelType(){
  725. return appearance.soga_model_type;
  726. }
  727. int16 GetModelType(){
  728. return appearance.model_type;
  729. }
  730. bool IsFlying() { return (GetInitialState() == 49156); }
  731. void SetPrimaryCommand(const char* name, const char* command, float distance = 10);
  732. void SetPrimaryCommands(vector<EntityCommand*>* commands);
  733. void SetSecondaryCommands(vector<EntityCommand*>* commands);
  734. vector<EntityCommand*>* GetPrimaryCommands() {return &primary_command_list;}
  735. vector<EntityCommand*>* GetSecondaryCommands() {return &secondary_command_list;}
  736. EntityCommand* FindEntityCommand(string command, bool primaryOnly=false);
  737. virtual EQ2Packet* serialize(Player* player, int16 version);
  738. EQ2Packet* spawn_serialize(Player* player, int16 version);
  739. EQ2Packet* spawn_update_packet(Player* player, int16 version, bool override_changes = false, bool override_vis_changes = false);
  740. EQ2Packet* player_position_update_packet(Player* player, int16 version);
  741. uchar* spawn_info_changes(Player* spawn, int16 version);
  742. uchar* spawn_pos_changes(Player* spawn, int16 version);
  743. uchar* spawn_vis_changes(Player* spawn, int16 version);
  744. uchar* spawn_info_changes_ex(Player* spawn, int16 version);
  745. uchar* spawn_pos_changes_ex(Player* spawn, int16 version);
  746. uchar* spawn_vis_changes_ex(Player* spawn, int16 version);
  747. virtual bool EngagedInCombat(){ return false; }
  748. virtual bool IsObject(){ return false; }
  749. virtual bool IsGroundSpawn(){ return false; }
  750. virtual bool IsNPC(){ return false; }
  751. virtual bool IsEntity(){ return false; }
  752. virtual bool IsPlayer(){ return false; }
  753. virtual bool IsWidget(){ return false; }
  754. virtual bool IsSign(){ return false; }
  755. virtual bool IsBot() { return false; }
  756. bool HasInfoChanged(){ return info_changed; }
  757. bool HasPositionChanged(){ return position_changed; }
  758. bool HasTarget(){ return target ? true : false; }
  759. int32 GetRespawnTime();
  760. void SetRespawnTime(int32 time);
  761. int32 GetExpireTime() { return expire_time; }
  762. void SetExpireTime(int32 new_expire_time) { expire_time = new_expire_time; }
  763. int32 GetExpireOffsetTime();
  764. void SetExpireOffsetTime(int32 time);
  765. int32 GetSpawnLocationID();
  766. void SetSpawnLocationID(int32 id);
  767. int32 GetSpawnEntryID();
  768. void SetSpawnEntryID(int32 id);
  769. int32 GetSpawnLocationPlacementID();
  770. void SetSpawnLocationPlacementID(int32 id);
  771. float GetXOffset() { return x_offset; }
  772. void SetXOffset(float new_x_offset) { x_offset = new_x_offset; }
  773. float GetYOffset() { return y_offset; }
  774. void SetYOffset(float new_y_offset) { y_offset = new_y_offset; }
  775. float GetZOffset() { return z_offset; }
  776. void SetZOffset(float new_z_offset) { z_offset = new_z_offset; }
  777. Spawn* GetTarget();
  778. void SetTarget(Spawn* spawn);
  779. Spawn* GetLastAttacker();
  780. void SetLastAttacker(Spawn* spawn);
  781. bool TakeDamage(int32 damage);
  782. void TakeDamage(Spawn* attacker, int32 damage);
  783. ZoneServer* GetZone();
  784. virtual void SetZone(ZoneServer* in_zone);
  785. void SetFactionID(int32 val) { faction_id = val; }
  786. int32 GetFactionID(){
  787. return faction_id;
  788. }
  789. static int32 NextID() {
  790. static CriticalSection id_lock;
  791. id_lock.lock();
  792. int32 ret = ++next_id;
  793. if (next_id == 0xFFFFFFFE)
  794. next_id = 1;
  795. else if ((next_id - 255) % 256 == 0) { //we dont want it to end in 255, it will confuse/crash the client
  796. id_lock.unlock();
  797. return NextID();
  798. }
  799. id_lock.unlock();
  800. return ret;
  801. }
  802. void AddProvidedQuest(int32 val){
  803. quest_ids.push_back(val);
  804. }
  805. vector<int32>* GetProvidedQuests(){
  806. return &quest_ids;
  807. }
  808. bool HasProvidedQuests(){
  809. return (quest_ids.size() > 0);
  810. }
  811. void SetSpawnScript(string name);
  812. const char* GetSpawnScript();
  813. vector<Spawn*>* GetSpawnGroup();
  814. bool HasSpawnGroup();
  815. bool IsInSpawnGroup(Spawn* spawn);
  816. void SendSpawnChanges(bool val){ send_spawn_changes = val; }
  817. void SetSpawnGroupID(int32 id);
  818. int32 GetSpawnGroupID();
  819. void AddSpawnToGroup(Spawn* spawn);
  820. void SetSpawnGroupList(vector<Spawn*>* list, Mutex* mutex);
  821. void RemoveSpawnFromGroup(bool erase_all = false);
  822. void SetRunningTo(Spawn* spawn){ running_to = spawn->GetID(); }
  823. Spawn* GetRunningTo();
  824. void SetTempVisualState(int val, bool update = true) { SetInfo(&tmp_visual_state, val, update); }
  825. int GetTempVisualState(){ return tmp_visual_state; }
  826. void SetTempActionState(int val, bool update = true) { SetInfo(&tmp_action_state, val, update); }
  827. int GetTempActionState(){ return tmp_action_state; }
  828. void AddAllowAccessSpawn(Spawn* spawn){ allowed_access[spawn->GetID()] = 1; }
  829. void RemoveSpawnAccess(Spawn* spawn);
  830. bool IsPrivateSpawn(){ return allowed_access.size() > 0 ;}
  831. bool AllowedAccess(Spawn* spawn){ return allowed_access.count(spawn->GetID()) > 0; }
  832. void MakeSpawnPublic() { allowed_access.clear(); }
  833. void SetSizeOffset(int8 offset);
  834. int8 GetSizeOffset();
  835. void SetMerchantID(int32 val);
  836. int32 GetMerchantID();
  837. void SetMerchantType(int8 val);
  838. int8 GetMerchantType();
  839. void SetMerchantLevelRange(int32 minLvl = 0, int32 maxLvl = 0);
  840. bool IsClientInMerchantLevelRange(Client* ent, bool sendMessageIfDenied = true);
  841. int32 GetMerchantMinLevel();
  842. int32 GetMerchantMaxLevel();
  843. void SetQuestsRequired(map<int32, vector<int16>* >* quests);
  844. void SetQuestsRequired(int32 quest_id, int16 quest_step);
  845. void SetRequiredHistory(int32 event_id, int32 value1, int32 value2);
  846. map<int32, vector<int16>* >* GetQuestsRequired();
  847. void SetTransporterID(int32 id);
  848. int32 GetTransporterID();
  849. bool MeetsSpawnAccessRequirements(Player* player);
  850. void RemovePrimaryCommands();
  851. void InitializePosPacketData(Player* player, PacketStruct* packet, bool bSpawnUpdate = false);
  852. void InitializeInfoPacketData(Player* player, PacketStruct* packet);
  853. void InitializeVisPacketData(Player* player, PacketStruct* packet);
  854. void InitializeHeaderPacketData(Player* player, PacketStruct* packet, int16 index);
  855. void InitializeFooterPacketData(Player* player, PacketStruct* packet);
  856. void MoveToLocation(Spawn* spawn, float distance, bool immediate = true, bool isMappedLocation = false);
  857. void AddMovementLocation(float x, float y, float z, float speed, int16 delay, const char* lua_function);
  858. void ProcessMovement(bool isSpawnListLocked=false);
  859. void ResetMovement();
  860. bool IsRunning();
  861. void CalculateRunningLocation(bool stop = false);
  862. void RunToLocation(float x, float y, float z, float following_x = 0, float following_y = 0, float following_z = 0);
  863. MovementLocation* GetCurrentRunningLocation();
  864. MovementLocation* GetLastRunningLocation();
  865. bool CalculateChange();
  866. void AddRunningLocation(float x, float y, float z, float speed, float distance_away = 0, bool attackable = true, bool finished_adding_locations = true, string lua_function = "", bool isMapped=false);
  867. bool RemoveRunningLocation();
  868. void ClearRunningLocations();
  869. void CopySpawnAppearance(Spawn* spawn);
  870. bool MovementInterrupted(){ return movement_interrupted; }
  871. void MovementInterrupted(bool val) { movement_interrupted = val; }
  872. bool NeedsToResumeMovement(){ return attack_resume_needed; }
  873. void NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
  874. bool HasMovementLoop(){ return movement_loop.size() > 0; }
  875. Timer* GetRunningTimer();
  876. float GetFaceTarget(float x, float z);
  877. void FaceTarget(float x, float z);
  878. void FaceTarget(Spawn* target);
  879. void SetInvulnerable(bool val);
  880. bool GetInvulnerable();
  881. bool changed;
  882. bool position_changed;
  883. bool info_changed;
  884. bool vis_changed;
  885. int16 size;
  886. int32 faction_id;
  887. int8 oversized_packet; //0xff
  888. int16 opcode;
  889. int32 id;
  890. int8 unknown1;
  891. int32 unknown2;
  892. int32 primary_command_list_id;
  893. int32 secondary_command_list_id;
  894. vector<EntityCommand*> primary_command_list;
  895. vector<EntityCommand*> secondary_command_list;
  896. int32 group_id;
  897. int8 group_len;
  898. vector<Spawn*>* spawn_group_list;
  899. AppearanceData appearance;
  900. int32 last_movement_update;
  901. int32 last_location_update;
  902. bool forceMapCheck;
  903. bool following;
  904. bool IsPet() { return is_pet; }
  905. void SetPet(bool val) { is_pet = val; }
  906. Mutex m_requiredQuests;
  907. Mutex m_requiredHistory;
  908. void SetFollowTarget(Spawn* spawn, int32 followDistance=0);
  909. Spawn* GetFollowTarget();
  910. /// <summary>Sets a user defined variable</summary>
  911. /// <param name='var'>Variable we are setting</param>
  912. /// <param name='val'>Value to set the variable to</param>
  913. void AddTempVariable(string var, string val);
  914. void AddTempVariable(string var, Spawn* val);
  915. void AddTempVariable(string var, ZoneServer* val);
  916. void AddTempVariable(string var, Quest* val);
  917. void AddTempVariable(string var, Item* val);
  918. /// <summary>Gets the value for the given variable</summary>
  919. /// <param name='var'>Variable to check</param>
  920. /// <returns>The value for the given variable, "" if variable was not set</returns>
  921. string GetTempVariable(string var);
  922. Spawn* GetTempVariableSpawn(string var);
  923. ZoneServer* GetTempVariableZone(string var);
  924. Item* GetTempVariableItem(string var);
  925. Quest* GetTempVariableQuest(string var);
  926. int8 GetTempVariableType(string var);
  927. void DeleteTempVariable(string var);
  928. void SetIllusionModel(int16 val, bool setUpdateFlags = true) {
  929. SetInfo(&m_illusionModel, val, setUpdateFlags);
  930. }
  931. int16 GetIllusionModel() { return m_illusionModel; }
  932. CellInfo Cell_Info;
  933. int32 GetSpawnAnim() { return m_spawnAnim; }
  934. void SetSpawnAnim(int32 value) { m_spawnAnim = value; }
  935. int32 GetAddedToWorldTimestamp() { return m_addedToWorldTimestamp; }
  936. void SetAddedToWorldTimestamp(int32 value) { m_addedToWorldTimestamp = value; }
  937. int16 GetSpawnAnimLeeway() { return m_spawnAnimLeeway; }
  938. void SetSpawnAnimLeeway(int16 value) { m_spawnAnimLeeway = value; }
  939. float FindDestGroundZ(glm::vec3 dest, float z_offset);
  940. float GetFixedZ(const glm::vec3& destination, int32 z_find_offset = 1);
  941. void FixZ(bool forceUpdate=false);
  942. bool CheckLoS(Spawn* target);
  943. bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc);
  944. void CalculateNewFearpoint();
  945. void StopMoving() {
  946. if (movement_locations)
  947. movement_locations->clear();
  948. }
  949. int16 pos_packet_size;
  950. int16 info_packet_size;
  951. int16 vis_packet_size;
  952. enum SpawnProximityType {
  953. SPAWNPROXIMITY_DATABASE_ID = 0,
  954. SPAWNPROXIMITY_LOCATION_ID = 1
  955. };
  956. struct SpawnProximity {
  957. float x;
  958. float y;
  959. float z;
  960. int32 spawn_value;
  961. int8 spawn_type;
  962. float distance;
  963. string in_range_lua_function;
  964. string leaving_range_lua_function;
  965. map<int32, bool> spawns_in_proximity;
  966. };
  967. void AddSpawnToProximity(int32 spawnValue, SpawnProximityType type);
  968. void RemoveSpawnFromProximity(int32 spawnValue, SpawnProximityType type);
  969. SpawnProximity* AddLUASpawnProximity(int32 spawnValue, SpawnProximityType type, float distance, string in_range_function, string leaving_range_function) {
  970. SpawnProximity* prox = new SpawnProximity;
  971. prox->spawn_value = spawnValue;
  972. prox->spawn_type = type;
  973. prox->distance = distance;
  974. prox->in_range_lua_function = in_range_function;
  975. prox->leaving_range_lua_function = leaving_range_function;
  976. spawn_proximities.Add(prox);
  977. has_spawn_proximities = true;
  978. return prox;
  979. }
  980. void RemoveSpawnProximities() {
  981. MutexList<SpawnProximity*>::iterator itr = spawn_proximities.begin();
  982. while (itr.Next()) {
  983. safe_delete(itr->value);
  984. }
  985. spawn_proximities.clear();
  986. has_spawn_proximities = false;
  987. }
  988. Mutex MCommandMutex;
  989. bool has_spawn_proximities;
  990. void SetPickupItemID(int32 itemid)
  991. {
  992. pickup_item_id = itemid;
  993. }
  994. void SetPickupUniqueItemID(int32 uniqueid)
  995. {
  996. pickup_unique_item_id = uniqueid;
  997. }
  998. int32 GetPickupItemID() { return pickup_item_id; }
  999. int32 GetPickupUniqueItemID() { return pickup_unique_item_id; }
  1000. bool IsSoundsDisabled() { return disable_sounds; }
  1001. void SetSoundsDisabled(bool val) { disable_sounds = val; }
  1002. protected:
  1003. bool send_spawn_changes;
  1004. bool invulnerable;
  1005. bool attack_resume_needed;
  1006. bool resume_movement;
  1007. bool movement_interrupted;
  1008. int32 running_timer_begin;
  1009. int32 running_timer_end;
  1010. vector<MovementData*> movement_loop;
  1011. bool running_timer_updated;
  1012. int16 movement_index;
  1013. int32 last_grid_update;
  1014. int32 movement_start_time;
  1015. Mutex MMovementLoop;
  1016. map<int32, int8> allowed_access;
  1017. vector<int32> quest_ids;
  1018. int32 database_id;
  1019. int32 packet_num;
  1020. int32 target;
  1021. int8 spawn_type;
  1022. int32 last_attacker;
  1023. int32 merchant_id;
  1024. int8 merchant_type;
  1025. int32 merchant_min_level;
  1026. int32 merchant_max_level;
  1027. int32 transporter_id;
  1028. int32 pickup_item_id;
  1029. int32 pickup_unique_item_id;
  1030. map<int32, vector<int16>* > required_quests;
  1031. map<int32, LUAHistory> required_history;
  1032. EquipmentItemList equipment_list;
  1033. MutexList<SpawnProximity*> spawn_proximities;
  1034. void CheckProximities();
  1035. private:
  1036. deque<MovementLocation*>* movement_locations;
  1037. Mutex* MMovementLocations;
  1038. Mutex* MSpawnGroup;
  1039. int8 size_offset;
  1040. int tmp_visual_state;
  1041. int tmp_action_state;
  1042. int32 running_to;
  1043. string spawn_script;
  1044. static int32 next_id;
  1045. ZoneServer* zone;
  1046. int32 spawn_location_id;
  1047. int32 spawn_entry_id;
  1048. int32 spawn_location_spawns_id;
  1049. int32 respawn;
  1050. int32 expire_time;
  1051. int32 expire_offset;
  1052. float x_offset;
  1053. float y_offset;
  1054. float z_offset;
  1055. int32 deviation;
  1056. BasicInfoStruct basic_info;
  1057. //string data;
  1058. bool is_pet;
  1059. // m_followTarget = spawn to follow around
  1060. int32 m_followTarget;
  1061. int32 m_followDistance;
  1062. bool req_quests_private;
  1063. int16 req_quests_override;
  1064. bool req_quests_continued_access;
  1065. float last_heading_angle;
  1066. map<string, int8> m_tempVariableTypes;
  1067. map<string, int32> m_tempVariableSpawn;
  1068. map<string, ZoneServer*> m_tempVariableZone;
  1069. map<string, Item*> m_tempVariableItem;
  1070. map<string, Quest*> m_tempVariableQuest;
  1071. // m_tempVariables = stores user defined variables from lua, will not persist through a zone
  1072. map<string, string> m_tempVariables;
  1073. int16 m_illusionModel;
  1074. int32 m_spawnAnim;
  1075. int32 m_addedToWorldTimestamp;
  1076. int16 m_spawnAnimLeeway;
  1077. Mutex m_Update;
  1078. bool disable_sounds;
  1079. };
  1080. #endif