Thread: SpiralAttack.cs

Results 1 to 7 of 7
  1. #1
    Stellar Spark's Avatar
    Join Date
    Jun 2013
    Gender
    female
    Posts
    724
    Reputation
    35
    Thanks
    799

    Lightbulb SpiralAttack.cs

    Hey everyone! I held on to this code for a while, until I realized there would be no point in doing so. The Spiral Attack behavior is a non-returning behavior that is basically ring attacks with incrementally growing offsets to look like a spiral. This code is especially designed to save space, so you won't fill up your behaviors with huge blocks of RingAttack.Instance(...).

    Create a new file in wServer/logic/attack called "SpiralAttack.cs"

    Paste the below code in:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using wServer.realm;
    using wServer.realm.entities;
    using wServer.svrPackets;
    
    namespace wServer.logic.attack
    {
        class InfiniteSpiralAttack : Behavior
        {
            int cooldown;
            int arms;
            float offsetIncrement;
            int projectileIndex;
            int incrementMultiplier = 0;
            private InfiniteSpiralAttack(int cooldown, int arms, float offsetIncrement, int projectileIndex)
            {
                this.cooldown = cooldown;
                this.arms = arms;
                this.offsetIncrement = offsetIncrement;
                this.projectileIndex = projectileIndex;
            }
            static readonly Dictionary<Tuple<int, int, float, int>, InfiniteSpiralAttack> instances = new Dictionary<Tuple<int, int, float, int>, InfiniteSpiralAttack>();
            public static InfiniteSpiralAttack Instance(int cooldown, int arms, float offsetIncrement = 1, int projectileIndex = 0)
            {
                var key = new Tuple<int, int, float, int>(cooldown, arms, offsetIncrement, projectileIndex);
                InfiniteSpiralAttack ret;
                if (!instances.TryGetValue(key, out ret))
                    ret = instances[key] = new InfiniteSpiralAttack(cooldown, arms, offsetIncrement, projectileIndex);
                return ret;
            }
    
            Random rand = new Random();
            protected override bool TickCore(RealmTime time)
            { 
    
                Behavior behav = RingAttack.Instance(arms, 0, (offsetIncrement * (float)Math.PI / 180) * incrementMultiplier, projectileIndex);
    
                int remainingTick;
                object o;
                if (!Host.StateStorage.TryGetValue(Key, out o))
                    remainingTick = rand.Next(0, cooldown);
                else
                    remainingTick = (int)o;
    
                remainingTick -= time.thisTickTimes;
                bool ret;
                if (remainingTick <= 0)
                {
                    if (behav != null)
                        behav.Tick(Host, time);
                    if (behav != null)
                        incrementMultiplier += 1;
                    remainingTick = rand.Next((int)(cooldown * 0.95), (int)(cooldown * 1.05));
                    ret = true;
                }
                else
                    ret = false;
                Host.StateStorage[Key] = remainingTick;
                return ret;
            }
        }
    }
    Usage:
    COOLDOWN = Millisecond interval between each ring attack
    ARMS = Number of projectiles fired at once
    offsetIncrement = The size of the offset increment. For most spirals, this value would be from 5 to 20.
    projectileIndex = ID of projectile used in the behavior

  2. The Following 5 Users Say Thank You to Stellar Spark For This Useful Post:

    1again (01-17-2014),CrazyJani (01-19-2014),Dragonlord3344 (01-27-2014),Lunati (01-21-2014),TJRAE%TJAJAZetjtjtjjt (10-23-2014)

  3. #2
    sacredmike's Avatar
    Join Date
    Jul 2013
    Gender
    male
    Location
    Uranus ;)
    Posts
    685
    Reputation
    15
    Thanks
    3,255
    My Mood
    Devilish
    This would have been nice to use while making Forbidden Jungle behavior.. Oh well.. I don't code anymore.
    So i guess it doesn't matter.
    Nice release anyway.. @ProHackBot999
    i'm actually just a horny boy

  4. #3
    Stellar Spark's Avatar
    Join Date
    Jun 2013
    Gender
    female
    Posts
    724
    Reputation
    35
    Thanks
    799
    Quote Originally Posted by sacredmike View Post
    This would have been nice to use while making Forbidden Jungle behavior.. Oh well.. I don't code anymore.
    So i guess it doesn't matter.
    Nice release anyway.. @ProHackBot999
    What Forbidden Jungle mob does a spiral attack?

  5. #4
    sacredmike's Avatar
    Join Date
    Jul 2013
    Gender
    male
    Location
    Uranus ;)
    Posts
    685
    Reputation
    15
    Thanks
    3,255
    My Mood
    Devilish
    Quote Originally Posted by ProHackBot999 View Post


    What Forbidden Jungle mob does a spiral attack?
    Wow, I haven't played RotMG is such a long time.. I don't even remember..
    i'm actually just a horny boy

  6. #5
    Doctorcherio's Avatar
    Join Date
    Apr 2013
    Gender
    male
    Posts
    53
    Reputation
    10
    Thanks
    26
    My Mood
    Cynical
    Im a complete noob could you pretty please make an example line showing how its used?
    something like

    Cooldown.Instance(1500, PredictiveMultiAttack.Instance(25, 10 * (float)Math.PI / 180, 4, 1, projectileIndex: 1)),

    except with the spiral. I would be very happy if you did thanks

  7. #6
    Stellar Spark's Avatar
    Join Date
    Jun 2013
    Gender
    female
    Posts
    724
    Reputation
    35
    Thanks
    799
    Quote Originally Posted by Doctorcherio View Post
    Im a complete noob could you pretty please make an example line showing how its used?
    something like

    Cooldown.Instance(1500, PredictiveMultiAttack.Instance(25, 10 * (float)Math.PI / 180, 4, 1, projectileIndex: 1)),

    except with the spiral. I would be very happy if you did thanks
    InfiniteSpiralAttack.Instance(1500, 4, 10, projectileIndex: 0)

    The first variable is the cooldown, which means in this example the spiral will trigger a ring every 1500 ms.
    The second variable is the arms, which is exactly the same as the number of shots in a RingAttack, where each shot will be equally spaced over 6~ radians.
    The third variable is the offsetIncrement. Every time the spiral is triggered, it fires off a ring attack that is slightly offset from the last one. This is the number of circular degrees that the spiral offsets every trigger.
    The fourth variable is the projectile Index, which takes data from the projectile XML.

    I hope that's a good enough explanation!

  8. #7
    filenub's Avatar
    Join Date
    May 2014
    Gender
    female
    Location
    ---
    Posts
    405
    Reputation
    10
    Thanks
    525
    Quote Originally Posted by ProHackBot999 View Post


    What Forbidden Jungle mob does a spiral attack?
    The boss does a spiral attack at a certain phase.