Spawn.h 44 KB

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