fix(Core/Maps): Fix instance factions (#21577)

This commit is contained in:
Takenbacon 2025-02-21 11:49:39 -08:00 committed by GitHub
parent 0161a611ef
commit d145b866a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 56 deletions

View File

@ -2206,15 +2206,6 @@ bool InstanceMap::AddPlayerToMap(Player* player)
m_resetAfterUnload = false;
m_unloadWhenEmpty = false;
if (instance_data && instance_data->IsTwoFactionInstance()
&& instance_data->GetTeamIdInInstance() == TEAM_NEUTRAL)
{
instance_data->SetTeamIdInInstance(player->GetTeamId());
if (Group* group = player->GetGroup())
if (Player* leader = ObjectAccessor::FindConnectedPlayer(group->GetLeaderGUID()))
instance_data->SetTeamIdInInstance(leader->GetTeamId());
}
// this will acquire the same mutex so it cannot be in the previous block
Map::AddPlayerToMap(player);

View File

@ -147,7 +147,7 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
map = FindInstanceMap(destInstId);
if (!map)
map = CreateInstance(destInstId, pSave, realdiff);
map = CreateInstance(destInstId, pSave, realdiff, player);
else if (IsSharedDifficultyMap(mapId) && !map->HavePlayers() && map->GetDifficulty() != realdiff)
{
if (player->isBeingLoaded()) // pussywizard: crashfix (assert(passengers.empty) fail in ~transport), could be added to a transport during loading from db
@ -160,7 +160,7 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
if (i->first == destInstId)
{
DestroyInstance(i);
map = CreateInstance(destInstId, pSave, realdiff);
map = CreateInstance(destInstId, pSave, realdiff, player);
break;
}
}
@ -170,14 +170,14 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
uint32 newInstanceId = sMapMgr->GenerateInstanceId();
ASSERT(!FindInstanceMap(newInstanceId)); // pussywizard: instance with new id can't exist
Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid());
map = CreateInstance(newInstanceId, nullptr, diff);
map = CreateInstance(newInstanceId, nullptr, diff, player);
}
}
return map;
}
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty)
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty, Player* player)
{
// load/create a map
std::lock_guard<std::mutex> guard(Lock);
@ -213,6 +213,16 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
else
map->CreateInstanceScript(false, "", 0);
if (map->GetInstanceScript() && map->GetInstanceScript()->IsTwoFactionInstance()
&& map->GetInstanceScript()->GetTeamIdInInstance() == TEAM_NEUTRAL)
{
ASSERT(player); // Player should exist, as checked by in MapInstanced::CreateInstanceForPlayer
map->GetInstanceScript()->SetTeamIdInInstance(player->GetTeamId());
if (Group* group = player->GetGroup())
if (Player* leader = ObjectAccessor::FindConnectedPlayer(group->GetLeaderGUID()))
map->GetInstanceScript()->SetTeamIdInInstance(leader->GetTeamId());
}
map->OnCreateMap();
if (!save) // this is for sure a dungeon (assert above), no need to check here

View File

@ -50,7 +50,7 @@ public:
void InitVisibilityDistance() override;
private:
InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty);
InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty, Player* player);
BattlegroundMap* CreateBattleground(uint32 InstanceId, Battleground* bg);
InstancedMaps m_InstancedMaps;

View File

@ -46,7 +46,6 @@ public:
}
uint32 m_auiEncounter[MAX_ENCOUNTER];
TeamId teamIdInInstance;
std::string str_data;
ObjectGuid NPC_BronjahmGUID;
ObjectGuid NPC_DevourerGUID;
@ -59,7 +58,6 @@ public:
void Initialize() override
{
memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));
teamIdInInstance = TEAM_NEUTRAL;
}
bool IsEncounterInProgress() const override
@ -72,21 +70,7 @@ 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);
// this will happen only after crash and loading the instance from db
if (m_auiEncounter[0] == DONE && m_auiEncounter[1] == DONE && (!NPC_LeaderSecondGUID || !instance->GetCreature(NPC_LeaderSecondGUID)))
@ -98,24 +82,6 @@ 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_BRONJAHM:
@ -125,7 +91,7 @@ public:
NPC_DevourerGUID = creature->GetGUID();
break;
case NPC_SYLVANAS_PART1:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_JAINA_PART1);
NPC_LeaderFirstGUID = creature->GetGUID();
@ -133,12 +99,12 @@ public:
creature->SetVisible(false);
break;
case NPC_SYLVANAS_PART2:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_JAINA_PART2);
NPC_LeaderSecondGUID = creature->GetGUID();
break;
case NPC_LORALEN:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_ELANDRA);
if (!NPC_GuardFirstGUID)
{
@ -148,7 +114,7 @@ public:
}
break;
case NPC_KALIRA:
if (teamIdInInstance == TEAM_ALLIANCE)
if (GetTeamIdInInstance() == TEAM_ALLIANCE)
creature->UpdateEntry(NPC_KORELN);
if (!NPC_GuardSecondGUID)
{
@ -170,9 +136,12 @@ public:
leader->GetMotionMaster()->MovePoint(1, boss->GetPositionX() + 10.0f * cos(angle), boss->GetPositionY() + 10.0f * std::sin(angle), boss->GetPositionZ());
}
for (int8 i = 0; outroPositions[i].entry[teamIdInInstance] != 0; ++i)
if (Creature* summon = instance->SummonCreature(outroPositions[i].entry[teamIdInInstance], outroPositions[i].startPosition))
summon->GetMotionMaster()->MovePath(outroPositions[i].pathId, false);
if (GetTeamIdInInstance() < TEAM_NEUTRAL) // Shouldn't happen, but just in case.
{
for (int8 i = 0; outroPositions[i].entry[GetTeamIdInInstance()] != 0; ++i)
if (Creature* summon = instance->SummonCreature(outroPositions[i].entry[GetTeamIdInInstance()], outroPositions[i].startPosition))
summon->GetMotionMaster()->MovePath(outroPositions[i].pathId, false);
}
}
void SetData(uint32 type, uint32 data) override