zoneserver.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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 ZONESERVER_H
  17. #define ZONESERVER_H
  18. #include <mutex>
  19. #include <shared_mutex>
  20. #include "../common/linked_list.h"
  21. #include "../common/timer.h"
  22. #include "../common/queue.h"
  23. #include "../common/servertalk.h"
  24. #include "../common/TCPConnection.h"
  25. #include "WorldTCPConnection.h"
  26. #include "../common/Mutex.h"
  27. #include "../common/DataBuffer.h"
  28. #include "net.h"
  29. #include "Player.h"
  30. #include "Combat.h"
  31. #include <list>
  32. #include <map>
  33. #include <set>
  34. #include "MutexList.h"
  35. #include "MutexMap.h"
  36. #include "MutexVector.h"
  37. #include "NPC.h"
  38. #include "Widget.h"
  39. #include "Object.h"
  40. #include "GroundSpawn.h"
  41. #include "Sign.h"
  42. #include "Zone/map.h"
  43. #include "Zone/pathfinder_interface.h"
  44. #include "Zone/mob_movement_manager.h"
  45. #include "Zone/region_map.h"
  46. extern NetConnection net; // needs to be here or compile errors in commands.cpp
  47. class SpellProcess;
  48. class TradeskillMgr;
  49. class Bot;
  50. #define EXPANSION_UNKNOWN 1
  51. #define EXPANSION_UNKNOWN2 64
  52. #define EXPANSION_UNKNOWN3 128
  53. #define EXPANSION_UNKNOWN4 256
  54. #define EXPANSION_UNKNOWN5 512
  55. #define EXPANSION_DOF 1024
  56. #define EXPANSION_KOS 2048
  57. #define EXPANSION_EOF 4096
  58. #define EXPANSION_ROK 8192
  59. #define EXPANSION_TSO 16384
  60. #define EXPANSION_DOV 65536 // This enables DoV and CoE AA tree's lower values disable both trees
  61. // Can't verify these 3 values
  62. // 32768 - SF
  63. // 131072 - AoD
  64. #define SPAWN_SCRIPT_SPAWN 0
  65. #define SPAWN_SCRIPT_RESPAWN 1
  66. #define SPAWN_SCRIPT_ATTACKED 2
  67. #define SPAWN_SCRIPT_TARGETED 3
  68. #define SPAWN_SCRIPT_HAILED 4
  69. #define SPAWN_SCRIPT_DEATH 5
  70. #define SPAWN_SCRIPT_KILLED 6
  71. #define SPAWN_SCRIPT_AGGRO 7
  72. #define SPAWN_SCRIPT_HEALTHCHANGED 8
  73. #define SPAWN_SCRIPT_RANDOMCHAT 9
  74. #define SPAWN_SCRIPT_CONVERSATION 10
  75. #define SPAWN_SCRIPT_TIMER 11
  76. #define SPAWN_SCRIPT_CUSTOM 12
  77. #define SPAWN_SCRIPT_HAILED_BUSY 13
  78. #define SPAWN_SCRIPT_CASTED_ON 14
  79. #define SPAWN_SCRIPT_AUTO_ATTACK_TICK 15
  80. #define SPAWN_SCRIPT_COMBAT_RESET 16
  81. #define SPAWN_SCRIPT_GROUP_DEAD 17
  82. #define SPAWN_SCRIPT_HEAR_SAY 18
  83. #define SPAWN_SCRIPT_PRESPAWN 19
  84. #define SPAWN_SCRIPT_USEDOOR 20
  85. #define SPAWN_SCRIPT_BOARD 21
  86. #define SPAWN_SCRIPT_DEBOARD 22
  87. #define SPAWN_CONDITIONAL_NONE 0
  88. #define SPAWN_CONDITIONAL_DAY 1
  89. #define SPAWN_CONDITIONAL_NIGHT 2
  90. #define SPAWN_CONDITIONAL_NOT_RAINING 4
  91. #define SPAWN_CONDITIONAL_RAINING 8
  92. #define MAX_REVIVEPOINT_DISTANCE 1000
  93. /* JA: TODO Turn into R_World Rules */
  94. #define SEND_SPAWN_DISTANCE 250 /* when spawns appear visually to the client */
  95. #define HEAR_SPAWN_DISTANCE 30 /* max distance a client can be from a spawn to 'hear' it */
  96. #define MAX_CHASE_DISTANCE 80
  97. #define REMOVE_SPAWN_DISTANCE 300 // increased distance between send/remove is ideal, this makes sure there is no overlap if a 'fast' client (AKA GM warp speed)
  98. #define TRACKING_STOP 0
  99. #define TRACKING_START 1
  100. #define TRACKING_UPDATE 2
  101. #define TRACKING_CLOSE_WINDOW 3
  102. #define TRACKING_TYPE_ENTITIES 1
  103. #define TRACKING_TYPE_HARVESTABLES 2
  104. #define TRACKING_SPAWN_TYPE_PC 0
  105. #define TRACKING_SPAWN_TYPE_NPC 1
  106. #define WAYPOINT_CATEGORY_GROUP 0
  107. #define WAYPOINT_CATEGORY_QUESTS 1
  108. #define WAYPOINT_CATEGORY_PEOPLE 2
  109. #define WAYPOINT_CATEGORY_PLACES 3
  110. #define WAYPOINT_CATEGORY_USER 4
  111. #define WAYPOINT_CATEGORY_DIRECTIONS 5
  112. #define WAYPOINT_CATEGORY_TRACKING 6
  113. #define WAYPOINT_CATEGORY_HOUSES 7
  114. #define WAYPOINT_CATEGORY_MAP 8
  115. struct PlayerProximity{
  116. float distance;
  117. string in_range_lua_function;
  118. string leaving_range_lua_function;
  119. map<Client*, bool> clients_in_proximity;
  120. };
  121. struct LocationProximity {
  122. float x;
  123. float y;
  124. float z;
  125. float max_variation;
  126. string in_range_lua_function;
  127. string leaving_range_lua_function;
  128. map<Client*, bool> clients_in_proximity;
  129. };
  130. struct LocationGrid {
  131. int32 id;
  132. int32 grid_id;
  133. string name;
  134. bool include_y;
  135. bool discovery;
  136. MutexList<Location*> locations;
  137. MutexMap<Player*, bool> players;
  138. };
  139. struct GridMap {
  140. int32 grid_id;
  141. std::map<int32, Spawn*> spawns;
  142. mutable std::shared_mutex MSpawns;
  143. };
  144. struct TrackedSpawn {
  145. Spawn* spawn;
  146. float distance;
  147. };
  148. struct HouseItem {
  149. int32 spawn_id;
  150. int32 item_id;
  151. int32 unique_id;
  152. Item* item;
  153. };
  154. class Widget;
  155. class Client;
  156. class Sign;
  157. class Object;
  158. class GroundSpawn;
  159. struct GroundSpawnEntry;
  160. struct GroundSpawnEntryItem;
  161. struct LootTable;
  162. struct LootDrop;
  163. struct GlobalLoot;
  164. struct TransportDestination;
  165. struct LocationTransportDestination;
  166. #ifdef WIN32
  167. void ZoneLoop(void *tmp);
  168. void SpawnLoop(void *tmp);
  169. void SendInitialSpawns(void *tmp);
  170. void SendLevelChangedSpawns(void*tmp);
  171. #else
  172. void *ZoneLoop(void *tmp);
  173. void *SpawnLoop(void *tmp);
  174. void *SendInitialSpawns(void *tmp);
  175. void *SendLevelChangedSpawns(void *tmp);
  176. #endif
  177. using namespace std;
  178. struct RevivePoint{
  179. int32 id;
  180. int32 zone_id; //usually this zone, but not always
  181. string location_name;
  182. float x;
  183. float y;
  184. float z;
  185. float heading;
  186. bool always_included;
  187. };
  188. struct SpawnScriptTimer {
  189. int32 timer;
  190. int32 spawn;
  191. int32 player;
  192. string function;
  193. int32 current_count;
  194. int32 max_count;
  195. };
  196. enum Instance_Type {
  197. NONE,
  198. GROUP_LOCKOUT_INSTANCE,
  199. GROUP_PERSIST_INSTANCE,
  200. RAID_LOCKOUT_INSTANCE,
  201. RAID_PERSIST_INSTANCE,
  202. SOLO_LOCKOUT_INSTANCE,
  203. SOLO_PERSIST_INSTANCE,
  204. TRADESKILL_INSTANCE, // allows anyone to enter, server searches for the first instance that is available
  205. PUBLIC_INSTANCE, // same as tradeskill, except dead spawns are tracked
  206. PERSONAL_HOUSE_INSTANCE,
  207. GUILD_HOUSE_INSTANCE,
  208. QUEST_INSTANCE
  209. };
  210. struct FlightPathInfo {
  211. float speed;
  212. bool flying;
  213. bool dismount;
  214. };
  215. struct FlightPathLocation {
  216. float X;
  217. float Y;
  218. float Z;
  219. };
  220. struct ZoneInfoSlideStructInfo {
  221. float unknown1[2];
  222. int32 unknown2[2];
  223. int32 unknown3;
  224. int32 unknown4;
  225. char slide[128];
  226. char voiceover[128];
  227. int32 key1;
  228. int32 key2;
  229. };
  230. struct ZoneInfoSlideStructTransitionInfo {
  231. int32 transition_x;
  232. int32 transition_y;
  233. float transition_zoom;
  234. float transition_time;
  235. };
  236. struct ZoneInfoSlideStruct {
  237. ZoneInfoSlideStructInfo* info;
  238. vector<ZoneInfoSlideStructTransitionInfo*> slide_transition_info;
  239. };
  240. enum SUBSPAWN_TYPES {
  241. COLLECTOR = 0,
  242. HOUSE_ITEM_SPAWN = 1,
  243. MAX_SUBSPAWN_TYPE = 20
  244. };
  245. // need to attempt to clean this up and add xml comments, remove unused code, find a logical way to sort the functions maybe by get/set/process/add etc...
  246. class ZoneServer {
  247. public:
  248. ZoneServer(const char* file);
  249. ~ZoneServer();
  250. void IncrementIncomingClients();
  251. void DecrementIncomingClients();
  252. void Init();
  253. bool Process();
  254. bool SpawnProcess();
  255. ZoneInfoSlideStruct* GenerateSlideStruct(float unknown1a, float unknown1b, int32 unknown2a, int32 unknown2b, int32 unknown3, int32 unknown4, const char* slide, const char* voiceover, int32 key1, int32 key2);
  256. void AddZoneInfoSlideStructTransitionInfo(ZoneInfoSlideStruct* info, int32 x, int32 y, float zoom, float transition_time);
  257. vector<ZoneInfoSlideStruct*>* GenerateTutorialSlides();
  258. void LoadRevivePoints(vector<RevivePoint*>* revive_points);
  259. vector<RevivePoint*>* GetRevivePoints(Client* client);
  260. RevivePoint* GetRevivePoint(int32 id);
  261. void AddClient(Client* client);
  262. void SimpleMessage(int8 type, const char* message, Spawn* from, float distance, bool send_to_sender = true);
  263. void HandleChatMessage(Spawn* from, const char* to, int16 channel, const char* message, float distance = 0, const char* channel_name = 0, bool show_bubble = true, int32 language = 0);
  264. void HandleChatMessage(Client* client, Spawn* from, const char* to, int16 channel, const char* message, float distance = 0, const char* channel_name = 0, bool show_bubble = true, int32 language = 0);
  265. void HandleChatMessage(Client* client, std::string fromName, const char* to, int16 channel, const char* message, float distance = 0, const char* channel_name = 0, int32 language = 0);
  266. void HandleChatMessage(std::string fromName, const char* to, int16 channel, const char* message, float distance, const char* channel_name, int32 language);
  267. void HandleBroadcast(const char* message);
  268. void HandleAnnouncement(const char* message);
  269. int16 SetSpawnTargetable(Spawn* spawn, float distance);
  270. int16 SetSpawnTargetable(int32 spawn_id);
  271. void ApplySetSpawnCommand(Client* client, Spawn* target, int8 type, const char* value);
  272. void SetSpawnCommand(Spawn* spawn, int8 type, char* value, Client* client = 0);
  273. void SetSpawnCommand(int32 spawn_id, int8 type, char* value, Client* client = 0);
  274. void AddLoot(NPC* npc, Spawn* killer = nullptr, GroupLootMethod loot_method = GroupLootMethod::METHOD_FFA, int8 item_rarity = 0, int32 group_id = 0);
  275. NPC* AddNPCSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  276. Object* AddObjectSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  277. GroundSpawn* AddGroundSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  278. Widget* AddWidgetSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  279. Sign* AddSignSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  280. void AddSpawn(Spawn* spawn);
  281. void RemoveDeadEnemyList(Spawn* spawn);
  282. void RemoveDeadSpawn(Spawn* spawn);
  283. void AddSpawnGroupLocation(int32 group_id, int32 location_id, int32 spawn_location_id);
  284. void AddSpawnGroupAssociation(int32 group_id1, int32 group_id2);
  285. void AddSpawnGroupChance(int32 group_id, float percent);
  286. void RemoveSpawn(Spawn* spawn, bool delete_spawn = true, bool respawn = true, bool lock = true, bool erase_from_spawn_list = true, bool lock_spell_process = false);
  287. void ProcessSpawnLocations();
  288. void SendQuestUpdates(Client* client, Spawn* spawn = 0);
  289. EQ2Packet* GetZoneInfoPacket(Client* client);
  290. Spawn* FindSpawn(Player* searcher, const char* name);
  291. bool CallSpawnScript(Spawn* npc, int8 type, Spawn* spawn = 0, const char* message = 0, bool is_door_open = false, sint32 input_value = 0, sint32* return_value = 0);
  292. void SendSpawnVisualState(Spawn* spawn, int16 type);
  293. void SendSpellFailedPacket(Client* client, int16 error);
  294. void SendInterruptPacket(Spawn* interrupted, LuaSpell* spell, bool fizzle=false);
  295. void HandleEmote(Spawn* originator, string name);
  296. Spawn* GetSpawnByDatabaseID(int32 id);
  297. Spawn* GetSpawnByID(int32 id, bool spawnListLocked=false);
  298. void PlaySoundFile(Client* client, const char* name, float origin_x, float origin_y, float origin_z);
  299. void SendZoneSpawns(Client* client);
  300. void StartZoneInitialSpawnThread(Client* client);
  301. void SendSpawnChanges();
  302. void SendSpawnChanges(Spawn* spawn);
  303. void SendSpawnChanges(Spawn* spawn, Client* client, bool override_changes = false, bool override_vis_changes = false);
  304. void SendSpawnChangesByDBID(int32 spawn_id, Client* client, bool override_changes = false, bool override_vis_changes = false);
  305. void SendPlayerPositionChanges(Player* player);
  306. void UpdateVitality(float amount);
  307. vector<Entity*> GetPlayers();
  308. void KillSpawn(bool spawnListLocked, Spawn* dead, Spawn* killer, bool send_packet = true, int8 type = 0, int8 damage_type = 0, int16 kill_blow_type = 0);
  309. void SendDamagePacket(Spawn* attacker, Spawn* victim, int8 type1, int8 type2, int8 damage_type, int16 damage, const char* spell_name);
  310. void SendHealPacket(Spawn* caster, Spawn* target, int16 type, int32 heal_amt, const char* spell_name);
  311. void SendCastSpellPacket(LuaSpell* spell, Entity* caster, int32 spell_visual_override = 0, int16 casttime_override = 0xFFFF);
  312. void SendCastSpellPacket(int32 spell_visual, Spawn* target, Spawn* caster = 0);
  313. void SendCastEntityCommandPacket(EntityCommand* entity_command, int32 spawn_id, int32 target_id);
  314. void TriggerCharSheetTimer();
  315. /// <summary>Sends the game time packet to all connected clients</summary>
  316. void SendTimeUpdateToAllClients();
  317. void AddWidgetTimer(Spawn* widget, float time);
  318. bool HasWidgetTimer(Spawn* widget);
  319. void Despawn(Spawn* spawn, int32 timer);
  320. void RepopSpawns(Client* client, Spawn* spawn);
  321. bool AddCloseSpawnsToSpawnGroup(Spawn* spawn, float radius);
  322. void Depop(bool respawns = false, bool repop = false);
  323. Spawn* GetSpawnGroup(int32 id);
  324. bool IsSpawnGroupAlive(int32 id);
  325. void AddEnemyList(NPC* npc);
  326. void ReloadClientQuests();
  327. void SendAllSpawnsForLevelChange(Client* client);
  328. void SendAllSpawnsForSeeInvisChange(Client* client);
  329. void SendAllSpawnsForVisChange(Client* client, bool limitToEntities=true);
  330. void AddLocationGrid(LocationGrid* grid);
  331. void RemoveLocationGrids();
  332. void DeleteTransporters();
  333. void CheckTransporters(Client* client);
  334. void WritePlayerStatistics();
  335. bool SendRadiusSpawnInfo(Client* client, float radius);
  336. void FindSpawn(Client* client, char* regSearchStr);
  337. volatile bool spawnthread_active;
  338. volatile bool combatthread_active;
  339. volatile int8 initial_spawn_threads_active;
  340. volatile bool client_thread_active;
  341. void AddChangedSpawn(Spawn* spawn);
  342. void AddDamagedSpawn(Spawn* spawn);
  343. void AddDrowningVictim(Player* player);
  344. void RemoveDrowningVictim(Player* player);
  345. Client* GetDrowningVictim(Player* player);
  346. void DeleteSpellProcess();
  347. void LoadSpellProcess();
  348. void LockAllSpells(Player* player);
  349. void UnlockAllSpells(Player* player);
  350. void RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, bool delete_recast = true, bool call_expire_function = true, bool lock_spell_process = false);
  351. void Interrupted(Entity* caster, Spawn* interruptor, int16 error_code, bool cancel = false, bool from_movement = false);
  352. Spell* GetSpell(Entity* caster);
  353. void ProcessSpell(Spell* spell, Entity* caster, Spawn* target = 0, bool lock = true, bool harvest_spell = false, LuaSpell* customSpell = 0, int16 custom_cast_time = 0, bool in_heroic_opp = false);
  354. void ProcessEntityCommand(EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock = true);
  355. void AddPlayerTracking(Player* player);
  356. void RemovePlayerTracking(Player* player, int8 mode);
  357. void SendUpdateTitles(Client *client, Title *suffix = 0, Title *prefix = 0);
  358. void SendUpdateTitles(Spawn *spawn, Title *suffix = 0, Title *prefix = 0);
  359. void RemoveTargetFromSpell(LuaSpell* spell, Spawn* target, bool remove_caster = false);
  360. /// <summary>Set the rain levl in the zone</summary>
  361. /// <param name='val'>Level of rain in the zone 0.0 - 1.1 (rain starts at 0.76)</param>
  362. void SetRain(float val);
  363. /// <summary>Sets the wind direction</summary>
  364. /// <param name='val'>Direction in degrees to set the wind</param>
  365. void SetWind(float val);
  366. /// <summary>Handles zone-wide weather changes</summary>
  367. void ProcessWeather();
  368. Spawn* GetClosestTransportSpawn(float x, float y, float z);
  369. Spawn* GetTransportByRailID(sint64 rail_id);
  370. void ResurrectSpawn(Spawn* spawn, Client* client);
  371. void HidePrivateSpawn(Spawn* spawn);
  372. Client* GetClientByName(char* name);
  373. Client* GetClientByCharID(int32 charid);
  374. bool SetPlayerTargetByName(Client* originator, char* targetName, float distance);
  375. std::vector<int32> GetGridsByLocation(Spawn* originator, glm::vec3 loc, float distance);
  376. /// <summary>Gets spawns for a true AoE spell</summary>
  377. std::vector<std::pair<int32, float>> GetAttackableSpawnsByDistance(Spawn* spawn, float distance);
  378. // Comparator function to sort by the value (second element of the pair)
  379. static bool compareByValue(const std::pair<int32, float>& a, const std::pair<int32, float>& b) {
  380. return a.second < b.second;
  381. }
  382. void StartZoneSpawnsForLevelThread(Client* client);
  383. void SendDispellPacket(Entity* caster, Spawn* target, string dispell_name, string spell_name, int8 dispell_type);
  384. void SetupInstance(int32 createdInstanceID=0);
  385. void SendUpdateDefaultCommand(Spawn* spawn, const char* command, float distance, Spawn* toplayer = NULL);
  386. map<int32, int32>* GetSpawnLocationsByGroup(int32 group_id);
  387. IPathfinder* pathing;
  388. MobMovementManager* movementMgr;
  389. /****************************************************
  390. Following functions are only used for LUA commands
  391. ****************************************************/
  392. int32 GetClosestLocation(Spawn* spawn);
  393. Spawn* GetClosestSpawn(Spawn* spawn, int32 spawn_id);
  394. SpawnLocation* GetSpawnLocation(int32 id);
  395. void PlayFlavor(Client* client, Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language);
  396. void PlayVoice(Client* client, Spawn* spawn, const char* mp3, int32 key1, int32 key2);
  397. void PlayFlavor(Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language);
  398. void PlayFlavorID(Spawn* spawn, int8 type, int32 id, int16 index, int8 language);
  399. void PlayVoice(Spawn* spawn, const char* mp3, int32 key1, int32 key2);
  400. void SendThreatPacket(Spawn* caster, Spawn* target, int32 threat_amt, const char* spell_name);
  401. void SendYellPacket(Spawn* yeller, float max_distance=50.0f);
  402. void KillSpawnByDistance(Spawn* spawn, float max_distance, bool include_players = false, bool send_packet = false);
  403. void SpawnSetByDistance(Spawn* spawn, float max_distance, string field, string value);
  404. void AddSpawnScriptTimer(SpawnScriptTimer* timer);
  405. Spawn* GetSpawnByLocationID(int32 location_id);
  406. void AddMovementNPC(Spawn* spawn);
  407. void AddPlayerProximity(Spawn* spawn, float distance, string in_range_function, string leaving_range_function);
  408. void AddLocationProximity(float x, float y, float z, float max_variation, string in_range_function, string leaving_range_function);
  409. void PlayAnimation(Spawn* spawn, int32 visual_state, Spawn* spawn2 = 0, int8 type = 1);
  410. void AddTransportSpawn(Spawn* spawn);
  411. vector<Spawn*> GetSpawnsByID(int32 id);
  412. vector<Spawn*> GetSpawnsByRailID(sint64 rail_id);
  413. void RemovePlayerPassenger(int32 char_id);
  414. bool IsDusk() { return isDusk; } // never used, probably meant for lua though
  415. /****************************************************
  416. Following functions are all contained in the header
  417. ****************************************************/
  418. inline const char* GetZoneName() { return zone_name; }
  419. void SetZoneName(char* new_zone) {
  420. if( strlen(new_zone) >= sizeof zone_name )
  421. return;
  422. strcpy(zone_name, new_zone);
  423. }
  424. inline const char* GetZoneFile() { return zone_file; }
  425. void SetZoneFile(char* zone) {
  426. if (strlen(zone) >= sizeof zone_file)
  427. return;
  428. strcpy(zone_file, zone);
  429. }
  430. inline const char* GetZoneSkyFile() { return zonesky_file; }
  431. void SetZoneSkyFile(char* zone) {
  432. if (strlen(zone) >= sizeof zonesky_file)
  433. return;
  434. strcpy(zonesky_file, zone);
  435. }
  436. inline const char* GetZoneDescription() { return zone_description; }
  437. void SetZoneDescription(char* desc) {
  438. if( strlen(desc) >= sizeof zone_description )
  439. return;
  440. strncpy(zone_description, desc, 255);
  441. }
  442. void SetUnderWorld(float under){ underworld = under; }
  443. float GetUnderWorld(){ return underworld; }
  444. inline int32 GetZoneID() { return zoneID; }
  445. void SetZoneID(int32 new_id){ zoneID = new_id; }
  446. inline bool IsCityZone() { return cityzone; }
  447. inline bool AlwaysLoaded() { return always_loaded; }
  448. void SetCityZone(bool val) { cityzone = val; }
  449. void SetAlwaysLoaded(bool val) { always_loaded = val; }
  450. inline int32& NumPlayers() { return pNumPlayers; }
  451. void SetMinimumStatus(sint16 minStatus) { minimumStatus = minStatus; }
  452. sint16 GetMinimumStatus() { return minimumStatus; }
  453. void SetMinimumLevel(int16 minLevel) { minimumLevel = minLevel; }
  454. void SetMaximumLevel(int16 maxLevel) { maximumLevel = maxLevel; }
  455. void SetMinimumVersion(int16 minVersion) { minimumVersion = minVersion; }
  456. int16 GetMinimumLevel() { return minimumLevel; }
  457. int16 GetMaximumLevel() { return maximumLevel; }
  458. int16 GetMinimumVersion() { return minimumVersion; }
  459. inline bool GetZoneLockState() { return locked; } // JA: /zone lock|unlock
  460. void SetZoneLockState(bool lock_state) { locked = lock_state; } // JA: /zone lock|unlock
  461. int32 GetInstanceID() { return instanceID; }
  462. bool IsInstanceZone() { return isInstance; }
  463. void SetInstanceID(int32 newInstanceID) { instanceID = newInstanceID; }
  464. void SetShutdownTimer(int val){
  465. shutdownTimer.SetTimer(val*1000);
  466. }
  467. void AddSpawnLocation(int32 id, SpawnLocation* spawnlocation) {
  468. MSpawnLocationList.writelock(__FUNCTION__, __LINE__);
  469. if (spawn_location_list.count(id) > 0)
  470. safe_delete(spawn_location_list[id]);
  471. spawn_location_list[id] = spawnlocation;
  472. MSpawnLocationList.releasewritelock(__FUNCTION__, __LINE__);
  473. }
  474. void SetInstanceType(int16 type) { InstanceType = (Instance_Type)type; if(type>0)isInstance=true; else isInstance=false; }
  475. Instance_Type GetInstanceType() { return InstanceType; }
  476. float GetSafeX(){ return safe_x; }
  477. float GetSafeY(){ return safe_y; }
  478. float GetSafeZ(){ return safe_z; }
  479. float GetSafeHeading() { return safe_heading; }
  480. void SetSafeX(float val){ safe_x = val; }
  481. void SetSafeY(float val){ safe_y = val; }
  482. void SetSafeZ(float val){ safe_z = val; }
  483. void SetSafeHeading(float val) { safe_heading = val; }
  484. float GetXPModifier() { return xp_mod; }
  485. void SetXPModifier(float val) { xp_mod = val; }
  486. void SetZoneMOTD(string z_motd) { zone_motd = z_motd; }
  487. string GetZoneMOTD() { return zone_motd; }
  488. bool isZoneShuttingDown ( ) { return zoneShuttingDown; }
  489. void Shutdown(){ zoneShuttingDown = true; }
  490. int32 GetClientCount(){ return clients.size(); }
  491. int32 GetDefaultLockoutTime() { return def_lockout_time; }
  492. int32 GetDefaultReenterTime() { return def_reenter_time; }
  493. int32 GetDefaultResetTime() { return def_reset_time; }
  494. int8 GetForceGroupZoneOption() { return group_zone_option; }
  495. void SetDefaultLockoutTime(int32 val) { def_lockout_time = val; }
  496. void SetDefaultReenterTime(int32 val) { def_reenter_time = val; }
  497. void SetDefaultResetTime(int32 val) { def_reset_time = val; }
  498. void SetForceGroupZoneOption(int8 val) { group_zone_option = val; }
  499. SpellProcess* GetSpellProcess() {return spellProcess;}
  500. bool FinishedDepop(){ return finished_depop; }
  501. /// <summary>Returns the Tradeskill Manager for this zone</summary>
  502. TradeskillMgr* GetTradeskillMgr() { return tradeskillMgr; }
  503. // had to add these to access weather from Commands
  504. bool isWeatherEnabled() { return weather_enabled; }
  505. void SetWeatherEnabled(bool val) { weather_enabled = val; }
  506. bool isWeatherAllowed() { return weather_allowed; }
  507. void SetWeatherAllowed(bool val) { weather_allowed = val; }
  508. int8 GetWeatherType() { return weather_type; }
  509. void SetWeatherType(int8 val) { weather_type = val; }
  510. int32 GetWeatherFrequency() { return weather_frequency; }
  511. void SetWeatherFrequency(int32 val) { weather_frequency = val; }
  512. float GetWeatherMinSeverity() { return weather_min_severity; }
  513. void SetWeatherMinSeverity(float val) { weather_min_severity = val; }
  514. float GetWeatherMaxSeverity() { return weather_max_severity; }
  515. void SetWeatherMaxSeverity(float val) { weather_max_severity = val; }
  516. float GetWeatherChangeAmount() { return weather_change_amount; }
  517. void SetWeatherChangeAmount(float val) { weather_change_amount = val; }
  518. float GetWeatherDynamicOffset() { return weather_dynamic_offset; }
  519. void SetWeatherDynamicOffset(float val) { weather_dynamic_offset = val; }
  520. int8 GetWeatherChance() { return weather_change_chance; }
  521. void SetWeatherChance(int8 val) { weather_change_chance = val; }
  522. float GetCurrentWeather() { return weather_current_severity; }
  523. void SetCurrentWeather(float val) { weather_current_severity = val; }
  524. int8 GetWeatherPattern() { return weather_pattern; }
  525. void SetWeatherPattern(int8 val) { weather_pattern = val; }
  526. void SetWeatherLastChangedTime(int32 val) { weather_last_changed_time = val; }
  527. int32 GetExpansionFlag() { return expansion_flag; }
  528. void SetExpansionFlag(int32 val) { expansion_flag = val; }
  529. int32 GetHolidayFlag() { return holiday_flag; }
  530. void SetHolidayFlag(int32 val) { holiday_flag = val; }
  531. int32 GetCanBind() { return can_bind; }
  532. void SetCanBind(int32 val) { can_bind = val; }
  533. bool GetCanGate() { return can_gate; }
  534. void SetCanGate(int32 val) { can_gate = val; }
  535. bool GetCanEvac() { return can_evac; }
  536. void SetCanEvac(int32 val) { can_evac = val; }
  537. void RemoveClientImmediately(Client* client);
  538. void ClearHate(Entity* entity);
  539. /****************************************************
  540. Following functions are pending deletion, left in for
  541. now just to make sure one won't be of future use.
  542. ****************************************************/
  543. //void RemoveFromRangeMap(Client* client); // never used?
  544. //void AddSpawnAssociatedGroup(vector<int32>* ret, int32 group_id); // never used, not even any code for it
  545. //inline const char* GetCAddress() { return clientaddress; } // never used?
  546. //inline int16 GetCPort() { return clientport; } // never used?
  547. //inline bool IsBootingUp() { return BootingUp; } // never used?
  548. //int32 GetShutdownTimer() {return shutdownTimer.GetTimerTime();} // never used
  549. // Following were private
  550. //char clientaddress[250]; // never used
  551. //int16 clientport; // never used
  552. //bool BootingUp; // never used
  553. //bool authenticated; // never used?
  554. //int16 next_index; // never used
  555. void AddFlightPath(int32 id, FlightPathInfo* info);
  556. void AddFlightPathLocation(int32 id, FlightPathLocation* location);
  557. void DeleteFlightPaths();
  558. void SendFlightPathsPackets(Client* client);
  559. int32 GetFlightPathIndex(int32 id);
  560. float GetFlightPathSpeed(int32 id);
  561. void SendSpawn(Spawn* spawn, Client* client); // moved from private to public for bots
  562. void ProcessSpawnConditional(int8 condition);
  563. void SetSpawnStructs(Client* client);
  564. void AddSpawnProximities(Spawn* spawn);
  565. void RemoveSpawnProximities(Spawn* spawn);
  566. void SetSpawnScript(SpawnEntry* entry, Spawn* spawn);
  567. bool IsLoading() {
  568. return LoadingData;
  569. }
  570. vector<HouseItem> GetHouseItems(Client* client);
  571. Spawn* GetSpawnFromUniqueItemID(int32 unique_id);
  572. void SendHouseItems(Client* client);
  573. MutexMap<int32, int32> house_object_database_lookup; // 1st int32 = model type, 2nd int32 = spawn id
  574. int32 GetWatchdogTime() { return watchdogTimestamp; }
  575. void SetWatchdogTime(int32 time) { watchdogTimestamp = time; }
  576. void CancelThreads();
  577. void AddPendingSpawnRemove(int32 id);
  578. void ProcessSpawnRemovals();
  579. bool SendRemoveSpawn(Client* client, Spawn* spawn, PacketStruct* packet = 0, bool delete_spawn = false);
  580. void AddSpawnToGroup(Spawn* spawn, int32 group_id);
  581. void QueueStateCommandToClients(int32 spawn_id, int32 state);
  582. void QueueDefaultCommand(int32 spawn_id, std::string command, float distance);
  583. void ProcessQueuedStateCommands();
  584. void RemoveClientsFromZone(ZoneServer* zone);
  585. void WorldTimeUpdateTrigger() { sync_game_time_timer.Trigger(); }
  586. void StopSpawnScriptTimer(Spawn* spawn, std::string functionName);
  587. Client* RemoveZoneServerFromClient(ZoneServer* zone);
  588. void SendSubSpawnUpdates(SUBSPAWN_TYPES subtype);
  589. bool HouseItemSpawnExists(int32 item_id);
  590. void ProcessPendingSpawns();
  591. void AddSpawnToGrid(Spawn* spawn, int32 grid_id);
  592. void RemoveSpawnFromGrid(Spawn* spawn, int32 grid_id);
  593. int32 GetSpawnCountInGrid(int32 grid_id);
  594. void SendClientSpawnListInGrid(Client* client, int32 grid_id);
  595. void AddIgnoredWidget(int32 id);
  596. void AddRespawn(Spawn* spawn);
  597. void AddRespawn(int32 locationID, int32 respawnTime);
  598. private:
  599. #ifndef WIN32
  600. pthread_t ZoneThread;
  601. pthread_t SpawnThread;
  602. #endif
  603. /* Private Functions */
  604. void AddTransporter(LocationTransportDestination* loc);
  605. void CheckDeadSpawnRemoval();
  606. void DeleteData(bool boot_clients = true);
  607. void DeleteFactionLists();
  608. void ProcessDepop(bool respawns_allowed = false, bool repop = false);
  609. /*
  610. Following functions were public but never used outside the zone server so moved them to private
  611. */
  612. void ClientProcess(bool ignore_shutdown_timer = false); // never used outside zone server
  613. void RemoveClient(Client* client); // never used outside zone server
  614. void DeterminePosition(SpawnLocation* spawnlocation, Spawn* spawn); // never used outside zone server
  615. void AddDeadSpawn(Spawn* spawn, int32 timer = 0xFFFFFFFF); // never used outside zone server
  616. int32 CalculateSpawnGroup(SpawnLocation* spawnlocation, bool respawn = false); // never used outside zone server
  617. float GetSpawnGroupChance(int32 group_id); // never used outside zone server
  618. vector<int32>* GetAssociatedLocations(set<int32>* groups); // never used outside zone server
  619. set<int32>* GetAssociatedGroups(int32 group_id); // never used outside zone server
  620. list<int32>* GetSpawnGroupsByLocation(int32 location_id); // never used outside zone server
  621. void ProcessSpawnLocation(int32 location_id, map<int32,int32>* instNPCs, map<int32,int32>* instGroundSpawns, map<int32,int32>* instObjSpawns, map<int32,int32>* instWidgetSpawns, map<int32,int32>* instSignSpawns, bool respawn = false); // never used outside zone server
  622. Spawn* ProcessSpawnLocation(SpawnLocation* spawnlocation, map<int32,int32>* instNPCs, map<int32,int32>* instGroundSpawns, map<int32,int32>* instObjSpawns, map<int32,int32>* instWidgetSpawns, map<int32,int32>* instSignSpawns, bool respawn = false); // never used outside zone server
  623. Spawn* ProcessInstanceSpawnLocation(SpawnLocation* spawnlocation, map<int32,int32>* instNPCs, map<int32,int32>* instGroundSpawns, map<int32,int32>* instObjSpawns, map<int32,int32>* instWidgetSpawns, map<int32,int32>* instSignSpawns, bool respawn = false); // never used outside zone server
  624. void SendRaidSheetChanges(); // never used outside zone server
  625. void SendCharSheetChanges(); // never used outside zone server
  626. void SendCharSheetChanges(Client* client); // never used outside zone server
  627. void SaveClients(); // never used outside zone server
  628. void CheckSendSpawnToClient(); // never used outside zone server
  629. void CheckSendSpawnToClient(Client* client, bool initial_login = false); // never used outside zone server
  630. void CheckRemoveSpawnFromClient(Spawn* spawn); // never used outside zone server
  631. void SaveClient(Client* client); // never used outside zone server
  632. void ProcessFaction(Spawn* spawn, Client* client); // never used outside zone server
  633. void RegenUpdate(); // never used outside zone server
  634. void SendCalculatedXP(Player* player, Spawn* victim); // never used outside zone server, might not be used at all any more
  635. void SendTimeUpdate(Client* client); // never used outside zone server
  636. void CheckWidgetTimers(); // never used outside zone server
  637. void CheckRespawns(); // never used outside zone server
  638. void CheckSpawnExpireTimers(); // never used outside zone server
  639. void AddSpawnExpireTimer(Spawn* spawn, int32 expire_time, int32 expire_offset = 0); // never used outside zone server
  640. void CheckSpawnRange(Client* client, Spawn* spawn, bool initial_login = false); // never used outside zone server
  641. void CheckSpawnRange(Spawn* spawn); // never used outside zone server
  642. void DeleteSpawnScriptTimers(Spawn* spawn, bool all = false); // never used outside zone server
  643. void DeleteSpawnScriptTimers(); // never used outside zone server
  644. void CheckSpawnScriptTimers(); // never used outside zone server
  645. bool PrepareSpawnID(Player* player, Spawn* spawn); // never used outside zone server
  646. void RemoveMovementNPC(Spawn* spawn); // never used outside zone server
  647. bool CheckNPCAttacks(NPC* npc, Spawn* victim, Client* client = 0); // never used outside zone server
  648. bool AggroVictim(NPC* npc, Spawn* victim, Client* client = 0); // never used outside zone server
  649. bool CheckEnemyList(NPC* npc); // never used outside zone server
  650. void RemovePlayerProximity(Spawn* spawn, bool all = false); // never used outside zone server
  651. void RemovePlayerProximity(Client* client); // never used outside zone server
  652. void CheckPlayerProximity(Spawn* spawn, Client* client); // never used outside zone server
  653. void RemoveLocationProximities(); // never used outside zone server
  654. void CheckLocationProximity(); // never used outside zone server
  655. void CheckLocationGrids(); // never used outside zone server
  656. void RemoveSpawnSupportFunctions(Spawn* spawn, bool lock_spell_process = false, bool shutdown = false); // never used outside zone server
  657. void ReloadTransporters(); // never used outside zone server
  658. void DeleteSpawns(bool delete_all); // never used outside zone server
  659. void AddPendingDelete(Spawn* spawn); // never used outside zone server
  660. void ClearDeadSpawns(); // never used outside zone server
  661. void RemoveChangedSpawn(Spawn* spawn); // never used outside zone server
  662. void ProcessDrowning(); // never used outside zone server
  663. void RemoveDamagedSpawn(Spawn* spawn); // never used outside zone server
  664. void ProcessTracking(); // never used outside zone server
  665. void ProcessTracking(Client* client); // never used outside zone server
  666. void SendEpicMobDeathToGuild(Player* killer, Spawn* victim); // never used outside zone server
  667. void ProcessAggroChecks(Spawn* spawn); // never used outside zone server
  668. /// <summary>Checks to see if it is time to remove a spawn and removes it</summary>
  669. /// <param name='force_delete_all'>Forces all spawns scheduled to be removed regardless of time</param>
  670. bool CombatProcess(Spawn* spawn); // never used outside zone server
  671. void LootProcess(Spawn* spawn);
  672. void CloseSpawnLootWindow(Spawn* spawn);
  673. void InitWeather(); // never used outside zone server
  674. ///<summary>Dismiss all pets in the zone, useful when the spell process needs to be reloaded</summary>
  675. void DismissAllPets(); // never used outside zone server
  676. /* Mutex Lists */
  677. std::map<int32, bool> changed_spawns; // int32 = spawn id
  678. vector<Client*> clients;
  679. MutexList<Client*> connected_clients; // probably remove this list so we are not maintaining 2 client lists
  680. MutexList<int32> damaged_spawns; // int32 = spawn id
  681. MutexList<LocationProximity*> location_proximities;
  682. MutexList<LocationGrid*> location_grids;
  683. MutexList<int32> remove_movement_spawns; // int32 = spawn id
  684. set<SpawnScriptTimer*> spawn_script_timers;
  685. Mutex MSpawnScriptTimers;
  686. set<SpawnScriptTimer*> remove_spawn_script_timers_list;
  687. Mutex MRemoveSpawnScriptTimersList;
  688. list<LocationTransportDestination*> transporter_locations;
  689. /* Mutex Maps */
  690. MutexMap<Client*, int32> drowning_victims;
  691. MutexMap<int32, int32> movement_spawns; // 1st int32 = spawn id
  692. MutexMap<int32, PlayerProximity*> player_proximities; // 1st int32 = spawn id
  693. MutexMap<int32, Player*> players_tracking;
  694. MutexMap<int32, int32> quick_database_id_lookup; // 1st int32 = database id, 2nd int32 = spawn id
  695. MutexMap<int32, int32> quick_location_id_lookup; // 1st int32 = location id, 2nd int32 = spawn id
  696. MutexMap<int32, int32> quick_group_id_lookup; // 1st int32 = group id, 2nd int32 = spawn id
  697. MutexMap<int32, int32> respawn_timers;
  698. map<Spawn*, int32> spawn_delete_list;
  699. MutexMap<int32, int32> spawn_expire_timers; // 1st int32 = spawn id
  700. map<int32, set<int32>* > spawn_group_associations;
  701. map<int32, float> spawn_group_chances;
  702. map<int32, map<int32, int32>* > spawn_group_locations;
  703. MutexMap<int32, MutexList<int32> > spawn_group_map; // MutexList<int32> is a list of spawn id's
  704. map<int32, list<int32>* > spawn_location_groups;
  705. map<int32, SpawnLocation*> spawn_location_list;
  706. MutexMap<Client*, MutexMap<int32, float >* > spawn_range_map; // int32 in the MutexMap<int32, float>* = spawn id, float = distance
  707. Mutex MWidgetTimers;
  708. map<int32, int32> widget_timers; // 1st int32 = spawn id
  709. std::map<int32, GridMap*> grid_maps;
  710. /* Mutexs */
  711. mutable std::shared_mutex MGridMaps;
  712. mutable std::shared_mutex MChangedSpawns;
  713. Mutex m_enemy_faction_list;
  714. Mutex m_npc_faction_list;
  715. Mutex m_reverse_enemy_faction_list;
  716. Mutex MDeadSpawns;
  717. CriticalSection* MMasterZoneLock; //This needs to be a recursive lock to fix a possible /reload spells crash with multiple zones loaded - Foof
  718. Mutex MMasterSpawnLock;
  719. Mutex MPendingSpawnListAdd;
  720. Mutex MSpawnList;
  721. Mutex MTransportSpawns;
  722. Mutex MSpawnGroupAssociation;
  723. Mutex MSpawnGroupLocations;
  724. Mutex MSpawnLocationGroups;
  725. Mutex MSpawnGroupChances;
  726. Mutex MTransportLocations;
  727. Mutex MSpawnLocationList;
  728. Mutex MSpawnDeleteList;
  729. Mutex MClientList;
  730. Mutex MIncomingClients;
  731. /* Maps */
  732. map<int32, int32> dead_spawns;
  733. map<int32, vector<int32>* > enemy_faction_list;
  734. map<int32, vector<int32>* > npc_faction_list;
  735. map<int32, vector<int32>* > reverse_enemy_faction_list;
  736. map<int32, Spawn*> spawn_list;
  737. map<int32, FlightPathInfo*> m_flightPaths;
  738. map<int32, vector<FlightPathLocation*> > m_flightPathRoutes;
  739. /* Lists */
  740. list<Spawn*> pending_spawn_list_add;
  741. /* Specialized Lists to update specific scenarios */
  742. std::map<int32, Spawn*> subspawn_list[SUBSPAWN_TYPES::MAX_SUBSPAWN_TYPE];
  743. std::map<int32, int32> housing_spawn_map;
  744. /* Vectors */
  745. vector<RevivePoint*>* revive_points;
  746. vector<int32> transport_spawns;
  747. /* Classes */
  748. SpellProcess* spellProcess;
  749. TradeskillMgr* tradeskillMgr;
  750. /* Timers */
  751. Timer aggro_timer;
  752. Timer charsheet_changes;
  753. Timer client_save;
  754. Timer location_prox_timer;
  755. Timer location_grid_timer;
  756. Timer movement_timer;
  757. Timer regenTimer;
  758. Timer respawn_timer;
  759. Timer shutdownTimer;
  760. Timer startupDelayTimer;
  761. Timer spawn_check_add;
  762. Timer spawn_check_remove;
  763. Timer spawn_expire_timer;
  764. Timer spawn_range;
  765. Timer spawn_update;
  766. Timer sync_game_time_timer;
  767. Timer tracking_timer;
  768. Timer weatherTimer;
  769. Timer widget_timer;
  770. Timer queue_updates;
  771. Timer shutdownDelayTimer;
  772. /* Enums */
  773. Instance_Type InstanceType;
  774. /* Variables */
  775. volatile bool finished_depop;
  776. volatile bool depop_zone;
  777. volatile bool repop_zone;
  778. volatile bool respawns_allowed;
  779. volatile bool LoadingData;
  780. std::atomic<bool> reloading_spellprocess;
  781. std::atomic<bool> zoneShuttingDown;
  782. std::atomic<bool> is_initialized;
  783. bool cityzone;
  784. bool always_loaded;
  785. bool isInstance;
  786. int32 pNumPlayers;
  787. sint16 minimumStatus;
  788. int16 minimumLevel;
  789. int16 maximumLevel;
  790. int16 minimumVersion;
  791. char zone_name[64];
  792. char zonesky_file[64];
  793. char zone_file[64];
  794. char zone_description[255];
  795. float underworld;
  796. float safe_x;
  797. float safe_y;
  798. float safe_z;
  799. float safe_heading;
  800. float xp_mod;
  801. volatile int32 zoneID;
  802. bool locked; // JA: implementing /zone lock|unlock commands
  803. int32 instanceID;
  804. string zone_motd;
  805. int32 def_reenter_time;
  806. int32 def_reset_time;
  807. int32 def_lockout_time;
  808. int8 group_zone_option;
  809. float rain;
  810. bool isDusk;
  811. int dusk_hour;
  812. int dawn_hour;
  813. int dusk_minute;
  814. int dawn_minute;
  815. int32 spawn_delete_timer;
  816. int32 expansion_flag;
  817. int32 holiday_flag;
  818. //devn00b:test
  819. int can_bind;
  820. bool can_gate;
  821. bool can_evac;
  822. map<int16, PacketStruct*> versioned_pos_structs;
  823. map<int16, PacketStruct*> versioned_info_structs;
  824. map<int16, PacketStruct*> versioned_vis_structs;
  825. /* Weather Stuff */
  826. bool weather_enabled; // false = disabled, true = enabled
  827. int8 weather_type; // 0 = normal, 1 = dynamic, 2 = random, 3 = chaotic
  828. int32 weather_frequency; // how often weather changes
  829. float weather_min_severity; // minimum weather severity in a zone
  830. float weather_max_severity; // maximum weather severity in a zone
  831. float weather_change_amount; // how much does the weather change each interval (normal weather conditions)
  832. float weather_dynamic_offset; // max amount the weather change each interval (dynamic weather conditions)
  833. int8 weather_change_chance; // percentage chance the weather will change
  834. int8 weather_pattern; // 0 = decreasing severity, 1 = increasing severity, 2 = random severity
  835. int32 weather_last_changed_time; // last time weather changed (used with weather_frequency)
  836. float weather_current_severity; // current weather conditions in a zone
  837. bool weather_allowed; // from zones.weather_allowed field in database
  838. bool weather_signaled; // whether or not we told the client "it begins to rain"
  839. bool reloading;
  840. map<int32, vector<EntityCommand*>* > entity_command_list;
  841. map<int32, map<int32, int16> > npc_skill_list;
  842. map<int32, vector<int32> > npc_equipment_list;
  843. map<int32, NPC*> npc_list;
  844. map<int32,Object*> object_list;
  845. map<int32,Sign*> sign_list;
  846. map<int32,Widget*> widget_list;
  847. map<int32, vector<GroundSpawnEntry*> > groundspawn_entries;
  848. map<int32, vector<GroundSpawnEntryItem*> > groundspawn_items;
  849. Mutex MGroundSpawnItems;
  850. map<int32,GroundSpawn*> groundspawn_list;
  851. map<int32,LootTable*> loot_tables;
  852. map<int32, vector<LootDrop*> > loot_drops;
  853. map<int32, vector<int32> > spawn_loot_list;
  854. vector<GlobalLoot*> level_loot_list;
  855. map<int16, vector<GlobalLoot*> > racial_loot_list;
  856. map<int32, vector<GlobalLoot*> > zone_loot_list;
  857. map<int32, vector<TransportDestination*> > transporters;
  858. map<int32, MutexList<LocationTransportDestination*>* > location_transporters;
  859. Mutex MTransporters;
  860. Mutex MTransportMaps;
  861. // Map <transport if, map name>
  862. map<int32, string> m_transportMaps;
  863. int32 watchdogTimestamp;
  864. std::map<int32, bool> m_pendingSpawnRemove;
  865. Mutex MPendingSpawnRemoval;
  866. std::map<int32, int32> lua_queued_state_commands;
  867. std::map<int32, std::map<std::string, float>> lua_spawn_update_command;
  868. std::mutex MLuaQueueStateCmd;
  869. mutable std::shared_mutex MIgnoredWidgets;
  870. std::map<int32, bool> ignored_widgets;
  871. Map* default_zone_map; // this is the map that npcs, ground spawns, so on use. May not be the same as the clients!
  872. public:
  873. Spawn* GetSpawn(int32 id);
  874. /* Entity Commands */
  875. map<int32, vector<EntityCommand*>*>* GetEntityCommandListAll() {return &entity_command_list;}
  876. vector<EntityCommand*>* GetEntityCommandList(int32 id);
  877. void SetEntityCommandList(int32 id, EntityCommand* command);
  878. void ClearEntityCommands();
  879. EntityCommand* GetEntityCommand(int32 id, string name);
  880. /* NPC's */
  881. void AddNPC(int32 id, NPC* npc);
  882. NPC* GetNPC(int32 id, bool override_loading = false) {
  883. if((!reloading || override_loading) && npc_list.count(id) > 0)
  884. return npc_list[id];
  885. else
  886. return 0;
  887. }
  888. NPC* GetNewNPC(int32 id) {
  889. if(!reloading && npc_list.count(id) > 0)
  890. return new NPC(npc_list[id]);
  891. else
  892. return 0;
  893. }
  894. /* NPC Skills */
  895. void AddNPCSkill(int32 list_id, int32 skill_id, int16 value);
  896. map<string, Skill*>* GetNPCSkills(int32 primary_list, int32 secondary_list);
  897. /* NPC Equipment */
  898. void AddNPCEquipment(int32 list_id, int32 item_id);
  899. void SetNPCEquipment(NPC* npc);
  900. /* Objects */
  901. void AddObject(int32 id, Object* object){ object_list[id] = object; }
  902. Object* GetObject(int32 id, bool override_loading = false) {
  903. if((!reloading || override_loading) && object_list.count(id) > 0)
  904. return object_list[id];
  905. else
  906. return 0;
  907. }
  908. Object* GetNewObject(int32 id) {
  909. if(!reloading && object_list.count(id) > 0)
  910. return object_list[id]->Copy();
  911. else
  912. return 0;
  913. }
  914. /* Signs */
  915. void AddSign(int32 id, Sign* sign){ sign_list[id] = sign; }
  916. Sign* GetSign(int32 id, bool override_loading = false) {
  917. if((!reloading || override_loading) && sign_list.count(id) > 0)
  918. return sign_list[id];
  919. else
  920. return 0;
  921. }
  922. Sign* GetNewSign(int32 id) {
  923. if(!reloading && sign_list.count(id) > 0)
  924. return sign_list[id]->Copy();
  925. else
  926. return 0;
  927. }
  928. /* Widgets */
  929. void AddWidget(int32 id, Widget* widget);
  930. Widget* GetWidget(int32 id, bool override_loading = false);
  931. Widget* GetNewWidget(int32 id);
  932. /* Groundspawns */
  933. // JA: groundspawn revamp
  934. void AddGroundSpawnEntry(int32 groundspawn_id, int16 min_skill_level, int16 min_adventure_level, int8 bonus_table, float harvest1, float harvest3, float harvest5, float harvest_imbue, float harvest_rare, float harvest10, int32 harvest_coin);
  935. void AddGroundSpawnItem(int32 groundspawn_id, int32 item_id, int8 is_rare, int32 grid_id);
  936. vector<GroundSpawnEntry*>* GetGroundSpawnEntries(int32 id);
  937. vector<GroundSpawnEntryItem*>* GetGroundSpawnEntryItems(int32 id);
  938. void LoadGroundSpawnEntries();
  939. void LoadGroundSpawnItems();
  940. //
  941. void DeleteGroundSpawnItems();
  942. void AddGroundSpawn(int32 id, GroundSpawn* spawn);
  943. GroundSpawn* GetGroundSpawn(int32 id, bool override_loading = false);
  944. GroundSpawn* GetNewGroundSpawn(int32 id);
  945. /* Pet names */
  946. vector<string> pet_names;
  947. /* Loot */
  948. void AddLootTable(int32 id, LootTable* table);
  949. void AddLootDrop(int32 id, LootDrop* drop);
  950. void AddSpawnLootList(int32 spawn_id, int32 id);
  951. void ClearSpawnLootList(int32 spawn_id);
  952. void AddLevelLootList(GlobalLoot* loot);
  953. void AddRacialLootList(int16 racial_id, GlobalLoot* loot);
  954. void AddZoneLootList(int32 zone, GlobalLoot* loot);
  955. void ClearLootTables();
  956. vector<int32> GetSpawnLootList(int32 spawn_id, int32 zone_id, int8 spawn_level, int16 racial_id, Spawn* spawn = 0);
  957. vector<LootDrop*>* GetLootDrops(int32 table_id);
  958. LootTable* GetLootTable(int32 table_id);
  959. /* Transporters */
  960. void AddLocationTransporter(int32 zone_id, string message, float trigger_x, float trigger_y, float trigger_z, float trigger_radius, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading, int32 cost, int32 unique_id);
  961. void AddTransporter(int32 transport_id, int8 type, string name, string message, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading,
  962. int32 cost, int32 unique_id, int8 min_level, int8 max_level, int32 quest_req, int16 quest_step_req, int32 quest_complete, int32 map_x, int32 map_y, int32 expansion_flag, int32 holiday_flag, int32 min_client_version,
  963. int32 max_client_version, int32 flight_path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color);
  964. void GetTransporters(vector<TransportDestination*>* returnList, Client* client, int32 transport_id);
  965. MutexList<LocationTransportDestination*>* GetLocationTransporters(int32 zone_id);
  966. void DeleteGlobalTransporters();
  967. ///<summary></summary>
  968. ///<param name='id'>The transport id</param>
  969. ///<param name='name'>Name of the map</param>
  970. void AddTransportMap(int32 id, string name);
  971. ///<summary>Checks to see if the transport has a map</summary>
  972. ///<param name='id'>The transport id we want to check</param>
  973. ///<returns>True if the transport id has a map</returns>
  974. bool TransportHasMap(int32 id);
  975. ///<summary>Gets the map name for the given transport id</summary>
  976. ///<param name='id'>The transport id that we want a map for</param>
  977. ///<returns>Map name</returns>
  978. string GetTransportMap(int32 id);
  979. ///<summary>Clears the list of transporter maps</summary>
  980. void DeleteTransporterMaps();
  981. void DeleteGlobalSpawns();
  982. void ReloadSpawns();
  983. void SendStateCommand(Spawn* spawn, int32 state);
  984. int32 lifetime_client_count;
  985. int32 incoming_clients;
  986. };
  987. #endif