Spawn.h 45 KB

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