Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Spells: Fixed target radius calculation for TARGET_DEST_*_RANDOM
Browse files Browse the repository at this point in the history
  • Loading branch information
meji46 authored and Ovahlord committed Dec 8, 2023
1 parent 1251a78 commit a601976
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/server/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ void Spell::SelectImplicitCasterDestTargets(SpellEffIndex effIndex, SpellImplici
{
case TARGET_DEST_CASTER_RANDOM:
if (dist > objSize)
dist = objSize + (dist - objSize) * rand_norm();
dist = objSize + (dist - objSize);
break;
case TARGET_DEST_CASTER_FRONT_LEFT:
case TARGET_DEST_CASTER_BACK_LEFT:
Expand Down Expand Up @@ -1620,8 +1620,6 @@ void Spell::SelectImplicitTargetDestTargets(SpellEffIndex effIndex, SpellImplici
{
float angle = targetType.CalcDirectionAngle(m_spellInfo->Effects[effIndex]);
float dist = m_spellInfo->Effects[effIndex].CalcRadius(nullptr, targetIndex);
if (targetType.GetTarget() == TARGET_DEST_TARGET_RANDOM)
dist *= rand_norm();

Position pos = dest._position;
target->MovePositionToFirstCollision(pos, dist, angle);
Expand Down Expand Up @@ -1656,8 +1654,6 @@ void Spell::SelectImplicitDestDestTargets(SpellEffIndex effIndex, SpellImplicitT
{
float angle = targetType.CalcDirectionAngle(m_spellInfo->Effects[effIndex]);
float dist = m_spellInfo->Effects[effIndex].CalcRadius(m_caster, targetIndex);
if (targetType.GetTarget() == TARGET_DEST_DEST_RANDOM)
dist *= rand_norm();

Position pos = dest._position;
m_caster->MovePositionToFirstCollision(pos, dist, angle);
Expand Down
14 changes: 14 additions & 0 deletions src/server/game/Spells/SpellInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,28 @@ float SpellEffectInfo::CalcRadius(WorldObject* caster /*= nullptr*/, SpellTarget
// TargetA -> TargetARadiusEntry
// TargetB -> TargetBRadiusEntry
// Aura effects have TargetARadiusEntry == TargetBRadiusEntry (mostly)
SpellImplicitTargetInfo target = TargetA;
SpellRadiusEntry const* entry = TargetARadiusEntry;
if (targetIndex == SpellTargetIndex::TargetB && HasRadius(targetIndex))
{
target = TargetB;
entry = TargetBRadiusEntry;
}

if (!entry)
return 0.0f;

float radius = entry->RadiusMin;

// Random targets use random value between RadiusMin and RadiusMax
// For other cases, client uses RadiusMax if RadiusMin is 0
if (target.GetTarget() == TARGET_DEST_CASTER_RANDOM ||
target.GetTarget() == TARGET_DEST_TARGET_RANDOM ||
target.GetTarget() == TARGET_DEST_DEST_RANDOM)
radius += (entry->RadiusMax - radius) * rand_norm();
else if (radius == 0.0f)
radius = entry->RadiusMax;

if (caster)
{
if (Unit* casterUnit = caster->ToUnit())
Expand Down

0 comments on commit a601976

Please sign in to comment.