Spawn.h 44 KB

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