Spawn.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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 "SpawnLists.h"
  26. #include <vector>
  27. #include "../common/ConfigReader.h"
  28. #include "Items/Items.h"
  29. #include "../common/Mutex.h"
  30. #include <deque>
  31. #define DAMAGE_PACKET_TYPE_SIPHON_SPELL 0x41
  32. #define DAMAGE_PACKET_TYPE_SIPHON_SPELL2 0x49
  33. #define DAMAGE_PACKET_TYPE_MULTIPLE_DAMAGE 0x80
  34. #define DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE 0xC0
  35. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE 0xC1
  36. #define DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG 0xC4
  37. #define DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG 0xC5
  38. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE2 0xC8
  39. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE3 0xC9
  40. #define DAMAGE_PACKET_TYPE_RANGE_DAMAGE 0xE2
  41. #define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG 0xE3
  42. #define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG2 0xEA
  43. #define DAMAGE_PACKET_RESULT_NO_DAMAGE 0
  44. #define DAMAGE_PACKET_RESULT_SUCCESSFUL 1
  45. #define DAMAGE_PACKET_RESULT_MISS 4
  46. #define DAMAGE_PACKET_RESULT_DODGE 8
  47. #define DAMAGE_PACKET_RESULT_PARRY 12
  48. #define DAMAGE_PACKET_RESULT_RIPOSTE 16
  49. #define DAMAGE_PACKET_RESULT_BLOCK 20
  50. #define DAMAGE_PACKET_RESULT_DEATH_BLOW 24
  51. #define DAMAGE_PACKET_RESULT_INVULNERABLE 28
  52. #define DAMAGE_PACKET_RESULT_RESIST 36
  53. #define DAMAGE_PACKET_RESULT_REFLECT 40
  54. #define DAMAGE_PACKET_RESULT_IMMUNE 44
  55. #define DAMAGE_PACKET_RESULT_DEFLECT 48
  56. #define DAMAGE_PACKET_RESULT_COUNTER 52
  57. #define DAMAGE_PACKET_RESULT_COUNTER_STRIKE 60
  58. #define DAMAGE_PACKET_RESULT_BASH 64
  59. #define DAMAGE_PACKET_DAMAGE_TYPE_SLASH 0
  60. #define DAMAGE_PACKET_DAMAGE_TYPE_CRUSH 1
  61. #define DAMAGE_PACKET_DAMAGE_TYPE_PIERCE 2
  62. #define DAMAGE_PACKET_DAMAGE_TYPE_HEAT 3
  63. #define DAMAGE_PACKET_DAMAGE_TYPE_COLD 4
  64. #define DAMAGE_PACKET_DAMAGE_TYPE_MAGIC 5
  65. #define DAMAGE_PACKET_DAMAGE_TYPE_MENTAL 6
  66. #define DAMAGE_PACKET_DAMAGE_TYPE_DIVINE 7
  67. #define DAMAGE_PACKET_DAMAGE_TYPE_DISEASE 8
  68. #define DAMAGE_PACKET_DAMAGE_TYPE_POISON 9
  69. #define DAMAGE_PACKET_DAMAGE_TYPE_DROWN 10
  70. #define DAMAGE_PACKET_DAMAGE_TYPE_FALLING 11
  71. #define DAMAGE_PACKET_DAMAGE_TYPE_PAIN 12
  72. #define HEAL_PACKET_TYPE_SIMPLE_HEAL 0
  73. #define HEAL_PACKET_TYPE_CRIT_HEAL 1
  74. #define HEAL_PACKET_TYPE_ABSORB 2
  75. #define HEAL_PACKET_TYPE_REGEN_ABSORB 4
  76. #define HEAL_PACKET_TYPE_SIMPLE_MANA 8
  77. #define HEAL_PACKET_TYPE_CRIT_MANA 9
  78. #define HEAL_PACKET_TYPE_SAVAGERY 16
  79. #define HEAL_PACKET_TYPE_CRIT_SAVAGERY 17
  80. #define HEAL_PACKET_TYPE_REPAIR 64
  81. #define HEAL_PACKET_TYPE_CRIT_REPAIR 65
  82. #define ARROW_COLOR_GRAY 0 // 3
  83. #define ARROW_COLOR_GREEN 1 // 1
  84. #define ARROW_COLOR_BLUE 2
  85. #define ARROW_COLOR_WHITE 3 // 3
  86. #define ARROW_COLOR_YELLOW 4 // 4
  87. #define ARROW_COLOR_ORANGE 5 // 5
  88. #define ARROW_COLOR_RED 6
  89. #define ACTIVITY_STATUS_ROLEPLAYING 1
  90. #define ACTIVITY_STATUS_ANONYMOUS 2
  91. #define ACTIVITY_STATUS_LINKDEAD 4
  92. #define ACTIVITY_STATUS_CAMPING 8
  93. #define ACTIVITY_STATUS_LFG 16
  94. #define ACTIVITY_STATUS_LFW 32
  95. #define ACTIVITY_STATUS_SOLID 64 //used by zone objects to remain solid
  96. #define ACTIVITY_STATUS_IMMUNITY_GAINED 8192
  97. #define ACTIVITY_STATUS_IMMUNITY_REMAINING 16384
  98. #define ACTIVITY_STATUS_AFK_1188 1
  99. #define ACTIVITY_STATUS_ROLEPLAYING_1188 2
  100. #define ACTIVITY_STATUS_ANONYMOUS_1188 4
  101. #define ACTIVITY_STATUS_LINKDEAD_1188 8
  102. #define ACTIVITY_STATUS_CAMPING_1188 16
  103. #define ACTIVITY_STATUS_LFG_1188 32
  104. #define ACTIVITY_STATUS_LFW_1188 64
  105. #define ACTIVITY_STATUS_SOLID_1188 128 //used by zone objects to remain solid
  106. #define ACTIVITY_STATUS_MENTORING_1188 4096
  107. #define ACTIVITY_STATUS_IMMUNITY_GAINED_1188 16384
  108. #define ACTIVITY_STATUS_IMMUNITY_REMAINING_1188 32768
  109. #define POS_STATE_KNEELING 64
  110. #define POS_STATE_SOLID 128 //used by most mobs to remaind solid (cant walk through them)
  111. #define POS_STATE_NOTARGET_CURSOR 256 //cant target and no cursor is displayed
  112. #define POS_STATE_CROUCHING 512
  113. #define MERCHANT_TYPE_NO_BUY 1
  114. #define MERCHANT_TYPE_NO_BUY_BACK 2
  115. #define MERCHANT_TYPE_SPELLS 4
  116. #define MERCHANT_TYPE_CRAFTING 8
  117. #define MERCHANT_TYPE_REPAIR 16
  118. #define MERCHANT_TYPE_LOTTO 32
  119. #define INFO_VIS_FLAG_INVIS 1
  120. #define INFO_VIS_FLAG_HIDE_HOOD 2
  121. #define INFO_VIS_FLAG_MOUNTED 4
  122. #define INFO_VIS_FLAG_CROUCH 8
  123. using namespace std;
  124. class Spell;
  125. class ZoneServer;
  126. class Quest;
  127. struct LUAHistory;
  128. struct Cell;
  129. struct CellInfo {
  130. Cell* CurrentCell;
  131. int CellListIndex;
  132. };
  133. struct MovementData{
  134. float x;
  135. float y;
  136. float z;
  137. float speed;
  138. int32 delay;
  139. string lua_function;
  140. };
  141. struct BasicInfoStruct{
  142. sint32 cur_hp;
  143. sint32 max_hp;
  144. sint32 hp_base;
  145. sint32 cur_power;
  146. sint32 max_power;
  147. sint32 power_base;
  148. sint32 cur_savagery;
  149. sint32 max_savagery;
  150. sint32 savagery_base;
  151. sint32 cur_dissonance;
  152. sint32 max_dissonance;
  153. sint32 dissonance_base;
  154. sint16 assigned_aa;
  155. sint16 unassigned_aa;
  156. sint16 tradeskill_aa;
  157. sint16 unassigned_tradeskill_aa;
  158. sint16 prestige_aa;
  159. sint16 unassigned_prestige_aa;
  160. sint16 tradeskill_prestige_aa;
  161. sint16 unassigned_tradeskill_prestige_aa;
  162. };
  163. struct MovementLocation{
  164. float x;
  165. float y;
  166. float z;
  167. float speed;
  168. //int32 start_time;
  169. //int32 end_time;
  170. bool attackable;
  171. string lua_function;
  172. };
  173. class Spawn {
  174. public:
  175. Spawn();
  176. virtual ~Spawn();
  177. template <class Field, class Value> void Set(Field* field, Value value, bool setUpdateFlags = true){
  178. if (setUpdateFlags) {
  179. changed = true;
  180. AddChangedZoneSpawn();
  181. }
  182. *field = value;
  183. }
  184. template <class Field> void Set(Field* field, const char* value, bool setUpdateFlags = true){
  185. if (setUpdateFlags) {
  186. changed = true;
  187. AddChangedZoneSpawn();
  188. }
  189. strcpy(field, value);
  190. }
  191. template <class Field, class Value> void SetPos(Field* field, Value value, bool setUpdateFlags = true){
  192. if(setUpdateFlags){
  193. position_changed = true;
  194. }
  195. Set(field, value, setUpdateFlags);
  196. }
  197. template <class Field, class Value> void SetInfo(Field* field, Value value, bool setUpdateFlags = true){
  198. if(setUpdateFlags){
  199. info_changed = true;
  200. }
  201. Set(field, value);
  202. }
  203. template <class Field, class Value> void SetVis(Field* field, Value value, bool setUpdateFlags = true){
  204. if(setUpdateFlags)
  205. vis_changed = true;
  206. Set(field, value);
  207. }
  208. template <class Field> void SetPos(Field* field, char* value, bool setUpdateFlags = true){
  209. if(setUpdateFlags){
  210. position_changed = true;
  211. }
  212. Set(field, value, setUpdateFlags);
  213. }
  214. template <class Field> void SetInfo(Field* field, char* value, bool setUpdateFlags = true){
  215. if(setUpdateFlags){
  216. info_changed = true;
  217. }
  218. Set(field, value);
  219. }
  220. EntityCommand* CreateEntityCommand(EntityCommand* old_command){
  221. EntityCommand* entity_command = new EntityCommand;
  222. entity_command->name = old_command->name;
  223. entity_command->distance = old_command->distance;
  224. entity_command->command = old_command->command;
  225. entity_command->error_text = old_command->error_text;
  226. entity_command->cast_time = old_command->cast_time;
  227. entity_command->spell_visual = old_command->spell_visual;
  228. return entity_command;
  229. }
  230. EntityCommand* CreateEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  231. EntityCommand* entity_command = new EntityCommand;
  232. entity_command->name = name;
  233. entity_command->distance = distance;
  234. entity_command->command = command;
  235. entity_command->error_text = error_text;
  236. entity_command->cast_time = cast_time;
  237. entity_command->spell_visual = spell_visual;
  238. return entity_command;
  239. }
  240. void AddChangedZoneSpawn();
  241. void AddPrimaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  242. primary_command_list.push_back(CreateEntityCommand(name, distance, command, error_text, cast_time, spell_visual));
  243. }
  244. void AddSecondaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  245. secondary_command_list.push_back(CreateEntityCommand(name, distance, command, error_text, cast_time, spell_visual));
  246. }
  247. int8 GetLockedNoLoot(){
  248. return appearance.locked_no_loot;
  249. }
  250. int16 GetEmoteState(){
  251. return appearance.emote_state;
  252. }
  253. int8 GetHideHood(){
  254. return appearance.hide_hood;
  255. }
  256. void SetLockedNoLoot(int8 new_val, bool updateFlags = true){
  257. SetVis(&appearance.locked_no_loot, new_val, updateFlags);
  258. }
  259. void SetHandFlag(int8 new_val, bool updateFlags = true){
  260. SetVis(&appearance.display_hand_icon, new_val, updateFlags);
  261. }
  262. void SetHideHood(int8 new_val, bool updateFlags = true){
  263. SetInfo(&appearance.hide_hood, new_val, updateFlags);
  264. }
  265. void SetEmoteState(int8 new_val, bool updateFlags = true){
  266. SetInfo(&appearance.emote_state, new_val, updateFlags);
  267. }
  268. void SetName(const char* new_name, bool updateFlags = true){
  269. SetInfo(appearance.name, new_name, updateFlags);
  270. }
  271. void SetPrefixTitle(const char* new_prefix_title, bool updateFlags = true) {
  272. SetInfo(appearance.prefix_title, new_prefix_title, updateFlags);
  273. }
  274. void SetSuffixTitle(const char* new_suffix_title, bool updateFlags = true) {
  275. SetInfo(appearance.suffix_title, new_suffix_title, updateFlags);
  276. }
  277. void SetSubTitle(const char* new_sub_title, bool updateFlags = true) {
  278. SetInfo(appearance.sub_title, new_sub_title, updateFlags);
  279. }
  280. void SetLastName(const char* new_last_name, bool updateFlags = true) {
  281. SetInfo(appearance.last_name, new_last_name, updateFlags);
  282. }
  283. void SetAdventureClass(int8 new_class, bool updateFlags = true) {
  284. SetInfo(&appearance.adventure_class, new_class, updateFlags);
  285. }
  286. void SetTradeskillClass(int8 new_class, bool updateFlags = true) {
  287. SetInfo(&appearance.tradeskill_class, new_class, updateFlags);
  288. }
  289. void SetSize(int16 new_size, bool updateFlags = true) {
  290. SetPos(&size, new_size, updateFlags);
  291. }
  292. void SetSpeedX(float speed_x, bool updateFlags = true) {
  293. SetPos(&appearance.pos.SpeedX, speed_x, updateFlags);
  294. }
  295. void SetSpeedY(float speed_y, bool updateFlags = true) {
  296. SetPos(&appearance.pos.SpeedY, speed_y, updateFlags);
  297. }
  298. void SetSpeedZ(float speed_z, bool updateFlags = true) {
  299. SetPos(&appearance.pos.SpeedZ, speed_z, updateFlags);
  300. }
  301. void SetX(float x, bool updateFlags = true){
  302. SetPos(&appearance.pos.X, x, updateFlags);
  303. }
  304. void SetY(float y, bool updateFlags = true){
  305. SetPos(&appearance.pos.Y, y, updateFlags);
  306. }
  307. void SetZ(float z, bool updateFlags = true){
  308. SetPos(&appearance.pos.Z, z, updateFlags);
  309. }
  310. void SetHeading(sint16 dir1, sint16 dir2, bool updateFlags = true){
  311. SetPos(&appearance.pos.Dir1, dir1, updateFlags);
  312. SetPos(&appearance.pos.Dir2, dir2, updateFlags);
  313. }
  314. void SetHeading(float heading, bool updateFlags = true){
  315. last_heading_angle = heading;
  316. if (heading != 180)
  317. heading = (heading - 180) * 64;
  318. SetPos(&appearance.pos.Dir1, (sint16)heading, updateFlags);
  319. SetPos(&appearance.pos.Dir2, (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(Spawn* spawn, bool ignore_y = false);
  573. float GetDistance(float x, float y, float z, bool ignore_y = false);
  574. float GetDistance(float x1, float y1, float z1, float x2, float y2, float z2);
  575. int8 GetEncounterLevel(){
  576. return appearance.encounter_level;
  577. }
  578. sint32 GetTotalPower();
  579. sint32 GetPower();
  580. sint32 GetTotalHP();
  581. sint32 GetHP();
  582. sint32 GetTotalHPBase();
  583. sint32 GetTotalPowerBase();
  584. sint32 GetTotalSavagery();
  585. sint32 GetSavagery();
  586. sint32 GetTotalDissonance();
  587. sint32 GetDissonance();
  588. sint32 GetTotalSavageryBase();
  589. sint32 GetTotalDissonanceBase();
  590. sint16 GetAssignedAA();
  591. sint16 GetUnassignedAA();
  592. sint16 GetTradeskillAA();
  593. sint16 GetUnassignedTradeskillAA();
  594. sint16 GetPrestigeAA();
  595. sint16 GetUnassignedPretigeAA();
  596. sint16 GetTradeskillPrestigeAA();
  597. sint16 GetUnassignedTradeskillPrestigeAA();
  598. void SetTotalPower(sint32 new_val);
  599. void SetTotalHP(sint32 new_val);
  600. void SetTotalSavagery(sint32 new_val);
  601. void SetTotalDissonance(sint32 new_val);
  602. void SetTotalPowerBase(sint32 new_val);
  603. void SetTotalHPBase(sint32 new_val);
  604. void SetTotalSavageryBase(sint32 new_val);
  605. void SetTotalDissonanceBase(sint32 new_val);
  606. void SetPower(sint32 power, bool setUpdateFlags = true);
  607. void SetHP(sint32 new_val, bool setUpdateFlags = true);
  608. void SetSavagery(sint32 savagery, bool setUpdateFlags = true);
  609. void SetDissonance(sint32 dissonance, bool setUpdateFlags = true);
  610. void SetAssignedAA(sint16 new_val);
  611. void SetUnassignedAA(sint16 new_val);
  612. void SetTradeskillAA(sint16 new_val);
  613. void SetUnassignedTradeskillAA(sint16 new_val);
  614. void SetPrestigeAA(sint16 new_val);
  615. void SetUnassignedPrestigeAA(sint16 new_val);
  616. void SetTradeskillPrestigeAA(sint16 new_val);
  617. void SetUnassignedTradeskillPrestigeAA(sint16 new_val);
  618. void SetPrivateQuestSpawn(bool val) {req_quests_private = val;}
  619. void SetQuestsRequiredOverride(int16 val) {req_quests_override = val;}
  620. void SetQuestsRequiredContinuedAccess(bool val) {req_quests_continued_access = val;}
  621. bool GetPrivateQuestSpawn() {return req_quests_private;}
  622. int16 GetQuestsRequiredOverride() {return req_quests_override;}
  623. bool GetQuestsRequiredContinuedAccess() {return req_quests_continued_access;}
  624. bool Alive(){ return GetHP() > 0; }
  625. int16 GetLevel(){
  626. return appearance.level;
  627. }
  628. int16 GetTSLevel(){
  629. return appearance.tradeskill_level;
  630. }
  631. int8 GetGender(){
  632. return appearance.gender;
  633. }
  634. int8 GetRace(){
  635. return appearance.race;
  636. }
  637. int8 GetLuaRaceId() {
  638. return appearance.lua_race_id;
  639. }
  640. int32 GetSize(){
  641. return size;
  642. }
  643. int32 GetDeviation(){
  644. return deviation;
  645. }
  646. void SetDeviation(int32 in_dev){
  647. deviation = in_dev;
  648. }
  649. float GetSpawnOrigHeading(){
  650. return appearance.pos.SpawnOrigHeading;
  651. }
  652. void SetSpawnOrigHeading(float val){
  653. appearance.pos.SpawnOrigHeading = val;
  654. }
  655. float GetSpawnOrigX(){
  656. return appearance.pos.SpawnOrigX;
  657. }
  658. float GetSpawnOrigY(){
  659. return appearance.pos.SpawnOrigY;
  660. }
  661. float GetSpawnOrigZ(){
  662. return appearance.pos.SpawnOrigZ;
  663. }
  664. float GetSpawnOrigPitch(){
  665. return appearance.pos.SpawnOrigPitch;
  666. }
  667. float GetSpawnOrigRoll(){
  668. return appearance.pos.SpawnOrigRoll;
  669. }
  670. void SetSpawnOrigX(float val){
  671. appearance.pos.SpawnOrigX = val;
  672. }
  673. void SetSpawnOrigY(float val){
  674. appearance.pos.SpawnOrigY = val;
  675. }
  676. void SetSpawnOrigZ(float val){
  677. appearance.pos.SpawnOrigZ = val;
  678. }
  679. void SetSpawnOrigRoll(float val){
  680. appearance.pos.SpawnOrigRoll = val;
  681. }
  682. void SetSpawnOrigPitch(float val){
  683. appearance.pos.SpawnOrigPitch = val;
  684. }
  685. void SetSogaModelType(int16 new_val, bool setUpdateFlags = true){
  686. SetInfo(&appearance.soga_model_type, new_val, setUpdateFlags);
  687. }
  688. void SetModelType(int16 model_type, bool setUpdateFlags = true){
  689. SetInfo(&appearance.model_type, model_type, setUpdateFlags);
  690. SetInfo(&appearance.soga_model_type, model_type, setUpdateFlags);
  691. }
  692. int16 GetSogaModelType(){
  693. return appearance.soga_model_type;
  694. }
  695. int16 GetModelType(){
  696. return appearance.model_type;
  697. }
  698. void SetPrimaryCommand(const char* name, const char* command, float distance = 10);
  699. void SetPrimaryCommands(vector<EntityCommand*>* commands);
  700. void SetSecondaryCommands(vector<EntityCommand*>* commands);
  701. vector<EntityCommand*>* GetPrimaryCommands() {return &primary_command_list;}
  702. vector<EntityCommand*>* GetSecondaryCommands() {return &secondary_command_list;}
  703. EntityCommand* FindEntityCommand(string command);
  704. virtual EQ2Packet* serialize(Player* player, int16 version);
  705. EQ2Packet* spawn_serialize(Player* player, int16 version);
  706. EQ2Packet* spawn_update_packet(Player* player, int16 version, bool override_changes = false, bool override_vis_changes = false);
  707. EQ2Packet* player_position_update_packet(Player* player, int16 version);
  708. uchar* spawn_info_changes(Player* spawn, int16 version);
  709. uchar* spawn_pos_changes(Player* spawn, int16 version);
  710. uchar* spawn_vis_changes(Player* spawn, int16 version);
  711. virtual bool EngagedInCombat(){ return false; }
  712. virtual bool IsObject(){ return false; }
  713. virtual bool IsGroundSpawn(){ return false; }
  714. virtual bool IsNPC(){ return false; }
  715. virtual bool IsEntity(){ return false; }
  716. virtual bool IsPlayer(){ return false; }
  717. virtual bool IsWidget(){ return false; }
  718. virtual bool IsSign(){ return false; }
  719. virtual bool IsBot() { return false; }
  720. bool HasInfoChanged(){ return info_changed; }
  721. bool HasPositionChanged(){ return position_changed; }
  722. bool HasTarget(){ return target ? true : false; }
  723. int32 GetRespawnTime();
  724. void SetRespawnTime(int32 time);
  725. int32 GetExpireTime() { return expire_time; }
  726. void SetExpireTime(int32 new_expire_time) { expire_time = new_expire_time; }
  727. int32 GetExpireOffsetTime();
  728. void SetExpireOffsetTime(int32 time);
  729. int32 GetSpawnLocationID();
  730. void SetSpawnLocationID(int32 id);
  731. int32 GetSpawnEntryID();
  732. void SetSpawnEntryID(int32 id);
  733. int32 GetSpawnLocationPlacementID();
  734. void SetSpawnLocationPlacementID(int32 id);
  735. float GetXOffset() { return x_offset; }
  736. void SetXOffset(float new_x_offset) { x_offset = new_x_offset; }
  737. float GetYOffset() { return y_offset; }
  738. void SetYOffset(float new_y_offset) { y_offset = new_y_offset; }
  739. float GetZOffset() { return z_offset; }
  740. void SetZOffset(float new_z_offset) { z_offset = new_z_offset; }
  741. Spawn* GetTarget();
  742. void SetTarget(Spawn* spawn);
  743. Spawn* GetLastAttacker();
  744. void SetLastAttacker(Spawn* spawn);
  745. bool TakeDamage(int32 damage);
  746. void TakeDamage(Spawn* attacker, int32 damage);
  747. ZoneServer* GetZone();
  748. virtual void SetZone(ZoneServer* in_zone);
  749. void SetFactionID(int32 val) { faction_id = val; }
  750. int32 GetFactionID(){
  751. return faction_id;
  752. }
  753. static int32 NextID() {
  754. static CriticalSection id_lock;
  755. id_lock.lock();
  756. int32 ret = ++next_id;
  757. if (next_id == 0xFFFFFFFE)
  758. next_id = 1;
  759. else if ((next_id - 255) % 256 == 0) { //we dont want it to end in 255, it will confuse/crash the client
  760. id_lock.unlock();
  761. return NextID();
  762. }
  763. id_lock.unlock();
  764. return ret;
  765. }
  766. void AddProvidedQuest(int32 val){
  767. quest_ids.push_back(val);
  768. }
  769. vector<int32>* GetProvidedQuests(){
  770. return &quest_ids;
  771. }
  772. bool HasProvidedQuests(){
  773. return (quest_ids.size() > 0);
  774. }
  775. void SetSpawnScript(string name);
  776. const char* GetSpawnScript();
  777. vector<Spawn*>* GetSpawnGroup();
  778. bool HasSpawnGroup();
  779. bool IsInSpawnGroup(Spawn* spawn);
  780. void SendSpawnChanges(bool val){ send_spawn_changes = val; }
  781. void SetSpawnGroupID(int32 id);
  782. int32 GetSpawnGroupID();
  783. void AddSpawnToGroup(Spawn* spawn);
  784. void SetSpawnGroupList(vector<Spawn*>* list, Mutex* mutex);
  785. void RemoveSpawnFromGroup(bool erase_all = false);
  786. void SetRunningTo(Spawn* spawn){ running_to = spawn->GetID(); }
  787. Spawn* GetRunningTo();
  788. void SetTempVisualState(int val, bool update = true) { SetInfo(&tmp_visual_state, val, update); }
  789. int GetTempVisualState(){ return tmp_visual_state; }
  790. void SetTempActionState(int val, bool update = true) { SetInfo(&tmp_action_state, val, update); }
  791. int GetTempActionState(){ return tmp_action_state; }
  792. void AddAllowAccessSpawn(Spawn* spawn){ allowed_access[spawn->GetID()] = 1; }
  793. void RemoveSpawnAccess(Spawn* spawn);
  794. bool IsPrivateSpawn(){ return allowed_access.size() > 0 ;}
  795. bool AllowedAccess(Spawn* spawn){ return allowed_access.count(spawn->GetID()) > 0; }
  796. void MakeSpawnPublic() { allowed_access.clear(); }
  797. void SetSizeOffset(int8 offset);
  798. int8 GetSizeOffset();
  799. void SetMerchantID(int32 val);
  800. int32 GetMerchantID();
  801. void SetMerchantType(int8 val);
  802. int8 GetMerchantType();
  803. void SetQuestsRequired(map<int32, vector<int16>* >* quests);
  804. void SetQuestsRequired(int32 quest_id, int16 quest_step);
  805. void SetRequiredHistory(int32 event_id, int32 value1, int32 value2);
  806. map<int32, vector<int16>* >* GetQuestsRequired();
  807. void SetTransporterID(int32 id);
  808. int32 GetTransporterID();
  809. bool MeetsSpawnAccessRequirements(Player* player);
  810. void InitializePosPacketData(Player* player, PacketStruct* packet);
  811. void InitializeInfoPacketData(Player* player, PacketStruct* packet);
  812. void InitializeVisPacketData(Player* player, PacketStruct* packet);
  813. void InitializeHeaderPacketData(Player* player, PacketStruct* packet, int16 index);
  814. void InitializeFooterPacketData(Player* player, PacketStruct* packet);
  815. void MoveToLocation(Spawn* spawn, float distance, bool immediate = true);
  816. void AddMovementLocation(float x, float y, float z, float speed, int16 delay, const char* lua_function);
  817. void ProcessMovement();
  818. void ResetMovement();
  819. bool IsRunning();
  820. void CalculateRunningLocation(bool stop = false);
  821. void RunToLocation(float x, float y, float z, float following_x = 0, float following_y = 0, float following_z = 0);
  822. MovementLocation* GetCurrentRunningLocation();
  823. MovementLocation* GetLastRunningLocation();
  824. bool CalculateChange();
  825. 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 = "");
  826. bool RemoveRunningLocation();
  827. void ClearRunningLocations();
  828. void CopySpawnAppearance(Spawn* spawn);
  829. bool MovementInterrupted(){ return movement_interrupted; }
  830. void MovementInterrupted(bool val) { movement_interrupted = val; }
  831. bool NeedsToResumeMovement(){ return attack_resume_needed; }
  832. void NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
  833. bool HasMovementLoop(){ return movement_loop.size() > 0; }
  834. Timer* GetRunningTimer();
  835. void FaceTarget(float x, float z);
  836. void FaceTarget(Spawn* target);
  837. void SetInvulnerable(bool val);
  838. bool GetInvulnerable();
  839. bool changed;
  840. bool position_changed;
  841. bool info_changed;
  842. bool vis_changed;
  843. int16 size;
  844. int32 faction_id;
  845. int8 oversized_packet; //0xff
  846. int16 opcode;
  847. int32 id;
  848. int8 unknown1;
  849. int32 unknown2;
  850. int32 primary_command_list_id;
  851. int32 secondary_command_list_id;
  852. vector<EntityCommand*> primary_command_list;
  853. vector<EntityCommand*> secondary_command_list;
  854. int32 group_id;
  855. int8 group_len;
  856. vector<Spawn*>* spawn_group_list;
  857. AppearanceData appearance;
  858. int32 last_movement_update;
  859. bool following;
  860. bool IsPet() { return is_pet; }
  861. void SetPet(bool val) { is_pet = val; }
  862. Mutex m_requiredQuests;
  863. Mutex m_requiredHistory;
  864. void SetFollowTarget(Spawn* spawn);
  865. Spawn* GetFollowTarget();
  866. /// <summary>Sets a user defined variable</summary>
  867. /// <param name='var'>Variable we are setting</param>
  868. /// <param name='val'>Value to set the variable to</param>
  869. void AddTempVariable(string var, string val);
  870. void AddTempVariable(string var, Spawn* val);
  871. void AddTempVariable(string var, ZoneServer* val);
  872. void AddTempVariable(string var, Quest* val);
  873. void AddTempVariable(string var, Item* val);
  874. /// <summary>Gets the value for the given variable</summary>
  875. /// <param name='var'>Variable to check</param>
  876. /// <returns>The value for the given variable, "" if variable was not set</returns>
  877. string GetTempVariable(string var);
  878. Spawn* GetTempVariableSpawn(string var);
  879. ZoneServer* GetTempVariableZone(string var);
  880. Item* GetTempVariableItem(string var);
  881. Quest* GetTempVariableQuest(string var);
  882. int8 GetTempVariableType(string var);
  883. void DeleteTempVariable(string var);
  884. void SetIllusionModel(int16 val, bool setUpdateFlags = true) {
  885. SetInfo(&m_illusionModel, val, setUpdateFlags);
  886. }
  887. int16 GetIllusionModel() { return m_illusionModel; }
  888. CellInfo Cell_Info;
  889. int32 GetSpawnAnim() { return m_spawnAnim; }
  890. void SetSpawnAnim(int32 value) { m_spawnAnim = value; }
  891. int32 GetAddedToWorldTimestamp() { return m_addedToWorldTimestamp; }
  892. void SetAddedToWorldTimestamp(int32 value) { m_addedToWorldTimestamp = value; }
  893. int16 GetSpawnAnimLeeway() { return m_spawnAnimLeeway; }
  894. void SetSpawnAnimLeeway(int16 value) { m_spawnAnimLeeway = value; }
  895. protected:
  896. bool send_spawn_changes;
  897. bool invulnerable;
  898. bool attack_resume_needed;
  899. bool resume_movement;
  900. bool movement_interrupted;
  901. int32 running_timer_begin;
  902. int32 running_timer_end;
  903. vector<MovementData*> movement_loop;
  904. bool running_timer_updated;
  905. int16 movement_index;
  906. int32 movement_start_time;
  907. Mutex MMovementLoop;
  908. map<int32, int8> allowed_access;
  909. vector<int32> quest_ids;
  910. int32 database_id;
  911. int32 packet_num;
  912. int32 target;
  913. int8 spawn_type;
  914. int32 last_attacker;
  915. int32 merchant_id;
  916. int8 merchant_type;
  917. int32 transporter_id;
  918. map<int32, vector<int16>* > required_quests;
  919. map<int32, LUAHistory> required_history;
  920. EquipmentItemList equipment_list;
  921. private:
  922. deque<MovementLocation*>* movement_locations;
  923. Mutex* MMovementLocations;
  924. Mutex* MSpawnGroup;
  925. int8 size_offset;
  926. int tmp_visual_state;
  927. int tmp_action_state;
  928. int32 running_to;
  929. string spawn_script;
  930. static int32 next_id;
  931. ZoneServer* zone;
  932. int32 spawn_location_id;
  933. int32 spawn_entry_id;
  934. int32 spawn_location_spawns_id;
  935. int32 respawn;
  936. int32 expire_time;
  937. int32 expire_offset;
  938. float x_offset;
  939. float y_offset;
  940. float z_offset;
  941. int32 deviation;
  942. BasicInfoStruct basic_info;
  943. //string data;
  944. bool is_pet;
  945. // m_followTarget = spawn to follow around
  946. int32 m_followTarget;
  947. bool req_quests_private;
  948. int16 req_quests_override;
  949. bool req_quests_continued_access;
  950. float last_heading_angle;
  951. map<string, int8> m_tempVariableTypes;
  952. map<string, int32> m_tempVariableSpawn;
  953. map<string, ZoneServer*> m_tempVariableZone;
  954. map<string, Item*> m_tempVariableItem;
  955. map<string, Quest*> m_tempVariableQuest;
  956. // m_tempVariables = stores user defined variables from lua, will not persist through a zone
  957. map<string, string> m_tempVariables;
  958. int16 m_illusionModel;
  959. int32 m_spawnAnim;
  960. int32 m_addedToWorldTimestamp;
  961. int16 m_spawnAnimLeeway;
  962. int16 pos_packet_size;
  963. int16 info_packet_size;
  964. int16 vis_packet_size;
  965. Mutex m_Update;
  966. };
  967. #endif