Spawn.h 41 KB

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