Spawn.h 44 KB

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