Spawn.h 41 KB

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