Spawn.h 45 KB

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