2010-10-07 15:54:07 +02:00
/*
2018-01-01 00:40:17 +01:00
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
2010-10-07 15:54:07 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-14 11:57:03 -05:00
#ifndef TRINITY_INSTANCE_DATA_H
#define TRINITY_INSTANCE_DATA_H
2009-10-17 15:51:44 -07:00
2009-05-30 22:15:05 -05:00
#include "ZoneScript.h"
2017-05-28 16:34:44 +02:00
#include "Common.h"
#include <map>
#include <memory>
#include <set>
2009-10-17 15:51:44 -07:00
2013-11-08 10:50:51 +01:00
#define OUT_SAVE_INST_DATA TC_LOG_DEBUG("scripts", "Saving Instance Data for Instance %s (Map %d, Instance Id %d)", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_SAVE_INST_DATA_COMPLETE TC_LOG_DEBUG("scripts", "Saving Instance Data for Instance %s (Map %d, Instance Id %d) completed.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA(a) TC_LOG_DEBUG("scripts", "Loading Instance Data for Instance %s (Map %d, Instance Id %d). Input is '%s'", instance->GetMapName(), instance->GetId(), instance->GetInstanceId(), a)
#define OUT_LOAD_INST_DATA_COMPLETE TC_LOG_DEBUG("scripts", "Instance Data Load for Instance %s (Map %d, Instance Id: %d) is complete.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA_FAIL TC_LOG_ERROR("scripts", "Unable to load Instance Data for Instance %s (Map %d, Instance Id: %d).", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
2010-08-08 22:54:58 +06:00
2017-05-28 16:34:44 +02:00
class AreaBoundary ;
2008-10-02 16:23:55 -05:00
class Creature ;
2017-05-28 16:34:44 +02:00
class GameObject ;
2018-06-16 17:24:10 +02:00
class InstanceMap ;
2016-03-11 17:09:26 +01:00
class ModuleReference ;
2017-05-28 16:34:44 +02:00
class Player ;
class Unit ;
enum CriteriaTypes : uint8 ;
enum CriteriaTimedTypes : uint8 ;
enum EncounterCreditType : uint8 ;
namespace WorldPackets
{
namespace WorldState
{
class InitWorldStates ;
}
}
2009-10-17 15:51:44 -07:00
2011-01-23 21:42:32 +01:00
enum EncounterFrameType
{
2012-03-30 02:43:17 +02:00
ENCOUNTER_FRAME_SET_COMBAT_RES_LIMIT = 0 ,
ENCOUNTER_FRAME_RESET_COMBAT_RES_LIMIT = 1 ,
ENCOUNTER_FRAME_ENGAGE = 2 ,
ENCOUNTER_FRAME_DISENGAGE = 3 ,
ENCOUNTER_FRAME_UPDATE_PRIORITY = 4 ,
ENCOUNTER_FRAME_ADD_TIMER = 5 ,
ENCOUNTER_FRAME_ENABLE_OBJECTIVE = 6 ,
ENCOUNTER_FRAME_UPDATE_OBJECTIVE = 7 ,
ENCOUNTER_FRAME_DISABLE_OBJECTIVE = 8 ,
ENCOUNTER_FRAME_UNK7 = 9 , // Seems to have something to do with sorting the encounter units
2012-09-11 01:11:14 +01:00
ENCOUNTER_FRAME_ADD_COMBAT_RES_LIMIT = 10
2011-01-23 21:42:32 +01:00
};
2009-05-01 18:24:12 -05:00
enum EncounterState
{
NOT_STARTED = 0 ,
IN_PROGRESS = 1 ,
FAIL = 2 ,
DONE = 3 ,
2009-05-11 03:17:13 -05:00
SPECIAL = 4 ,
2012-09-10 13:03:38 +02:00
TO_BE_DECIDED = 5
2009-05-01 18:24:12 -05:00
};
2009-10-17 15:51:44 -07:00
2009-05-09 14:08:42 -05:00
enum DoorType
{
2011-05-16 13:24:08 +02:00
DOOR_TYPE_ROOM = 0 , // Door can open if encounter is not in progress
DOOR_TYPE_PASSAGE = 1 , // Door can open if encounter is done
DOOR_TYPE_SPAWN_HOLE = 2 , // Door can open if encounter is in progress, typically used for spawning places
2012-09-10 13:03:38 +02:00
MAX_DOOR_TYPES
2009-05-09 14:08:42 -05:00
};
2009-10-17 15:51:44 -07:00
2009-05-16 14:49:30 -05:00
struct DoorData
{
uint32 entry , bossId ;
DoorType type ;
};
2009-10-17 15:51:44 -07:00
2016-01-13 15:33:17 +01:00
struct BossBoundaryEntry
{
2016-01-19 13:01:43 +00:00
uint32 BossId ;
AreaBoundary const * Boundary ;
2016-01-13 15:33:17 +01:00
};
2016-01-19 13:01:43 +00:00
2016-03-11 16:37:14 +01:00
struct TC_GAME_API BossBoundaryData
2016-01-18 18:35:20 +01:00
{
typedef std :: vector < BossBoundaryEntry > StorageType ;
typedef StorageType :: const_iterator const_iterator ;
BossBoundaryData ( std :: initializer_list < BossBoundaryEntry > data ) : _data ( data ) { }
~ BossBoundaryData ();
const_iterator begin () const { return _data . begin (); }
const_iterator end () const { return _data . end (); }
private :
StorageType _data ;
};
2016-01-13 15:33:17 +01:00
2009-05-16 14:49:30 -05:00
struct MinionData
{
uint32 entry , bossId ;
};
2009-10-17 15:51:44 -07:00
2014-09-18 00:25:05 +02:00
struct ObjectData
{
uint32 entry ;
uint32 type ;
};
2017-05-28 16:34:44 +02:00
typedef std :: set < AreaBoundary const *> CreatureBoundary ;
2009-05-01 18:24:12 -05:00
struct BossInfo
{
2013-10-27 22:27:46 +01:00
BossInfo () : state ( TO_BE_DECIDED ) { }
2009-05-01 18:24:12 -05:00
EncounterState state ;
2014-09-14 16:14:12 +02:00
GuidSet door [ MAX_DOOR_TYPES ];
GuidSet minion ;
2016-01-13 15:33:17 +01:00
CreatureBoundary boundary ;
2009-05-09 14:08:42 -05:00
};
2009-10-17 15:51:44 -07:00
2009-05-09 14:08:42 -05:00
struct DoorInfo
{
2016-01-13 15:33:17 +01:00
explicit DoorInfo ( BossInfo * _bossInfo , DoorType _type )
: bossInfo ( _bossInfo ), type ( _type ) { }
2011-09-15 14:08:17 +02:00
BossInfo * bossInfo ;
2009-05-09 14:08:42 -05:00
DoorType type ;
};
2009-10-17 15:51:44 -07:00
2009-05-16 14:49:30 -05:00
struct MinionInfo
2009-05-09 14:08:42 -05:00
{
2013-10-27 22:27:46 +01:00
explicit MinionInfo ( BossInfo * _bossInfo ) : bossInfo ( _bossInfo ) { }
2011-09-15 14:08:17 +02:00
BossInfo * bossInfo ;
2009-05-01 18:24:12 -05:00
};
2009-10-17 15:51:44 -07:00
2009-05-16 14:49:30 -05:00
typedef std :: multimap < uint32 /*entry*/ , DoorInfo > DoorInfoMap ;
2013-01-02 09:53:43 +01:00
typedef std :: pair < DoorInfoMap :: const_iterator , DoorInfoMap :: const_iterator > DoorInfoMapBounds ;
2009-05-16 14:49:30 -05:00
typedef std :: map < uint32 /*entry*/ , MinionInfo > MinionInfoMap ;
2014-09-18 00:25:05 +02:00
typedef std :: map < uint32 /*type*/ , ObjectGuid /*guid*/ > ObjectGuidMap ;
typedef std :: map < uint32 /*entry*/ , uint32 /*type*/ > ObjectInfoMap ;
2009-10-17 15:51:44 -07:00
2016-03-11 16:37:14 +01:00
class TC_GAME_API InstanceScript : public ZoneScript
2008-10-02 16:23:55 -05:00
{
public :
2018-06-16 17:24:10 +02:00
explicit InstanceScript ( InstanceMap * map );
2011-02-03 22:20:40 +01:00
2013-10-27 22:27:46 +01:00
virtual ~ InstanceScript () { }
2009-10-17 15:51:44 -07:00
2018-06-16 17:24:10 +02:00
InstanceMap * instance ;
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// On creation, NOT load.
2014-09-25 22:28:20 +02:00
// PLEASE INITIALIZE FIELDS IN THE CONSTRUCTOR INSTEAD !!!
// KEEPING THIS METHOD ONLY FOR BACKWARD COMPATIBILITY !!!
2013-10-27 22:27:46 +01:00
virtual void Initialize () { }
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// On load
virtual void Load ( char const * data );
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// When save is needed, this function generates the data
virtual std :: string GetSaveData ();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SaveToDB ();
2009-10-17 15:51:44 -07:00
2013-10-27 22:27:46 +01:00
virtual void Update ( uint32 /*diff*/ ) { }
2016-04-14 22:43:21 +02:00
void UpdateCombatResurrection ( uint32 /*diff*/ );
2009-10-17 15:51:44 -07:00
2015-12-31 19:51:07 +01:00
// Used by the map's CannotEnter function.
2014-09-07 00:42:14 +02:00
// This is to prevent players from entering during boss encounters.
2009-05-01 18:24:12 -05:00
virtual bool IsEncounterInProgress () const ;
2009-10-17 15:51:44 -07:00
2014-09-18 00:25:05 +02:00
// Called when a creature/gameobject is added to map or removed from map.
// Insert/Remove objectguid to dynamic guid store
virtual void OnCreatureCreate ( Creature * creature ) override ;
virtual void OnCreatureRemove ( Creature * creature ) override ;
virtual void OnGameObjectCreate ( GameObject * go ) override ;
virtual void OnGameObjectRemove ( GameObject * go ) override ;
ObjectGuid GetObjectGuid ( uint32 type ) const ;
virtual ObjectGuid GetGuidData ( uint32 type ) const override ;
2017-05-28 16:34:44 +02:00
Creature * GetCreature ( uint32 type );
GameObject * GetGameObject ( uint32 type );
2014-09-18 00:25:05 +02:00
2014-09-07 00:42:14 +02:00
// Called when a player successfully enters the instance.
2013-10-27 22:27:46 +01:00
virtual void OnPlayerEnter ( Player * /*player*/ ) { }
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// Handle open / close objects
// * use HandleGameObject(0, boolen, GO); in OnObjectCreate in instance scripts
// * use HandleGameObject(GUID, boolen, NULL); in any other script
2014-09-14 16:14:12 +02:00
void HandleGameObject ( ObjectGuid guid , bool open , GameObject * go = nullptr );
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// Change active state of doors or buttons
2014-09-14 16:14:12 +02:00
void DoUseDoorOrButton ( ObjectGuid guid , uint32 withRestoreTime = 0 , bool useAlternativeState = false );
2015-05-17 14:50:30 +02:00
void DoCloseDoorOrButton ( ObjectGuid guid );
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// Respawns a GO having negative spawntimesecs in gameobject-table
2014-09-14 16:14:12 +02:00
void DoRespawnGameObject ( ObjectGuid guid , uint32 timeToDespawn = MINUTE );
2009-10-17 15:51:44 -07:00
2014-09-07 00:42:14 +02:00
// Sends world state update to all players in instance
2011-03-19 10:54:16 +01:00
void DoUpdateWorldState ( uint32 worldstateId , uint32 worldstateValue );
2009-10-17 15:51:44 -07:00
2009-10-16 16:45:01 -07:00
// Send Notify to all players in instance
2011-03-19 10:54:16 +01:00
void DoSendNotifyToInstance ( char const * format , ...);
2009-10-17 15:51:44 -07:00
2010-03-23 19:15:17 +01:00
// Update Achievement Criteria for all players in instance
2016-05-07 01:16:29 +02:00
void DoUpdateCriteria ( CriteriaTypes type , uint32 miscValue1 = 0 , uint32 miscValue2 = 0 , Unit * unit = NULL );
2010-03-23 19:15:17 +01:00
2010-04-27 22:26:30 +02:00
// Start/Stop Timed Achievement Criteria for all players in instance
2016-05-07 01:16:29 +02:00
void DoStartCriteriaTimer ( CriteriaTimedTypes type , uint32 entry );
void DoStopCriteriaTimer ( CriteriaTimedTypes type , uint32 entry );
2010-04-27 22:26:30 +02:00
2009-10-16 16:45:01 -07:00
// Remove Auras due to Spell on all players in instance
void DoRemoveAurasDueToSpellOnPlayers ( uint32 spell );
2009-10-17 15:51:44 -07:00
2011-01-01 23:37:35 +01:00
// Cast spell on all players in instance
void DoCastSpellOnPlayers ( uint32 spell );
2010-04-11 17:50:30 +02:00
// Return wether server allow two side groups or not
2017-05-28 16:34:44 +02:00
bool ServerAllowsTwoSideGroups ();
2010-04-11 17:50:30 +02:00
2009-05-20 11:44:38 -05:00
virtual bool SetBossState ( uint32 id , EncounterState state );
2009-08-12 08:01:06 -05:00
EncounterState GetBossState ( uint32 id ) const { return id < bosses . size () ? bosses [ id ]. state : TO_BE_DECIDED ; }
2015-10-10 13:22:55 +02:00
static std :: string GetBossStateName ( uint8 state );
2016-01-13 15:33:17 +01:00
CreatureBoundary const * GetBossBoundary ( uint32 id ) const { return id < bosses . size () ? & bosses [ id ]. boundary : NULL ; }
2009-12-25 16:01:19 +01:00
// Achievement criteria additional requirements check
// NOTE: not use this if same can be checked existed requirement types from AchievementCriteriaRequirementType
virtual bool CheckAchievementCriteriaMeet ( uint32 /*criteria_id*/ , Player const * /*source*/ , Unit const * /*target*/ = NULL , uint32 /*miscvalue1*/ = 0 );
2011-01-01 23:37:35 +01:00
// Checks boss requirements (one boss required to kill other)
2014-09-18 00:25:05 +02:00
virtual bool CheckRequiredBosses ( uint32 /*bossId*/ , Player const * /*player*/ = nullptr ) const { return true ; }
2011-01-01 23:37:35 +01:00
2011-02-03 22:20:40 +01:00
// Checks encounter state at kill/spellcast
2017-05-28 16:34:44 +02:00
void UpdateEncounterStateForKilledCreature ( uint32 creatureId , Unit * source );
void UpdateEncounterStateForSpellCast ( uint32 spellId , Unit * source );
2011-02-03 22:20:40 +01:00
// Used only during loading
void SetCompletedEncountersMask ( uint32 newMask ) { completedEncounters = newMask ; }
2011-01-24 11:38:59 +01:00
// Returns completed encounters mask for packets
2011-02-03 22:20:40 +01:00
uint32 GetCompletedEncounterMask () const { return completedEncounters ; }
2011-01-24 11:38:59 +01:00
2016-07-16 14:58:33 +02:00
// Sets the entrance location (WorldSafeLoc) id
void SetEntranceLocation ( uint32 worldSafeLocationId );
// Sets a temporary entrance that does not get saved to db
void SetTemporaryEntranceLocation ( uint32 worldSafeLocationId ) { _temporaryEntranceId = worldSafeLocationId ; }
// Get's the current entrance id
uint32 GetEntranceLocation () const { return _temporaryEntranceId ? _temporaryEntranceId : _entranceId ; }
2016-04-14 22:43:21 +02:00
void SendEncounterUnit ( uint32 type , Unit * unit = NULL , uint8 priority = 0 );
void SendEncounterStart ( uint32 inCombatResCount = 0 , uint32 maxInCombatResCount = 0 , uint32 inCombatResChargeRecovery = 0 , uint32 nextCombatResChargeTime = 0 );
void SendEncounterEnd ();
2011-01-23 16:59:33 +01:00
2016-07-07 13:30:24 +02:00
void SendBossKillCredit ( uint32 encounterId );
2015-02-16 19:18:45 +01:00
virtual void FillInitialWorldStates ( WorldPackets :: WorldState :: InitWorldStates & /*packet*/ ) { }
2011-03-13 21:49:07 +01:00
2012-09-26 17:46:00 +02:00
// ReCheck PhaseTemplate related conditions
void UpdatePhasing ();
2015-03-08 22:04:34 +01:00
uint32 GetEncounterCount () const { return uint32 ( bosses . size ()); }
2014-10-18 22:03:29 +01:00
2016-04-14 22:43:21 +02:00
void InitializeCombatResurrections ( uint8 charges = 1 , uint32 interval = 0 );
void AddCombatResurrectionCharge ();
void UseCombatResurrection ();
void ResetCombatResurrections ();
uint8 GetCombatResurrectionCharges () const { return _combatResurrectionCharges ; }
uint32 GetCombatResurrectionChargeInterval () const ;
2009-05-06 00:06:38 -05:00
protected :
2014-09-07 00:42:14 +02:00
void SetHeaders ( std :: string const & dataHeaders );
2009-05-16 14:49:30 -05:00
void SetBossNumber ( uint32 number ) { bosses . resize ( number ); }
2016-01-13 15:33:17 +01:00
void LoadBossBoundaries ( BossBoundaryData const & data );
2011-03-19 10:54:16 +01:00
void LoadDoorData ( DoorData const * data );
void LoadMinionData ( MinionData const * data );
2014-09-18 00:25:05 +02:00
void LoadObjectData ( ObjectData const * creatureData , ObjectData const * gameObjectData );
void AddObject ( Creature * obj , bool add );
void AddObject ( GameObject * obj , bool add );
void AddObject ( WorldObject * obj , uint32 type , bool add );
2009-10-17 15:51:44 -07:00
2015-03-21 23:57:49 +01:00
virtual void AddDoor ( GameObject * door , bool add );
2011-03-19 10:54:16 +01:00
void AddMinion ( Creature * minion , bool add );
2009-10-17 15:51:44 -07:00
2015-03-21 23:57:49 +01:00
virtual void UpdateDoorState ( GameObject * door );
2011-09-15 14:08:17 +02:00
void UpdateMinionState ( Creature * minion , EncounterState state );
2009-10-17 15:51:44 -07:00
2015-03-21 23:57:49 +01:00
// Exposes private data that should never be modified unless exceptional cases.
// Pay very much attention at how the returned BossInfo data is modified to avoid issues.
BossInfo * GetBossInfo ( uint32 id );
2014-09-07 00:42:14 +02:00
// Instance Load and Save
bool ReadSaveDataHeaders ( std :: istringstream & data );
void ReadSaveDataBossStates ( std :: istringstream & data );
virtual void ReadSaveDataMore ( std :: istringstream & /*data*/ ) { }
void WriteSaveDataHeaders ( std :: ostringstream & data );
void WriteSaveDataBossStates ( std :: ostringstream & data );
virtual void WriteSaveDataMore ( std :: ostringstream & /*data*/ ) { }
2015-08-23 14:43:11 +02:00
bool _SkipCheckRequiredBosses ( Player const * player = nullptr ) const ;
2009-05-01 18:24:12 -05:00
private :
2014-09-18 00:25:05 +02:00
static void LoadObjectData ( ObjectData const * creatureData , ObjectInfoMap & objectInfo );
2017-05-28 16:34:44 +02:00
void UpdateEncounterState ( EncounterCreditType type , uint32 creditEntry , Unit * source );
2014-09-18 00:25:05 +02:00
2014-09-07 00:42:14 +02:00
std :: vector < char > headers ;
2009-05-01 18:24:12 -05:00
std :: vector < BossInfo > bosses ;
2009-05-09 14:08:42 -05:00
DoorInfoMap doors ;
2009-05-16 14:49:30 -05:00
MinionInfoMap minions ;
2014-09-18 00:25:05 +02:00
ObjectInfoMap _creatureInfo ;
ObjectInfoMap _gameObjectInfo ;
ObjectGuidMap _objectGuids ;
2011-02-03 22:20:40 +01:00
uint32 completedEncounters ; // completed encounter mask, bit indexes are DungeonEncounter.dbc boss numbers, used for packets
2016-07-16 14:58:33 +02:00
uint32 _entranceId ;
uint32 _temporaryEntranceId ;
2016-04-14 22:43:21 +02:00
uint32 _combatResurrectionTimer ;
uint8 _combatResurrectionCharges ; // the counter for available battle resurrections
bool _combatResurrectionTimerStarted ;
2016-03-11 17:09:26 +01:00
#ifdef TRINITY_API_USE_DYNAMIC_LINKING
// Strong reference to the associated script module
std :: shared_ptr < ModuleReference > module_reference ;
#endif // #ifndef TRINITY_API_USE_DYNAMIC_LINKING
2008-10-02 16:23:55 -05:00
};
2013-08-21 19:43:46 +02:00
#endif // TRINITY_INSTANCE_DATA_H