Spawn.h 33 KB

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