Spawn.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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, int16 offset = 0, int32 value = 0, int16 offset2 = 0, int16 offset3 = 0, int16 offset4 = 0, int32 value2 = 0);
  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. bool HasTrapTriggered() {
  778. return trap_triggered;
  779. }
  780. void SetTrapTriggered(bool triggered) {
  781. trap_triggered = triggered;
  782. }
  783. void AddLootItem(int32 id, int16 charges = 1) {
  784. Item* master_item = master_item_list.GetItem(id);
  785. if (master_item) {
  786. Item* item = new Item(master_item);
  787. item->details.count = charges;
  788. loot_items.push_back(item);
  789. }
  790. }
  791. bool HasLoot() {
  792. if (loot_items.size() == 0 && loot_coins == 0)
  793. return false;
  794. return true;
  795. }
  796. bool HasLootItemID(int32 id);
  797. int32 GetLootItemID();
  798. Item* LootItem(int32 id);
  799. vector<Item*>* GetLootItems() {
  800. return &loot_items;
  801. }
  802. void LockLoot() {
  803. MLootItems.lock();
  804. }
  805. void UnlockLoot() {
  806. MLootItems.unlock();
  807. }
  808. int32 GetLootCoins() {
  809. return loot_coins;
  810. }
  811. void SetLootCoins(int32 val) {
  812. loot_coins = val;
  813. }
  814. void AddLootCoins(int32 coins) {
  815. loot_coins += coins;
  816. }
  817. void ClearLootList() {
  818. vector<Item*>::iterator itr;
  819. for (itr = loot_items.begin(); itr != loot_items.end(); itr++)
  820. safe_delete(*itr);
  821. loot_items.clear();
  822. }
  823. Spawn* GetTarget();
  824. void SetTarget(Spawn* spawn);
  825. Spawn* GetLastAttacker();
  826. void SetLastAttacker(Spawn* spawn);
  827. bool TakeDamage(int32 damage);
  828. void TakeDamage(Spawn* attacker, int32 damage);
  829. ZoneServer* GetZone();
  830. virtual void SetZone(ZoneServer* in_zone);
  831. void SetFactionID(int32 val) { faction_id = val; }
  832. int32 GetFactionID(){
  833. return faction_id;
  834. }
  835. static int32 NextID() {
  836. static CriticalSection id_lock;
  837. id_lock.lock();
  838. int32 ret = ++next_id;
  839. if (next_id == 0xFFFFFFFE)
  840. next_id = 1;
  841. else if ((next_id - 255) % 256 == 0) { //we dont want it to end in 255, it will confuse/crash the client
  842. id_lock.unlock();
  843. return NextID();
  844. }
  845. id_lock.unlock();
  846. return ret;
  847. }
  848. void AddProvidedQuest(int32 val){
  849. quest_ids.push_back(val);
  850. }
  851. vector<int32>* GetProvidedQuests(){
  852. return &quest_ids;
  853. }
  854. bool HasProvidedQuests(){
  855. return (quest_ids.size() > 0);
  856. }
  857. void SetSpawnScript(string name);
  858. const char* GetSpawnScript();
  859. vector<Spawn*>* GetSpawnGroup();
  860. bool HasSpawnGroup();
  861. bool IsInSpawnGroup(Spawn* spawn);
  862. void SendSpawnChanges(bool val){ send_spawn_changes = val; }
  863. void SetSpawnGroupID(int32 id);
  864. int32 GetSpawnGroupID();
  865. void AddSpawnToGroup(Spawn* spawn);
  866. void SetSpawnGroupList(vector<Spawn*>* list, Mutex* mutex);
  867. void RemoveSpawnFromGroup(bool erase_all = false);
  868. void SetRunningTo(Spawn* spawn){ running_to = spawn->GetID(); }
  869. Spawn* GetRunningTo();
  870. void SetTempVisualState(int val, bool update = true) { SetInfo(&tmp_visual_state, val, update); }
  871. int GetTempVisualState(){ return tmp_visual_state; }
  872. void SetTempActionState(int val, bool update = true) { SetInfo(&tmp_action_state, val, update); }
  873. int GetTempActionState(){ return tmp_action_state; }
  874. void AddAllowAccessSpawn(Spawn* spawn){ allowed_access[spawn->GetID()] = 1; }
  875. void RemoveSpawnAccess(Spawn* spawn);
  876. bool IsPrivateSpawn(){ return allowed_access.size() > 0 ;}
  877. bool AllowedAccess(Spawn* spawn){ return allowed_access.count(spawn->GetID()) > 0; }
  878. void MakeSpawnPublic() { allowed_access.clear(); }
  879. void SetSizeOffset(int8 offset);
  880. int8 GetSizeOffset();
  881. void SetMerchantID(int32 val);
  882. int32 GetMerchantID();
  883. void SetMerchantType(int8 val);
  884. int8 GetMerchantType();
  885. void SetMerchantLevelRange(int32 minLvl = 0, int32 maxLvl = 0);
  886. bool IsClientInMerchantLevelRange(Client* ent, bool sendMessageIfDenied = true);
  887. int32 GetMerchantMinLevel();
  888. int32 GetMerchantMaxLevel();
  889. void SetQuestsRequired(map<int32, vector<int16>* >* quests);
  890. void SetQuestsRequired(int32 quest_id, int16 quest_step);
  891. void SetRequiredHistory(int32 event_id, int32 value1, int32 value2);
  892. map<int32, vector<int16>* >* GetQuestsRequired();
  893. void SetTransporterID(int32 id);
  894. int32 GetTransporterID();
  895. bool MeetsSpawnAccessRequirements(Player* player);
  896. void RemovePrimaryCommands();
  897. void InitializePosPacketData(Player* player, PacketStruct* packet, bool bSpawnUpdate = false);
  898. void InitializeInfoPacketData(Player* player, PacketStruct* packet);
  899. void InitializeVisPacketData(Player* player, PacketStruct* packet);
  900. void InitializeHeaderPacketData(Player* player, PacketStruct* packet, int16 index);
  901. void InitializeFooterPacketData(Player* player, PacketStruct* packet);
  902. void MoveToLocation(Spawn* spawn, float distance, bool immediate = true, bool isMappedLocation = false);
  903. void AddMovementLocation(float x, float y, float z, float speed, int16 delay, const char* lua_function);
  904. void ProcessMovement(bool isSpawnListLocked=false);
  905. void ResetMovement();
  906. bool IsRunning();
  907. void CalculateRunningLocation(bool stop = false);
  908. void RunToLocation(float x, float y, float z, float following_x = 0, float following_y = 0, float following_z = 0);
  909. MovementLocation* GetCurrentRunningLocation();
  910. MovementLocation* GetLastRunningLocation();
  911. bool CalculateChange();
  912. 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);
  913. bool RemoveRunningLocation();
  914. void ClearRunningLocations();
  915. void CopySpawnAppearance(Spawn* spawn);
  916. bool MovementInterrupted(){ return movement_interrupted; }
  917. void MovementInterrupted(bool val) { movement_interrupted = val; }
  918. bool NeedsToResumeMovement(){ return attack_resume_needed; }
  919. void NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
  920. bool HasMovementLoop(){ return movement_loop.size() > 0; }
  921. Timer* GetRunningTimer();
  922. float GetFaceTarget(float x, float z);
  923. void FaceTarget(float x, float z);
  924. void FaceTarget(Spawn* target);
  925. void SetInvulnerable(bool val);
  926. bool GetInvulnerable();
  927. bool changed;
  928. bool position_changed;
  929. bool info_changed;
  930. bool vis_changed;
  931. int16 size;
  932. int32 faction_id;
  933. int8 oversized_packet; //0xff
  934. int32 id;
  935. int8 unknown1;
  936. int32 unknown2;
  937. int32 primary_command_list_id;
  938. int32 secondary_command_list_id;
  939. vector<EntityCommand*> primary_command_list;
  940. vector<EntityCommand*> secondary_command_list;
  941. int32 group_id;
  942. int8 group_len;
  943. vector<Spawn*>* spawn_group_list;
  944. AppearanceData appearance;
  945. int32 last_movement_update;
  946. int32 last_location_update;
  947. bool forceMapCheck;
  948. bool following;
  949. bool IsPet() { return is_pet; }
  950. void SetPet(bool val) { is_pet = val; }
  951. Mutex m_requiredQuests;
  952. Mutex m_requiredHistory;
  953. void SetFollowTarget(Spawn* spawn, int32 followDistance=0);
  954. Spawn* GetFollowTarget();
  955. /// <summary>Sets a user defined variable</summary>
  956. /// <param name='var'>Variable we are setting</param>
  957. /// <param name='val'>Value to set the variable to</param>
  958. void AddTempVariable(string var, string val);
  959. void AddTempVariable(string var, Spawn* val);
  960. void AddTempVariable(string var, ZoneServer* val);
  961. void AddTempVariable(string var, Quest* val);
  962. void AddTempVariable(string var, Item* val);
  963. /// <summary>Gets the value for the given variable</summary>
  964. /// <param name='var'>Variable to check</param>
  965. /// <returns>The value for the given variable, "" if variable was not set</returns>
  966. string GetTempVariable(string var);
  967. Spawn* GetTempVariableSpawn(string var);
  968. ZoneServer* GetTempVariableZone(string var);
  969. Item* GetTempVariableItem(string var);
  970. Quest* GetTempVariableQuest(string var);
  971. int8 GetTempVariableType(string var);
  972. void DeleteTempVariable(string var);
  973. void SetIllusionModel(int16 val, bool setUpdateFlags = true) {
  974. SetInfo(&m_illusionModel, val, setUpdateFlags);
  975. }
  976. int16 GetIllusionModel() { return m_illusionModel; }
  977. CellInfo Cell_Info;
  978. int32 GetSpawnAnim() { return m_spawnAnim; }
  979. void SetSpawnAnim(int32 value) { m_spawnAnim = value; }
  980. int32 GetAddedToWorldTimestamp() { return m_addedToWorldTimestamp; }
  981. void SetAddedToWorldTimestamp(int32 value) { m_addedToWorldTimestamp = value; }
  982. int16 GetSpawnAnimLeeway() { return m_spawnAnimLeeway; }
  983. void SetSpawnAnimLeeway(int16 value) { m_spawnAnimLeeway = value; }
  984. float FindDestGroundZ(glm::vec3 dest, float z_offset);
  985. float GetFixedZ(const glm::vec3& destination, int32 z_find_offset = 1);
  986. void FixZ(bool forceUpdate=false);
  987. bool CheckLoS(Spawn* target);
  988. bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc);
  989. void CalculateNewFearpoint();
  990. void StopMoving() {
  991. if (movement_locations)
  992. movement_locations->clear();
  993. }
  994. int16 pos_packet_size;
  995. int16 info_packet_size;
  996. int16 vis_packet_size;
  997. enum SpawnProximityType {
  998. SPAWNPROXIMITY_DATABASE_ID = 0,
  999. SPAWNPROXIMITY_LOCATION_ID = 1
  1000. };
  1001. struct SpawnProximity {
  1002. float x;
  1003. float y;
  1004. float z;
  1005. int32 spawn_value;
  1006. int8 spawn_type;
  1007. float distance;
  1008. string in_range_lua_function;
  1009. string leaving_range_lua_function;
  1010. map<int32, bool> spawns_in_proximity;
  1011. };
  1012. void AddSpawnToProximity(int32 spawnValue, SpawnProximityType type);
  1013. void RemoveSpawnFromProximity(int32 spawnValue, SpawnProximityType type);
  1014. SpawnProximity* AddLUASpawnProximity(int32 spawnValue, SpawnProximityType type, float distance, string in_range_function, string leaving_range_function) {
  1015. SpawnProximity* prox = new SpawnProximity;
  1016. prox->spawn_value = spawnValue;
  1017. prox->spawn_type = type;
  1018. prox->distance = distance;
  1019. prox->in_range_lua_function = in_range_function;
  1020. prox->leaving_range_lua_function = leaving_range_function;
  1021. spawn_proximities.Add(prox);
  1022. has_spawn_proximities = true;
  1023. return prox;
  1024. }
  1025. void RemoveSpawnProximities() {
  1026. MutexList<SpawnProximity*>::iterator itr = spawn_proximities.begin();
  1027. while (itr.Next()) {
  1028. safe_delete(itr->value);
  1029. }
  1030. spawn_proximities.clear();
  1031. has_spawn_proximities = false;
  1032. }
  1033. Mutex MCommandMutex;
  1034. bool has_spawn_proximities;
  1035. void SetPickupItemID(int32 itemid)
  1036. {
  1037. pickup_item_id = itemid;
  1038. }
  1039. void SetPickupUniqueItemID(int32 uniqueid)
  1040. {
  1041. pickup_unique_item_id = uniqueid;
  1042. }
  1043. int32 GetPickupItemID() { return pickup_item_id; }
  1044. int32 GetPickupUniqueItemID() { return pickup_unique_item_id; }
  1045. bool IsSoundsDisabled() { return disable_sounds; }
  1046. void SetSoundsDisabled(bool val) { disable_sounds = val; }
  1047. protected:
  1048. bool send_spawn_changes;
  1049. bool invulnerable;
  1050. bool attack_resume_needed;
  1051. bool resume_movement;
  1052. bool movement_interrupted;
  1053. int32 running_timer_begin;
  1054. int32 running_timer_end;
  1055. vector<MovementData*> movement_loop;
  1056. bool running_timer_updated;
  1057. int16 movement_index;
  1058. int32 last_grid_update;
  1059. int32 movement_start_time;
  1060. Mutex MMovementLoop;
  1061. map<int32, int8> allowed_access;
  1062. vector<int32> quest_ids;
  1063. int32 database_id;
  1064. int32 packet_num;
  1065. int32 target;
  1066. int8 spawn_type;
  1067. int32 last_attacker;
  1068. int32 merchant_id;
  1069. int8 merchant_type;
  1070. int32 merchant_min_level;
  1071. int32 merchant_max_level;
  1072. int32 transporter_id;
  1073. int32 pickup_item_id;
  1074. int32 pickup_unique_item_id;
  1075. map<int32, vector<int16>* > required_quests;
  1076. map<int32, LUAHistory> required_history;
  1077. EquipmentItemList equipment_list;
  1078. MutexList<SpawnProximity*> spawn_proximities;
  1079. void CheckProximities();
  1080. private:
  1081. vector<Item*> loot_items;
  1082. int32 loot_coins;
  1083. bool trap_triggered;
  1084. deque<MovementLocation*>* movement_locations;
  1085. Mutex MLootItems;
  1086. Mutex* MMovementLocations;
  1087. Mutex* MSpawnGroup;
  1088. int8 size_offset;
  1089. int tmp_visual_state;
  1090. int tmp_action_state;
  1091. int32 running_to;
  1092. string spawn_script;
  1093. static int32 next_id;
  1094. ZoneServer* zone;
  1095. int32 spawn_location_id;
  1096. int32 spawn_entry_id;
  1097. int32 spawn_location_spawns_id;
  1098. int32 respawn;
  1099. int32 expire_time;
  1100. int32 expire_offset;
  1101. float x_offset;
  1102. float y_offset;
  1103. float z_offset;
  1104. int32 deviation;
  1105. BasicInfoStruct basic_info;
  1106. //string data;
  1107. bool is_pet;
  1108. // m_followTarget = spawn to follow around
  1109. int32 m_followTarget;
  1110. int32 m_followDistance;
  1111. bool req_quests_private;
  1112. int16 req_quests_override;
  1113. bool req_quests_continued_access;
  1114. float last_heading_angle;
  1115. map<string, int8> m_tempVariableTypes;
  1116. map<string, int32> m_tempVariableSpawn;
  1117. map<string, ZoneServer*> m_tempVariableZone;
  1118. map<string, Item*> m_tempVariableItem;
  1119. map<string, Quest*> m_tempVariableQuest;
  1120. // m_tempVariables = stores user defined variables from lua, will not persist through a zone
  1121. map<string, string> m_tempVariables;
  1122. int16 m_illusionModel;
  1123. int32 m_spawnAnim;
  1124. int32 m_addedToWorldTimestamp;
  1125. int16 m_spawnAnimLeeway;
  1126. Mutex m_Update;
  1127. bool disable_sounds;
  1128. };
  1129. #endif