Skip to content

Commit

Permalink
Merge branch 'azerothcore:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSCREWEDSoftware authored Jan 18, 2025
2 parents 23fb846 + 459ffa7 commit e1e8949
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 517 deletions.
148 changes: 148 additions & 0 deletions data/sql/updates/db_world/2025_01_18_00.sql

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10384,6 +10384,10 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
if (meleeAttack)
AddUnitState(UNIT_STATE_MELEE_ATTACKING);

// Update leash timer when attacking creatures
if (victim->IsCreature())
victim->ToCreature()->UpdateLeashExtensionTime();

// set position before any AI calls/assistance
//if (IsCreature())
// ToCreature()->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
Expand All @@ -10393,6 +10397,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
SetInCombatWith(victim);
if (victim->IsPlayer())
victim->SetInCombatWith(this);

AddThreat(victim, 0.0f);

creature->SendAIReaction(AI_REACTION_HOSTILE);
Expand Down Expand Up @@ -13623,9 +13628,6 @@ void Unit::SetInCombatWith(Unit* enemy, uint32 duration)
}
}

if (Creature* pCreature = ToCreature())
pCreature->UpdateLeashExtensionTime();

SetInCombatState(false, enemy, duration);
}

Expand Down Expand Up @@ -13700,6 +13702,10 @@ void Unit::CombatStart(Unit* victim, bool initialAggro)
SetInCombatWith(victim);
victim->SetInCombatWith(this);

// Update leash timer when attacking creatures
if (victim->IsCreature())
victim->ToCreature()->UpdateLeashExtensionTime();

// Xinef: If pet started combat - put owner in combat
if (!alreadyInCombat && IsInCombat())
{
Expand Down Expand Up @@ -13736,6 +13742,12 @@ void Unit::CombatStartOnCast(Unit* target, bool initialAggro, uint32 duration)
// Xinef: If pet started combat - put owner in combat
if (Unit* owner = GetOwner())
owner->SetInCombatWith(target, duration);

// Update leash timer when attacking creatures
if (target->IsCreature())
target->ToCreature()->UpdateLeashExtensionTime();
else if (ToCreature()) // Reset leash if it is a spell caster, else it may evade inbetween casts
ToCreature()->UpdateLeashExtensionTime();
}

Unit* who = target->GetCharmerOrOwnerOrSelf();
Expand Down
46 changes: 46 additions & 0 deletions src/server/game/Instances/InstanceScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ void InstanceScript::SaveToDB()
CharacterDatabase.Execute(stmt);
}

void InstanceScript::OnPlayerEnter(Player* player)
{
if (!IsTwoFactionInstance())
return;

if (GetTeamIdInInstance() == TEAM_NEUTRAL)
{
if (Group* group = player->GetGroup())
{
if (Player* leader = ObjectAccessor::FindConnectedPlayer(group->GetLeaderGUID()))
_teamIdInInstance = leader->GetTeamId();
else
_teamIdInInstance = player->GetTeamId();
}
else
_teamIdInInstance = player->GetTeamId();
}

if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFaction((_teamIdInInstance == TEAM_HORDE) ? 1610 /*FACTION_HORDE*/ : 1 /*FACTION_ALLIANCE*/);
}

void InstanceScript::OnPlayerLeave(Player* player)
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP) && IsTwoFactionInstance())
player->SetFactionForRace(player->getRace());
}

void InstanceScript::OnCreatureCreate(Creature* creature)
{
AddObject(creature);
Expand Down Expand Up @@ -848,3 +876,21 @@ bool InstanceHasScript(WorldObject const* obj, char const* scriptName)

return false;
}

bool InstanceScript::IsTwoFactionInstance() const
{
switch (instance->GetId())
{
case 540: // Shattered Halls
case 576: // Nexus
case 631: // Icecrown Citadel
case 632: // Forge of Souls
case 649: // Trial of the Champion
case 650: // Trial of the Crusader
case 658: // Pit of Saron
case 668: // Halls of Reflection
return true;
}

return false;
}
10 changes: 7 additions & 3 deletions src/server/game/Instances/InstanceScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ typedef std::map<ObjectGuid::LowType /*spawnId*/, uint8 /*state*/> ObjectStateMa
class InstanceScript : public ZoneScript
{
public:
explicit InstanceScript(Map* map) : instance(map), completedEncounters(0) {}
explicit InstanceScript(Map* map) : instance(map), completedEncounters(0), _teamIdInInstance(TEAM_NEUTRAL) {}

~InstanceScript() override {}

Expand Down Expand Up @@ -182,10 +182,10 @@ class InstanceScript : public ZoneScript
GameObject* GetGameObject(uint32 type);

//Called when a player successfully enters the instance.
virtual void OnPlayerEnter(Player* /*player*/) {}
virtual void OnPlayerEnter(Player* /*player*/);

//Called when a player successfully leaves the instance.
virtual void OnPlayerLeave(Player* /*player*/) {}
virtual void OnPlayerLeave(Player* /*player*/);

virtual void OnPlayerAreaUpdate(Player* /*player*/, uint32 /*oldArea*/, uint32 /*newArea*/) {}

Expand Down Expand Up @@ -322,6 +322,9 @@ class InstanceScript : public ZoneScript
void WritePersistentData(std::ostringstream& data);
virtual void WriteSaveDataMore(std::ostringstream& /*data*/) { }

TeamId GetTeamIdInInstance() const { return _teamIdInInstance; }
bool IsTwoFactionInstance() const;

private:
static void LoadObjectData(ObjectData const* creatureData, ObjectInfoMap& objectInfo);

Expand All @@ -336,6 +339,7 @@ class InstanceScript : public ZoneScript
ObjectGuidMap _objectGuids;
ObjectStateMap _objectStateMap;
uint32 completedEncounters; // completed encounter mask, bit indexes are DungeonEncounter.dbc boss numbers, used for packets
TeamId _teamIdInInstance;
std::unordered_set<uint32> _activatedAreaTriggers;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class instance_trial_of_the_champion : public InstanceMapScript
}

bool CLEANED;
TeamId TeamIdInInstance;
uint32 InstanceProgress;
uint32 m_auiEncounter[MAX_ENCOUNTER];
std::string str_data;
Expand All @@ -83,7 +82,6 @@ class instance_trial_of_the_champion : public InstanceMapScript

void Initialize() override
{
TeamIdInInstance = TEAM_NEUTRAL;
InstanceProgress = 0;
memset(&m_auiEncounter, 0, sizeof(m_auiEncounter));

Expand All @@ -109,67 +107,49 @@ class instance_trial_of_the_champion : public InstanceMapScript

void OnCreatureCreate(Creature* creature) override
{
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())
{
// Grand Champions:
case NPC_MOKRA:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_JACOB);
break;
case NPC_ERESSEA:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_AMBROSE);
break;
case NPC_RUNOK:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_COLOSOS);
break;
case NPC_ZULTORE:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_JAELYNE);
break;
case NPC_VISCERI:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_LANA);
break;

// Grand Champion Minions:
case NPC_ORGRIMMAR_MINION:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_STORMWIND_MINION);
break;
case NPC_SILVERMOON_MINION:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_GNOMEREGAN_MINION);
break;
case NPC_THUNDER_BLUFF_MINION:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_EXODAR_MINION);
break;
case NPC_SENJIN_MINION:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_DARNASSUS_MINION);
break;
case NPC_UNDERCITY_MINION:
if (TeamIdInInstance == TEAM_HORDE)
if (GetTeamIdInInstance() == TEAM_HORDE)
creature->UpdateEntry(NPC_IRONFORGE_MINION);
break;

Expand All @@ -183,7 +163,7 @@ class instance_trial_of_the_champion : public InstanceMapScript
case NPC_JAEREN:
case NPC_ARELAS:
NPC_AnnouncerGUID = creature->GetGUID();
//if (TeamIdInInstance == TEAM_ALLIANCE)
//if (GetTeamIdInInstance() == TEAM_ALLIANCE)
// creature->UpdateEntry(NPC_ARELAS);
creature->SetReactState(REACT_PASSIVE);
break;
Expand Down Expand Up @@ -283,36 +263,14 @@ class instance_trial_of_the_champion : public InstanceMapScript

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);

if (DoNeedCleanup(player))
{
InstanceCleanup();
}

events.RescheduleEvent(EVENT_CHECK_PLAYERS, CLEANUP_CHECK_INTERVAL);
}

void OnPlayerLeave(Player* player) override
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
player->SetFactionForRace(player->getRace());
}

bool DoNeedCleanup(Player* ignoredPlayer = nullptr)
{
uint8 aliveCount = 0;
Expand Down Expand Up @@ -497,7 +455,7 @@ class instance_trial_of_the_champion : public InstanceMapScript
case DATA_INSTANCE_PROGRESS:
return InstanceProgress;
case DATA_TEAMID_IN_INSTANCE:
return TeamIdInInstance;
return GetTeamIdInInstance();
}

return 0;
Expand Down
Loading

0 comments on commit e1e8949

Please sign in to comment.