9
3

Spawn.h 38 KB

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