Spawn.h 34 KB

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