Core/Battleground: Changed HandleKillUnit hook to accept any Unit* as killer

This commit is contained in:
Jeremy
2024-01-01 03:26:56 +01:00
committed by ModoX
parent 22614d6bcc
commit bf107e0581
8 changed files with 28 additions and 19 deletions

View File

@@ -413,7 +413,7 @@ class TC_GAME_API Battleground : public ZoneScript
virtual void HandleAreaTrigger(Player* /*player*/, uint32 /*trigger*/, bool /*entered*/);
// must be implemented in BG subclass if need AND call base class generic code
virtual void HandleKillPlayer(Player* player, Player* killer);
virtual void HandleKillUnit(Creature* /*creature*/, Player* /*killer*/) { }
virtual void HandleKillUnit(Creature* /*creature*/, Unit* /*killer*/) { }
// Battleground events
virtual void EventPlayerDroppedFlag(Player* /*player*/) { }

View File

@@ -73,12 +73,15 @@ void BattlegroundAV::HandleKillPlayer(Player* player, Player* killer)
UpdateScore(GetPlayerTeam(player->GetGUID()), -1);
}
void BattlegroundAV::HandleKillUnit(Creature* unit, Player* killer)
void BattlegroundAV::HandleKillUnit(Creature* unit, Unit* killer)
{
TC_LOG_DEBUG("bg.battleground", "bg_av HandleKillUnit {}", unit->GetEntry());
if (GetStatus() != STATUS_IN_PROGRESS)
return;
uint32 entry = unit->GetEntry();
Player* killerPlayer = killer->GetCharmerOrOwnerPlayerOrPlayerItself();
/*
uint32 triggerSpawnID = 0;
if (creature->GetEntry() == BG_AV_CreatureInfo[AV_NPC_A_CAPTAIN][0])
@@ -148,10 +151,10 @@ void BattlegroundAV::HandleKillUnit(Creature* unit, Player* killer)
if (Creature* herold = GetBGCreature(AV_CPLACE_HERALD))
herold->AI()->Talk(TEXT_FROSTWOLF_GENERAL_DEAD);
}
else if (entry == BG_AV_CreatureInfo[AV_NPC_N_MINE_N_4] || entry == BG_AV_CreatureInfo[AV_NPC_N_MINE_A_4] || entry == BG_AV_CreatureInfo[AV_NPC_N_MINE_H_4])
ChangeMineOwner(AV_NORTH_MINE, GetPlayerTeam(killer->GetGUID()));
else if (entry == BG_AV_CreatureInfo[AV_NPC_S_MINE_N_4] || entry == BG_AV_CreatureInfo[AV_NPC_S_MINE_A_4] || entry == BG_AV_CreatureInfo[AV_NPC_S_MINE_H_4])
ChangeMineOwner(AV_SOUTH_MINE, GetPlayerTeam(killer->GetGUID()));
else if ((entry == BG_AV_CreatureInfo[AV_NPC_N_MINE_N_4] || entry == BG_AV_CreatureInfo[AV_NPC_N_MINE_A_4] || entry == BG_AV_CreatureInfo[AV_NPC_N_MINE_H_4]) && killerPlayer)
ChangeMineOwner(AV_NORTH_MINE, GetPlayerTeam(killerPlayer->GetGUID()));
else if ((entry == BG_AV_CreatureInfo[AV_NPC_S_MINE_N_4] || entry == BG_AV_CreatureInfo[AV_NPC_S_MINE_A_4] || entry == BG_AV_CreatureInfo[AV_NPC_S_MINE_H_4]) && killerPlayer)
ChangeMineOwner(AV_SOUTH_MINE, GetPlayerTeam(killerPlayer->GetGUID()));
}
void BattlegroundAV::HandleQuestComplete(uint32 questid, Player* player)

View File

@@ -1599,7 +1599,7 @@ class BattlegroundAV : public Battleground
/*handlestuff*/ //these are functions which get called from extern
void EventPlayerClickedOnFlag(Player* source, GameObject* target_obj) override;
void HandleKillPlayer(Player* player, Player* killer) override;
void HandleKillUnit(Creature* unit, Player* killer) override;
void HandleKillUnit(Creature* unit, Unit* killer) override;
void HandleQuestComplete(uint32 questid, Player* player) override;
bool CanActivateGO(int32 GOId, uint32 team) const override;

View File

@@ -364,7 +364,7 @@ bool BattlegroundIC::SetupBattleground()
return true;
}
void BattlegroundIC::HandleKillUnit(Creature* unit, Player* killer)
void BattlegroundIC::HandleKillUnit(Creature* unit, Unit* killer)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
@@ -384,7 +384,9 @@ void BattlegroundIC::HandleKillUnit(Creature* unit, Player* killer)
//Achievement Mowed Down
// TO-DO: This should be done on the script of each vehicle of the BG.
if (unit->IsVehicle())
killer->CastSpell(killer, SPELL_DESTROYED_VEHICLE_ACHIEVEMENT, true);
{
if (Player* killerPlayer = killer->GetCharmerOrOwnerPlayerOrPlayerItself())
killerPlayer->CastSpell(killerPlayer, SPELL_DESTROYED_VEHICLE_ACHIEVEMENT, true);
}
void BattlegroundIC::HandleKillPlayer(Player* player, Player* killer)

View File

@@ -929,7 +929,7 @@ class BattlegroundIC : public Battleground
void HandleAreaTrigger(Player* player, uint32 trigger, bool entered) override;
bool SetupBattleground() override;
void SpawnLeader(uint32 teamid);
void HandleKillUnit(Creature* unit, Player* killer) override;
void HandleKillUnit(Creature* unit, Unit* killer) override;
void HandleKillPlayer(Player* player, Player* killer) override;
void EventPlayerClickedOnFlag(Player* source, GameObject* /*target_obj*/) override;

View File

@@ -592,11 +592,12 @@ void BattlegroundSA::ProcessEvent(WorldObject* obj, uint32 eventId, WorldObject*
}
}
void BattlegroundSA::HandleKillUnit(Creature* creature, Player* killer)
void BattlegroundSA::HandleKillUnit(Creature* creature, Unit* killer)
{
if (creature->GetEntry() == NPC_DEMOLISHER_SA)
{
UpdatePvpStat(killer, PVP_STAT_DEMOLISHERS_DESTROYED, 1);
if (Player* killerPlayer = killer->GetCharmerOrOwnerPlayerOrPlayerItself())
UpdatePvpStat(killerPlayer, PVP_STAT_DEMOLISHERS_DESTROYED, 1);
int32 worldStateId = Attackers == TEAM_HORDE ? BG_SA_DESTROYED_HORDE_VEHICLES : BG_SA_DESTROYED_ALLIANCE_VEHICLES;
int32 currentDestroyedVehicles = sWorldStateMgr->GetValue(worldStateId, GetBgMap());
UpdateWorldState(worldStateId, currentDestroyedVehicles + 1);

View File

@@ -542,7 +542,7 @@ class BattlegroundSA : public Battleground
bool SetupBattleground() override;
void Reset() override;
/// Called when a player kill a unit in bg
void HandleKillUnit(Creature* creature, Player* killer) override;
void HandleKillUnit(Creature* creature, Unit* killer) override;
/// Return the nearest graveyard where player can respawn
WorldSafeLocsEntry const* GetClosestGraveyard(Player* player) override;
/// Called when someone activates an event

View File

@@ -10950,14 +10950,17 @@ void Unit::SetMeleeAnimKitId(uint16 animKitId)
// pvp->HandlePlayerActivityChangedpVictim->ToPlayer();
// battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
if (player && player->InBattleground())
if (attacker)
{
if (Battleground* bg = player->GetBattleground())
if (BattlegroundMap* bgMap = victim->GetMap()->ToBattlegroundMap())
{
if (Player* playerVictim = victim->ToPlayer())
bg->HandleKillPlayer(playerVictim, player);
else
bg->HandleKillUnit(victim->ToCreature(), player);
if (Battleground* bg = bgMap->GetBG())
{
if (Player* playerVictim = victim->ToPlayer())
bg->HandleKillPlayer(playerVictim, player);
else
bg->HandleKillUnit(victim->ToCreature(), attacker);
}
}
}