mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-29 13:22:48 +01:00
*Add some InstanceData functions to better handle instance doors.
--HG-- branch : trunk
This commit is contained in:
@@ -8,15 +8,6 @@
|
||||
#include "InstanceData.h"
|
||||
#include "Map.h"
|
||||
|
||||
enum EncounterState
|
||||
{
|
||||
NOT_STARTED = 0,
|
||||
IN_PROGRESS = 1,
|
||||
FAIL = 2,
|
||||
DONE = 3,
|
||||
SPECIAL = 4
|
||||
};
|
||||
|
||||
#define OUT_SAVE_INST_DATA debug_log("TSCR: Saving Instance Data for Instance %s (Map %d, Instance Id %d)", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
|
||||
#define OUT_SAVE_INST_DATA_COMPLETE debug_log("TSCR: Saving Instance Data for Instance %s (Map %d, Instance Id %d) completed.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
|
||||
#define OUT_LOAD_INST_DATA(a) debug_log("TSCR: Loading Instance Data for Instance %s (Map %d, Instance Id %d). Input is '%s'", instance->GetMapName(), instance->GetId(), instance->GetInstanceId(), a)
|
||||
|
||||
@@ -191,6 +191,9 @@ void Creature::RemoveFromWorld()
|
||||
///- Remove the creature from the accessor
|
||||
if(IsInWorld())
|
||||
{
|
||||
if(Map *map = FindMap())
|
||||
if(map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData())
|
||||
((InstanceMap*)map)->GetInstanceData()->OnCreatureRemove(this);
|
||||
if(m_formation)
|
||||
formation_mgr.RemoveCreatureFromGroup(m_formation, this);
|
||||
ObjectAccessor::Instance().RemoveObject(this);
|
||||
@@ -1371,7 +1374,7 @@ bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 team, const
|
||||
//Notify the map's instance data.
|
||||
//Only works if you create the object in it, not if it is moves to that map.
|
||||
//Normally non-players do not teleport to other maps.
|
||||
Map *map = MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
|
||||
Map *map = FindMap();
|
||||
if(map && map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData())
|
||||
{
|
||||
((InstanceMap*)map)->GetInstanceData()->OnCreatureCreate(this, Entry);
|
||||
|
||||
@@ -94,6 +94,9 @@ void GameObject::RemoveFromWorld()
|
||||
///- Remove the gameobject from the accessor
|
||||
if(IsInWorld())
|
||||
{
|
||||
if(Map *map = FindMap())
|
||||
if(map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData())
|
||||
((InstanceMap*)map)->GetInstanceData()->OnObjectRemove(this);
|
||||
ObjectAccessor::Instance().RemoveObject(this);
|
||||
WorldObject::RemoveFromWorld();
|
||||
}
|
||||
|
||||
@@ -40,3 +40,92 @@ void InstanceData::HandleGameObject(uint64 GUID, bool open, GameObject *go)
|
||||
debug_log("TSCR: InstanceData: HandleGameObject failed");
|
||||
}
|
||||
|
||||
bool InstanceData::IsEncounterInProgress() const
|
||||
{
|
||||
for(std::vector<BossInfo>::const_iterator itr = bosses.begin(); itr != bosses.end(); ++itr)
|
||||
if(itr->state == IN_PROGRESS)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void InstanceData::AddBossRoomDoor(uint32 id, GameObject *door)
|
||||
{
|
||||
if(id < bosses.size())
|
||||
{
|
||||
BossInfo *bossInfo = &bosses[id];
|
||||
bossInfo->roomDoor.insert(door);
|
||||
// Room door is only closed when encounter is in progress
|
||||
if(bossInfo->state == IN_PROGRESS)
|
||||
door->SetGoState(1);
|
||||
else
|
||||
door->SetGoState(0);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceData::AddBossPassageDoor(uint32 id, GameObject *door)
|
||||
{
|
||||
if(id < bosses.size())
|
||||
{
|
||||
BossInfo *bossInfo = &bosses[id];
|
||||
bossInfo->passageDoor.insert(door);
|
||||
// Passage door is only opened when boss is defeated
|
||||
if(bossInfo->state == DONE)
|
||||
door->SetGoState(0);
|
||||
else
|
||||
door->SetGoState(1);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceData::RemoveBossRoomDoor(uint32 id, GameObject *door)
|
||||
{
|
||||
if(id < bosses.size())
|
||||
{
|
||||
bosses[id].roomDoor.erase(door);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceData::RemoveBossPassageDoor(uint32 id, GameObject *door)
|
||||
{
|
||||
if(id < bosses.size())
|
||||
{
|
||||
bosses[id].passageDoor.erase(door);
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceData::SetBossState(uint32 id, EncounterState state)
|
||||
{
|
||||
if(id < bosses.size())
|
||||
{
|
||||
BossInfo *bossInfo = &bosses[id];
|
||||
|
||||
bossInfo->state = state;
|
||||
switch(state)
|
||||
{
|
||||
case NOT_STARTED:
|
||||
// Open all room doors, close all passage doors
|
||||
for(DoorSet::iterator i = bossInfo->roomDoor.begin(); i != bossInfo->roomDoor.end(); ++i)
|
||||
(*i)->SetGoState(0);
|
||||
for(DoorSet::iterator i = bossInfo->passageDoor.begin(); i != bossInfo->passageDoor.end(); ++i)
|
||||
(*i)->SetGoState(1);
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
// Close all doors
|
||||
for(DoorSet::iterator i = bossInfo->roomDoor.begin(); i != bossInfo->roomDoor.end(); ++i)
|
||||
(*i)->SetGoState(1);
|
||||
for(DoorSet::iterator i = bossInfo->passageDoor.begin(); i != bossInfo->passageDoor.end(); ++i)
|
||||
(*i)->SetGoState(1);
|
||||
break;
|
||||
case DONE:
|
||||
// Open all doors
|
||||
for(DoorSet::iterator i = bossInfo->roomDoor.begin(); i != bossInfo->roomDoor.end(); ++i)
|
||||
(*i)->SetGoState(0);
|
||||
for(DoorSet::iterator i = bossInfo->passageDoor.begin(); i != bossInfo->passageDoor.end(); ++i)
|
||||
(*i)->SetGoState(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,24 @@ class Player;
|
||||
class GameObject;
|
||||
class Creature;
|
||||
|
||||
enum EncounterState
|
||||
{
|
||||
NOT_STARTED = 0,
|
||||
IN_PROGRESS = 1,
|
||||
FAIL = 2,
|
||||
DONE = 3,
|
||||
SPECIAL = 4
|
||||
};
|
||||
|
||||
typedef std::set<GameObject*> DoorSet;
|
||||
|
||||
struct BossInfo
|
||||
{
|
||||
BossInfo() : state(NOT_STARTED) {}
|
||||
EncounterState state;
|
||||
DoorSet roomDoor, passageDoor;
|
||||
};
|
||||
|
||||
class TRINITY_DLL_SPEC InstanceData
|
||||
{
|
||||
public:
|
||||
@@ -56,7 +74,7 @@ class TRINITY_DLL_SPEC InstanceData
|
||||
|
||||
//Used by the map's CanEnter function.
|
||||
//This is to prevent players from entering during boss encounters.
|
||||
virtual bool IsEncounterInProgress() const { return false; };
|
||||
virtual bool IsEncounterInProgress() const;
|
||||
|
||||
//Called when a player successfully enters the instance.
|
||||
virtual void OnPlayerEnter(Player *) {}
|
||||
@@ -67,6 +85,9 @@ class TRINITY_DLL_SPEC InstanceData
|
||||
//called on creature creation
|
||||
virtual void OnCreatureCreate(Creature * /*creature*/, uint32 /*creature_entry*/) {}
|
||||
|
||||
virtual void OnCreatureRemove(Creature*) {}
|
||||
virtual void OnObjectRemove(GameObject*) {}
|
||||
|
||||
//All-purpose data storage 32 bit
|
||||
virtual uint32 GetData(uint32) { return 0; }
|
||||
virtual void SetData(uint32, uint32 data) {}
|
||||
@@ -74,7 +95,27 @@ class TRINITY_DLL_SPEC InstanceData
|
||||
//Handle open / close objects
|
||||
//use HandleGameObject(NULL,boolen,GO); in OnObjectCreate in instance scripts
|
||||
//use HandleGameObject(GUID,boolen,NULL); in any other script
|
||||
virtual void HandleGameObject(uint64 GUID, bool open, GameObject *go = NULL);
|
||||
void HandleGameObject(uint64 GUID, bool open, GameObject *go = NULL);
|
||||
|
||||
protected:
|
||||
void AddBossRoomDoor(uint32 id, GameObject *door);
|
||||
void AddBossPassageDoor(uint32 id, GameObject *door);
|
||||
void RemoveBossRoomDoor(uint32 id, GameObject *door);
|
||||
void RemoveBossPassageDoor(uint32 id, GameObject *door);
|
||||
|
||||
void SetBossState(uint32 id, EncounterState state);
|
||||
|
||||
std::string GetBossSave()
|
||||
{
|
||||
std::ostringstream saveStream;
|
||||
for(std::vector<BossInfo>::iterator i = bosses.begin(); i != bosses.end(); ++i)
|
||||
saveStream << (uint32)i->state << " ";
|
||||
return saveStream.str();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<BossInfo> bosses;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user