refactor(Core/Instances): Implement GetTeamIdInInstance() for two-fac… (#21168)

This commit is contained in:
Andrew
2025-01-17 23:51:25 -03:00
committed by GitHub
parent 30a9c87d7d
commit 4a3fab424c
10 changed files with 156 additions and 514 deletions

View File

@@ -96,12 +96,6 @@ public:
}
}
void OnPlayerLeave(Player* player) override
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFactionForRace(player->getRace());
}
void OnCreatureCreate(Creature* creature) override
{
if (teamIdInInstance == TEAM_NEUTRAL)

View File

@@ -144,7 +144,6 @@ public:
};
uint32 EncounterMask;
TeamId TeamIdInInstance;
ObjectGuid NPC_FalricGUID;
ObjectGuid NPC_MarwynGUID;
ObjectGuid NPC_LichKingIntroGUID;
@@ -190,7 +189,6 @@ public:
void Initialize() override
{
EncounterMask = 0;
TeamIdInInstance = TEAM_NEUTRAL;
memset(&TrashActive, 0, sizeof(TrashActive));
TrashCounter = 0;
memset(&chosenComposition, 0, sizeof(chosenComposition));
@@ -214,69 +212,15 @@ public:
return (instance->HavePlayers() && WaveNumber) || IsDuringLKFight; // during LK fight npcs are active and will unset this variable
}
void OnPlayerEnter(Player* player) override
{
if (TeamIdInInstance == TEAM_NEUTRAL)
{
if (Group* group = player->GetGroup())
{
if (Player* gLeader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()))
TeamIdInInstance = Player::TeamIdForRace(gLeader->getRace());
else
TeamIdInInstance = player->GetTeamId();
}
else
TeamIdInInstance = player->GetTeamId();
}
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFaction((TeamIdInInstance == TEAM_HORDE) ? 1610 : 1);
}
void OnPlayerLeave(Player* player) override
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFactionForRace(player->getRace());
}
void OnCreatureCreate(Creature* creature) override
{
if (TeamIdInInstance == TEAM_NEUTRAL)
{
Map::PlayerList const& players = instance->GetPlayers();
if (!players.IsEmpty())
for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
if (Player* p = itr->GetSource())
if (!p->IsGameMaster())
{
if (Group* group = p->GetGroup())
{
if (Player* gLeader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()))
{
TeamIdInInstance = Player::TeamIdForRace(gLeader->getRace());
break;
}
else
{
TeamIdInInstance = p->GetTeamId();
break;
}
}
else
{
TeamIdInInstance = p->GetTeamId();
break;
}
}
}
switch (creature->GetEntry())
{
case NPC_SYLVANAS_PART1:
creature->SetVisible(false);
creature->SetSpeed(MOVE_RUN, 1.1);
NPC_LeaderIntroGUID = creature->GetGUID();
if (TeamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_JAINA_PART1);
creature->RemoveNpcFlag(UNIT_NPC_FLAG_GOSSIP | UNIT_NPC_FLAG_QUESTGIVER);
creature->RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING);
@@ -284,7 +228,7 @@ public:
case NPC_DARK_RANGER_LORALEN:
creature->SetVisible(false);
NPC_GuardGUID = creature->GetGUID();
if (TeamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ARCHMAGE_KORELN);
break;
case NPC_UTHER:
@@ -345,7 +289,7 @@ public:
creature->CastSpell(creature, SPELL_SOUL_REAPER, true);
}
else if (!(EncounterMask & (1 << DATA_LICH_KING)))
creature->AddAura(TeamIdInInstance == TEAM_ALLIANCE ? SPELL_JAINA_ICE_PRISON : SPELL_SYLVANAS_DARK_BINDING, creature);
creature->AddAura(GetTeamIdInInstance() == TEAM_ALLIANCE ? SPELL_JAINA_ICE_PRISON : SPELL_SYLVANAS_DARK_BINDING, creature);
else
creature->SetVisible(false);
@@ -359,7 +303,7 @@ public:
NPC_LeaderGUID = creature->GetGUID();
creature->SetWalk(false);
creature->SetSheath(SHEATH_STATE_MELEE);
if (TeamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_JAINA_PART2);
creature->SetWalk(false);
creature->SetHealth(creature->GetMaxHealth() / 20);
@@ -368,9 +312,9 @@ public:
if (!(EncounterMask & (1 << DATA_LK_INTRO)))
{
creature->SetSheath(SHEATH_STATE_MELEE);
creature->SetUInt32Value(UNIT_NPC_EMOTESTATE, TeamIdInInstance == TEAM_ALLIANCE ? EMOTE_ONESHOT_ATTACK2HTIGHT : EMOTE_ONESHOT_ATTACK1H); //the fight cannot be in the form of an emote, it is causing bugs.
creature->SetUInt32Value(UNIT_NPC_EMOTESTATE, GetTeamIdInInstance() == TEAM_ALLIANCE ? EMOTE_ONESHOT_ATTACK2HTIGHT : EMOTE_ONESHOT_ATTACK1H); //the fight cannot be in the form of an emote, it is causing bugs.
creature->RemoveNpcFlag(UNIT_NPC_FLAG_GOSSIP | UNIT_NPC_FLAG_QUESTGIVER);
creature->CastSpell(creature, TeamIdInInstance == TEAM_ALLIANCE ? SPELL_JAINA_ICE_BARRIER : SPELL_SYLVANAS_CLOAK_OF_DARKNESS, true);
creature->CastSpell(creature, GetTeamIdInInstance() == TEAM_ALLIANCE ? SPELL_JAINA_ICE_BARRIER : SPELL_SYLVANAS_CLOAK_OF_DARKNESS, true);
}
else if (!(EncounterMask & (1 << DATA_LICH_KING)))
{
@@ -577,7 +521,7 @@ public:
if (!c->IsAlive())
{
c->Respawn();
if (TeamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
c->UpdateEntry(NPC_JAINA_PART2);
}
c->GetThreatMgr().ClearAllThreat();
@@ -605,7 +549,7 @@ public:
c->UpdatePosition(c->GetHomePosition(), true);
c->StopMovingOnCurrentPos();
c->RemoveAllAuras();
c->AddAura(TeamIdInInstance == TEAM_ALLIANCE ? SPELL_JAINA_ICE_PRISON : SPELL_SYLVANAS_DARK_BINDING, c);
c->AddAura(GetTeamIdInInstance() == TEAM_ALLIANCE ? SPELL_JAINA_ICE_PRISON : SPELL_SYLVANAS_DARK_BINDING, c);
c->AI()->Reset();
c->setActive(false);
c->RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING);
@@ -1126,18 +1070,18 @@ public:
break;
case 2:
{
uint32 entry = TeamIdInInstance == TEAM_ALLIANCE ? GO_THE_SKYBREAKER : GO_ORGRIMS_HAMMER;
uint32 entry = GetTeamIdInInstance() == TEAM_ALLIANCE ? GO_THE_SKYBREAKER : GO_ORGRIMS_HAMMER;
T1 = sTransportMgr->CreateTransport(entry, 0, instance);
++outroStep;
outroTimer = TeamIdInInstance == TEAM_ALLIANCE ? 10000 : 10500;
outroTimer = GetTeamIdInInstance() == TEAM_ALLIANCE ? 10000 : 10500;
}
break;
case 3:
if (T1)
T1->EnableMovement(false);
if (Creature* c = instance->GetCreature(NPC_ShipCaptainGUID))
c->AI()->Talk(TeamIdInInstance == TEAM_ALLIANCE ? SAY_FIRE_ALLY : SAY_FIRE_HORDE);
c->AI()->Talk(GetTeamIdInInstance() == TEAM_ALLIANCE ? SAY_FIRE_ALLY : SAY_FIRE_HORDE);
if (Creature* c = instance->GetCreature(NPC_LeaderGUID))
{
c->RemoveAllAuras();
@@ -1185,10 +1129,10 @@ public:
T1->EnableMovement(false);
if (Creature* leader = instance->GetCreature(NPC_LeaderGUID))
{
uint8 index = TeamIdInInstance == TEAM_ALLIANCE ? 0 : 1;
uint8 index = GetTeamIdInInstance() == TEAM_ALLIANCE ? 0 : 1;
for (uint8 i = 0; i < 3; ++i)
if (StairsPos[index][i].GetPositionX())
if (GameObject* go = leader->SummonGameObject(TeamIdInInstance == TEAM_ALLIANCE ? GO_STAIRS_ALLIANCE : GO_STAIRS_HORDE, StairsPos[index][i].GetPositionX(), StairsPos[index][i].GetPositionY(), StairsPos[index][i].GetPositionZ(), StairsPos[index][i].GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 86400, false))
if (GameObject* go = leader->SummonGameObject(GetTeamIdInInstance() == TEAM_ALLIANCE ? GO_STAIRS_ALLIANCE : GO_STAIRS_HORDE, StairsPos[index][i].GetPositionX(), StairsPos[index][i].GetPositionY(), StairsPos[index][i].GetPositionZ(), StairsPos[index][i].GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 86400, false))
go->SetGameObjectFlag(GO_FLAG_INTERACT_COND | GO_FLAG_NOT_SELECTABLE);
//Position pos = TeamIdInInstance == TEAM_ALLIANCE ? AllyPortalPos : HordePortalPos;
//leader->SummonGameObject(GO_PORTAL_TO_DALARAN, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 86400);
@@ -1200,7 +1144,7 @@ public:
break;
case 8:
if (Creature* c = instance->GetCreature(NPC_ShipCaptainGUID))
c->AI()->Talk(TeamIdInInstance == TEAM_ALLIANCE ? SAY_ONBOARD_ALLY : SAY_ONBOARD_HORDE);
c->AI()->Talk(GetTeamIdInInstance() == TEAM_ALLIANCE ? SAY_ONBOARD_ALLY : SAY_ONBOARD_HORDE);
if (Creature* c = instance->GetCreature(NPC_LeaderGUID))
{
c->AddUnitMovementFlag(MOVEMENTFLAG_WALKING);
@@ -1212,7 +1156,7 @@ public:
break;
case 9:
if (Creature* c = instance->GetCreature(NPC_LeaderGUID))
c->AI()->Talk(TeamIdInInstance == TEAM_ALLIANCE ? SAY_JAINA_FINAL_1 : SAY_SYLVANA_FINAL);
c->AI()->Talk(GetTeamIdInInstance() == TEAM_ALLIANCE ? SAY_JAINA_FINAL_1 : SAY_SYLVANA_FINAL);
HandleGameObject(GO_CaveInGUID, true);
++outroStep;
outroTimer = 11000;
@@ -1223,7 +1167,7 @@ public:
for (Map::PlayerList::const_iterator itr = instance->GetPlayers().begin(); itr != instance->GetPlayers().end(); ++itr)
if (Player* p = itr->GetSource())
p->KilledMonsterCredit(NPC_WRATH_OF_THE_LICH_KING_CREDIT);
if (TeamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
if (Creature* c = instance->GetCreature(NPC_LeaderGUID))
{
c->AI()->Talk(SAY_JAINA_FINAL_2);

View File

@@ -35,7 +35,6 @@ public:
}
uint32 m_auiEncounter[MAX_ENCOUNTER];
TeamId teamIdInInstance;
uint32 InstanceProgress;
std::string str_data;
@@ -61,7 +60,6 @@ public:
void Initialize() override
{
memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
teamIdInInstance = TEAM_NEUTRAL;
InstanceProgress = INSTANCE_PROGRESS_NONE;
bAchievEleven = true;
@@ -78,62 +76,24 @@ public:
void OnPlayerEnter(Player* player) override
{
if (teamIdInInstance == TEAM_NEUTRAL)
{
if (Group* group = player->GetGroup())
{
if (Player* gLeader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()))
teamIdInInstance = Player::TeamIdForRace(gLeader->getRace());
else
teamIdInInstance = player->GetTeamId();
}
else
teamIdInInstance = player->GetTeamId();
}
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFaction((teamIdInInstance == TEAM_HORDE) ? 1610 : 1);
InstanceScript::OnPlayerEnter(player);
instance->LoadGrid(LeaderIntroPos.GetPositionX(), LeaderIntroPos.GetPositionY());
if (Creature* c = instance->GetCreature(GetGuidData(DATA_LEADER_FIRST_GUID)))
c->AI()->SetData(DATA_START_INTRO, 0);
}
void OnPlayerLeave(Player* player) override
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFactionForRace(player->getRace());
}
uint32 GetCreatureEntry(ObjectGuid::LowType /*guidLow*/, CreatureData const* data) override
{
if (teamIdInInstance == TEAM_NEUTRAL)
{
Map::PlayerList const& players = instance->GetPlayers();
if (!players.IsEmpty())
if (Player* player = players.begin()->GetSource())
{
if (Group* group = player->GetGroup())
{
if (Player* gLeader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()))
teamIdInInstance = Player::TeamIdForRace(gLeader->getRace());
else
teamIdInInstance = player->GetTeamId();
}
else
teamIdInInstance = player->GetTeamId();
}
}
uint32 entry = data->id1;
switch (entry)
{
case NPC_RESCUED_ALLIANCE_SLAVE:
if (teamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
return 0;
break;
case NPC_RESCUED_HORDE_SLAVE:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
return 0;
break;
}
@@ -143,28 +103,10 @@ public:
void OnCreatureCreate(Creature* creature) override
{
if (teamIdInInstance == TEAM_NEUTRAL)
{
Map::PlayerList const& players = instance->GetPlayers();
if (!players.IsEmpty())
if (Player* player = players.begin()->GetSource())
{
if (Group* group = player->GetGroup())
{
if (Player* gLeader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()))
teamIdInInstance = Player::TeamIdForRace(gLeader->getRace());
else
teamIdInInstance = player->GetTeamId();
}
else
teamIdInInstance = player->GetTeamId();
}
}
switch (creature->GetEntry())
{
case NPC_SYLVANAS_PART1:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_JAINA_PART1);
NPC_LeaderFirstGUID = creature->GetGUID();
@@ -183,7 +125,7 @@ public:
}
break;
case NPC_SYLVANAS_PART2:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_JAINA_PART2);
NPC_LeaderSecondGUID = creature->GetGUID();
break;
@@ -213,50 +155,50 @@ public:
}
break;
case NPC_LORALEN:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ELANDRA);
if (!NPC_GuardFirstGUID)
NPC_GuardFirstGUID = creature->GetGUID();
break;
case NPC_KALIRA:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_KORELN);
if (!NPC_GuardSecondGUID)
NPC_GuardSecondGUID = creature->GetGUID();
break;
case NPC_HORDE_SLAVE_1:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ALLIANCE_SLAVE_1);
break;
case NPC_HORDE_SLAVE_2:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ALLIANCE_SLAVE_2);
break;
case NPC_HORDE_SLAVE_3:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ALLIANCE_SLAVE_3);
break;
case NPC_HORDE_SLAVE_4:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ALLIANCE_SLAVE_4);
break;
case NPC_GORKUN_IRONSKULL_1:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_MARTIN_VICTUS_1);
break;
case NPC_GARFROST:
NPC_GarfrostGUID = creature->GetGUID();
break;
case NPC_FREED_SLAVE_1_HORDE:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_FREED_SLAVE_1_ALLIANCE);
break;
case NPC_FREED_SLAVE_2_HORDE:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_FREED_SLAVE_2_ALLIANCE);
break;
case NPC_FREED_SLAVE_3_HORDE:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_FREED_SLAVE_3_ALLIANCE);
break;
case NPC_GORKUN_IRONSKULL_2:
@@ -266,7 +208,7 @@ public:
c->AI()->DoAction(1); // despawn summons
c->DespawnOrUnsummon();
}
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_MARTIN_VICTUS_2);
NPC_MartinOrGorkunGUID = creature->GetGUID();
break;
@@ -370,7 +312,7 @@ public:
case DATA_INSTANCE_PROGRESS:
return InstanceProgress;
case DATA_TEAMID_IN_INSTANCE:
return teamIdInInstance;
return GetTeamIdInInstance();
case DATA_GARFROST:
return m_auiEncounter[0];
case DATA_ICK: