Jump to content

Random Target in a certain radius


Guest caeruleaus

Recommended Posts

okay, I'm working on fixing the trinket Althor's Abacus

It trigger's spell Item - Icecrown 25 Normal Healer Trinket 2

which then triggers spell:

Echoes of Light

It has ImplictTargetA1 as 31 which is TARGET_ALL_FRIENDLY_UNITS_IN_AREA

and ImplicitTargetB1 as 23 which is TARGET_GAMEOBJECT (I'm assuming it's for healing destructible gameobjects that are friendly to you in wintergrasp).

Right now i just want to fix it so it will choose ONE friendly random target near the caster within the defined radius of (in the DBCs it's 31 yards, on WoWhead it says 40) 31 yards. I tried seeing it i could do it by just using FillAreaTargets and then choosing the first unit from the targetmap but that doesnt seem to work. So now i just want to get a random target and then push it to the targetmap.

Link to comment
Share on other sites

I remember this being posted a while back, but I can't recall which thread or whom the author is, so I beg the pardon of the author. This patch was for correcting the behavior of spells that work on a random area within a circle of a given radius. Perhaps this may be of help to you in your own code, caeruleaus.

diff --git a/src/game/Spell.cpp
@@ -1390,10 +1390,12 @@ void Spell::SetTargetMap(uint32 effIndex, uint32 targetMode, UnitList& targetUni
    switch(targetMode)
    {
        case TARGET_RANDOM_NEARBY_LOC:
-            radius *= sqrt(rand_norm()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
-                                         // no 'break' expected since we use code in case TARGET_RANDOM_CIRCUMFERENCE_POINT!!!
+            // Get a random point IN circle around the CASTER(!). Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
+            radius *= sqrt(rand_norm());
+            // no 'break' expected since we use code in case TARGET_RANDOM_CIRCUMFERENCE_POINT!!!
        case TARGET_RANDOM_CIRCUMFERENCE_POINT:
        {
+            // Get a random point AT the CIRCUMREFERENCE(!).
            float angle = 2.0 * M_PI * rand_norm();
            float dest_x, dest_y, dest_z;
            m_caster->GetClosePoint(dest_x, dest_y, dest_z, 0.0f, radius, angle);
@@ -1404,20 +1406,22 @@ void Spell::SetTargetMap(uint32 effIndex, uint32 targetMode, UnitList& targetUni
        }
        case TARGET_RANDOM_NEARBY_DEST:
        {
-            radius *= sqrt(rand_norm()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
-            float angle = 2.0 * M_PI * rand_norm();
-            float dest_x = m_targets.m_destX + cos(angle) * radius;
-            float dest_y = m_targets.m_destY + sin(angle) * radius;
-            float dest_z = m_caster->GetPositionZ();
-            m_caster->UpdateGroundPositionZ(dest_x, dest_y, dest_z);
-            m_targets.setDestination(dest_x, dest_y, dest_z);
-
-            if (radius > 0.0f)
+            // Get a random point IN the CIRCEL around current M_TARGETS COORDINATES(!).
+            if (radius > 0)
            {
-                // caster included here?
-                FillAreaTargets(targetUnitMap, dest_x, dest_y, radius, PUSH_DEST_CENTER, SPELL_TARGETS_AOE_DAMAGE);
+                // Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
+                radius *= sqrt(rand_norm());
+                float angle = 2.0 * M_PI * rand_norm();
+                float dest_x = m_targets.m_destX + cos(angle) * radius;
+                float dest_y = m_targets.m_destY + sin(angle) * radius;
+                float dest_z = m_caster->GetPositionZ();
+                m_caster->UpdateGroundPositionZ(dest_x, dest_y, dest_z);
+                m_targets.setDestination(dest_x, dest_y, dest_z);
            }
-            else
+
+            // This targetMode is often used as 'last' implicitTarget for positive spells, that just require coordinates
+            // and no unitTarget (e.g. summon effects). As MaNGOS always needs a unitTarget we add just the caster here.
+            if (IsPositiveSpell(m_spellInfo->Id))
                targetUnitMap.push_back(m_caster);

            break;

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use