9
3

Spawn.h 48 KB

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