Spawn.h 34 KB

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