9
3

Spawn.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  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(Spawn* spawn, bool ignore_y = false);
  572. float GetDistance(float x, float y, float z, bool ignore_y = false);
  573. float GetDistance(float x1, float y1, float z1, float x2, float y2, float z2);
  574. int8 GetEncounterLevel(){
  575. return appearance.encounter_level;
  576. }
  577. sint32 GetTotalPower();
  578. sint32 GetPower();
  579. sint32 GetTotalHP();
  580. sint32 GetHP();
  581. sint32 GetTotalHPBase();
  582. sint32 GetTotalPowerBase();
  583. sint32 GetTotalSavagery();
  584. sint32 GetSavagery();
  585. sint32 GetTotalDissonance();
  586. sint32 GetDissonance();
  587. sint32 GetTotalSavageryBase();
  588. sint32 GetTotalDissonanceBase();
  589. sint16 GetAssignedAA();
  590. sint16 GetUnassignedAA();
  591. sint16 GetTradeskillAA();
  592. sint16 GetUnassignedTradeskillAA();
  593. sint16 GetPrestigeAA();
  594. sint16 GetUnassignedPretigeAA();
  595. sint16 GetTradeskillPrestigeAA();
  596. sint16 GetUnassignedTradeskillPrestigeAA();
  597. void SetTotalPower(sint32 new_val);
  598. void SetTotalHP(sint32 new_val);
  599. void SetTotalSavagery(sint32 new_val);
  600. void SetTotalDissonance(sint32 new_val);
  601. void SetTotalPowerBase(sint32 new_val);
  602. void SetTotalHPBase(sint32 new_val);
  603. void SetTotalSavageryBase(sint32 new_val);
  604. void SetTotalDissonanceBase(sint32 new_val);
  605. void SetPower(sint32 power, bool setUpdateFlags = true);
  606. void SetHP(sint32 new_val, bool setUpdateFlags = true);
  607. void SetSavagery(sint32 savagery, bool setUpdateFlags = true);
  608. void SetDissonance(sint32 dissonance, bool setUpdateFlags = true);
  609. void SetAssignedAA(sint16 new_val);
  610. void SetUnassignedAA(sint16 new_val);
  611. void SetTradeskillAA(sint16 new_val);
  612. void SetUnassignedTradeskillAA(sint16 new_val);
  613. void SetPrestigeAA(sint16 new_val);
  614. void SetUnassignedPrestigeAA(sint16 new_val);
  615. void SetTradeskillPrestigeAA(sint16 new_val);
  616. void SetUnassignedTradeskillPrestigeAA(sint16 new_val);
  617. void SetPrivateQuestSpawn(bool val) {req_quests_private = val;}
  618. void SetQuestsRequiredOverride(int16 val) {req_quests_override = val;}
  619. void SetQuestsRequiredContinuedAccess(bool val) {req_quests_continued_access = val;}
  620. bool GetPrivateQuestSpawn() {return req_quests_private;}
  621. int16 GetQuestsRequiredOverride() {return req_quests_override;}
  622. bool GetQuestsRequiredContinuedAccess() {return req_quests_continued_access;}
  623. bool Alive(){ return GetHP() > 0; }
  624. int16 GetLevel(){
  625. return appearance.level;
  626. }
  627. int16 GetTSLevel(){
  628. return appearance.tradeskill_level;
  629. }
  630. int8 GetGender(){
  631. return appearance.gender;
  632. }
  633. int8 GetRace(){
  634. return appearance.race;
  635. }
  636. int8 GetLuaRaceId() {
  637. return appearance.lua_race_id;
  638. }
  639. int32 GetSize(){
  640. return size;
  641. }
  642. int32 GetDeviation(){
  643. return deviation;
  644. }
  645. void SetDeviation(int32 in_dev){
  646. deviation = in_dev;
  647. }
  648. float GetSpawnOrigHeading(){
  649. return appearance.pos.SpawnOrigHeading;
  650. }
  651. void SetSpawnOrigHeading(float val){
  652. appearance.pos.SpawnOrigHeading = val;
  653. }
  654. float GetSpawnOrigX(){
  655. return appearance.pos.SpawnOrigX;
  656. }
  657. float GetSpawnOrigY(){
  658. return appearance.pos.SpawnOrigY;
  659. }
  660. float GetSpawnOrigZ(){
  661. return appearance.pos.SpawnOrigZ;
  662. }
  663. float GetSpawnOrigPitch(){
  664. return appearance.pos.SpawnOrigPitch;
  665. }
  666. float GetSpawnOrigRoll(){
  667. return appearance.pos.SpawnOrigRoll;
  668. }
  669. void SetSpawnOrigX(float val){
  670. appearance.pos.SpawnOrigX = val;
  671. }
  672. void SetSpawnOrigY(float val){
  673. appearance.pos.SpawnOrigY = val;
  674. }
  675. void SetSpawnOrigZ(float val){
  676. appearance.pos.SpawnOrigZ = val;
  677. }
  678. void SetSpawnOrigRoll(float val){
  679. appearance.pos.SpawnOrigRoll = val;
  680. }
  681. void SetSpawnOrigPitch(float val){
  682. appearance.pos.SpawnOrigPitch = val;
  683. }
  684. void SetSogaModelType(int16 new_val, bool setUpdateFlags = true){
  685. SetInfo(&appearance.soga_model_type, new_val, setUpdateFlags);
  686. }
  687. void SetModelType(int16 model_type, bool setUpdateFlags = true){
  688. SetInfo(&appearance.model_type, model_type, setUpdateFlags);
  689. SetInfo(&appearance.soga_model_type, model_type, setUpdateFlags);
  690. }
  691. int16 GetSogaModelType(){
  692. return appearance.soga_model_type;
  693. }
  694. int16 GetModelType(){
  695. return appearance.model_type;
  696. }
  697. void SetPrimaryCommand(const char* name, const char* command, float distance = 10);
  698. void SetPrimaryCommands(vector<EntityCommand*>* commands);
  699. void SetSecondaryCommands(vector<EntityCommand*>* commands);
  700. vector<EntityCommand*>* GetPrimaryCommands() {return &primary_command_list;}
  701. vector<EntityCommand*>* GetSecondaryCommands() {return &secondary_command_list;}
  702. EntityCommand* FindEntityCommand(string command);
  703. virtual EQ2Packet* serialize(Player* player, int16 version);
  704. EQ2Packet* spawn_serialize(Player* player, int16 version);
  705. EQ2Packet* spawn_update_packet(Player* player, int16 version, bool override_changes = false, bool override_vis_changes = false);
  706. EQ2Packet* player_position_update_packet(Player* player, int16 version);
  707. uchar* spawn_info_changes(Player* spawn, int16 version);
  708. uchar* spawn_pos_changes(Player* spawn, int16 version);
  709. uchar* spawn_vis_changes(Player* spawn, int16 version);
  710. virtual bool EngagedInCombat(){ return false; }
  711. virtual bool IsObject(){ return false; }
  712. virtual bool IsGroundSpawn(){ return false; }
  713. virtual bool IsNPC(){ return false; }
  714. virtual bool IsEntity(){ return false; }
  715. virtual bool IsPlayer(){ return false; }
  716. virtual bool IsWidget(){ return false; }
  717. virtual bool IsSign(){ return false; }
  718. virtual bool IsBot() { return false; }
  719. bool HasInfoChanged(){ return info_changed; }
  720. bool HasPositionChanged(){ return position_changed; }
  721. bool HasTarget(){ return target ? true : false; }
  722. int32 GetRespawnTime();
  723. void SetRespawnTime(int32 time);
  724. int32 GetExpireTime() { return expire_time; }
  725. void SetExpireTime(int32 new_expire_time) { expire_time = new_expire_time; }
  726. int32 GetExpireOffsetTime();
  727. void SetExpireOffsetTime(int32 time);
  728. int32 GetSpawnLocationID();
  729. void SetSpawnLocationID(int32 id);
  730. int32 GetSpawnEntryID();
  731. void SetSpawnEntryID(int32 id);
  732. int32 GetSpawnLocationPlacementID();
  733. void SetSpawnLocationPlacementID(int32 id);
  734. float GetXOffset() { return x_offset; }
  735. void SetXOffset(float new_x_offset) { x_offset = new_x_offset; }
  736. float GetYOffset() { return y_offset; }
  737. void SetYOffset(float new_y_offset) { y_offset = new_y_offset; }
  738. float GetZOffset() { return z_offset; }
  739. void SetZOffset(float new_z_offset) { z_offset = new_z_offset; }
  740. Spawn* GetTarget();
  741. void SetTarget(Spawn* spawn);
  742. Spawn* GetLastAttacker();
  743. void SetLastAttacker(Spawn* spawn);
  744. bool TakeDamage(int32 damage);
  745. void TakeDamage(Spawn* attacker, int32 damage);
  746. ZoneServer* GetZone();
  747. virtual void SetZone(ZoneServer* in_zone);
  748. void SetFactionID(int32 val) { faction_id = val; }
  749. int32 GetFactionID(){
  750. return faction_id;
  751. }
  752. static int32 NextID() {
  753. static CriticalSection id_lock;
  754. id_lock.lock();
  755. int32 ret = ++next_id;
  756. if (next_id == 0xFFFFFFFE)
  757. next_id = 1;
  758. else if ((next_id - 255) % 256 == 0) { //we dont want it to end in 255, it will confuse/crash the client
  759. id_lock.unlock();
  760. return NextID();
  761. }
  762. id_lock.unlock();
  763. return ret;
  764. }
  765. void AddProvidedQuest(int32 val){
  766. quest_ids.push_back(val);
  767. }
  768. vector<int32>* GetProvidedQuests(){
  769. return &quest_ids;
  770. }
  771. bool HasProvidedQuests(){
  772. return (quest_ids.size() > 0);
  773. }
  774. void SetSpawnScript(string name);
  775. const char* GetSpawnScript();
  776. vector<Spawn*>* GetSpawnGroup();
  777. bool HasSpawnGroup();
  778. bool IsInSpawnGroup(Spawn* spawn);
  779. void SendSpawnChanges(bool val){ send_spawn_changes = val; }
  780. void SetSpawnGroupID(int32 id);
  781. int32 GetSpawnGroupID();
  782. void AddSpawnToGroup(Spawn* spawn);
  783. void SetSpawnGroupList(vector<Spawn*>* list, Mutex* mutex);
  784. void RemoveSpawnFromGroup(bool erase_all = false);
  785. void SetRunningTo(Spawn* spawn){ running_to = spawn->GetID(); }
  786. Spawn* GetRunningTo();
  787. void SetTempVisualState(int val, bool update = true) { SetInfo(&tmp_visual_state, val, update); }
  788. int GetTempVisualState(){ return tmp_visual_state; }
  789. void SetTempActionState(int val, bool update = true) { SetInfo(&tmp_action_state, val, update); }
  790. int GetTempActionState(){ return tmp_action_state; }
  791. void AddAllowAccessSpawn(Spawn* spawn){ allowed_access[spawn->GetID()] = 1; }
  792. void RemoveSpawnAccess(Spawn* spawn);
  793. bool IsPrivateSpawn(){ return allowed_access.size() > 0 ;}
  794. bool AllowedAccess(Spawn* spawn){ return allowed_access.count(spawn->GetID()) > 0; }
  795. void MakeSpawnPublic() { allowed_access.clear(); }
  796. void SetSizeOffset(int8 offset);
  797. int8 GetSizeOffset();
  798. void SetMerchantID(int32 val);
  799. int32 GetMerchantID();
  800. void SetMerchantType(int8 val);
  801. int8 GetMerchantType();
  802. void SetQuestsRequired(map<int32, vector<int16>* >* quests);
  803. void SetQuestsRequired(int32 quest_id, int16 quest_step);
  804. void SetRequiredHistory(int32 event_id, int32 value1, int32 value2);
  805. map<int32, vector<int16>* >* GetQuestsRequired();
  806. void SetTransporterID(int32 id);
  807. int32 GetTransporterID();
  808. bool MeetsSpawnAccessRequirements(Player* player);
  809. void InitializePosPacketData(Player* player, PacketStruct* packet, bool bSpawnUpdate = false);
  810. void InitializeInfoPacketData(Player* player, PacketStruct* packet);
  811. void InitializeVisPacketData(Player* player, PacketStruct* packet);
  812. void InitializeHeaderPacketData(Player* player, PacketStruct* packet, int16 index);
  813. void InitializeFooterPacketData(Player* player, PacketStruct* packet);
  814. void MoveToLocation(Spawn* spawn, float distance, bool immediate = true);
  815. void AddMovementLocation(float x, float y, float z, float speed, int16 delay, const char* lua_function);
  816. void ProcessMovement();
  817. void ResetMovement();
  818. bool IsRunning();
  819. void CalculateRunningLocation(bool stop = false);
  820. void RunToLocation(float x, float y, float z, float following_x = 0, float following_y = 0, float following_z = 0);
  821. MovementLocation* GetCurrentRunningLocation();
  822. MovementLocation* GetLastRunningLocation();
  823. bool CalculateChange();
  824. 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 = "");
  825. bool RemoveRunningLocation();
  826. void ClearRunningLocations();
  827. void CopySpawnAppearance(Spawn* spawn);
  828. bool MovementInterrupted(){ return movement_interrupted; }
  829. void MovementInterrupted(bool val) { movement_interrupted = val; }
  830. bool NeedsToResumeMovement(){ return attack_resume_needed; }
  831. void NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
  832. bool HasMovementLoop(){ return movement_loop.size() > 0; }
  833. Timer* GetRunningTimer();
  834. void FaceTarget(float x, float z);
  835. void FaceTarget(Spawn* target);
  836. void SetInvulnerable(bool val);
  837. bool GetInvulnerable();
  838. bool changed;
  839. bool position_changed;
  840. bool info_changed;
  841. bool vis_changed;
  842. int16 size;
  843. int32 faction_id;
  844. int8 oversized_packet; //0xff
  845. int16 opcode;
  846. int32 id;
  847. int8 unknown1;
  848. int32 unknown2;
  849. int32 primary_command_list_id;
  850. int32 secondary_command_list_id;
  851. vector<EntityCommand*> primary_command_list;
  852. vector<EntityCommand*> secondary_command_list;
  853. int32 group_id;
  854. int8 group_len;
  855. vector<Spawn*>* spawn_group_list;
  856. AppearanceData appearance;
  857. int32 last_movement_update;
  858. bool following;
  859. bool IsPet() { return is_pet; }
  860. void SetPet(bool val) { is_pet = val; }
  861. Mutex m_requiredQuests;
  862. Mutex m_requiredHistory;
  863. void SetFollowTarget(Spawn* spawn);
  864. Spawn* GetFollowTarget();
  865. /// <summary>Sets a user defined variable</summary>
  866. /// <param name='var'>Variable we are setting</param>
  867. /// <param name='val'>Value to set the variable to</param>
  868. void AddTempVariable(string var, string val);
  869. void AddTempVariable(string var, Spawn* val);
  870. void AddTempVariable(string var, ZoneServer* val);
  871. void AddTempVariable(string var, Quest* val);
  872. void AddTempVariable(string var, Item* val);
  873. /// <summary>Gets the value for the given variable</summary>
  874. /// <param name='var'>Variable to check</param>
  875. /// <returns>The value for the given variable, "" if variable was not set</returns>
  876. string GetTempVariable(string var);
  877. Spawn* GetTempVariableSpawn(string var);
  878. ZoneServer* GetTempVariableZone(string var);
  879. Item* GetTempVariableItem(string var);
  880. Quest* GetTempVariableQuest(string var);
  881. int8 GetTempVariableType(string var);
  882. void DeleteTempVariable(string var);
  883. void SetIllusionModel(int16 val, bool setUpdateFlags = true) {
  884. SetInfo(&m_illusionModel, val, setUpdateFlags);
  885. }
  886. int16 GetIllusionModel() { return m_illusionModel; }
  887. CellInfo Cell_Info;
  888. int32 GetSpawnAnim() { return m_spawnAnim; }
  889. void SetSpawnAnim(int32 value) { m_spawnAnim = value; }
  890. int32 GetAddedToWorldTimestamp() { return m_addedToWorldTimestamp; }
  891. void SetAddedToWorldTimestamp(int32 value) { m_addedToWorldTimestamp = value; }
  892. int16 GetSpawnAnimLeeway() { return m_spawnAnimLeeway; }
  893. void SetSpawnAnimLeeway(int16 value) { m_spawnAnimLeeway = value; }
  894. protected:
  895. bool send_spawn_changes;
  896. bool invulnerable;
  897. bool attack_resume_needed;
  898. bool resume_movement;
  899. bool movement_interrupted;
  900. int32 running_timer_begin;
  901. int32 running_timer_end;
  902. vector<MovementData*> movement_loop;
  903. bool running_timer_updated;
  904. int16 movement_index;
  905. int32 movement_start_time;
  906. Mutex MMovementLoop;
  907. map<int32, int8> allowed_access;
  908. vector<int32> quest_ids;
  909. int32 database_id;
  910. int32 packet_num;
  911. int32 target;
  912. int8 spawn_type;
  913. int32 last_attacker;
  914. int32 merchant_id;
  915. int8 merchant_type;
  916. int32 transporter_id;
  917. map<int32, vector<int16>* > required_quests;
  918. map<int32, LUAHistory> required_history;
  919. EquipmentItemList equipment_list;
  920. private:
  921. deque<MovementLocation*>* movement_locations;
  922. Mutex* MMovementLocations;
  923. Mutex* MSpawnGroup;
  924. int8 size_offset;
  925. int tmp_visual_state;
  926. int tmp_action_state;
  927. int32 running_to;
  928. string spawn_script;
  929. static int32 next_id;
  930. ZoneServer* zone;
  931. int32 spawn_location_id;
  932. int32 spawn_entry_id;
  933. int32 spawn_location_spawns_id;
  934. int32 respawn;
  935. int32 expire_time;
  936. int32 expire_offset;
  937. float x_offset;
  938. float y_offset;
  939. float z_offset;
  940. int32 deviation;
  941. BasicInfoStruct basic_info;
  942. //string data;
  943. bool is_pet;
  944. // m_followTarget = spawn to follow around
  945. int32 m_followTarget;
  946. bool req_quests_private;
  947. int16 req_quests_override;
  948. bool req_quests_continued_access;
  949. float last_heading_angle;
  950. map<string, int8> m_tempVariableTypes;
  951. map<string, int32> m_tempVariableSpawn;
  952. map<string, ZoneServer*> m_tempVariableZone;
  953. map<string, Item*> m_tempVariableItem;
  954. map<string, Quest*> m_tempVariableQuest;
  955. // m_tempVariables = stores user defined variables from lua, will not persist through a zone
  956. map<string, string> m_tempVariables;
  957. int16 m_illusionModel;
  958. int32 m_spawnAnim;
  959. int32 m_addedToWorldTimestamp;
  960. int16 m_spawnAnimLeeway;
  961. int16 pos_packet_size;
  962. int16 info_packet_size;
  963. int16 vis_packet_size;
  964. Mutex m_Update;
  965. };
  966. #endif