fix(Core/Unit): Improve check for players to automatically stand if a… (#7869)

* fix(Core/Unit): Improve check for players to automatically stand if attacked

* vicitm -> victim
This commit is contained in:
Kitzunu
2021-09-19 22:14:57 +02:00
committed by GitHub
parent 9febed8fa8
commit b70083599b
+29 -26
View File
@@ -12718,64 +12718,67 @@ void Unit::SetInCombatWith(Unit* enemy, uint32 duration)
SetInCombatState(false, enemy, duration); SetInCombatState(false, enemy, duration);
} }
void Unit::CombatStart(Unit* target, bool initialAggro) void Unit::CombatStart(Unit* victim, bool initialAggro)
{ {
// Xinef: Dont allow to start combat with triggers // Xinef: Dont allow to start combat with triggers
if (target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->IsTrigger()) if (victim->GetTypeId() == TYPEID_UNIT && victim->ToCreature()->IsTrigger())
return; return;
if (initialAggro) if (initialAggro)
{ {
if (!target->IsStandState()) // Make player victim stand up automatically
target->SetStandState(UNIT_STAND_STATE_STAND); if (victim->getStandState() && victim->IsPlayer())
if (!target->IsInCombat() && target->GetTypeId() != TYPEID_PLAYER && !target->ToCreature()->HasReactState(REACT_PASSIVE) && target->ToCreature()->IsAIEnabled)
{ {
if (target->IsPet()) victim->SetStandState(UNIT_STAND_STATE_STAND);
target->ToCreature()->AI()->AttackedBy(this); // PetAI has special handler before AttackStart() }
if (!victim->IsInCombat() && victim->GetTypeId() != TYPEID_PLAYER && !victim->ToCreature()->HasReactState(REACT_PASSIVE) && victim->ToCreature()->IsAIEnabled)
{
if (victim->IsPet())
victim->ToCreature()->AI()->AttackedBy(this); // PetAI has special handler before AttackStart()
else else
{ {
target->ToCreature()->AI()->AttackStart(this); victim->ToCreature()->AI()->AttackStart(this);
// if the target is an NPC with a pet or minion, pet should react. // if the target is an NPC with a pet or minion, pet should react.
if (Unit* targetControlledUnit = target->GetFirstControlled()) if (Unit* victimControlledUnit = victim->GetFirstControlled())
{ {
targetControlledUnit->SetInCombatWith(this); victimControlledUnit->SetInCombatWith(this);
SetInCombatWith(targetControlledUnit); SetInCombatWith(victimControlledUnit);
targetControlledUnit->AddThreat(this, 0.0f); victimControlledUnit->AddThreat(this, 0.0f);
} }
} }
// if unit has an owner, put owner in combat. // if unit has an owner, put owner in combat.
if (Unit* targetOwner = target->GetOwner()) if (Unit* victimOwner = victim->GetOwner())
{ {
if (!(targetOwner->IsInCombatWith(this))) if (!(victimOwner->IsInCombatWith(this)))
{ {
/* warding off to not take over aggro for no reason /* warding off to not take over aggro for no reason
Using only AddThreat causes delay in attack */ Using only AddThreat causes delay in attack */
if (!targetOwner->IsInCombat() && targetOwner->IsAIEnabled) if (!victimOwner->IsInCombat() && victimOwner->IsAIEnabled)
{ {
targetOwner->ToCreature()->AI()->AttackStart(this); victimOwner->ToCreature()->AI()->AttackStart(this);
} }
targetOwner->SetInCombatWith(this); victimOwner->SetInCombatWith(this);
SetInCombatWith(targetOwner); SetInCombatWith(victimOwner);
targetOwner->AddThreat(this, 0.0f); victimOwner->AddThreat(this, 0.0f);
} }
} }
} }
SetInCombatWith(target); SetInCombatWith(victim);
target->SetInCombatWith(this); victim->SetInCombatWith(this);
target->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_ONESHOT_NONE); victim->SetUInt32Value(UNIT_NPC_EMOTESTATE, EMOTE_ONESHOT_NONE);
// Xinef: If pet started combat - put owner in combat // Xinef: If pet started combat - put owner in combat
if (Unit* owner = GetOwner()) if (Unit* owner = GetOwner())
{ {
owner->SetInCombatWith(target); owner->SetInCombatWith(victim);
target->SetInCombatWith(owner); victim->SetInCombatWith(owner);
} }
} }
Unit* who = target->GetCharmerOrOwnerOrSelf(); Unit* who = victim->GetCharmerOrOwnerOrSelf();
if (who->GetTypeId() == TYPEID_PLAYER) if (who->GetTypeId() == TYPEID_PLAYER)
SetContestedPvP(who->ToPlayer()); SetContestedPvP(who->ToPlayer());