Spawn.h 40 KB

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