mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-29 13:22:48 +01:00
Scripts/Trial of the Champion: "Refactor" encounter state management to use InstanceScript::Get/SetBossState so people attempting to fix this instance don't feel compelled to change EVERY SINGLE BOSS FILE when fixing one of them
This commit is contained in:
@@ -205,7 +205,7 @@ public:
|
||||
if (MovementType != POINT_MOTION_TYPE)
|
||||
return;
|
||||
|
||||
instance->SetData(BOSS_ARGENT_CHALLENGE_E, DONE);
|
||||
instance->SetBossState(BOSS_ARGENT_CHALLENGE_E, DONE);
|
||||
|
||||
me->DisappearAndDie();
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
if (MovementType != POINT_MOTION_TYPE || Point != 0)
|
||||
return;
|
||||
|
||||
instance->SetData(BOSS_ARGENT_CHALLENGE_P, DONE);
|
||||
instance->SetBossState(BOSS_ARGENT_CHALLENGE_P, DONE);
|
||||
|
||||
me->DisappearAndDie();
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ public:
|
||||
{
|
||||
DoCast(me, SPELL_KILL_CREDIT);
|
||||
|
||||
instance->SetData(BOSS_BLACK_KNIGHT, DONE);
|
||||
instance->SetBossState(BOSS_BLACK_KNIGHT, DONE);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ public:
|
||||
|
||||
void JustDied(Unit* /*killer*/) override
|
||||
{
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -522,7 +522,7 @@ public:
|
||||
else if (me->GetGUID() == instance->GetGuidData(DATA_GRAND_CHAMPION_3))
|
||||
me->SetHomePosition(754.34f, 660.70f, 412.39f, 4.79f);
|
||||
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
|
||||
EnterEvadeMode();
|
||||
bHome = true;
|
||||
@@ -579,7 +579,7 @@ public:
|
||||
|
||||
void JustDied(Unit* /*killer*/) override
|
||||
{
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -672,7 +672,7 @@ public:
|
||||
else if (me->GetGUID() == instance->GetGuidData(DATA_GRAND_CHAMPION_3))
|
||||
me->SetHomePosition(754.34f, 660.70f, 412.39f, 4.79f);
|
||||
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
|
||||
EnterEvadeMode();
|
||||
bHome = true;
|
||||
@@ -731,7 +731,7 @@ public:
|
||||
|
||||
void JustDied(Unit* /*killer*/) override
|
||||
{
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -823,7 +823,7 @@ public:
|
||||
else if (me->GetGUID() == instance->GetGuidData(DATA_GRAND_CHAMPION_3))
|
||||
me->SetHomePosition(754.34f, 660.70f, 412.39f, 4.79f);
|
||||
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
|
||||
EnterEvadeMode();
|
||||
bHome = true;
|
||||
@@ -892,7 +892,7 @@ public:
|
||||
|
||||
void JustDied(Unit* /*killer*/) override
|
||||
{
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -976,7 +976,7 @@ public:
|
||||
else if (me->GetGUID() == instance->GetGuidData(DATA_GRAND_CHAMPION_3))
|
||||
me->SetHomePosition(754.34f, 660.70f, 412.39f, 4.79f);
|
||||
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, IN_PROGRESS);
|
||||
|
||||
EnterEvadeMode();
|
||||
bHome = true;
|
||||
@@ -1018,7 +1018,7 @@ public:
|
||||
|
||||
void JustDied(Unit* /*killer*/) override
|
||||
{
|
||||
instance->SetData(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
instance->SetBossState(BOSS_GRAND_CHAMPIONS, DONE);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ EndScriptData */
|
||||
#include "Player.h"
|
||||
#include "trial_of_the_champion.h"
|
||||
|
||||
#define MAX_ENCOUNTER 4
|
||||
constexpr uint32 ToCEncounterCount = 4;
|
||||
|
||||
class instance_trial_of_the_champion : public InstanceMapScript
|
||||
{
|
||||
@@ -49,18 +49,15 @@ public:
|
||||
instance_trial_of_the_champion_InstanceMapScript(Map* map) : InstanceScript(map)
|
||||
{
|
||||
SetHeaders(DataHeader);
|
||||
SetBossNumber(ToCEncounterCount);
|
||||
uiMovementDone = 0;
|
||||
uiGrandChampionsDeaths = 0;
|
||||
uiArgentSoldierDeaths = 0;
|
||||
teamInInstance = 0;
|
||||
|
||||
bDone = false;
|
||||
|
||||
memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
|
||||
}
|
||||
|
||||
uint32 m_auiEncounter[MAX_ENCOUNTER];
|
||||
|
||||
uint32 teamInInstance;
|
||||
uint16 uiMovementDone;
|
||||
uint16 uiGrandChampionsDeaths;
|
||||
@@ -79,21 +76,8 @@ public:
|
||||
|
||||
GuidList VehicleList;
|
||||
|
||||
std::string str_data;
|
||||
|
||||
bool bDone;
|
||||
|
||||
bool IsEncounterInProgress() const override
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
|
||||
{
|
||||
if (m_auiEncounter[i] == IN_PROGRESS)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnPlayerEnter(Player* player) override
|
||||
{
|
||||
if (!teamInInstance)
|
||||
@@ -165,6 +149,59 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool SetBossState(uint32 id, EncounterState state) override
|
||||
{
|
||||
if (!InstanceScript::SetBossState(id, state))
|
||||
return false;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case BOSS_GRAND_CHAMPIONS:
|
||||
if (state == IN_PROGRESS)
|
||||
{
|
||||
for (ObjectGuid guid : VehicleList)
|
||||
if (Creature* summon = instance->GetCreature(guid))
|
||||
summon->RemoveFromWorld();
|
||||
}
|
||||
else if (state == DONE)
|
||||
{
|
||||
++uiGrandChampionsDeaths;
|
||||
if (uiGrandChampionsDeaths == 3)
|
||||
{
|
||||
if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
|
||||
{
|
||||
pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
|
||||
pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
pAnnouncer->SummonGameObject(instance->IsHeroic() ? GO_CHAMPIONS_LOOT_H : GO_CHAMPIONS_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, QuaternionData(), 25h);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BOSS_ARGENT_CHALLENGE_E:
|
||||
if (state == DONE)
|
||||
{
|
||||
if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
|
||||
{
|
||||
pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
|
||||
pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
pAnnouncer->SummonGameObject(instance->IsHeroic() ? GO_EADRIC_LOOT_H : GO_EADRIC_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, QuaternionData(), 25h);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BOSS_ARGENT_CHALLENGE_P:
|
||||
if (state == DONE)
|
||||
{
|
||||
if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
|
||||
{
|
||||
pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
|
||||
pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
pAnnouncer->SummonGameObject(instance->IsHeroic() ? GO_PALETRESS_LOOT_H : GO_PALETRESS_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, QuaternionData(), 25h);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetData(uint32 uiType, uint32 uiData) override
|
||||
{
|
||||
switch (uiType)
|
||||
@@ -177,27 +214,6 @@ public:
|
||||
pAnnouncer->AI()->SetData(DATA_IN_POSITION, 0);
|
||||
}
|
||||
break;
|
||||
case BOSS_GRAND_CHAMPIONS:
|
||||
m_auiEncounter[0] = uiData;
|
||||
if (uiData == IN_PROGRESS)
|
||||
{
|
||||
for (GuidList::const_iterator itr = VehicleList.begin(); itr != VehicleList.end(); ++itr)
|
||||
if (Creature* summon = instance->GetCreature(*itr))
|
||||
summon->RemoveFromWorld();
|
||||
}else if (uiData == DONE)
|
||||
{
|
||||
++uiGrandChampionsDeaths;
|
||||
if (uiGrandChampionsDeaths == 3)
|
||||
{
|
||||
if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
|
||||
{
|
||||
pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
|
||||
pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
pAnnouncer->SummonGameObject(instance->IsHeroic()? GO_CHAMPIONS_LOOT_H : GO_CHAMPIONS_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, QuaternionData(), 25h);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DATA_ARGENT_SOLDIER_DEFEATED:
|
||||
uiArgentSoldierDeaths = uiData;
|
||||
if (uiArgentSoldierDeaths == 9)
|
||||
@@ -210,24 +226,6 @@ public:
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BOSS_ARGENT_CHALLENGE_E:
|
||||
m_auiEncounter[1] = uiData;
|
||||
if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
|
||||
{
|
||||
pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
|
||||
pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
pAnnouncer->SummonGameObject(instance->IsHeroic()? GO_EADRIC_LOOT_H : GO_EADRIC_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, QuaternionData(), 25h);
|
||||
}
|
||||
break;
|
||||
case BOSS_ARGENT_CHALLENGE_P:
|
||||
m_auiEncounter[2] = uiData;
|
||||
if (Creature* pAnnouncer = instance->GetCreature(uiAnnouncerGUID))
|
||||
{
|
||||
pAnnouncer->GetMotionMaster()->MovePoint(0, 748.309f, 619.487f, 411.171f);
|
||||
pAnnouncer->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
pAnnouncer->SummonGameObject(instance->IsHeroic()? GO_PALETRESS_LOOT_H : GO_PALETRESS_LOOT, 746.59f, 618.49f, 411.09f, 1.42f, QuaternionData(), 25h);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (uiData == DONE)
|
||||
@@ -238,11 +236,6 @@ public:
|
||||
{
|
||||
switch (uiData)
|
||||
{
|
||||
case BOSS_GRAND_CHAMPIONS: return m_auiEncounter[0];
|
||||
case BOSS_ARGENT_CHALLENGE_E: return m_auiEncounter[1];
|
||||
case BOSS_ARGENT_CHALLENGE_P: return m_auiEncounter[2];
|
||||
case BOSS_BLACK_KNIGHT: return m_auiEncounter[3];
|
||||
|
||||
case DATA_MOVEMENT_DONE: return uiMovementDone;
|
||||
case DATA_ARGENT_SOLDIER_DEFEATED: return uiArgentSoldierDeaths;
|
||||
}
|
||||
@@ -281,60 +274,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetSaveData() override
|
||||
void WriteSaveDataMore(std::ostringstream& stream) override
|
||||
{
|
||||
OUT_SAVE_INST_DATA;
|
||||
|
||||
std::ostringstream saveStream;
|
||||
|
||||
saveStream << "T C " << m_auiEncounter[0]
|
||||
<< ' ' << m_auiEncounter[1]
|
||||
<< ' ' << m_auiEncounter[2]
|
||||
<< ' ' << m_auiEncounter[3]
|
||||
<< ' ' << uiGrandChampionsDeaths
|
||||
<< ' ' << uiMovementDone;
|
||||
|
||||
str_data = saveStream.str();
|
||||
|
||||
OUT_SAVE_INST_DATA_COMPLETE;
|
||||
return str_data;
|
||||
stream << uiGrandChampionsDeaths << ' ' << uiMovementDone;
|
||||
}
|
||||
|
||||
void Load(char const* in) override
|
||||
void ReadSaveDataMore(std::istringstream& stream) override
|
||||
{
|
||||
if (!in)
|
||||
{
|
||||
OUT_LOAD_INST_DATA_FAIL;
|
||||
return;
|
||||
}
|
||||
|
||||
OUT_LOAD_INST_DATA(in);
|
||||
|
||||
char dataHead1, dataHead2;
|
||||
uint16 data0, data1, data2, data3, data4, data5;
|
||||
|
||||
std::istringstream loadStream(in);
|
||||
loadStream >> dataHead1 >> dataHead2 >> data0 >> data1 >> data2 >> data3 >> data4 >> data5;
|
||||
|
||||
if (dataHead1 == 'T' && dataHead2 == 'C')
|
||||
{
|
||||
m_auiEncounter[0] = data0;
|
||||
m_auiEncounter[1] = data1;
|
||||
m_auiEncounter[2] = data2;
|
||||
m_auiEncounter[3] = data3;
|
||||
|
||||
for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
|
||||
if (m_auiEncounter[i] == IN_PROGRESS)
|
||||
m_auiEncounter[i] = NOT_STARTED;
|
||||
|
||||
uiGrandChampionsDeaths = data4;
|
||||
uiMovementDone = data5;
|
||||
} else OUT_LOAD_INST_DATA_FAIL;
|
||||
|
||||
OUT_LOAD_INST_DATA_COMPLETE;
|
||||
stream >> uiGrandChampionsDeaths >> uiMovementDone;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
void AddSC_instance_trial_of_the_champion()
|
||||
|
||||
@@ -348,20 +348,20 @@ public:
|
||||
{
|
||||
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
|
||||
|
||||
if (instance->GetData(BOSS_BLACK_KNIGHT) == NOT_STARTED)
|
||||
if (instance->GetBossState(BOSS_BLACK_KNIGHT) == NOT_STARTED)
|
||||
{
|
||||
if (instance->GetData(BOSS_ARGENT_CHALLENGE_E) == NOT_STARTED && instance->GetData(BOSS_ARGENT_CHALLENGE_P) == NOT_STARTED)
|
||||
if (instance->GetBossState(BOSS_ARGENT_CHALLENGE_E) == NOT_STARTED && instance->GetBossState(BOSS_ARGENT_CHALLENGE_P) == NOT_STARTED)
|
||||
{
|
||||
if (instance->GetData(BOSS_GRAND_CHAMPIONS) == NOT_STARTED)
|
||||
if (instance->GetBossState(BOSS_GRAND_CHAMPIONS) == NOT_STARTED)
|
||||
SetData(DATA_START, 0);
|
||||
|
||||
if (instance->GetData(BOSS_GRAND_CHAMPIONS) == DONE)
|
||||
if (instance->GetBossState(BOSS_GRAND_CHAMPIONS) == DONE)
|
||||
DoStartArgentChampionEncounter();
|
||||
}
|
||||
|
||||
if ((instance->GetData(BOSS_GRAND_CHAMPIONS) == DONE &&
|
||||
instance->GetData(BOSS_ARGENT_CHALLENGE_E) == DONE) ||
|
||||
instance->GetData(BOSS_ARGENT_CHALLENGE_P) == DONE)
|
||||
if ((instance->GetBossState(BOSS_GRAND_CHAMPIONS) == DONE &&
|
||||
instance->GetBossState(BOSS_ARGENT_CHALLENGE_E) == DONE) ||
|
||||
instance->GetBossState(BOSS_ARGENT_CHALLENGE_P) == DONE)
|
||||
me->SummonCreature(VEHICLE_BLACK_KNIGHT, 769.834f, 651.915f, 447.035f, 0);
|
||||
}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ public:
|
||||
|
||||
void JustSummoned(Creature* summon) override
|
||||
{
|
||||
if (instance->GetData(BOSS_GRAND_CHAMPIONS) == NOT_STARTED)
|
||||
if (instance->GetBossState(BOSS_GRAND_CHAMPIONS) == NOT_STARTED)
|
||||
{
|
||||
summon->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
|
||||
summon->SetReactState(REACT_PASSIVE);
|
||||
@@ -452,16 +452,16 @@ public:
|
||||
|
||||
bool OnGossipHello(Player* player) override
|
||||
{
|
||||
if (((instance->GetData(BOSS_GRAND_CHAMPIONS) == DONE &&
|
||||
instance->GetData(BOSS_BLACK_KNIGHT) == DONE &&
|
||||
instance->GetData(BOSS_ARGENT_CHALLENGE_E) == DONE) ||
|
||||
instance->GetData(BOSS_ARGENT_CHALLENGE_P) == DONE))
|
||||
if (((instance->GetBossState(BOSS_GRAND_CHAMPIONS) == DONE &&
|
||||
instance->GetBossState(BOSS_BLACK_KNIGHT) == DONE &&
|
||||
instance->GetBossState(BOSS_ARGENT_CHALLENGE_E) == DONE) ||
|
||||
instance->GetBossState(BOSS_ARGENT_CHALLENGE_P) == DONE))
|
||||
return false;
|
||||
|
||||
if (instance->GetData(BOSS_GRAND_CHAMPIONS) == NOT_STARTED &&
|
||||
instance->GetData(BOSS_ARGENT_CHALLENGE_E) == NOT_STARTED &&
|
||||
instance->GetData(BOSS_ARGENT_CHALLENGE_P) == NOT_STARTED &&
|
||||
instance->GetData(BOSS_BLACK_KNIGHT) == NOT_STARTED)
|
||||
if (instance->GetBossState(BOSS_GRAND_CHAMPIONS) == NOT_STARTED &&
|
||||
instance->GetBossState(BOSS_ARGENT_CHALLENGE_E) == NOT_STARTED &&
|
||||
instance->GetBossState(BOSS_ARGENT_CHALLENGE_P) == NOT_STARTED &&
|
||||
instance->GetBossState(BOSS_BLACK_KNIGHT) == NOT_STARTED)
|
||||
AddGossipItemFor(player, GOSSIP_ICON_CHAT, GOSSIP_START_EVENT1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
|
||||
else
|
||||
AddGossipItemFor(player, GOSSIP_ICON_CHAT, GOSSIP_START_EVENT2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
|
||||
enum TCData
|
||||
{
|
||||
BOSS_GRAND_CHAMPIONS,
|
||||
BOSS_ARGENT_CHALLENGE_E,
|
||||
BOSS_ARGENT_CHALLENGE_P,
|
||||
BOSS_BLACK_KNIGHT,
|
||||
BOSS_GRAND_CHAMPIONS = 0,
|
||||
BOSS_ARGENT_CHALLENGE_E = 1,
|
||||
BOSS_ARGENT_CHALLENGE_P = 2,
|
||||
BOSS_BLACK_KNIGHT = 3,
|
||||
|
||||
DATA_MOVEMENT_DONE,
|
||||
DATA_LESSER_CHAMPIONS_DEFEATED,
|
||||
DATA_START,
|
||||
|
||||
Reference in New Issue
Block a user