Spawn.h 48 KB

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