Spawn.h 38 KB

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