9
3

Spawn.h 43 KB

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