Spawn.h 33 KB

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