9
3

Spawn.h 43 KB

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