Spawn.h 41 KB

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