zoneserver.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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 HandleBroadcast(const char* message);
  266. void HandleAnnouncement(const char* message);
  267. int16 SetSpawnTargetable(Spawn* spawn, float distance);
  268. int16 SetSpawnTargetable(int32 spawn_id);
  269. void ApplySetSpawnCommand(Client* client, Spawn* target, int8 type, const char* value);
  270. void SetSpawnCommand(Spawn* spawn, int8 type, char* value, Client* client = 0);
  271. void SetSpawnCommand(int32 spawn_id, int8 type, char* value, Client* client = 0);
  272. void AddLoot(NPC* npc, Spawn* killer = nullptr);
  273. NPC* AddNPCSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  274. Object* AddObjectSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  275. GroundSpawn* AddGroundSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  276. Widget* AddWidgetSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  277. Sign* AddSignSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry);
  278. void AddSpawn(Spawn* spawn);
  279. void RemoveDeadEnemyList(Spawn* spawn);
  280. void RemoveDeadSpawn(Spawn* spawn);
  281. void AddSpawnGroupLocation(int32 group_id, int32 location_id, int32 spawn_location_id);
  282. void AddSpawnGroupAssociation(int32 group_id1, int32 group_id2);
  283. void AddSpawnGroupChance(int32 group_id, float percent);
  284. 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);
  285. void ProcessSpawnLocations();
  286. void SendQuestUpdates(Client* client, Spawn* spawn = 0);
  287. EQ2Packet* GetZoneInfoPacket(Client* client);
  288. Spawn* FindSpawn(Player* searcher, const char* name);
  289. 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);
  290. void SendSpawnVisualState(Spawn* spawn, int16 type);
  291. void SendSpellFailedPacket(Client* client, int16 error);
  292. void SendInterruptPacket(Spawn* interrupted, LuaSpell* spell, bool fizzle=false);
  293. void HandleEmote(Spawn* originator, string name);
  294. Client* GetClientBySpawn(Spawn* spawn);
  295. Spawn* GetSpawnByDatabaseID(int32 id);
  296. Spawn* GetSpawnByID(int32 id, bool spawnListLocked=false);
  297. void PlaySoundFile(Client* client, const char* name, float origin_x, float origin_y, float origin_z);
  298. void SendZoneSpawns(Client* client);
  299. void StartZoneInitialSpawnThread(Client* client);
  300. void SendSpawnChanges();
  301. void SendSpawnChanges(Spawn* spawn);
  302. void SendSpawnChanges(Spawn* spawn, Client* client, bool override_changes = false, bool override_vis_changes = false);
  303. void SendSpawnChangesByDBID(int32 spawn_id, Client* client, bool override_changes = false, bool override_vis_changes = false);
  304. void SendPlayerPositionChanges(Player* player);
  305. void UpdateVitality(float amount);
  306. vector<Entity*> GetPlayers();
  307. void KillSpawn(bool spawnListLocked, Spawn* dead, Spawn* killer, bool send_packet = true, int8 type = 0, int8 damage_type = 0, int16 kill_blow_type = 0);
  308. void SendDamagePacket(Spawn* attacker, Spawn* victim, int8 type1, int8 type2, int8 damage_type, int16 damage, const char* spell_name);
  309. void SendHealPacket(Spawn* caster, Spawn* target, int16 type, int32 heal_amt, const char* spell_name);
  310. void SendCastSpellPacket(LuaSpell* spell, Entity* caster);
  311. void SendCastSpellPacket(int32 spell_visual, Spawn* target, Spawn* caster = 0);
  312. void SendCastEntityCommandPacket(EntityCommand* entity_command, int32 spawn_id, int32 target_id);
  313. void TriggerCharSheetTimer();
  314. /// <summary>Sends the game time packet to all connected clients</summary>
  315. void SendTimeUpdateToAllClients();
  316. void AddWidgetTimer(Spawn* widget, float time);
  317. bool HasWidgetTimer(Spawn* widget);
  318. void Despawn(Spawn* spawn, int32 timer);
  319. void RepopSpawns(Client* client, Spawn* spawn);
  320. bool AddCloseSpawnsToSpawnGroup(Spawn* spawn, float radius);
  321. void Depop(bool respawns = false, bool repop = false);
  322. Spawn* GetSpawnGroup(int32 id);
  323. void AddEnemyList(NPC* npc);
  324. void ReloadClientQuests();
  325. void SendAllSpawnsForLevelChange(Client* client);
  326. void SendAllSpawnsForSeeInvisChange(Client* client);
  327. void SendAllSpawnsForVisChange(Client* client, bool limitToEntities=true);
  328. void AddLocationGrid(LocationGrid* grid);
  329. void RemoveLocationGrids();
  330. void DeleteTransporters();
  331. void CheckTransporters(Client* client);
  332. void WritePlayerStatistics();
  333. bool SendRadiusSpawnInfo(Client* client, float radius);
  334. void FindSpawn(Client* client, char* regSearchStr);
  335. volatile bool spawnthread_active;
  336. volatile bool combatthread_active;
  337. volatile int8 initial_spawn_threads_active;
  338. volatile bool client_thread_active;
  339. void AddChangedSpawn(Spawn* spawn);
  340. void AddDamagedSpawn(Spawn* spawn);
  341. void AddDrowningVictim(Player* player);
  342. void RemoveDrowningVictim(Player* player);
  343. Client* GetDrowningVictim(Player* player);
  344. void DeleteSpellProcess();
  345. void LoadSpellProcess();
  346. void LockAllSpells(Player* player);
  347. void UnlockAllSpells(Player* player);
  348. void RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, bool delete_recast = true, bool call_expire_function = true, bool lock_spell_process = false);
  349. void Interrupted(Entity* caster, Spawn* interruptor, int16 error_code, bool cancel = false, bool from_movement = false);
  350. Spell* GetSpell(Entity* caster);
  351. 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);
  352. void ProcessEntityCommand(EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock = true);
  353. void AddPlayerTracking(Player* player);
  354. void RemovePlayerTracking(Player* player, int8 mode);
  355. void SendUpdateTitles(Client *client, Title *suffix = 0, Title *prefix = 0);
  356. void SendUpdateTitles(Spawn *spawn, Title *suffix = 0, Title *prefix = 0);
  357. void RemoveTargetFromSpell(LuaSpell* spell, Spawn* target, bool remove_caster = false);
  358. /// <summary>Set the rain levl in the zone</summary>
  359. /// <param name='val'>Level of rain in the zone 0.0 - 1.1 (rain starts at 0.76)</param>
  360. void SetRain(float val);
  361. /// <summary>Sets the wind direction</summary>
  362. /// <param name='val'>Direction in degrees to set the wind</param>
  363. void SetWind(float val);
  364. /// <summary>Handles zone-wide weather changes</summary>
  365. void ProcessWeather();
  366. Spawn* GetClosestTransportSpawn(float x, float y, float z);
  367. Spawn* GetTransportByRailID(sint64 rail_id);
  368. void ResurrectSpawn(Spawn* spawn, Client* client);
  369. void HidePrivateSpawn(Spawn* spawn);
  370. Client* GetClientByName(char* name);
  371. Client* GetClientByCharID(int32 charid);
  372. /// <summary>Gets spawns for a true AoE spell</summary>
  373. vector<int32> GetAttackableSpawnsByDistance(Spawn* spawn, float distance);
  374. void StartZoneSpawnsForLevelThread(Client* client);
  375. void SendDispellPacket(Entity* caster, Spawn* target, string dispell_name, string spell_name, int8 dispell_type);
  376. void SetupInstance(int32 createdInstanceID=0);
  377. void SendUpdateDefaultCommand(Spawn* spawn, const char* command, float distance, Spawn* toplayer = NULL);
  378. map<int32, int32>* GetSpawnLocationsByGroup(int32 group_id);
  379. IPathfinder* pathing;
  380. MobMovementManager* movementMgr;
  381. /****************************************************
  382. Following functions are only used for LUA commands
  383. ****************************************************/
  384. int32 GetClosestLocation(Spawn* spawn);
  385. Spawn* GetClosestSpawn(Spawn* spawn, int32 spawn_id);
  386. SpawnLocation* GetSpawnLocation(int32 id);
  387. void PlayFlavor(Client* client, Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language);
  388. void PlayVoice(Client* client, Spawn* spawn, const char* mp3, int32 key1, int32 key2);
  389. void PlayFlavor(Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language);
  390. void PlayFlavorID(Spawn* spawn, int8 type, int32 id, int16 index, int8 language);
  391. void PlayVoice(Spawn* spawn, const char* mp3, int32 key1, int32 key2);
  392. void SendThreatPacket(Spawn* caster, Spawn* target, int32 threat_amt, const char* spell_name);
  393. void SendYellPacket(Spawn* yeller, float max_distance=50.0f);
  394. void KillSpawnByDistance(Spawn* spawn, float max_distance, bool include_players = false, bool send_packet = false);
  395. void SpawnSetByDistance(Spawn* spawn, float max_distance, string field, string value);
  396. void AddSpawnScriptTimer(SpawnScriptTimer* timer);
  397. Spawn* GetSpawnByLocationID(int32 location_id);
  398. void AddMovementNPC(Spawn* spawn);
  399. void AddPlayerProximity(Spawn* spawn, float distance, string in_range_function, string leaving_range_function);
  400. void AddLocationProximity(float x, float y, float z, float max_variation, string in_range_function, string leaving_range_function);
  401. void PlayAnimation(Spawn* spawn, int32 visual_state, Spawn* spawn2 = 0, int8 type = 1);
  402. void AddTransportSpawn(Spawn* spawn);
  403. vector<Spawn*> GetSpawnsByID(int32 id);
  404. vector<Spawn*> GetSpawnsByRailID(sint64 rail_id);
  405. void RemovePlayerPassenger(int32 char_id);
  406. bool IsDusk() { return isDusk; } // never used, probably meant for lua though
  407. /****************************************************
  408. Following functions are all contained in the header
  409. ****************************************************/
  410. inline const char* GetZoneName() { return zone_name; }
  411. void SetZoneName(char* new_zone) {
  412. if( strlen(new_zone) >= sizeof zone_name )
  413. return;
  414. strcpy(zone_name, new_zone);
  415. }
  416. inline const char* GetZoneFile() { return zone_file; }
  417. void SetZoneFile(char* zone) {
  418. if (strlen(zone) >= sizeof zone_file)
  419. return;
  420. strcpy(zone_file, zone);
  421. }
  422. inline const char* GetZoneSkyFile() { return zonesky_file; }
  423. void SetZoneSkyFile(char* zone) {
  424. if (strlen(zone) >= sizeof zonesky_file)
  425. return;
  426. strcpy(zonesky_file, zone);
  427. }
  428. inline const char* GetZoneDescription() { return zone_description; }
  429. void SetZoneDescription(char* desc) {
  430. if( strlen(desc) >= sizeof zone_description )
  431. return;
  432. strcpy(zone_description, desc);
  433. }
  434. void SetUnderWorld(float under){ underworld = under; }
  435. float GetUnderWorld(){ return underworld; }
  436. inline int32 GetZoneID() { return zoneID; }
  437. void SetZoneID(int32 new_id){ zoneID = new_id; }
  438. inline bool IsCityZone() { return cityzone; }
  439. inline bool AlwaysLoaded() { return always_loaded; }
  440. void SetCityZone(bool val) { cityzone = val; }
  441. void SetAlwaysLoaded(bool val) { always_loaded = val; }
  442. inline int32& NumPlayers() { return pNumPlayers; }
  443. void SetMinimumStatus(sint16 minStatus) { minimumStatus = minStatus; }
  444. sint16 GetMinimumStatus() { return minimumStatus; }
  445. void SetMinimumLevel(int16 minLevel) { minimumLevel = minLevel; }
  446. void SetMaximumLevel(int16 maxLevel) { maximumLevel = maxLevel; }
  447. void SetMinimumVersion(int16 minVersion) { minimumVersion = minVersion; }
  448. int16 GetMinimumLevel() { return minimumLevel; }
  449. int16 GetMaximumLevel() { return maximumLevel; }
  450. int16 GetMinimumVersion() { return minimumVersion; }
  451. inline bool GetZoneLockState() { return locked; } // JA: /zone lock|unlock
  452. void SetZoneLockState(bool lock_state) { locked = lock_state; } // JA: /zone lock|unlock
  453. int32 GetInstanceID() { return instanceID; }
  454. bool IsInstanceZone() { return isInstance; }
  455. void SetShutdownTimer(int val){
  456. shutdownTimer.SetTimer(val*1000);
  457. }
  458. void AddSpawnLocation(int32 id, SpawnLocation* spawnlocation) {
  459. MSpawnLocationList.writelock(__FUNCTION__, __LINE__);
  460. if (spawn_location_list.count(id) > 0)
  461. safe_delete(spawn_location_list[id]);
  462. spawn_location_list[id] = spawnlocation;
  463. MSpawnLocationList.releasewritelock(__FUNCTION__, __LINE__);
  464. }
  465. void SetInstanceType(int16 type) { InstanceType = (Instance_Type)type; if(type>0)isInstance=true; else isInstance=false; }
  466. Instance_Type GetInstanceType() { return InstanceType; }
  467. float GetSafeX(){ return safe_x; }
  468. float GetSafeY(){ return safe_y; }
  469. float GetSafeZ(){ return safe_z; }
  470. float GetSafeHeading() { return safe_heading; }
  471. void SetSafeX(float val){ safe_x = val; }
  472. void SetSafeY(float val){ safe_y = val; }
  473. void SetSafeZ(float val){ safe_z = val; }
  474. void SetSafeHeading(float val) { safe_heading = val; }
  475. float GetXPModifier() { return xp_mod; }
  476. void SetXPModifier(float val) { xp_mod = val; }
  477. void SetZoneMOTD(string z_motd) { zone_motd = z_motd; }
  478. string GetZoneMOTD() { return zone_motd; }
  479. bool isZoneShuttingDown ( ) { return zoneShuttingDown; }
  480. void Shutdown(){ zoneShuttingDown = true; }
  481. int32 GetClientCount(){ return clients.size(); }
  482. int32 GetDefaultLockoutTime() { return def_lockout_time; }
  483. int32 GetDefaultReenterTime() { return def_reenter_time; }
  484. int32 GetDefaultResetTime() { return def_reset_time; }
  485. int8 GetForceGroupZoneOption() { return group_zone_option; }
  486. void SetDefaultLockoutTime(int32 val) { def_lockout_time = val; }
  487. void SetDefaultReenterTime(int32 val) { def_reenter_time = val; }
  488. void SetDefaultResetTime(int32 val) { def_reset_time = val; }
  489. void SetForceGroupZoneOption(int8 val) { group_zone_option = val; }
  490. SpellProcess* GetSpellProcess() {return spellProcess;}
  491. bool FinishedDepop(){ return finished_depop; }
  492. /// <summary>Returns the Tradeskill Manager for this zone</summary>
  493. TradeskillMgr* GetTradeskillMgr() { return tradeskillMgr; }
  494. // had to add these to access weather from Commands
  495. bool isWeatherEnabled() { return weather_enabled; }
  496. void SetWeatherEnabled(bool val) { weather_enabled = val; }
  497. bool isWeatherAllowed() { return weather_allowed; }
  498. void SetWeatherAllowed(bool val) { weather_allowed = val; }
  499. int8 GetWeatherType() { return weather_type; }
  500. void SetWeatherType(int8 val) { weather_type = val; }
  501. int32 GetWeatherFrequency() { return weather_frequency; }
  502. void SetWeatherFrequency(int32 val) { weather_frequency = val; }
  503. float GetWeatherMinSeverity() { return weather_min_severity; }
  504. void SetWeatherMinSeverity(float val) { weather_min_severity = val; }
  505. float GetWeatherMaxSeverity() { return weather_max_severity; }
  506. void SetWeatherMaxSeverity(float val) { weather_max_severity = val; }
  507. float GetWeatherChangeAmount() { return weather_change_amount; }
  508. void SetWeatherChangeAmount(float val) { weather_change_amount = val; }
  509. float GetWeatherDynamicOffset() { return weather_dynamic_offset; }
  510. void SetWeatherDynamicOffset(float val) { weather_dynamic_offset = val; }
  511. int8 GetWeatherChance() { return weather_change_chance; }
  512. void SetWeatherChance(int8 val) { weather_change_chance = val; }
  513. float GetCurrentWeather() { return weather_current_severity; }
  514. void SetCurrentWeather(float val) { weather_current_severity = val; }
  515. int8 GetWeatherPattern() { return weather_pattern; }
  516. void SetWeatherPattern(int8 val) { weather_pattern = val; }
  517. void SetWeatherLastChangedTime(int32 val) { weather_last_changed_time = val; }
  518. int32 GetExpansionFlag() { return expansion_flag; }
  519. void SetExpansionFlag(int32 val) { expansion_flag = val; }
  520. int32 GetHolidayFlag() { return holiday_flag; }
  521. void SetHolidayFlag(int32 val) { holiday_flag = val; }
  522. int32 GetCanBind() { return can_bind; }
  523. void SetCanBind(int32 val) { can_bind = val; }
  524. bool GetCanGate() { return can_gate; }
  525. void SetCanGate(int32 val) { can_gate = val; }
  526. void RemoveClientImmediately(Client* client);
  527. void ClearHate(Entity* entity);
  528. /****************************************************
  529. Following functions are pending deletion, left in for
  530. now just to make sure one won't be of future use.
  531. ****************************************************/
  532. //void RemoveFromRangeMap(Client* client); // never used?
  533. //void AddSpawnAssociatedGroup(vector<int32>* ret, int32 group_id); // never used, not even any code for it
  534. //inline const char* GetCAddress() { return clientaddress; } // never used?
  535. //inline int16 GetCPort() { return clientport; } // never used?
  536. //inline bool IsBootingUp() { return BootingUp; } // never used?
  537. //int32 GetShutdownTimer() {return shutdownTimer.GetTimerTime();} // never used
  538. // Following were private
  539. //char clientaddress[250]; // never used
  540. //int16 clientport; // never used
  541. //bool BootingUp; // never used
  542. //bool authenticated; // never used?
  543. //int16 next_index; // never used
  544. void AddFlightPath(int32 id, FlightPathInfo* info);
  545. void AddFlightPathLocation(int32 id, FlightPathLocation* location);
  546. void DeleteFlightPaths();
  547. void SendFlightPathsPackets(Client* client);
  548. int32 GetFlightPathIndex(int32 id);
  549. float GetFlightPathSpeed(int32 id);
  550. void SendSpawn(Spawn* spawn, Client* client); // moved from private to public for bots
  551. void ProcessSpawnConditional(int8 condition);
  552. void SetSpawnStructs(Client* client);
  553. void AddSpawnProximities(Spawn* spawn);
  554. void RemoveSpawnProximities(Spawn* spawn);
  555. void SetSpawnScript(SpawnEntry* entry, Spawn* spawn);
  556. bool IsLoading() {
  557. return LoadingData;
  558. }
  559. vector<HouseItem> GetHouseItems(Client* client);
  560. Spawn* GetSpawnFromUniqueItemID(int32 unique_id);
  561. void SendHouseItems(Client* client);
  562. MutexMap<int32, int32> house_object_database_lookup; // 1st int32 = model type, 2nd int32 = spawn id
  563. int32 GetWatchdogTime() { return watchdogTimestamp; }
  564. void SetWatchdogTime(int32 time) { watchdogTimestamp = time; }
  565. void CancelThreads();
  566. void AddPendingSpawnRemove(int32 id);
  567. void ProcessSpawnRemovals();
  568. bool SendRemoveSpawn(Client* client, Spawn* spawn, PacketStruct* packet = 0, bool delete_spawn = false);
  569. void AddSpawnToGroup(Spawn* spawn, int32 group_id);
  570. void QueueStateCommandToClients(int32 spawn_id, int32 state);
  571. void QueueDefaultCommand(int32 spawn_id, std::string command, float distance);
  572. void ProcessQueuedStateCommands();
  573. void UpdateClientSpawnMap(Player* player, Client* client);
  574. void RemoveClientsFromZone(ZoneServer* zone);
  575. void WorldTimeUpdateTrigger() { sync_game_time_timer.Trigger(); }
  576. void StopSpawnScriptTimer(Spawn* spawn, std::string functionName);
  577. Client* RemoveZoneServerFromClient(ZoneServer* zone);
  578. void SendSubSpawnUpdates(SUBSPAWN_TYPES subtype);
  579. bool HouseItemSpawnExists(int32 item_id);
  580. void ProcessPendingSpawns();
  581. void AddSpawnToGrid(Spawn* spawn, int32 grid_id);
  582. void RemoveSpawnFromGrid(Spawn* spawn, int32 grid_id);
  583. int32 GetSpawnCountInGrid(int32 grid_id);
  584. void SendClientSpawnListInGrid(Client* client, int32 grid_id);
  585. void AddIgnoredWidget(int32 id);
  586. private:
  587. #ifndef WIN32
  588. pthread_t ZoneThread;
  589. pthread_t SpawnThread;
  590. #endif
  591. /* Private Functions */
  592. void AddTransporter(LocationTransportDestination* loc);
  593. void CheckDeadSpawnRemoval();
  594. void DeleteData(bool boot_clients = true);
  595. void DeleteFactionLists();
  596. void ProcessDepop(bool respawns_allowed = false, bool repop = false);
  597. /*
  598. Following functions were public but never used outside the zone server so moved them to private
  599. */
  600. void ClientProcess(bool ignore_shutdown_timer = false); // never used outside zone server
  601. void RemoveClient(Client* client); // never used outside zone server
  602. void DeterminePosition(SpawnLocation* spawnlocation, Spawn* spawn); // never used outside zone server
  603. void AddDeadSpawn(Spawn* spawn, int32 timer = 0xFFFFFFFF); // never used outside zone server
  604. int32 CalculateSpawnGroup(SpawnLocation* spawnlocation, bool respawn = false); // never used outside zone server
  605. float GetSpawnGroupChance(int32 group_id); // never used outside zone server
  606. vector<int32>* GetAssociatedLocations(set<int32>* groups); // never used outside zone server
  607. set<int32>* GetAssociatedGroups(int32 group_id); // never used outside zone server
  608. list<int32>* GetSpawnGroupsByLocation(int32 location_id); // never used outside zone server
  609. void ProcessSpawnLocation(int32 location_id, bool respawn = false); // never used outside zone server
  610. Spawn* ProcessSpawnLocation(SpawnLocation* spawnlocation, bool respawn = false); // never used outside zone server
  611. 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
  612. void SendCharSheetChanges(); // never used outside zone server
  613. void SendCharSheetChanges(Client* client); // never used outside zone server
  614. void SaveClients(); // never used outside zone server
  615. void CheckSendSpawnToClient(); // never used outside zone server
  616. void CheckSendSpawnToClient(Client* client, bool initial_login = false); // never used outside zone server
  617. void CheckRemoveSpawnFromClient(Spawn* spawn); // never used outside zone server
  618. void SaveClient(Client* client); // never used outside zone server
  619. void ProcessFaction(Spawn* spawn, Client* client); // never used outside zone server
  620. void RegenUpdate(); // never used outside zone server
  621. void SendCalculatedXP(Player* player, Spawn* victim); // never used outside zone server, might not be used at all any more
  622. void SendTimeUpdate(Client* client); // never used outside zone server
  623. void CheckWidgetTimers(); // never used outside zone server
  624. void CheckRespawns(); // never used outside zone server
  625. void CheckSpawnExpireTimers(); // never used outside zone server
  626. void AddSpawnExpireTimer(Spawn* spawn, int32 expire_time, int32 expire_offset = 0); // never used outside zone server
  627. void CheckSpawnRange(Client* client, Spawn* spawn, bool initial_login = false); // never used outside zone server
  628. void CheckSpawnRange(Spawn* spawn); // never used outside zone server
  629. void DeleteSpawnScriptTimers(Spawn* spawn, bool all = false); // never used outside zone server
  630. void DeleteSpawnScriptTimers(); // never used outside zone server
  631. void CheckSpawnScriptTimers(); // never used outside zone server
  632. bool PrepareSpawnID(Player* player, Spawn* spawn); // never used outside zone server
  633. void RemoveMovementNPC(Spawn* spawn); // never used outside zone server
  634. bool CheckNPCAttacks(NPC* npc, Spawn* victim, Client* client = 0); // never used outside zone server
  635. bool AggroVictim(NPC* npc, Spawn* victim, Client* client = 0); // never used outside zone server
  636. bool CheckEnemyList(NPC* npc); // never used outside zone server
  637. void RemovePlayerProximity(Spawn* spawn, bool all = false); // never used outside zone server
  638. void RemovePlayerProximity(Client* client); // never used outside zone server
  639. void CheckPlayerProximity(Spawn* spawn, Client* client); // never used outside zone server
  640. void RemoveLocationProximities(); // never used outside zone server
  641. void CheckLocationProximity(); // never used outside zone server
  642. void CheckLocationGrids(); // never used outside zone server
  643. void RemoveSpawnSupportFunctions(Spawn* spawn, bool lock_spell_process = false); // never used outside zone server
  644. void ReloadTransporters(); // never used outside zone server
  645. void DeleteSpawns(bool delete_all); // never used outside zone server
  646. void AddPendingDelete(Spawn* spawn); // never used outside zone server
  647. void RemovePendingDelete(Spawn* spawn); // never used outside zone server
  648. void ClearDeadSpawns(); // never used outside zone server
  649. void RemoveChangedSpawn(Spawn* spawn); // never used outside zone server
  650. void ProcessDrowning(); // never used outside zone server
  651. void RemoveDamagedSpawn(Spawn* spawn); // never used outside zone server
  652. void ProcessTracking(); // never used outside zone server
  653. void ProcessTracking(Client* client); // never used outside zone server
  654. void SendEpicMobDeathToGuild(Player* killer, Spawn* victim); // never used outside zone server
  655. void ProcessAggroChecks(Spawn* spawn); // never used outside zone server
  656. /// <summary>Checks to see if it is time to remove a spawn and removes it</summary>
  657. /// <param name='force_delete_all'>Forces all spawns scheduled to be removed regardless of time</param>
  658. bool CombatProcess(Spawn* spawn); // never used outside zone server
  659. void InitWeather(); // never used outside zone server
  660. ///<summary>Dismiss all pets in the zone, useful when the spell process needs to be reloaded</summary>
  661. void DismissAllPets(); // never used outside zone server
  662. /* Mutex Lists */
  663. std::map<int32, bool> changed_spawns; // int32 = spawn id
  664. vector<Client*> clients;
  665. MutexList<Client*> connected_clients; // probably remove this list so we are not maintaining 2 client lists
  666. MutexList<int32> damaged_spawns; // int32 = spawn id
  667. MutexList<LocationProximity*> location_proximities;
  668. MutexList<LocationGrid*> location_grids;
  669. MutexList<int32> remove_movement_spawns; // int32 = spawn id
  670. set<SpawnScriptTimer*> spawn_script_timers;
  671. Mutex MSpawnScriptTimers;
  672. set<SpawnScriptTimer*> remove_spawn_script_timers_list;
  673. Mutex MRemoveSpawnScriptTimersList;
  674. list<LocationTransportDestination*> transporter_locations;
  675. /* Mutex Maps */
  676. MutexMap<Spawn*, Client*> client_spawn_map; // ok
  677. MutexMap<Client*, int32> drowning_victims;
  678. MutexMap<int32, int32> movement_spawns; // 1st int32 = spawn id
  679. MutexMap<int32, PlayerProximity*> player_proximities; // 1st int32 = spawn id
  680. MutexMap<int32, Player*> players_tracking;
  681. MutexMap<int32, int32> quick_database_id_lookup; // 1st int32 = database id, 2nd int32 = spawn id
  682. MutexMap<int32, int32> quick_location_id_lookup; // 1st int32 = location id, 2nd int32 = spawn id
  683. MutexMap<int32, int32> quick_group_id_lookup; // 1st int32 = group id, 2nd int32 = spawn id
  684. MutexMap<int32, int32> respawn_timers;
  685. map<Spawn*, int32> spawn_delete_list;
  686. MutexMap<int32, int32> spawn_expire_timers; // 1st int32 = spawn id
  687. map<int32, set<int32>* > spawn_group_associations;
  688. map<int32, float> spawn_group_chances;
  689. map<int32, map<int32, int32>* > spawn_group_locations;
  690. MutexMap<int32, MutexList<int32> > spawn_group_map; // MutexList<int32> is a list of spawn id's
  691. map<int32, list<int32>* > spawn_location_groups;
  692. map<int32, SpawnLocation*> spawn_location_list;
  693. MutexMap<Client*, MutexMap<int32, float >* > spawn_range_map; // int32 in the MutexMap<int32, float>* = spawn id, float = distance
  694. Mutex MWidgetTimers;
  695. map<int32, int32> widget_timers; // 1st int32 = spawn id
  696. std::map<int32, GridMap*> grid_maps;
  697. /* Mutexs */
  698. mutable std::shared_mutex MGridMaps;
  699. mutable std::shared_mutex MChangedSpawns;
  700. Mutex m_enemy_faction_list;
  701. Mutex m_npc_faction_list;
  702. Mutex m_reverse_enemy_faction_list;
  703. Mutex MDeadSpawns;
  704. CriticalSection* MMasterZoneLock; //This needs to be a recursive lock to fix a possible /reload spells crash with multiple zones loaded - Foof
  705. Mutex MMasterSpawnLock;
  706. Mutex MPendingSpawnListAdd;
  707. Mutex MSpawnList;
  708. Mutex MTransportSpawns;
  709. Mutex MSpawnGroupAssociation;
  710. Mutex MSpawnGroupLocations;
  711. Mutex MSpawnLocationGroups;
  712. Mutex MSpawnGroupChances;
  713. Mutex MTransportLocations;
  714. Mutex MSpawnLocationList;
  715. Mutex MSpawnDeleteList;
  716. Mutex MClientList;
  717. Mutex MIncomingClients;
  718. /* Maps */
  719. map<int32, int32> dead_spawns;
  720. map<int32, vector<int32>* > enemy_faction_list;
  721. map<int32, vector<int32>* > npc_faction_list;
  722. map<int32, vector<int32>* > reverse_enemy_faction_list;
  723. map<int32, Spawn*> spawn_list;
  724. map<int32, FlightPathInfo*> m_flightPaths;
  725. map<int32, vector<FlightPathLocation*> > m_flightPathRoutes;
  726. /* Lists */
  727. list<Spawn*> pending_spawn_list_add;
  728. /* Specialized Lists to update specific scenarios */
  729. std::map<int32, Spawn*> subspawn_list[SUBSPAWN_TYPES::MAX_SUBSPAWN_TYPE];
  730. std::map<int32, int32> housing_spawn_map;
  731. /* Vectors */
  732. vector<RevivePoint*>* revive_points;
  733. vector<int32> transport_spawns;
  734. /* Classes */
  735. SpellProcess* spellProcess;
  736. TradeskillMgr* tradeskillMgr;
  737. /* Timers */
  738. Timer aggro_timer;
  739. Timer charsheet_changes;
  740. Timer client_save;
  741. Timer location_prox_timer;
  742. Timer location_grid_timer;
  743. Timer movement_timer;
  744. Timer regenTimer;
  745. Timer respawn_timer;
  746. Timer shutdownTimer;
  747. Timer startupDelayTimer;
  748. Timer spawn_check_add;
  749. Timer spawn_check_remove;
  750. Timer spawn_expire_timer;
  751. Timer spawn_range;
  752. Timer spawn_update;
  753. Timer sync_game_time_timer;
  754. Timer tracking_timer;
  755. Timer weatherTimer;
  756. Timer widget_timer;
  757. Timer queue_updates;
  758. Timer shutdownDelayTimer;
  759. /* Enums */
  760. Instance_Type InstanceType;
  761. /* Variables */
  762. volatile bool finished_depop;
  763. volatile bool depop_zone;
  764. volatile bool repop_zone;
  765. volatile bool respawns_allowed;
  766. volatile bool LoadingData;
  767. std::atomic<bool> reloading_spellprocess;
  768. std::atomic<bool> zoneShuttingDown;
  769. bool cityzone;
  770. bool always_loaded;
  771. bool isInstance;
  772. int32 pNumPlayers;
  773. sint16 minimumStatus;
  774. int16 minimumLevel;
  775. int16 maximumLevel;
  776. int16 minimumVersion;
  777. char zone_name[64];
  778. char zonesky_file[64];
  779. char zone_file[64];
  780. char zone_description[255];
  781. float underworld;
  782. float safe_x;
  783. float safe_y;
  784. float safe_z;
  785. float safe_heading;
  786. float xp_mod;
  787. volatile int32 zoneID;
  788. bool locked; // JA: implementing /zone lock|unlock commands
  789. int32 instanceID;
  790. string zone_motd;
  791. int32 def_reenter_time;
  792. int32 def_reset_time;
  793. int32 def_lockout_time;
  794. int8 group_zone_option;
  795. float rain;
  796. bool isDusk;
  797. int dusk_hour;
  798. int dawn_hour;
  799. int dusk_minute;
  800. int dawn_minute;
  801. int32 spawn_delete_timer;
  802. int32 expansion_flag;
  803. int32 holiday_flag;
  804. //devn00b:test
  805. int can_bind;
  806. bool can_gate;
  807. map<int16, PacketStruct*> versioned_pos_structs;
  808. map<int16, PacketStruct*> versioned_info_structs;
  809. map<int16, PacketStruct*> versioned_vis_structs;
  810. /* Weather Stuff */
  811. bool weather_enabled; // false = disabled, true = enabled
  812. int8 weather_type; // 0 = normal, 1 = dynamic, 2 = random, 3 = chaotic
  813. int32 weather_frequency; // how often weather changes
  814. float weather_min_severity; // minimum weather severity in a zone
  815. float weather_max_severity; // maximum weather severity in a zone
  816. float weather_change_amount; // how much does the weather change each interval (normal weather conditions)
  817. float weather_dynamic_offset; // max amount the weather change each interval (dynamic weather conditions)
  818. int8 weather_change_chance; // percentage chance the weather will change
  819. int8 weather_pattern; // 0 = decreasing severity, 1 = increasing severity, 2 = random severity
  820. int32 weather_last_changed_time; // last time weather changed (used with weather_frequency)
  821. float weather_current_severity; // current weather conditions in a zone
  822. bool weather_allowed; // from zones.weather_allowed field in database
  823. bool weather_signaled; // whether or not we told the client "it begins to rain"
  824. bool reloading;
  825. map<int32, vector<EntityCommand*>* > entity_command_list;
  826. map<int32, map<int32, int16> > npc_skill_list;
  827. map<int32, vector<int32> > npc_equipment_list;
  828. map<int32, NPC*> npc_list;
  829. map<int32,Object*> object_list;
  830. map<int32,Sign*> sign_list;
  831. map<int32,Widget*> widget_list;
  832. map<int32, vector<GroundSpawnEntry*> > groundspawn_entries;
  833. map<int32, vector<GroundSpawnEntryItem*> > groundspawn_items;
  834. Mutex MGroundSpawnItems;
  835. map<int32,GroundSpawn*> groundspawn_list;
  836. map<int32,LootTable*> loot_tables;
  837. map<int32, vector<LootDrop*> > loot_drops;
  838. map<int32, vector<int32> > spawn_loot_list;
  839. vector<GlobalLoot*> level_loot_list;
  840. map<int16, vector<GlobalLoot*> > racial_loot_list;
  841. map<int32, vector<GlobalLoot*> > zone_loot_list;
  842. map<int32, vector<TransportDestination*> > transporters;
  843. map<int32, MutexList<LocationTransportDestination*>* > location_transporters;
  844. Mutex MTransporters;
  845. Mutex MTransportMaps;
  846. // Map <transport if, map name>
  847. map<int32, string> m_transportMaps;
  848. int32 watchdogTimestamp;
  849. std::map<int32, bool> m_pendingSpawnRemove;
  850. Mutex MPendingSpawnRemoval;
  851. std::map<int32, int32> lua_queued_state_commands;
  852. std::map<int32, std::map<std::string, float>> lua_spawn_update_command;
  853. std::mutex MLuaQueueStateCmd;
  854. mutable std::shared_mutex MIgnoredWidgets;
  855. std::map<int32, bool> ignored_widgets;
  856. public:
  857. Spawn* GetSpawn(int32 id);
  858. /* Entity Commands */
  859. map<int32, vector<EntityCommand*>*>* GetEntityCommandListAll() {return &entity_command_list;}
  860. vector<EntityCommand*>* GetEntityCommandList(int32 id);
  861. void SetEntityCommandList(int32 id, EntityCommand* command);
  862. void ClearEntityCommands();
  863. EntityCommand* GetEntityCommand(int32 id, string name);
  864. /* NPC's */
  865. void AddNPC(int32 id, NPC* npc);
  866. NPC* GetNPC(int32 id, bool override_loading = false) {
  867. if((!reloading || override_loading) && npc_list.count(id) > 0)
  868. return npc_list[id];
  869. else
  870. return 0;
  871. }
  872. NPC* GetNewNPC(int32 id) {
  873. if(!reloading && npc_list.count(id) > 0)
  874. return new NPC(npc_list[id]);
  875. else
  876. return 0;
  877. }
  878. /* NPC Skills */
  879. void AddNPCSkill(int32 list_id, int32 skill_id, int16 value);
  880. map<string, Skill*>* GetNPCSkills(int32 primary_list, int32 secondary_list);
  881. /* NPC Equipment */
  882. void AddNPCEquipment(int32 list_id, int32 item_id);
  883. void SetNPCEquipment(NPC* npc);
  884. /* Objects */
  885. void AddObject(int32 id, Object* object){ object_list[id] = object; }
  886. Object* GetObject(int32 id, bool override_loading = false) {
  887. if((!reloading || override_loading) && object_list.count(id) > 0)
  888. return object_list[id];
  889. else
  890. return 0;
  891. }
  892. Object* GetNewObject(int32 id) {
  893. if(!reloading && object_list.count(id) > 0)
  894. return object_list[id]->Copy();
  895. else
  896. return 0;
  897. }
  898. /* Signs */
  899. void AddSign(int32 id, Sign* sign){ sign_list[id] = sign; }
  900. Sign* GetSign(int32 id, bool override_loading = false) {
  901. if((!reloading || override_loading) && sign_list.count(id) > 0)
  902. return sign_list[id];
  903. else
  904. return 0;
  905. }
  906. Sign* GetNewSign(int32 id) {
  907. if(!reloading && sign_list.count(id) > 0)
  908. return sign_list[id]->Copy();
  909. else
  910. return 0;
  911. }
  912. /* Widgets */
  913. void AddWidget(int32 id, Widget* widget);
  914. Widget* GetWidget(int32 id, bool override_loading = false);
  915. Widget* GetNewWidget(int32 id);
  916. /* Groundspawns */
  917. // JA: groundspawn revamp
  918. 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);
  919. void AddGroundSpawnItem(int32 groundspawn_id, int32 item_id, int8 is_rare, int32 grid_id);
  920. vector<GroundSpawnEntry*>* GetGroundSpawnEntries(int32 id);
  921. vector<GroundSpawnEntryItem*>* GetGroundSpawnEntryItems(int32 id);
  922. void LoadGroundSpawnEntries();
  923. void LoadGroundSpawnItems();
  924. //
  925. void DeleteGroundSpawnItems();
  926. void AddGroundSpawn(int32 id, GroundSpawn* spawn);
  927. GroundSpawn* GetGroundSpawn(int32 id, bool override_loading = false);
  928. GroundSpawn* GetNewGroundSpawn(int32 id);
  929. /* Pet names */
  930. vector<string> pet_names;
  931. /* Loot */
  932. void AddLootTable(int32 id, LootTable* table);
  933. void AddLootDrop(int32 id, LootDrop* drop);
  934. void AddSpawnLootList(int32 spawn_id, int32 id);
  935. void ClearSpawnLootList(int32 spawn_id);
  936. void AddLevelLootList(GlobalLoot* loot);
  937. void AddRacialLootList(int16 racial_id, GlobalLoot* loot);
  938. void AddZoneLootList(int32 zone, GlobalLoot* loot);
  939. void ClearLootTables();
  940. vector<int32> GetSpawnLootList(int32 spawn_id, int32 zone_id, int8 spawn_level, int16 racial_id, Spawn* spawn = 0);
  941. vector<LootDrop*>* GetLootDrops(int32 table_id);
  942. LootTable* GetLootTable(int32 table_id);
  943. /* Transporters */
  944. 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);
  945. 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,
  946. 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,
  947. int32 max_client_version, int32 flight_path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color);
  948. void GetTransporters(vector<TransportDestination*>* returnList, Client* client, int32 transport_id);
  949. MutexList<LocationTransportDestination*>* GetLocationTransporters(int32 zone_id);
  950. void DeleteGlobalTransporters();
  951. ///<summary></summary>
  952. ///<param name='id'>The transport id</param>
  953. ///<param name='name'>Name of the map</param>
  954. void AddTransportMap(int32 id, string name);
  955. ///<summary>Checks to see if the transport has a map</summary>
  956. ///<param name='id'>The transport id we want to check</param>
  957. ///<returns>True if the transport id has a map</returns>
  958. bool TransportHasMap(int32 id);
  959. ///<summary>Gets the map name for the given transport id</summary>
  960. ///<param name='id'>The transport id that we want a map for</param>
  961. ///<returns>Map name</returns>
  962. string GetTransportMap(int32 id);
  963. ///<summary>Clears the list of transporter maps</summary>
  964. void DeleteTransporterMaps();
  965. void DeleteGlobalSpawns();
  966. void ReloadSpawns();
  967. void SendStateCommand(Spawn* spawn, int32 state);
  968. int32 lifetime_client_count;
  969. int32 incoming_clients;
  970. };
  971. #endif