Skip to content

Commit

Permalink
Set creatures in combat with vehicle passengers
Browse files Browse the repository at this point in the history
This will avoid the situation when hostile targets evade when a vehicle
dies.
Also fix threat logic as vehicles shouldn't be second choice targets
Finally remove the UNIT_FLAG_PET_IN_COMBAT for vehicles

Signed-off-by: Xfurry <xfurry.cmangos@outlook.com>
  • Loading branch information
xfurry committed Jan 21, 2018
1 parent f58d6f7 commit 074c151
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/game/AI/BaseAI/CreatureAI.cpp
Expand Up @@ -18,6 +18,7 @@

#include "AI/BaseAI/CreatureAI.h"
#include "Entities/Creature.h"
#include "Entities/Vehicle.h"
#include "Server/DBCStores.h"
#include "Spells/Spell.h"
#include "Spells/SpellMgr.h"
Expand Down Expand Up @@ -247,6 +248,39 @@ void CreatureAI::AttackStart(Unit* who)
m_creature->CastSpell(m_creature, 43783, TRIGGERED_OLD_TRIGGERED);

HandleMovementOnAttackStart(who);

// for controlled vehicles set the creature in combat with the passengers
if (who->IsVehicle())
AttackPassengersIfCan(who);
}
}

void CreatureAI::AttackPassengersIfCan(Unit* who)
{
if (!who->IsVehicle())
return;

// set the victim's passengers in combat (if possible)
for (uint8 i = 0; i < MAX_VEHICLE_SEAT; ++i)
{
uint32 seatId = who->GetVehicleInfo()->GetVehicleEntry()->m_seatID[i];
if (!seatId)
continue;

Unit* passenger = who->GetVehicleInfo()->GetPassenger(i);
if (!passenger)
continue;

if (VehicleSeatEntry const* seatEntry = sVehicleSeatStore.LookupEntry(seatId))
{
// validate seat flags
if (seatEntry->m_flags & SEAT_FLAG_NOT_SELECTABLE || seatEntry->m_flags & SEAT_FLAG_HIDE_PASSENGER)
continue;

m_creature->AddThreat(passenger);
m_creature->SetInCombatWith(passenger);
passenger->SetInCombatWith(m_creature);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/game/AI/BaseAI/CreatureAI.h
Expand Up @@ -316,6 +316,9 @@ class CreatureAI
/// This function is used to do the actual melee damage (if possible)
bool DoMeleeAttackIfReady() const;

/// Helper function which handles the combat reaction for vehicle passengers
void AttackPassengersIfCan(Unit* who);

/// Internal helper function, to check if a spell can be cast
CanCastResult CanCastSpell(Unit* target, const SpellEntry* spellInfo, bool isTriggered) const;

Expand Down
4 changes: 2 additions & 2 deletions src/game/Entities/Unit.cpp
Expand Up @@ -8877,7 +8877,7 @@ void Unit::ClearInCombat()
m_CombatTimer = 0;
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);

if (HasCharmer() || (GetTypeId() != TYPEID_PLAYER && ((Creature*)this)->IsPet()))
if (HasCharmer() || (GetTypeId() != TYPEID_PLAYER && (((Creature*)this)->IsPet() || ((Creature*)this)->IsVehicle())))
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);

if (GetTypeId() == TYPEID_PLAYER)
Expand Down Expand Up @@ -9713,7 +9713,7 @@ bool Unit::IsSecondChoiceTarget(Unit* pTarget, bool taunt, bool checkThreatArea)
const Creature* thisCreature = GetTypeId() == TYPEID_UNIT ? static_cast<const Creature*>(this) : nullptr;

return
pTarget->IsTargetUnderControl(*this) ||
(!pTarget->IsVehicle() && pTarget->IsTargetUnderControl(*this)) ||
(!taunt && pTarget->IsImmuneToDamage(GetMeleeDamageSchoolMask())) ||
pTarget->hasNegativeAuraWithInterruptFlag(AURA_INTERRUPT_FLAG_DAMAGE) ||
(thisCreature && checkThreatArea && thisCreature->IsOutOfThreatArea(pTarget));
Expand Down

0 comments on commit 074c151

Please sign in to comment.