Spawn.h 40 KB

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