Spawn.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __EQ2_SPAWN__
  17. #define __EQ2_SPAWN__
  18. #include "../common/types.h"
  19. #include "../common/EQPacket.h"
  20. #include "../common/EQ2_Common_Structs.h"
  21. #include "../common/MiscFunctions.h"
  22. #include "../common/opcodemgr.h"
  23. #include "../common/timer.h"
  24. #include "Commands/Commands.h"
  25. #include "Zone/position.h"
  26. #include "SpawnLists.h"
  27. #include <vector>
  28. #include "../common/ConfigReader.h"
  29. #include "Items/Items.h"
  30. #include "Zone/map.h"
  31. #include "../common/Mutex.h"
  32. #include <deque>
  33. #include <memory> // needed for LS to compile properly on linux
  34. #define DAMAGE_PACKET_TYPE_SIPHON_SPELL 0x41
  35. #define DAMAGE_PACKET_TYPE_SIPHON_SPELL2 0x49
  36. #define DAMAGE_PACKET_TYPE_MULTIPLE_DAMAGE 0x80
  37. #define DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE 0xC0
  38. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE 0xC1
  39. #define DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG 0xC4
  40. #define DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG 0xC5
  41. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE2 0xC8
  42. #define DAMAGE_PACKET_TYPE_SPELL_DAMAGE3 0xC9
  43. #define DAMAGE_PACKET_TYPE_RANGE_DAMAGE 0xE2
  44. #define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG 0xE3
  45. #define DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG2 0xEA
  46. #define DAMAGE_PACKET_RESULT_NO_DAMAGE 0
  47. #define DAMAGE_PACKET_RESULT_SUCCESSFUL 1
  48. #define DAMAGE_PACKET_RESULT_MISS 4
  49. #define DAMAGE_PACKET_RESULT_DODGE 8
  50. #define DAMAGE_PACKET_RESULT_PARRY 12
  51. #define DAMAGE_PACKET_RESULT_RIPOSTE 16
  52. #define DAMAGE_PACKET_RESULT_BLOCK 20
  53. #define DAMAGE_PACKET_RESULT_DEATH_BLOW 24
  54. #define DAMAGE_PACKET_RESULT_INVULNERABLE 28
  55. #define DAMAGE_PACKET_RESULT_RESIST 36
  56. #define DAMAGE_PACKET_RESULT_REFLECT 40
  57. #define DAMAGE_PACKET_RESULT_IMMUNE 44
  58. #define DAMAGE_PACKET_RESULT_DEFLECT 48
  59. #define DAMAGE_PACKET_RESULT_COUNTER 52
  60. #define DAMAGE_PACKET_RESULT_COUNTER_STRIKE 60
  61. #define DAMAGE_PACKET_RESULT_BASH 64
  62. #define DAMAGE_PACKET_DAMAGE_TYPE_SLASH 0
  63. #define DAMAGE_PACKET_DAMAGE_TYPE_CRUSH 1
  64. #define DAMAGE_PACKET_DAMAGE_TYPE_PIERCE 2
  65. #define DAMAGE_PACKET_DAMAGE_TYPE_HEAT 3
  66. #define DAMAGE_PACKET_DAMAGE_TYPE_COLD 4
  67. #define DAMAGE_PACKET_DAMAGE_TYPE_MAGIC 5
  68. #define DAMAGE_PACKET_DAMAGE_TYPE_MENTAL 6
  69. #define DAMAGE_PACKET_DAMAGE_TYPE_DIVINE 7
  70. #define DAMAGE_PACKET_DAMAGE_TYPE_DISEASE 8
  71. #define DAMAGE_PACKET_DAMAGE_TYPE_POISON 9
  72. #define DAMAGE_PACKET_DAMAGE_TYPE_DROWN 10
  73. #define DAMAGE_PACKET_DAMAGE_TYPE_FALLING 11
  74. #define DAMAGE_PACKET_DAMAGE_TYPE_PAIN 12
  75. #define HEAL_PACKET_TYPE_SIMPLE_HEAL 0
  76. #define HEAL_PACKET_TYPE_CRIT_HEAL 1
  77. #define HEAL_PACKET_TYPE_ABSORB 2
  78. #define HEAL_PACKET_TYPE_REGEN_ABSORB 4
  79. #define HEAL_PACKET_TYPE_SIMPLE_MANA 8
  80. #define HEAL_PACKET_TYPE_CRIT_MANA 9
  81. #define HEAL_PACKET_TYPE_SAVAGERY 16
  82. #define HEAL_PACKET_TYPE_CRIT_SAVAGERY 17
  83. #define HEAL_PACKET_TYPE_REPAIR 64
  84. #define HEAL_PACKET_TYPE_CRIT_REPAIR 65
  85. #define ARROW_COLOR_GRAY 0 // 3
  86. #define ARROW_COLOR_GREEN 1 // 1
  87. #define ARROW_COLOR_BLUE 2
  88. #define ARROW_COLOR_WHITE 3 // 3
  89. #define ARROW_COLOR_YELLOW 4 // 4
  90. #define ARROW_COLOR_ORANGE 5 // 5
  91. #define ARROW_COLOR_RED 6
  92. #define ACTIVITY_STATUS_ROLEPLAYING 1
  93. #define ACTIVITY_STATUS_ANONYMOUS 2
  94. #define ACTIVITY_STATUS_LINKDEAD 4
  95. #define ACTIVITY_STATUS_CAMPING 8
  96. #define ACTIVITY_STATUS_LFG 16
  97. #define ACTIVITY_STATUS_LFW 32
  98. #define ACTIVITY_STATUS_SOLID 64 //used by zone objects to remain solid
  99. #define ACTIVITY_STATUS_IMMUNITY_GAINED 8192
  100. #define ACTIVITY_STATUS_IMMUNITY_REMAINING 16384
  101. #define ACTIVITY_STATUS_AFK_1188 1
  102. #define ACTIVITY_STATUS_ROLEPLAYING_1188 2
  103. #define ACTIVITY_STATUS_ANONYMOUS_1188 4
  104. #define ACTIVITY_STATUS_LINKDEAD_1188 8
  105. #define ACTIVITY_STATUS_CAMPING_1188 16
  106. #define ACTIVITY_STATUS_LFG_1188 32
  107. #define ACTIVITY_STATUS_LFW_1188 64
  108. #define ACTIVITY_STATUS_SOLID_1188 128 //used by zone objects to remain solid
  109. #define ACTIVITY_STATUS_MENTORING_1188 4096
  110. #define ACTIVITY_STATUS_IMMUNITY_GAINED_1188 16384
  111. #define ACTIVITY_STATUS_IMMUNITY_REMAINING_1188 32768
  112. #define POS_STATE_KNEELING 64
  113. #define POS_STATE_SOLID 128 //used by most mobs to remaind solid (cant walk through them)
  114. #define POS_STATE_NOTARGET_CURSOR 256 //cant target and no cursor is displayed
  115. #define POS_STATE_CROUCHING 512
  116. #define MERCHANT_TYPE_NO_BUY 1
  117. #define MERCHANT_TYPE_NO_BUY_BACK 2
  118. #define MERCHANT_TYPE_SPELLS 4
  119. #define MERCHANT_TYPE_CRAFTING 8
  120. #define MERCHANT_TYPE_REPAIR 16
  121. #define MERCHANT_TYPE_LOTTO 32
  122. #define INFO_VIS_FLAG_INVIS 1
  123. #define INFO_VIS_FLAG_HIDE_HOOD 2
  124. #define INFO_VIS_FLAG_MOUNTED 4
  125. #define INFO_VIS_FLAG_CROUCH 8
  126. using namespace std;
  127. class Spell;
  128. class ZoneServer;
  129. class Quest;
  130. struct LUAHistory;
  131. struct Cell;
  132. struct CellInfo {
  133. Cell* CurrentCell;
  134. int CellListIndex;
  135. };
  136. struct MovementData{
  137. float x;
  138. float y;
  139. float z;
  140. float speed;
  141. int32 delay;
  142. string lua_function;
  143. };
  144. struct BasicInfoStruct{
  145. sint32 cur_hp;
  146. sint32 max_hp;
  147. sint32 hp_base;
  148. sint32 cur_power;
  149. sint32 max_power;
  150. sint32 power_base;
  151. sint32 cur_savagery;
  152. sint32 max_savagery;
  153. sint32 savagery_base;
  154. sint32 cur_dissonance;
  155. sint32 max_dissonance;
  156. sint32 dissonance_base;
  157. sint16 assigned_aa;
  158. sint16 unassigned_aa;
  159. sint16 tradeskill_aa;
  160. sint16 unassigned_tradeskill_aa;
  161. sint16 prestige_aa;
  162. sint16 unassigned_prestige_aa;
  163. sint16 tradeskill_prestige_aa;
  164. sint16 unassigned_tradeskill_prestige_aa;
  165. };
  166. struct MovementLocation{
  167. float x;
  168. float y;
  169. float z;
  170. float speed;
  171. //int32 start_time;
  172. //int32 end_time;
  173. bool attackable;
  174. string lua_function;
  175. bool mapped;
  176. int32 gridid;
  177. };
  178. struct SpawnUpdate {
  179. int32 spawn_id;
  180. bool info_changed;
  181. bool vis_changed;
  182. bool pos_changed;
  183. shared_ptr<Client> client;
  184. };
  185. struct SpawnData {
  186. Spawn* spawn;
  187. uchar* data;
  188. int32 size;
  189. };
  190. class Spawn {
  191. public:
  192. Spawn();
  193. virtual ~Spawn();
  194. template <class Field, class Value> void Set(Field* field, Value value, bool setUpdateFlags = true){
  195. if (setUpdateFlags) {
  196. changed = true;
  197. AddChangedZoneSpawn();
  198. }
  199. *field = value;
  200. }
  201. template <class Field> void Set(Field* field, const char* value, bool setUpdateFlags = true){
  202. if (setUpdateFlags) {
  203. changed = true;
  204. AddChangedZoneSpawn();
  205. }
  206. strcpy(field, value);
  207. }
  208. template <class Field, class Value> void SetPos(Field* field, Value value, bool setUpdateFlags = true){
  209. if(setUpdateFlags){
  210. position_changed = true;
  211. }
  212. Set(field, value, setUpdateFlags);
  213. }
  214. template <class Field, class Value> void SetInfo(Field* field, Value value, bool setUpdateFlags = true){
  215. if(setUpdateFlags){
  216. info_changed = true;
  217. }
  218. Set(field, value);
  219. }
  220. template <class Field, class Value> void SetVis(Field* field, Value value, bool setUpdateFlags = true){
  221. if(setUpdateFlags)
  222. vis_changed = true;
  223. Set(field, value);
  224. }
  225. template <class Field> void SetPos(Field* field, char* value, bool setUpdateFlags = true){
  226. if(setUpdateFlags){
  227. position_changed = true;
  228. }
  229. Set(field, value, setUpdateFlags);
  230. }
  231. template <class Field> void SetInfo(Field* field, char* value, bool setUpdateFlags = true){
  232. if(setUpdateFlags){
  233. info_changed = true;
  234. }
  235. Set(field, value);
  236. }
  237. EntityCommand* CreateEntityCommand(EntityCommand* old_command){
  238. EntityCommand* entity_command = new EntityCommand;
  239. entity_command->name = old_command->name;
  240. entity_command->distance = old_command->distance;
  241. entity_command->command = old_command->command;
  242. entity_command->error_text = old_command->error_text;
  243. entity_command->cast_time = old_command->cast_time;
  244. entity_command->spell_visual = old_command->spell_visual;
  245. return entity_command;
  246. }
  247. EntityCommand* CreateEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  248. EntityCommand* entity_command = new EntityCommand;
  249. entity_command->name = name;
  250. entity_command->distance = distance;
  251. entity_command->command = command;
  252. entity_command->error_text = error_text;
  253. entity_command->cast_time = cast_time;
  254. entity_command->spell_visual = spell_visual;
  255. return entity_command;
  256. }
  257. void AddChangedZoneSpawn();
  258. void AddPrimaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  259. primary_command_list.push_back(CreateEntityCommand(name, distance, command, error_text, cast_time, spell_visual));
  260. }
  261. void AddSecondaryEntityCommand(const char* name, float distance, const char* command, const char* error_text, int16 cast_time, int32 spell_visual){
  262. secondary_command_list.push_back(CreateEntityCommand(name, distance, command, error_text, cast_time, spell_visual));
  263. }
  264. int8 GetLockedNoLoot(){
  265. return appearance.locked_no_loot;
  266. }
  267. int16 GetEmoteState(){
  268. return appearance.emote_state;
  269. }
  270. int8 GetHideHood(){
  271. return appearance.hide_hood;
  272. }
  273. void SetLockedNoLoot(int8 new_val, bool updateFlags = true){
  274. SetVis(&appearance.locked_no_loot, new_val, updateFlags);
  275. }
  276. void SetHandFlag(int8 new_val, bool updateFlags = true){
  277. SetVis(&appearance.display_hand_icon, new_val, updateFlags);
  278. }
  279. void SetHideHood(int8 new_val, bool updateFlags = true){
  280. SetInfo(&appearance.hide_hood, new_val, updateFlags);
  281. }
  282. void SetEmoteState(int8 new_val, bool updateFlags = true){
  283. SetInfo(&appearance.emote_state, new_val, updateFlags);
  284. }
  285. void SetName(const char* new_name, bool updateFlags = true){
  286. SetInfo(appearance.name, new_name, updateFlags);
  287. }
  288. void SetPrefixTitle(const char* new_prefix_title, bool updateFlags = true) {
  289. SetInfo(appearance.prefix_title, new_prefix_title, updateFlags);
  290. }
  291. void SetSuffixTitle(const char* new_suffix_title, bool updateFlags = true) {
  292. SetInfo(appearance.suffix_title, new_suffix_title, updateFlags);
  293. }
  294. void SetSubTitle(const char* new_sub_title, bool updateFlags = true) {
  295. SetInfo(appearance.sub_title, new_sub_title, updateFlags);
  296. }
  297. void SetLastName(const char* new_last_name, bool updateFlags = true) {
  298. SetInfo(appearance.last_name, new_last_name, updateFlags);
  299. }
  300. void SetAdventureClass(int8 new_class, bool updateFlags = true) {
  301. SetInfo(&appearance.adventure_class, new_class, updateFlags);
  302. }
  303. void SetTradeskillClass(int8 new_class, bool updateFlags = true) {
  304. SetInfo(&appearance.tradeskill_class, new_class, updateFlags);
  305. }
  306. void SetSize(int16 new_size, bool updateFlags = true) {
  307. SetPos(&size, new_size, updateFlags);
  308. }
  309. void SetSpeedX(float speed_x, bool updateFlags = true) {
  310. SetPos(&appearance.pos.SpeedX, speed_x, updateFlags);
  311. }
  312. void SetSpeedY(float speed_y, bool updateFlags = true) {
  313. SetPos(&appearance.pos.SpeedY, speed_y, updateFlags);
  314. }
  315. void SetSpeedZ(float speed_z, bool updateFlags = true) {
  316. SetPos(&appearance.pos.SpeedZ, speed_z, updateFlags);
  317. }
  318. void SetX(float x, bool updateFlags = true){
  319. SetPos(&appearance.pos.X, x, updateFlags);
  320. }
  321. void SetY(float y, bool updateFlags = true, bool disableYMapFix = false);
  322. void SetZ(float z, bool updateFlags = true){
  323. SetPos(&appearance.pos.Z, z, updateFlags);
  324. }
  325. void SetHeading(sint16 dir1, sint16 dir2, bool updateFlags = true){
  326. SetPos(&appearance.pos.Dir1, dir1, updateFlags);
  327. SetPos(&appearance.pos.Dir2, dir2, updateFlags);
  328. }
  329. void SetHeading(float heading, bool updateFlags = true){
  330. last_heading_angle = heading;
  331. if (heading != 180)
  332. heading = (heading - 180) * 64;
  333. SetHeading((sint16)heading, (sint16)heading, updateFlags);
  334. }
  335. void SetPitch(sint16 pitch1, sint16 pitch2, bool updateFlags = true){
  336. SetPos(&appearance.pos.Pitch1, (sint16)pitch1, updateFlags);
  337. SetPos(&appearance.pos.Pitch2, (sint16)pitch2, updateFlags);
  338. }
  339. void SetPitch(float pitch, bool updateFlags = true){
  340. if (pitch == 0){
  341. SetPos(&appearance.pos.Pitch1, (sint16)0, updateFlags);
  342. SetPos(&appearance.pos.Pitch2, (sint16)0, updateFlags);
  343. return;
  344. }
  345. if (pitch != 180)
  346. pitch = (pitch - 180) * 64;
  347. SetPos(&appearance.pos.Pitch1, (sint16)pitch, updateFlags);
  348. SetPos(&appearance.pos.Pitch2, (sint16)pitch, updateFlags);
  349. }
  350. void SetRoll(float roll, bool updateFlags = true){
  351. if (roll == 0){
  352. SetPos(&appearance.pos.Roll, (sint16)0, updateFlags);
  353. return;
  354. }
  355. else if (roll != 180)
  356. roll = (roll - 180) * 64;
  357. SetPos(&appearance.pos.Roll, (sint16)roll, updateFlags);
  358. }
  359. void SetVisualState(int16 state, bool updateFlags = true){
  360. SetInfo(&appearance.visual_state, state, updateFlags);
  361. }
  362. void SetActionState(int16 state, bool updateFlags = true){
  363. SetInfo(&appearance.action_state, state, updateFlags);
  364. }
  365. void SetMoodState(int16 state, bool updateFlags = true){
  366. SetInfo(&appearance.mood_state, state, updateFlags);
  367. }
  368. void SetInitialState(int16 state, bool updateFlags = true){
  369. SetPos(&appearance.pos.state, state, updateFlags);
  370. }
  371. void SetActivityStatus(int16 state, bool updateFlags = true){
  372. SetInfo(&appearance.activity_status, state, updateFlags);
  373. }
  374. void SetCollisionRadius(int32 radius, bool updateFlags = true){
  375. SetPos(&appearance.pos.collision_radius, radius, updateFlags);
  376. }
  377. int16 GetCollisionRadius(){
  378. return appearance.pos.collision_radius;
  379. }
  380. int16 GetVisualState(){
  381. return appearance.visual_state;
  382. }
  383. int16 GetActionState(){
  384. return appearance.action_state;
  385. }
  386. int16 GetMoodState(){
  387. return appearance.mood_state;
  388. }
  389. int16 GetInitialState(){
  390. return appearance.pos.state;
  391. }
  392. int16 GetActivityStatus(){
  393. return appearance.activity_status;
  394. }
  395. int32 GetPrimaryCommandListID(){
  396. return primary_command_list_id;
  397. }
  398. int32 GetSecondaryCommandListID(){
  399. return secondary_command_list_id;
  400. }
  401. void SetID(int32 in_id){
  402. Set(&id, in_id);
  403. }
  404. void SetEncounterLevel(int8 enc_level, bool setUpdateFlags = true){
  405. SetInfo(&appearance.encounter_level, enc_level, setUpdateFlags);
  406. }
  407. void SetLevel(int16 level, bool setUpdateFlags = true){
  408. SetInfo(&appearance.level, level, setUpdateFlags);
  409. }
  410. void SetTSLevel(int16 tradeskill_level, bool setUpdateFlags = true){
  411. SetInfo(&appearance.tradeskill_level, tradeskill_level, setUpdateFlags);
  412. }
  413. void SetGender(int8 gender, bool setUpdateFlags = true){
  414. SetInfo(&appearance.gender, gender, setUpdateFlags);
  415. }
  416. void SetShowName(int8 new_val, bool setUpdateFlags = true){
  417. SetVis(&appearance.display_name, new_val, setUpdateFlags);
  418. }
  419. void SetShowLevel(int8 new_val, bool setUpdateFlags = true){
  420. SetVis(&appearance.show_level, new_val, setUpdateFlags);
  421. }
  422. void SetHeroic(int8 new_val, bool setUpdateFlags = true){
  423. SetInfo(&appearance.heroic_flag, new_val, setUpdateFlags);
  424. }
  425. void SetTargetable(int8 new_val, bool setUpdateFlags = true){
  426. SetVis(&appearance.targetable, new_val, setUpdateFlags);
  427. }
  428. void SetShowCommandIcon(int8 new_val, bool setUpdateFlags = true){
  429. SetVis(&appearance.show_command_icon, new_val, setUpdateFlags);
  430. }
  431. void SetShowHandIcon(int8 new_val, bool setUpdateFlags = true){
  432. SetVis(&appearance.display_hand_icon, new_val, setUpdateFlags);
  433. }
  434. void SetAttackable(int8 new_val, bool setUpdateFlags = true){
  435. SetInfo(&appearance.attackable, new_val, setUpdateFlags);
  436. }
  437. void SetLocation(int32 id, bool setUpdateFlags = true){
  438. SetPos(&appearance.pos.grid_id, id, setUpdateFlags);
  439. }
  440. void SetRace(int8 race, bool setUpdateFlags = true){
  441. SetInfo(&appearance.race, race, setUpdateFlags);
  442. }
  443. void SetIcon(int8 icon, bool setUpdateFlags = true){
  444. SetInfo(&appearance.icon, icon, setUpdateFlags);
  445. }
  446. void AddIconValue(int8 val){
  447. if(!(appearance.icon & val))
  448. SetIcon(appearance.icon+val);
  449. }
  450. void RemoveIconValue(int8 val){
  451. if((appearance.icon & val))
  452. SetIcon(appearance.icon-val);
  453. }
  454. int8 GetIconValue(){
  455. return appearance.icon;
  456. }
  457. virtual void SetSpeed(float speed){
  458. SetPos(&appearance.pos.Speed1, (int8)speed);
  459. }
  460. virtual float GetSpeed(){
  461. return (float)appearance.pos.Speed1;
  462. }
  463. virtual float GetBaseSpeed(){
  464. return (float)appearance.pos.Speed1;
  465. }
  466. void SetSpawnType(int8 new_type){
  467. SetInfo(&spawn_type, new_type);
  468. }
  469. int8 GetSpawnType(){
  470. return spawn_type;
  471. }
  472. void SetDatabaseID(int32 new_id){
  473. database_id = new_id;
  474. }
  475. int32 GetDatabaseID(){
  476. return database_id;
  477. }
  478. int8 GetShowHandIcon(){
  479. return appearance.display_hand_icon;
  480. }
  481. int32 GetLocation(){
  482. return appearance.pos.grid_id;
  483. }
  484. int8 GetAttackable(){
  485. return appearance.attackable;
  486. }
  487. int8 GetShowName(){
  488. return appearance.display_name;
  489. }
  490. int8 GetShowLevel(){
  491. return appearance.show_level;
  492. }
  493. int8 GetHeroic(){
  494. return appearance.heroic_flag;
  495. }
  496. int8 GetTargetable(){
  497. return appearance.targetable;
  498. }
  499. int8 GetShowCommandIcon(){
  500. return appearance.show_command_icon;
  501. }
  502. char* GetName(){
  503. return appearance.name;
  504. }
  505. char* GetPrefixTitle(){
  506. return appearance.prefix_title;
  507. }
  508. char* GetSuffixTitle(){
  509. return appearance.suffix_title;
  510. }
  511. char* GetSubTitle() {
  512. return appearance.sub_title;
  513. }
  514. char* GetLastName() {
  515. return appearance.last_name;
  516. }
  517. int8 GetAdventureClass() {
  518. return appearance.adventure_class;
  519. }
  520. int8 GetTradeskillClass() {
  521. return appearance.tradeskill_class;
  522. }
  523. float GetDestinationX(){
  524. return appearance.pos.X2;
  525. }
  526. float GetX() {
  527. return appearance.pos.X;
  528. }
  529. float GetSpeedX() {
  530. return appearance.pos.SpeedX;
  531. }
  532. float GetSpeedY() {
  533. return appearance.pos.SpeedY;
  534. }
  535. float GetSpeedZ() {
  536. return appearance.pos.SpeedZ;
  537. }
  538. float GetDestinationY(){
  539. return appearance.pos.Y2;
  540. }
  541. float GetY(){
  542. return appearance.pos.Y;
  543. }
  544. float GetDestinationZ(){
  545. return appearance.pos.Z2;
  546. }
  547. float GetZ(){
  548. return appearance.pos.Z;
  549. }
  550. float GetHeading(){
  551. float heading = 0;
  552. if(appearance.pos.Dir1 != 0){
  553. heading = ((float)appearance.pos.Dir1)/((float)64);
  554. if(heading >= 180)
  555. heading -= 180;
  556. else
  557. heading += 180;
  558. }
  559. return heading;
  560. }
  561. float GetPitch(){
  562. float pitch = 0;
  563. if(appearance.pos.Pitch1 != 0){
  564. pitch = ((float)appearance.pos.Pitch1)/((float)64);
  565. if(pitch >= 180)
  566. pitch -= 180;
  567. else
  568. pitch += 180;
  569. }
  570. return pitch;
  571. }
  572. float GetRoll(){
  573. float roll = 0;
  574. if(appearance.pos.Roll != 0){
  575. roll = ((float)appearance.pos.Roll)/((float)64);
  576. if(roll >= 180)
  577. roll -= 180;
  578. else
  579. roll += 180;
  580. }
  581. return roll;
  582. }
  583. int32 GetID(){
  584. return id;
  585. }
  586. float GetDistance(float x1, float y1, float z1, float x2, float y2, float z2);
  587. float GetDistance(float x, float y, float z, float radius, bool ignore_y = false);
  588. float GetDistance(float x, float y, float z, bool ignore_y = false);
  589. float GetDistance(Spawn* spawn, bool ignore_y = false, bool includeRadius=true);
  590. float GetDistance(Spawn* spawn, float x1, float y1, float z1, bool includeRadius=true);
  591. float CalculateRadius(Spawn* target);
  592. int8 GetEncounterLevel(){
  593. return appearance.encounter_level;
  594. }
  595. sint32 GetTotalPower();
  596. sint32 GetPower();
  597. sint32 GetTotalHP();
  598. sint32 GetHP();
  599. sint32 GetTotalHPBase();
  600. sint32 GetTotalPowerBase();
  601. sint32 GetTotalSavagery();
  602. sint32 GetSavagery();
  603. sint32 GetTotalDissonance();
  604. sint32 GetDissonance();
  605. sint32 GetTotalSavageryBase();
  606. sint32 GetTotalDissonanceBase();
  607. sint16 GetAssignedAA();
  608. sint16 GetUnassignedAA();
  609. sint16 GetTradeskillAA();
  610. sint16 GetUnassignedTradeskillAA();
  611. sint16 GetPrestigeAA();
  612. sint16 GetUnassignedPretigeAA();
  613. sint16 GetTradeskillPrestigeAA();
  614. sint16 GetUnassignedTradeskillPrestigeAA();
  615. void SetTotalPower(sint32 new_val);
  616. void SetTotalHP(sint32 new_val);
  617. void SetTotalSavagery(sint32 new_val);
  618. void SetTotalDissonance(sint32 new_val);
  619. void SetTotalPowerBase(sint32 new_val);
  620. void SetTotalHPBase(sint32 new_val);
  621. void SetTotalSavageryBase(sint32 new_val);
  622. void SetTotalDissonanceBase(sint32 new_val);
  623. void SetPower(sint32 power, bool setUpdateFlags = true);
  624. void SetHP(sint32 new_val, bool setUpdateFlags = true);
  625. void SetSavagery(sint32 savagery, bool setUpdateFlags = true);
  626. void SetDissonance(sint32 dissonance, bool setUpdateFlags = true);
  627. void SetAssignedAA(sint16 new_val);
  628. void SetUnassignedAA(sint16 new_val);
  629. void SetTradeskillAA(sint16 new_val);
  630. void SetUnassignedTradeskillAA(sint16 new_val);
  631. void SetPrestigeAA(sint16 new_val);
  632. void SetUnassignedPrestigeAA(sint16 new_val);
  633. void SetTradeskillPrestigeAA(sint16 new_val);
  634. void SetUnassignedTradeskillPrestigeAA(sint16 new_val);
  635. void SetPrivateQuestSpawn(bool val) {req_quests_private = val;}
  636. void SetQuestsRequiredOverride(int16 val) {req_quests_override = val;}
  637. void SetQuestsRequiredContinuedAccess(bool val) {req_quests_continued_access = val;}
  638. bool GetPrivateQuestSpawn() {return req_quests_private;}
  639. int16 GetQuestsRequiredOverride() {return req_quests_override;}
  640. bool GetQuestsRequiredContinuedAccess() {return req_quests_continued_access;}
  641. bool Alive(){ return GetHP() > 0; }
  642. int16 GetLevel(){
  643. return appearance.level;
  644. }
  645. int16 GetTSLevel(){
  646. return appearance.tradeskill_level;
  647. }
  648. int8 GetGender(){
  649. return appearance.gender;
  650. }
  651. int8 GetRace(){
  652. return appearance.race;
  653. }
  654. int8 GetLuaRaceId() {
  655. return appearance.lua_race_id;
  656. }
  657. int32 GetSize(){
  658. return size;
  659. }
  660. int32 GetDeviation(){
  661. return deviation;
  662. }
  663. void SetDeviation(int32 in_dev){
  664. deviation = in_dev;
  665. }
  666. float GetSpawnOrigHeading(){
  667. return appearance.pos.SpawnOrigHeading;
  668. }
  669. void SetSpawnOrigHeading(float val){
  670. appearance.pos.SpawnOrigHeading = val;
  671. }
  672. float GetSpawnOrigX(){
  673. return appearance.pos.SpawnOrigX;
  674. }
  675. float GetSpawnOrigY(){
  676. return appearance.pos.SpawnOrigY;
  677. }
  678. float GetSpawnOrigZ(){
  679. return appearance.pos.SpawnOrigZ;
  680. }
  681. float GetSpawnOrigPitch(){
  682. return appearance.pos.SpawnOrigPitch;
  683. }
  684. float GetSpawnOrigRoll(){
  685. return appearance.pos.SpawnOrigRoll;
  686. }
  687. void SetSpawnOrigX(float val){
  688. appearance.pos.SpawnOrigX = val;
  689. }
  690. void SetSpawnOrigY(float val){
  691. appearance.pos.SpawnOrigY = val;
  692. }
  693. void SetSpawnOrigZ(float val){
  694. appearance.pos.SpawnOrigZ = val;
  695. }
  696. void SetSpawnOrigRoll(float val){
  697. appearance.pos.SpawnOrigRoll = val;
  698. }
  699. void SetSpawnOrigPitch(float val){
  700. appearance.pos.SpawnOrigPitch = val;
  701. }
  702. void SetSogaModelType(int16 new_val, bool setUpdateFlags = true){
  703. SetInfo(&appearance.soga_model_type, new_val, setUpdateFlags);
  704. }
  705. void SetModelType(int16 model_type, bool setUpdateFlags = true){
  706. SetInfo(&appearance.model_type, model_type, setUpdateFlags);
  707. SetInfo(&appearance.soga_model_type, model_type, setUpdateFlags);
  708. }
  709. int16 GetSogaModelType(){
  710. return appearance.soga_model_type;
  711. }
  712. int16 GetModelType(){
  713. return appearance.model_type;
  714. }
  715. void SetPrimaryCommand(const char* name, const char* command, float distance = 10);
  716. void SetPrimaryCommands(vector<EntityCommand*>* commands);
  717. void SetSecondaryCommands(vector<EntityCommand*>* commands);
  718. vector<EntityCommand*>* GetPrimaryCommands() {return &primary_command_list;}
  719. vector<EntityCommand*>* GetSecondaryCommands() {return &secondary_command_list;}
  720. EntityCommand* FindEntityCommand(string command);
  721. virtual EQ2Packet* serialize(Player* player, int16 version);
  722. EQ2Packet* spawn_serialize(Player* player, int16 version);
  723. EQ2Packet* spawn_update_packet(Player* player, int16 version, bool override_changes = false, bool override_vis_changes = false);
  724. EQ2Packet* player_position_update_packet(Player* player, int16 version);
  725. uchar* spawn_info_changes(Player* spawn, int16 version);
  726. uchar* spawn_pos_changes(Player* spawn, int16 version);
  727. uchar* spawn_vis_changes(Player* spawn, int16 version);
  728. uchar* spawn_info_changes_ex(Player* spawn, int16 version);
  729. uchar* spawn_pos_changes_ex(Player* spawn, int16 version);
  730. uchar* spawn_vis_changes_ex(Player* spawn, int16 version);
  731. virtual bool EngagedInCombat(){ return false; }
  732. virtual bool IsObject(){ return false; }
  733. virtual bool IsGroundSpawn(){ return false; }
  734. virtual bool IsNPC(){ return false; }
  735. virtual bool IsEntity(){ return false; }
  736. virtual bool IsPlayer(){ return false; }
  737. virtual bool IsWidget(){ return false; }
  738. virtual bool IsSign(){ return false; }
  739. virtual bool IsBot() { return false; }
  740. bool HasInfoChanged(){ return info_changed; }
  741. bool HasPositionChanged(){ return position_changed; }
  742. bool HasTarget(){ return target ? true : false; }
  743. int32 GetRespawnTime();
  744. void SetRespawnTime(int32 time);
  745. int32 GetExpireTime() { return expire_time; }
  746. void SetExpireTime(int32 new_expire_time) { expire_time = new_expire_time; }
  747. int32 GetExpireOffsetTime();
  748. void SetExpireOffsetTime(int32 time);
  749. int32 GetSpawnLocationID();
  750. void SetSpawnLocationID(int32 id);
  751. int32 GetSpawnEntryID();
  752. void SetSpawnEntryID(int32 id);
  753. int32 GetSpawnLocationPlacementID();
  754. void SetSpawnLocationPlacementID(int32 id);
  755. float GetXOffset() { return x_offset; }
  756. void SetXOffset(float new_x_offset) { x_offset = new_x_offset; }
  757. float GetYOffset() { return y_offset; }
  758. void SetYOffset(float new_y_offset) { y_offset = new_y_offset; }
  759. float GetZOffset() { return z_offset; }
  760. void SetZOffset(float new_z_offset) { z_offset = new_z_offset; }
  761. Spawn* GetTarget();
  762. void SetTarget(Spawn* spawn);
  763. Spawn* GetLastAttacker();
  764. void SetLastAttacker(Spawn* spawn);
  765. bool TakeDamage(int32 damage);
  766. void TakeDamage(Spawn* attacker, int32 damage);
  767. ZoneServer* GetZone();
  768. virtual void SetZone(ZoneServer* in_zone);
  769. void SetFactionID(int32 val) { faction_id = val; }
  770. int32 GetFactionID(){
  771. return faction_id;
  772. }
  773. static int32 NextID() {
  774. static CriticalSection id_lock;
  775. id_lock.lock();
  776. int32 ret = ++next_id;
  777. if (next_id == 0xFFFFFFFE)
  778. next_id = 1;
  779. else if ((next_id - 255) % 256 == 0) { //we dont want it to end in 255, it will confuse/crash the client
  780. id_lock.unlock();
  781. return NextID();
  782. }
  783. id_lock.unlock();
  784. return ret;
  785. }
  786. void AddProvidedQuest(int32 val){
  787. quest_ids.push_back(val);
  788. }
  789. vector<int32>* GetProvidedQuests(){
  790. return &quest_ids;
  791. }
  792. bool HasProvidedQuests(){
  793. return (quest_ids.size() > 0);
  794. }
  795. void SetSpawnScript(string name);
  796. const char* GetSpawnScript();
  797. vector<Spawn*>* GetSpawnGroup();
  798. bool HasSpawnGroup();
  799. bool IsInSpawnGroup(Spawn* spawn);
  800. void SendSpawnChanges(bool val){ send_spawn_changes = val; }
  801. void SetSpawnGroupID(int32 id);
  802. int32 GetSpawnGroupID();
  803. void AddSpawnToGroup(Spawn* spawn);
  804. void SetSpawnGroupList(vector<Spawn*>* list, Mutex* mutex);
  805. void RemoveSpawnFromGroup(bool erase_all = false);
  806. void SetRunningTo(Spawn* spawn){ running_to = spawn->GetID(); }
  807. Spawn* GetRunningTo();
  808. void SetTempVisualState(int val, bool update = true) { SetInfo(&tmp_visual_state, val, update); }
  809. int GetTempVisualState(){ return tmp_visual_state; }
  810. void SetTempActionState(int val, bool update = true) { SetInfo(&tmp_action_state, val, update); }
  811. int GetTempActionState(){ return tmp_action_state; }
  812. void AddAllowAccessSpawn(Spawn* spawn){ allowed_access[spawn->GetID()] = 1; }
  813. void RemoveSpawnAccess(Spawn* spawn);
  814. bool IsPrivateSpawn(){ return allowed_access.size() > 0 ;}
  815. bool AllowedAccess(Spawn* spawn){ return allowed_access.count(spawn->GetID()) > 0; }
  816. void MakeSpawnPublic() { allowed_access.clear(); }
  817. void SetSizeOffset(int8 offset);
  818. int8 GetSizeOffset();
  819. void SetMerchantID(int32 val);
  820. int32 GetMerchantID();
  821. void SetMerchantType(int8 val);
  822. int8 GetMerchantType();
  823. void SetQuestsRequired(map<int32, vector<int16>* >* quests);
  824. void SetQuestsRequired(int32 quest_id, int16 quest_step);
  825. void SetRequiredHistory(int32 event_id, int32 value1, int32 value2);
  826. map<int32, vector<int16>* >* GetQuestsRequired();
  827. void SetTransporterID(int32 id);
  828. int32 GetTransporterID();
  829. bool MeetsSpawnAccessRequirements(Player* player);
  830. void InitializePosPacketData(Player* player, PacketStruct* packet, bool bSpawnUpdate = false);
  831. void InitializeInfoPacketData(Player* player, PacketStruct* packet);
  832. void InitializeVisPacketData(Player* player, PacketStruct* packet);
  833. void InitializeHeaderPacketData(Player* player, PacketStruct* packet, int16 index);
  834. void InitializeFooterPacketData(Player* player, PacketStruct* packet);
  835. void MoveToLocation(Spawn* spawn, float distance, bool immediate = true, bool isMappedLocation = false);
  836. void AddMovementLocation(float x, float y, float z, float speed, int16 delay, const char* lua_function);
  837. void ProcessMovement(bool isSpawnListLocked=false);
  838. void ResetMovement();
  839. bool IsRunning();
  840. void CalculateRunningLocation(bool stop = false);
  841. void RunToLocation(float x, float y, float z, float following_x = 0, float following_y = 0, float following_z = 0);
  842. MovementLocation* GetCurrentRunningLocation();
  843. MovementLocation* GetLastRunningLocation();
  844. bool CalculateChange();
  845. void AddRunningLocation(float x, float y, float z, float speed, float distance_away = 0, bool attackable = true, bool finished_adding_locations = true, string lua_function = "", bool isMapped=false);
  846. bool RemoveRunningLocation();
  847. void ClearRunningLocations();
  848. void CopySpawnAppearance(Spawn* spawn);
  849. bool MovementInterrupted(){ return movement_interrupted; }
  850. void MovementInterrupted(bool val) { movement_interrupted = val; }
  851. bool NeedsToResumeMovement(){ return attack_resume_needed; }
  852. void NeedsToResumeMovement(bool val) { attack_resume_needed = val; }
  853. bool HasMovementLoop(){ return movement_loop.size() > 0; }
  854. Timer* GetRunningTimer();
  855. float GetFaceTarget(float x, float z);
  856. void FaceTarget(float x, float z);
  857. void FaceTarget(Spawn* target);
  858. void SetInvulnerable(bool val);
  859. bool GetInvulnerable();
  860. bool changed;
  861. bool position_changed;
  862. bool info_changed;
  863. bool vis_changed;
  864. int16 size;
  865. int32 faction_id;
  866. int8 oversized_packet; //0xff
  867. int16 opcode;
  868. int32 id;
  869. int8 unknown1;
  870. int32 unknown2;
  871. int32 primary_command_list_id;
  872. int32 secondary_command_list_id;
  873. vector<EntityCommand*> primary_command_list;
  874. vector<EntityCommand*> secondary_command_list;
  875. int32 group_id;
  876. int8 group_len;
  877. vector<Spawn*>* spawn_group_list;
  878. AppearanceData appearance;
  879. int32 last_movement_update;
  880. int32 last_location_update;
  881. bool forceMapCheck;
  882. bool following;
  883. bool IsPet() { return is_pet; }
  884. void SetPet(bool val) { is_pet = val; }
  885. Mutex m_requiredQuests;
  886. Mutex m_requiredHistory;
  887. void SetFollowTarget(Spawn* spawn);
  888. Spawn* GetFollowTarget();
  889. /// <summary>Sets a user defined variable</summary>
  890. /// <param name='var'>Variable we are setting</param>
  891. /// <param name='val'>Value to set the variable to</param>
  892. void AddTempVariable(string var, string val);
  893. void AddTempVariable(string var, Spawn* val);
  894. void AddTempVariable(string var, ZoneServer* val);
  895. void AddTempVariable(string var, Quest* val);
  896. void AddTempVariable(string var, Item* val);
  897. /// <summary>Gets the value for the given variable</summary>
  898. /// <param name='var'>Variable to check</param>
  899. /// <returns>The value for the given variable, "" if variable was not set</returns>
  900. string GetTempVariable(string var);
  901. Spawn* GetTempVariableSpawn(string var);
  902. ZoneServer* GetTempVariableZone(string var);
  903. Item* GetTempVariableItem(string var);
  904. Quest* GetTempVariableQuest(string var);
  905. int8 GetTempVariableType(string var);
  906. void DeleteTempVariable(string var);
  907. void SetIllusionModel(int16 val, bool setUpdateFlags = true) {
  908. SetInfo(&m_illusionModel, val, setUpdateFlags);
  909. }
  910. int16 GetIllusionModel() { return m_illusionModel; }
  911. CellInfo Cell_Info;
  912. int32 GetSpawnAnim() { return m_spawnAnim; }
  913. void SetSpawnAnim(int32 value) { m_spawnAnim = value; }
  914. int32 GetAddedToWorldTimestamp() { return m_addedToWorldTimestamp; }
  915. void SetAddedToWorldTimestamp(int32 value) { m_addedToWorldTimestamp = value; }
  916. int16 GetSpawnAnimLeeway() { return m_spawnAnimLeeway; }
  917. void SetSpawnAnimLeeway(int16 value) { m_spawnAnimLeeway = value; }
  918. float FindDestGroundZ(glm::vec3 dest, float z_offset);
  919. float GetFixedZ(const glm::vec3& destination, int32 z_find_offset = 1);
  920. void FixZ(bool forceUpdate=false);
  921. bool CheckLoS(Spawn* target);
  922. bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc);
  923. void CalculateNewFearpoint();
  924. void StopMoving() {
  925. if (movement_locations)
  926. movement_locations->clear();
  927. }
  928. int16 pos_packet_size;
  929. int16 info_packet_size;
  930. int16 vis_packet_size;
  931. protected:
  932. bool send_spawn_changes;
  933. bool invulnerable;
  934. bool attack_resume_needed;
  935. bool resume_movement;
  936. bool movement_interrupted;
  937. int32 running_timer_begin;
  938. int32 running_timer_end;
  939. vector<MovementData*> movement_loop;
  940. bool running_timer_updated;
  941. int16 movement_index;
  942. int32 last_grid_update;
  943. int32 movement_start_time;
  944. Mutex MMovementLoop;
  945. map<int32, int8> allowed_access;
  946. vector<int32> quest_ids;
  947. int32 database_id;
  948. int32 packet_num;
  949. int32 target;
  950. int8 spawn_type;
  951. int32 last_attacker;
  952. int32 merchant_id;
  953. int8 merchant_type;
  954. int32 transporter_id;
  955. map<int32, vector<int16>* > required_quests;
  956. map<int32, LUAHistory> required_history;
  957. EquipmentItemList equipment_list;
  958. private:
  959. deque<MovementLocation*>* movement_locations;
  960. Mutex* MMovementLocations;
  961. Mutex* MSpawnGroup;
  962. int8 size_offset;
  963. int tmp_visual_state;
  964. int tmp_action_state;
  965. int32 running_to;
  966. string spawn_script;
  967. static int32 next_id;
  968. ZoneServer* zone;
  969. int32 spawn_location_id;
  970. int32 spawn_entry_id;
  971. int32 spawn_location_spawns_id;
  972. int32 respawn;
  973. int32 expire_time;
  974. int32 expire_offset;
  975. float x_offset;
  976. float y_offset;
  977. float z_offset;
  978. int32 deviation;
  979. BasicInfoStruct basic_info;
  980. //string data;
  981. bool is_pet;
  982. // m_followTarget = spawn to follow around
  983. int32 m_followTarget;
  984. bool req_quests_private;
  985. int16 req_quests_override;
  986. bool req_quests_continued_access;
  987. float last_heading_angle;
  988. map<string, int8> m_tempVariableTypes;
  989. map<string, int32> m_tempVariableSpawn;
  990. map<string, ZoneServer*> m_tempVariableZone;
  991. map<string, Item*> m_tempVariableItem;
  992. map<string, Quest*> m_tempVariableQuest;
  993. // m_tempVariables = stores user defined variables from lua, will not persist through a zone
  994. map<string, string> m_tempVariables;
  995. int16 m_illusionModel;
  996. int32 m_spawnAnim;
  997. int32 m_addedToWorldTimestamp;
  998. int16 m_spawnAnimLeeway;
  999. Mutex m_Update;
  1000. };
  1001. #endif