Skip to content

Commit

Permalink
Fixes daze absorb and duplicate target flags (#67)
Browse files Browse the repository at this point in the history
- Fixes daze absorb and duplicate target flags
- Fix chests showing out of range even when in range
  • Loading branch information
RidingKeys authored and H0zen committed Jun 1, 2018
1 parent 5aa68fa commit 77d2850
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
51 changes: 29 additions & 22 deletions src/game/Object/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,28 +1767,35 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
DealDamage(pVictim, damageInfo->damage, &cleanDamage, DIRECT_DAMAGE, SpellSchoolMask(damageInfo->damageSchoolMask), NULL, durabilityLoss);

// If this is a creature and it attacks from behind it has a probability to daze it's victim
if ((damageInfo->hitOutCome == MELEE_HIT_CRIT || damageInfo->hitOutCome == MELEE_HIT_CRUSHING || damageInfo->hitOutCome == MELEE_HIT_NORMAL || damageInfo->hitOutCome == MELEE_HIT_GLANCING) &&
GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGuid() && !pVictim->HasInArc(M_PI_F, this))
{
// -probability is between 0% and 40%
// 20% base chance
float Probability = 20.0f;

// there is a newbie protection, at level 10 just 7% base chance; assuming linear function
if (pVictim->getLevel() < 30)
{ Probability = 0.65f * pVictim->getLevel() + 0.5f; }

uint32 VictimDefense = pVictim->GetDefenseSkillValue();
uint32 AttackerMeleeSkill = GetUnitMeleeSkill();

Probability *= AttackerMeleeSkill / (float)VictimDefense;

if (Probability > 40.0f)
{ Probability = 40.0f; }

if (roll_chance_f(Probability))
{ CastSpell(pVictim, 1604, true); }
}
if ((!damageInfo->absorb) && (damageInfo->hitOutCome == MELEE_HIT_CRIT || damageInfo->hitOutCome == MELEE_HIT_CRUSHING || damageInfo->hitOutCome == MELEE_HIT_NORMAL || damageInfo->hitOutCome == MELEE_HIT_GLANCING) &&
GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGuid() && !pVictim->HasInArc(M_PI_F, this))
{
// -probability is between 0% and 40%
// 20% base chance
float Probability = 20.0f;

// there is a newbie protection, at level 10 just 7% base chance; assuming linear function
if (pVictim->getLevel() < 30)
{
Probability = 0.65f * pVictim->getLevel() + 0.5f;
}

uint32 VictimDefense = pVictim->GetDefenseSkillValue();
uint32 AttackerMeleeSkill = GetUnitMeleeSkill();

Probability *= AttackerMeleeSkill / (float)VictimDefense;

if (Probability > 40.0f)
{
Probability = 40.0f;
}

if (roll_chance_f(Probability))
{
CastSpell(pVictim, 1604, true);
}

}

// update at damage Judgement aura duration that applied by attacker at victim
if (damageInfo->damage)
Expand Down
10 changes: 2 additions & 8 deletions src/game/WorldHandlers/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,20 +1575,14 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
Cell::VisitAllObjects(m_caster, searcher, max_range);
break;
}
case TARGET_RANDOM_UNIT_CHAIN_IN_AREA: // This works the same as Target_random_friend_chain_in_area but is named differently for some reason
case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA:
{
MaNGOS::AnyFriendlyUnitInObjectRangeCheck u_check(m_caster, max_range);
MaNGOS::UnitListSearcher<MaNGOS::AnyFriendlyUnitInObjectRangeCheck> searcher(tempTargetUnitMap, u_check);
Cell::VisitAllObjects(m_caster, searcher, max_range);
break;
}
case TARGET_RANDOM_UNIT_CHAIN_IN_AREA:
{
MaNGOS::AnyUnitInObjectRangeCheck u_check(m_caster, max_range);
MaNGOS::UnitListSearcher<MaNGOS::AnyUnitInObjectRangeCheck> searcher(tempTargetUnitMap, u_check);
Cell::VisitAllObjects(m_caster, searcher, max_range);
break;
}
}

if (tempTargetUnitMap.empty())
Expand Down Expand Up @@ -4980,7 +4974,7 @@ SpellCastResult Spell::CheckCast(bool strict)
{ return SPELL_FAILED_ALREADY_OPEN; }

// Is the lock within the spell max range?
if (!IsLockInRange(go))
if (!IsLockInRange(go) && go->GetGoType() == GAMEOBJECT_TYPE_TRAP)
{ return SPELL_FAILED_OUT_OF_RANGE; }
}
else if (Item* item = m_targets.getItemTarget())
Expand Down

0 comments on commit 77d2850

Please sign in to comment.