fix(Core/Group): CF Faction Assign & Leader Instance Faction (#21118)

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
manstfu
2025-01-13 12:54:47 +01:00
committed by GitHub
parent 67afd97edf
commit bf4118362a
10 changed files with 349 additions and 24 deletions

View File

@@ -20,6 +20,7 @@
#include "ScriptedCreature.h"
#include "nexus.h"
#include "Player.h"
#include "Group.h"
DoorData const doorData[] =
{
@@ -48,15 +49,29 @@ public:
SetHeaders(DataHeader);
SetBossNumber(MAX_ENCOUNTERS);
LoadDoorData(doorData);
TeamIdInInstance = TEAM_NEUTRAL;
}
void OnCreatureCreate(Creature* creature) override
{
Map::PlayerList const& players = instance->GetPlayers();
TeamId TeamIdInInstance = TEAM_NEUTRAL;
if (!players.IsEmpty())
if (Player* pPlayer = players.begin()->GetSource())
TeamIdInInstance = pPlayer->GetTeamId();
if (TeamIdInInstance == TEAM_NEUTRAL)
{
Map::PlayerList const& players = instance->GetPlayers();
if (!players.IsEmpty())
if (Player* pPlayer = players.begin()->GetSource())
{
if (Group* group = pPlayer->GetGroup())
{
if (Player* gLeader = ObjectAccessor::FindPlayer(group->GetLeaderGUID()))
TeamIdInInstance = Player::TeamIdForRace(gLeader->getRace());
else
TeamIdInInstance = pPlayer->GetTeamId();
}
else
TeamIdInInstance = pPlayer->GetTeamId();
}
}
switch (creature->GetEntry())
{
@@ -88,6 +103,31 @@ 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);
}
void OnPlayerLeave(Player* player) override
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFactionForRace(player->getRace());
}
void OnGameObjectCreate(GameObject* gameObject) override
{
switch (gameObject->GetEntry())
@@ -154,6 +194,8 @@ public:
(*i)->RemoveGameObjectFlag(GO_FLAG_NOT_SELECTABLE);
return true;
}
protected:
TeamId TeamIdInInstance;
};
};