Example #1
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            BuzzStorage storage = (BuzzStorage)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            if (storage.RemainingTime > 0)
            {
                storage.RemainingTime -= time.thisTickTimes;
                Status = CycleStatus.NotStarted;
            }
            else
            {
                Status = CycleStatus.InProgress;
                if (storage.RemainingDistance <= 0)
                {
                    do
                    {
                        storage.Direction = new Vector2(Random.Next(-1, 2), Random.Next(-1, 2));
                    } while (storage.Direction.X == 0 && storage.Direction.Y == 0);
                    storage.Direction.Normalize();
                    storage.RemainingDistance = this.dist;
                    Status = CycleStatus.Completed;
                }
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + storage.Direction.X * dist, host.Y + storage.Direction.Y * dist);
                host.UpdateCount++;

                storage.RemainingDistance -= dist;
            }

            state = storage;
        }
Example #2
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cooldown;
            if (state == null) cooldown = 1000;
            else cooldown = (int)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var player = (Player)host.GetNearestEntity(distance, null);
            if (player != null)
            {
                Vector2 vect;
                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                vect.Normalize();
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + (-vect.X) * dist, host.Y + (-vect.Y) * dist);
                host.UpdateCount++;

                if (cooldown <= 0)
                {
                    Status = CycleStatus.Completed;
                    cooldown = 1000;
                }
                else
                {
                    Status = CycleStatus.InProgress;
                    cooldown -= time.thisTickTimes;
                }
            }

            state = cooldown;
        }
Example #3
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            var s = (OrbitState) state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            Entity entity = host.GetNearestEntity(acquireRange, target);
            if (entity != null)
            {
                double angle;
                if (host.Y == entity.Y && host.X == entity.X) //small offset
                    angle = Math.Atan2(host.Y - entity.Y + (Random.NextDouble()*2 - 1),
                        host.X - entity.X + (Random.NextDouble()*2 - 1));
                else
                    angle = Math.Atan2(host.Y - entity.Y, host.X - entity.X);
                float angularSpd = host.GetSpeed(s.Speed)/s.Radius;
                angle += angularSpd*(time.thisTickTimes/1000f);

                double x = entity.X + Math.Cos(angle)*radius;
                double y = entity.Y + Math.Sin(angle)*radius;
                Vector2 vect = new Vector2((float) x, (float) y) - new Vector2(host.X, host.Y);
                vect.Normalize();
                vect *= host.GetSpeed(s.Speed)*(time.thisTickTimes/1000f);

                host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
                host.UpdateCount++;

                Status = CycleStatus.InProgress;
            }

            state = s;
        }
Example #4
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            WanderStorage storage;
            if (state == null) storage = new WanderStorage();
            else storage = (WanderStorage)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            Status = CycleStatus.InProgress;
            if (storage.RemainingDistance <= 0)
            {
                storage.Direction = new Vector2(Random.Next(-1, 2), Random.Next(-1, 2));
                storage.Direction.Normalize();
                storage.RemainingDistance = period.Next(Random) / 1000f;
                Status = CycleStatus.Completed;
            }
            float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
            host.ValidateAndMove(host.X + storage.Direction.X * dist, host.Y + storage.Direction.Y * dist);
            host.UpdateCount++;

            storage.RemainingDistance -= dist;

            state = storage;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            float dist;
            if (state == null) dist = distance;
            else dist = (float)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            float moveDist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
            if (dist > 0)
            {
                Status = CycleStatus.InProgress;
                host.ValidateAndMove(host.X + moveDist, host.Y);
                host.UpdateCount++;
                dist -= moveDist;
                if (dist <= 0)
                {
                    dist = -distance;
                    Status = CycleStatus.Completed;
                }
            }
            else
            {
                Status = CycleStatus.InProgress;
                host.ValidateAndMove(host.X - moveDist, host.Y);
                host.UpdateCount++;
                dist += moveDist;
                if (dist >= 0)
                {
                    dist = distance;
                    Status = CycleStatus.Completed;
                }
            }

            state = dist;
        }
Example #6
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            ChargeState s;
            if (state == null) s = new ChargeState();
            else s = (ChargeState)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            if (s.RemainingTime <= 0)
            {
                if (s.Direction == Vector2.Zero)
                {
                    var player = (Player)host.GetNearestEntity(range, null);
                    if (player != null && player.X != host.X && player.Y != host.Y)
                    {
                        s.Direction = new Vector2(player.X - host.X, player.Y - host.Y);
                        var d = s.Direction.Length();
                        s.Direction.Normalize();
                        s.RemainingTime = coolDown.Next(Random);
                        if (d / host.GetSpeed(speed) < s.RemainingTime)
                            s.RemainingTime = (int)(d / host.GetSpeed(speed) * 1000);
                        Status = CycleStatus.InProgress;
                    }
                }
                else
                {
                    s.Direction = Vector2.Zero;
                    s.RemainingTime = coolDown.Next(Random);
                    Status = CycleStatus.Completed;
                }
            }
            if (s.Direction != Vector2.Zero)
            {
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + s.Direction.X * dist, host.Y + s.Direction.Y * dist);
                host.UpdateCount++;
                Status = CycleStatus.InProgress;
            }
            s.RemainingTime -= time.thisTickTimes;

            state = s;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if (host is Pet) if ((host as Pet).PlayerOwner != null) return;

            WmapTile tile = host.Owner.Map[(int)host.X, (int)host.Y].Clone();
            if (tile.Region == TileRegion.None && host.Owner is PetYard)
            {
                Position pos = (host as Pet).SpawnPoint;
                host.Move(pos.X, pos.Y);
                return;
            }

            if (host.GetNearestEntity(1, null) == null)
            {
                WanderStorage storage;
                if (state == null) storage = new WanderStorage();
                else storage = (WanderStorage)state;

                Status = CycleStatus.NotStarted;

                if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return;

                Status = CycleStatus.InProgress;
                if (storage.RemainingDistance <= 0)
                {
                    storage.Direction = new Vector2(Random.Next(-2, 2), Random.Next(-2, 2));
                    storage.Direction.Normalize();
                    storage.RemainingDistance = coolDown.Next(Random) / 1000f;
                    Status = CycleStatus.Completed;
                }

                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + storage.Direction.X * dist, host.Y + storage.Direction.Y * dist);
                host.UpdateCount++;

                storage.RemainingDistance -= dist;

                state = storage;
            }
        }
Example #8
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var map = host.Owner.Map;
            var tile = map[(int)host.X, (int)host.Y];
            if (tile.Elevation != 0 && tile.Elevation < altitude)
            {
                Vector2 vect;
                vect = new Vector2(map.Width / 2 - host.X, map.Height / 2 - host.Y);
                vect.Normalize();
                float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                host.UpdateCount++;

                Status = CycleStatus.InProgress;
            }
            else
                Status = CycleStatus.Completed;
        }
Example #9
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if ((host as Pet)?.PlayerOwner != null)
            {
                return;
            }

            var      map  = host.Owner.Map;
            var      x    = (int)host.X;
            var      y    = (int)host.Y;
            WmapTile tile = null;

            if (map.Contains(x, y))
            {
                tile = map[x, y];
            }

            if (tile == null || (tile.Region == TileRegion.None && host.Owner is PetYard))
            {
                host.Move(spawnPoint.X, spawnPoint.Y);
                return;
            }

            if (host.GetNearestEntity(1, null) != null)
            {
                return;
            }
            WanderStorage storage;

            if (state == null)
            {
                storage = new WanderStorage();
            }
            else
            {
                storage = (WanderStorage)state;
            }

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed))
            {
                return;
            }

            Status = CycleStatus.InProgress;
            if (storage.RemainingDistance <= 0)
            {
                storage.Direction = new Vector2(Random.Next(-2, 2), Random.Next(-2, 2));
                storage.Direction.Normalize();
                storage.RemainingDistance = coolDown.Next(Random) / 1000f;
                Status = CycleStatus.Completed;
            }

            float dist = host.GetSpeed(speed) * (time.ElaspedMsDelta / 1000f);

            host.ValidateAndMove(host.X + storage.Direction.X * dist, host.Y + storage.Direction.Y * dist);

            storage.RemainingDistance -= dist;

            state = storage;
        }
Example #10
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed))
            {
                return;
            }

            var     player = host.GetNearestEntity(acquireRange, null);
            Vector2 vect;

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (player != null && s.RemainingTime <= 0)
                {
                    s.State = F.Acquired;
                    if (duration > 0)
                    {
                        s.RemainingTime = duration;
                    }
                    goto case F.Acquired;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime <= 0 && duration > 0)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = coolDown.Next(Random);
                    Status          = CycleStatus.Completed;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }

                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > range)
                {
                    Status  = CycleStatus.InProgress;
                    vect.X -= Random.Next(-2, 2) / 2f;
                    vect.Y -= Random.Next(-2, 2) / 2f;
                    vect.Normalize();
                    float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }
                else
                {
                    Status          = CycleStatus.Completed;
                    s.State         = F.Resting;
                    s.RemainingTime = 0;
                }
                break;

            case F.Resting:
                if (player == null)
                {
                    s.State = F.DontKnowWhere;
                    if (duration > 0)
                    {
                        s.RemainingTime = duration;
                    }
                    break;
                }
                Status = CycleStatus.Completed;
                vect   = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > range + 1)
                {
                    s.State         = F.Acquired;
                    s.RemainingTime = duration;
                    goto case F.Acquired;
                }
                break;
            }

            state = s;
        }
Example #11
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            Player player = host.GetPlayerOwner();

            if (player.Owner == null)
            {
                host.Owner.LeaveWorld(host);
                return;
            }

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 1000;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }

                var vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > 20)
                {
                    host.Move(player.X, player.Y);
                }
                else if (vect.Length() > 1)
                {
                    var dist = host.GetSpeed(0.5f) * (time.ElapsedMsDelta / 1000f);
                    if (vect.Length() > 2)
                    {
                        dist = host.GetSpeed(0.7f + ((float)player.Stats[4] / 100)) * (time.ElapsedMsDelta / 1000f);
                    }

                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                }

                break;
            }

            state = s;
        }
Example #12
0
        //State storage: follow state


        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            var pet = host;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed))
            {
                return;
            }

            Player player = host.playerOwner; //GetNearestEntity(acquireRange, null);

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }

                var vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > 20)
                {
                    host.Move(player.X, player.Y);
                }
                else if (vect.Length() > 1)
                {
                    var dist = host.GetSpeed(0.5f) * (time.thisTickTimes / 1000f);
                    if (vect.Length() > 2)
                    {
                        dist = host.GetSpeed(0.5f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length() > 3.5)
                    {
                        dist = host.GetSpeed(0.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length() > 5)
                    {
                        dist = host.GetSpeed(1.0f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length() > 6)
                    {
                        dist = host.GetSpeed(1.35f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length() > 7)
                    {
                        dist = host.GetSpeed(1.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length() > 10)
                    {
                        dist = host.GetSpeed(2f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }

                    Status = CycleStatus.InProgress;
                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                }
                host.UpdateCount++;

                break;
            }

            state = s;
        }
Example #13
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            ProtectState s;

            if (state == null)
            {
                s = ProtectState.DontKnowWhere;
            }
            else
            {
                s = (ProtectState)state;
            }

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed))
            {
                return;
            }

            Entity  entity = host.GetNearestEntity(acquireRange, protectee);
            Vector2 vect;

            switch (s)
            {
            case ProtectState.DontKnowWhere:
                if (entity != null)
                {
                    s = ProtectState.Protecting;
                    goto case ProtectState.Protecting;
                }
                break;

            case ProtectState.Protecting:
                if (entity == null)
                {
                    s = ProtectState.DontKnowWhere;
                    break;
                }
                vect = new Vector2(entity.X - host.X, entity.Y - host.Y);
                if (vect.Length > reprotectRange)
                {
                    Status = CycleStatus.InProgress;
                    vect.Normalize();
                    float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }
                else
                {
                    Status = CycleStatus.Completed;
                    s      = ProtectState.Protected;
                }
                break;

            case ProtectState.Protected:
                if (entity == null)
                {
                    s = ProtectState.DontKnowWhere;
                    break;
                }
                Status = CycleStatus.Completed;
                vect   = new Vector2(entity.X - host.X, entity.Y - host.Y);
                if (vect.Length > protectionRange)
                {
                    s = ProtectState.Protecting;
                    goto case ProtectState.Protecting;
                }
                break;
            }

            state = s;
        }
Example #14
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;
            if (state == null) s = new FollowState();
            else s = (FollowState)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var player = (Player)host.GetNearestEntity(acquireRange, null);
            Vector2 vect;
            switch (s.State)
            {
                case F.DontKnowWhere:
                    if (player != null && s.RemainingTime <= 0)
                    {
                        s.State = F.Acquired;
                        if (duration > 0)
                            s.RemainingTime = duration;
                        goto case F.Acquired;
                    }
                    else if (s.RemainingTime > 0)
                        s.RemainingTime -= time.thisTickTimes;
                    break;
                case F.Acquired:
                    if (player == null)
                    {
                        s.State = F.DontKnowWhere;
                        s.RemainingTime = 0;
                        break;
                    }
                    else if (s.RemainingTime <= 0 && duration > 0)
                    {
                        s.State = F.DontKnowWhere;
                        s.RemainingTime = coolDown.Next(Random);
                        Status = CycleStatus.Completed;
                        break;
                    }
                    if (s.RemainingTime > 0)
                        s.RemainingTime -= time.thisTickTimes;

                    vect = new Vector2(player.X - host.X, player.Y - host.Y);
                    if (vect.Length() > range)
                    {
                        Status = CycleStatus.InProgress;
                        vect.X -= Random.Next(-2, 2) / 2f;
                        vect.Y -= Random.Next(-2, 2) / 2f;
                        vect.Normalize();
                        float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                        host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                        host.UpdateCount++;
                    }
                    else
                    {
                        Status = CycleStatus.Completed;
                        s.State = F.Resting;
                        s.RemainingTime = 0;
                    }
                    break;
                case F.Resting:
                    if (player == null)
                    {
                        s.State = F.DontKnowWhere;
                        if (duration > 0)
                            s.RemainingTime = duration;
                        break;
                    }
                    Status = CycleStatus.Completed;
                    vect = new Vector2(player.X - host.X, player.Y - host.Y);
                    if (vect.Length() > range + 1)
                    {
                        s.State = F.Acquired;
                        s.RemainingTime = duration;
                        goto case F.Acquired;
                    }
                    break;

            }

            state = s;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            SwirlState s = (SwirlState)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) return;

            int period = (int)(1000 * radius / host.GetSpeed(speed) * (2 * Math.PI));
            if (!s.Acquired &&
                s.RemainingTime <= 0 &&
                targeted)
            {
                Entity entity = host.GetNearestEntity(acquireRange, null);
                if (entity != null && entity.X != host.X && entity.Y != host.Y)
                {
                    //find circle which pass through host and player pos
                    double l = entity.Dist(host);
                    float hx = (host.X + entity.X) / 2;
                    float hy = (host.Y + entity.Y) / 2;
                    double c = Math.Sqrt(Math.Abs(radius * radius - l * l) / 4);
                    s.Center = new Vector2(
                        (float)(hx + c * (host.Y - entity.Y) / l),
                        (float)(hy + c * (entity.X - host.X) / l));

                    s.RemainingTime = period;
                    s.Acquired = true;
                }
                else
                    s.Acquired = false;
            }
            else if (s.RemainingTime <= 0 || (s.RemainingTime - period > 200 && host.GetNearestEntity(2, null) != null))
            {
                if (targeted)
                {
                    s.Acquired = false;
                    Entity entity = host.GetNearestEntity(acquireRange, null);
                    if (entity != null)
                        s.RemainingTime = 0;
                    else
                        s.RemainingTime = 5000;
                }
                else
                    s.RemainingTime = 5000;
            }
            else
                s.RemainingTime -= time.thisTickTimes;

            double angle;
            if (host.Y == s.Center.Y && host.X == s.Center.X) //small offset
                angle = Math.Atan2(host.Y - s.Center.Y + (Random.NextDouble() * 2 - 1),
                    host.X - s.Center.X + (Random.NextDouble() * 2 - 1));
            else
                angle = Math.Atan2(host.Y - s.Center.Y, host.X - s.Center.X);

            double spd = host.GetSpeed(speed) * (s.Acquired ? 1 : 0.2);
            double angularSpd = spd / radius;
            angle += angularSpd * (time.thisTickTimes / 1000f);

            double x = s.Center.X + Math.Cos(angle) * radius;
            double y = s.Center.Y + Math.Sin(angle) * radius;
            Vector2 vect = new Vector2((float)x, (float)y) - new Vector2(host.X, host.Y);
            vect.Normalize();
            vect *= (float)spd * (time.thisTickTimes / 1000f);

            host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
            host.UpdateCount++;

            Status = CycleStatus.InProgress;

            state = s;
        }
Example #16
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            ProtectState s;
            if (state == null) s = ProtectState.DontKnowWhere;
            else s = (ProtectState)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return;

            var entity = host.GetNearestEntity(acquireRange, protectee);
            Vector2 vect;
            switch (s)
            {
                case ProtectState.DontKnowWhere:
                    if (entity != null)
                    {
                        s = ProtectState.Protecting;
                        goto case ProtectState.Protecting;
                    }
                    break;
                case ProtectState.Protecting:
                    if (entity == null)
                    {
                        s = ProtectState.DontKnowWhere;
                        break;
                    }
                    vect = new Vector2(entity.X - host.X, entity.Y - host.Y);
                    if (vect.Length() > reprotectRange)
                    {
                        Status = CycleStatus.InProgress;
                        vect.Normalize();
                        float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f);
                        host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                        host.UpdateCount++;
                    }
                    else
                    {
                        Status = CycleStatus.Completed;
                        s = ProtectState.Protected;
                    }
                    break;
                case ProtectState.Protected:
                    if (entity == null)
                    {
                        s = ProtectState.DontKnowWhere;
                        break;
                    }
                    Status = CycleStatus.Completed;
                    vect = new Vector2(entity.X - host.X, entity.Y - host.Y);
                    if (vect.Length() > protectionRange)
                    {
                        s = ProtectState.Protecting;
                        goto case ProtectState.Protecting;
                    }
                    break;

            }

            state = s;
        }
Example #17
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if ((host as Pet)?.PlayerOwner == null)
            {
                return;
            }
            var         pet = (Pet)host;
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            var player = host.GetEntity(pet.PlayerOwner.Id) as Player;

            if (player == null)
            {
                var tile = host.Owner.Map[(int)host.X, (int)host.Y].Clone();
                if (tile.Region != TileRegion.PetRegion)
                {
                    if (!(host.Owner is PetYard))
                    {
                        host.Owner.LeaveWorld(host);
                        return;
                    }
                    if (tile.Region != TileRegion.Spawn)
                    {
                        host.Owner.LeaveWorld(host);
                        return;
                    }
                }
            }

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }

                var vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length > 20)
                {
                    host.Move(player.X, player.Y);
                    host.UpdateCount++;
                }
                else if (vect.Length > 3)
                {
                    var dist = host.GetSpeed(0.5f) * (time.thisTickTimes / 1000f);
                    if (vect.Length > 5)
                    {
                        dist = host.GetSpeed(0.5f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 6.5)
                    {
                        dist = host.GetSpeed(0.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 8)
                    {
                        dist = host.GetSpeed(1.0f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 9)
                    {
                        dist = host.GetSpeed(1.35f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 10)
                    {
                        dist = host.GetSpeed(1.5f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 15)
                    {
                        dist = host.GetSpeed(2f + (player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }

                    Status = CycleStatus.InProgress;
                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }

                break;
            }

            state = s;
        }
Example #18
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            Player player = host.GetPlayerOwner();

            if (player.Owner == null)
            {
                host.Owner.LeaveWorld(host);
                return;
            }

            Vector2 vect;

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }

                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length > 20)
                {
                    host.Move(player.X, player.Y);
                    host.UpdateCount++;
                }
                else if (vect.Length > 1)
                {
                    float dist = host.EntitySpeed(player.Stats[4] / 10, time);

                    if (vect.Length > 2 && vect.Length <= 3.5)
                    {
                        dist *= 1.75f;
                    }
                    else if (vect.Length > 3.5 && vect.Length <= 5)
                    {
                        dist *= 2f;
                    }
                    else if (vect.Length > 5 && vect.Length <= 6)
                    {
                        dist *= 2.25f;
                    }
                    else if (vect.Length > 6 && vect.Length <= 7)
                    {
                        dist *= 2.75f;
                    }
                    else if (vect.Length > 7 && vect.Length <= 10)
                    {
                        dist *= 3f;
                    }
                    else if (vect.Length > 10 && vect.Length <= 20)
                    {
                        dist *= 3.25f;
                    }

                    Status  = CycleStatus.InProgress;
                    vect.X -= Random.Next(-2, 2) / 2f;
                    vect.Y -= Random.Next(-2, 2) / 2f;
                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }

                break;
            }

            state = s;
        }
Example #19
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if ((host as Pet)?.PlayerOwner == null)
            {
                return;
            }
            var         pet = (Pet)host;
            FollowState s;

            if (state == null)
            {
                s               = new FollowState();
                s.State         = F.DontKnowWhere;
                s.RemainingTime = 1000;
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;


            var player = host.Owner.GetEntity(pet.PlayerOwner.Id) as Player;

            if (player == null)
            {
                var tile = host.Owner.Map[(int)host.X, (int)host.Y];
                if (tile.Region != TileRegion.PetRegion)
                {
                    if (!(host.Owner is PetYard))
                    {
                        host.Owner.LeaveWorld(host);
                        Status = CycleStatus.Completed;
                        return;
                    }
                    if (tile.Region != TileRegion.Spawn)
                    {
                        host.Owner.LeaveWorld(host);
                        Status = CycleStatus.Completed;
                        return;
                    }
                }
            }

            Status = CycleStatus.InProgress;

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 1000;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }

                var vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length() > 20)
                {
                    host.Move(player.X, player.Y);
                }
                else if (vect.Length() > 1)
                {
                    var dist = host.GetSpeed(0.5f) * (time.ElapsedMsDelta / 1000f);
                    if (vect.Length() > 2)
                    {
                        dist = host.GetSpeed(0.7f + ((float)player.Stats[4] / 100)) * (time.ElapsedMsDelta / 1000f);
                    }

                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                }

                break;
            }

            state = s;
        }
Example #20
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            Player player                = host.GetPlayerOwner();
            Entity pet                   = player.Pet;
            bool   hatchling             = player.HatchlingPet;
            bool   hatchlingNotification = player.HatchlingNotification;

            if (hatchling && !hatchlingNotification)
            {
                NOTIFICATION _notification = new NOTIFICATION
                {
                    Color    = new ARGB(0xFFFFFF),
                    ObjectId = host.Id,
                    Text     = "{\"key\":\"blank\",\"tokens\":{\"data\":\"New Pet!\"}}"
                };

                host.Owner.BroadcastMessage(_notification, null);

                player.HatchlingNotification = true;

                player.SendInfo("Please, leave vault to activate your pet (HP healing, MP healing, follow and shoot behaviors).");
                return;
            }

            if (player.Owner == null || pet == null || host == null)
            {
                pet.Owner.LeaveWorld(host);
                return;
            }

            Vector2 vect = new Vector2(player.X - pet.X, player.Y - pet.Y);

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }

                vect = new Vector2(player.X - pet.X, player.Y - pet.Y);

                if (vect.Length > 1 && vect.Length <= 20)
                {
                    float dist = host.EntitySpeed(player.Stats[4] / 10, time);

                    if (vect.Length > 2 && vect.Length <= 3.5)
                    {
                        dist *= 1.75f;
                    }
                    else if (vect.Length > 3.5 && vect.Length <= 5)
                    {
                        dist *= 2f;
                    }
                    else if (vect.Length > 5 && vect.Length <= 6)
                    {
                        dist *= 2.25f;
                    }
                    else if (vect.Length > 6 && vect.Length <= 7)
                    {
                        dist *= 2.75f;
                    }
                    else if (vect.Length > 7 && vect.Length <= 10)
                    {
                        dist *= 3f;
                    }
                    else if (vect.Length > 10 && vect.Length <= 20)
                    {
                        dist *= 3.25f;
                    }

                    Status = CycleStatus.InProgress;
                    vect.Normalize();
                    pet.ValidateAndMove(pet.X + vect.X * dist, pet.Y + vect.Y * dist);
                    pet.UpdateCount++;
                }

                break;
            }

            state = s;
        }
Example #21
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            //var en = host.GetNearestEntity(20, null);
            //var player = en as Player;

            //if (en == null)
            //{
            //    return;
            //}

            OrbitState s = (OrbitState)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed))
            {
                return;
            }

            if (playerCircle == 1)
            {
                Player entity = host.GetPlayerOwner();

                if (entity != null)
                {
                    double angle;
                    if (host.Y == entity.Y && host.X == entity.X) //small offset
                    {
                        angle = Math.Atan2(host.Y - entity.Y + (Random.NextDouble() * 2 - 1),
                                           host.X - entity.X + (Random.NextDouble() * 2 - 1));
                    }
                    else
                    {
                        angle = Math.Atan2(host.Y - entity.Y, host.X - entity.X);
                    }
                    float angularSpd = host.GetSpeed(s.Speed) / s.Radius;
                    angle += angularSpd * (time.thisTickTimes / 1000f);

                    double  x    = entity.X + Math.Cos(angle) * radius;
                    double  y    = entity.Y + Math.Sin(angle) * radius;
                    Vector2 vect = new Vector2((float)x, (float)y) - new Vector2(host.X, host.Y);
                    vect.Normalize();
                    vect *= host.GetSpeed(s.Speed) * (time.thisTickTimes / 1000f);

                    host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
                    host.UpdateCount++;

                    Status = CycleStatus.InProgress;
                }
            }



            else
            {
                Entity entity = host.GetNearestEntity(acquireRange, target);

                if (entity != null)
                {
                    double angle;
                    if (host.Y == entity.Y && host.X == entity.X) //small offset
                    {
                        angle = Math.Atan2(host.Y - entity.Y + (Random.NextDouble() * 2 - 1),
                                           host.X - entity.X + (Random.NextDouble() * 2 - 1));
                    }
                    else
                    {
                        angle = Math.Atan2(host.Y - entity.Y, host.X - entity.X);
                    }
                    float angularSpd = host.GetSpeed(s.Speed) / s.Radius;
                    angle += angularSpd * (time.thisTickTimes / 1000f);

                    double  x    = entity.X + Math.Cos(angle) * radius;
                    double  y    = entity.Y + Math.Sin(angle) * radius;
                    Vector2 vect = new Vector2((float)x, (float)y) - new Vector2(host.X, host.Y);
                    vect.Normalize();
                    vect *= host.GetSpeed(s.Speed) * (time.thisTickTimes / 1000f);

                    host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
                    host.UpdateCount++;

                    Status = CycleStatus.InProgress;
                }
            }

            state = s;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            Player player = host.GetPlayerOwner();

            if (player.Owner == null)
            {
                host.Owner.LeaveWorld(host);
                return;
            }

            Vector2 vect;

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }
                else
                {
                    s.State = F.Acquired;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.thisTickTimes;
                }

                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length > 20)
                {
                    host.Move(player.X, player.Y);
                    host.UpdateCount++;
                }
                else if (vect.Length > 1)
                {
                    float dist = host.GetSpeed(1.2f) * (time.thisTickTimes / 1000f);
                    if (vect.Length > 2)
                    {
                        dist = host.GetSpeed(1.2f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 3.5)
                    {
                        dist = host.GetSpeed(1.2f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 5)
                    {
                        dist = host.GetSpeed(1.3f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 6)
                    {
                        dist = host.GetSpeed(1.4f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }
                    else if (vect.Length > 7)
                    {
                        dist = host.GetSpeed(1.5f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                    }

                    Status  = CycleStatus.InProgress;
                    vect.X -= Random.Next(-2, 2) / 2f;
                    vect.Y -= Random.Next(-2, 2) / 2f;
                    vect.Normalize();
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }

                break;
            }

            state = s;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;
            if (state == null) s = new FollowState();
            else s = (FollowState)state;

            Status = CycleStatus.NotStarted;

            Player player = host.GetPlayerOwner();
            if (player.Owner == null)
            {
                host.Owner.LeaveWorld(host);
                return;
            }

            Vector2 vect;
            switch (s.State)
            {
                case F.DontKnowWhere:
                    if (s.RemainingTime > 0)
                        s.RemainingTime -= time.thisTickTimes;
                    else
                        s.State = F.Acquired;
                    break;

                case F.Acquired:
                    if (player == null)
                    {
                        s.State = F.DontKnowWhere;
                        s.RemainingTime = 0;
                        break;
                    }
                    if (s.RemainingTime > 0)
                        s.RemainingTime -= time.thisTickTimes;

                    vect = new Vector2(player.X - host.X, player.Y - host.Y);
                    if (vect.Length > 20)
                    {
                        host.Move(player.X, player.Y);
                        host.UpdateCount++;
                    }
                    else if (vect.Length > 1)
                    {
                        float dist = host.GetSpeed(1.2f) * (time.thisTickTimes / 1000f);
                        if (vect.Length > 2)
                            dist = host.GetSpeed(1.2f + ((float)player.Stats[4] / 100)) * (time.thisTickTimes / 1000f);
                        else if (vect.Length > 3.5)
                            dist = host.GetSpeed(1.2f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                        else if (vect.Length > 5)
                            dist = host.GetSpeed(1.3f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                        else if (vect.Length > 6)
                            dist = host.GetSpeed(1.4f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);
                        else if (vect.Length > 7)
                            dist = host.GetSpeed(1.5f + ((float)player.Stats[4] + (float)player.Boost[4] / 100)) * (time.thisTickTimes / 1000f);

                        Status = CycleStatus.InProgress;
                        vect.X -= Random.Next(-2, 2) / 2f;
                        vect.Y -= Random.Next(-2, 2) / 2f;
                        vect.Normalize();
                        host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                        host.UpdateCount++;
                    }

                    break;
            }

            state = s;
        }
Example #24
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            SwirlState s = (SwirlState)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed))
            {
                return;
            }

            int period = (int)(1000 * radius / host.GetSpeed(speed) * (2 * Math.PI));

            if (!s.Acquired &&
                s.RemainingTime <= 0 &&
                targeted)
            {
                Entity entity = host.GetNearestEntity(acquireRange, null);
                if (entity != null && entity.X != host.X && entity.Y != host.Y)
                {
                    //find circle which pass through host and player pos
                    double l  = entity.Dist(host);
                    float  hx = (host.X + entity.X) / 2;
                    float  hy = (host.Y + entity.Y) / 2;
                    double c  = Math.Sqrt(Math.Abs(radius * radius - l * l) / 4);
                    s.Center = new Vector2(
                        (float)(hx + c * (host.Y - entity.Y) / l),
                        (float)(hy + c * (entity.X - host.X) / l));

                    s.RemainingTime = period;
                    s.Acquired      = true;
                }
                else
                {
                    s.Acquired = false;
                }
            }
            else if (s.RemainingTime <= 0 || (s.RemainingTime - period > 200 && host.GetNearestEntity(2, null) != null))
            {
                if (targeted)
                {
                    s.Acquired = false;
                    Entity entity = host.GetNearestEntity(acquireRange, null);
                    if (entity != null)
                    {
                        s.RemainingTime = 0;
                    }
                    else
                    {
                        s.RemainingTime = 5000;
                    }
                }
                else
                {
                    s.RemainingTime = 5000;
                }
            }
            else
            {
                s.RemainingTime -= time.thisTickTimes;
            }

            double angle;

            if (host.Y == s.Center.Y && host.X == s.Center.X) //small offset
            {
                angle = Math.Atan2(host.Y - s.Center.Y + (Random.NextDouble() * 2 - 1),
                                   host.X - s.Center.X + (Random.NextDouble() * 2 - 1));
            }
            else
            {
                angle = Math.Atan2(host.Y - s.Center.Y, host.X - s.Center.X);
            }

            double spd        = host.GetSpeed(speed) * (s.Acquired ? 1 : 0.2);
            double angularSpd = spd / radius;

            angle += angularSpd * (time.thisTickTimes / 1000f);

            double  x    = s.Center.X + Math.Cos(angle) * radius;
            double  y    = s.Center.Y + Math.Sin(angle) * radius;
            Vector2 vect = new Vector2((float)x, (float)y) - new Vector2(host.X, host.Y);

            vect.Normalize();
            vect *= (float)spd * (time.thisTickTimes / 1000f);

            host.ValidateAndMove(host.X + vect.X, host.Y + vect.Y);
            host.UpdateCount++;

            Status = CycleStatus.InProgress;

            state = s;
        }
Example #25
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            FollowState s;

            if (state == null)
            {
                s = new FollowState();
            }
            else
            {
                s = (FollowState)state;
            }

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed))
            {
                return;
            }

            Entity en = host.GetNearestEntity(acquireRange, null);

            if (!(en is Player))
            {
                return;                  //It returned me a enemy, thats why we check for a player here
            }
            Player  player = en as Player;
            Vector2 vect;

            switch (s.State)
            {
            case F.DontKnowWhere:
                if (player != null && s.RemainingTime <= 0)
                {
                    s.State = F.Acquired;
                    if (duration > 0)
                    {
                        s.RemainingTime = duration;
                    }
                    goto case F.Acquired;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }
                break;

            case F.Acquired:
                if (player == null)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = 0;
                    break;
                }
                if (s.RemainingTime <= 0 && duration > 0)
                {
                    s.State         = F.DontKnowWhere;
                    s.RemainingTime = coolDown.Next(Random);
                    Status          = CycleStatus.Completed;
                    break;
                }
                if (s.RemainingTime > 0)
                {
                    s.RemainingTime -= time.ElapsedMsDelta;
                }

                vect = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length > range)
                {
                    Status  = CycleStatus.InProgress;
                    vect.X -= Random.Next(-2, 2) / 2f;
                    vect.Y -= Random.Next(-2, 2) / 2f;
                    vect.Normalize();
                    float dist = host.GetSpeed2(speed, time);
                    host.ValidateAndMove(host.X + vect.X * dist, host.Y + vect.Y * dist);
                    host.UpdateCount++;
                }
                else
                {
                    Status          = CycleStatus.Completed;
                    s.State         = F.Resting;
                    s.RemainingTime = 0;
                }
                break;

            case F.Resting:
                if (player == null)
                {
                    s.State = F.DontKnowWhere;
                    if (duration > 0)
                    {
                        s.RemainingTime = duration;
                    }
                    break;
                }
                Status = CycleStatus.Completed;
                vect   = new Vector2(player.X - host.X, player.Y - host.Y);
                if (vect.Length > range + 1)
                {
                    s.State         = F.Acquired;
                    s.RemainingTime = duration;
                    goto case F.Acquired;
                }
                break;
            }

            state = s;
        }
Example #26
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            double      effectiveSpeed;
            ChargeState s;

            if (state == null)
            {
                s = new ChargeState();
            }
            else
            {
                s = (ChargeState)state;
            }

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffects.Paralyzed))
            {
                return;
            }

            if (host.HasConditionEffect(ConditionEffects.Slowed))
            {
                effectiveSpeed = speed * 0.5;
            }
            else
            {
                effectiveSpeed = speed;
            }

            if (s.RemainingTime <= 0)
            {
                if (s.Direction == Vector2.Zero)
                {
                    var player = host.GetNearestEntity(range, null);
                    if (player != null && player.X != host.X && player.Y != host.Y)
                    {
                        s.Direction = new Vector2(player.X - host.X, player.Y - host.Y);
                        float d = s.Direction.Length();
                        s.Direction.Normalize();
                        s.RemainingTime = coolDown.Next(Random);
                        if (d / host.GetSpeed(speed) < s.RemainingTime)
                        {
                            s.RemainingTime = (int)(d / host.GetSpeed(speed) * 1000);
                        }
                        Status = CycleStatus.InProgress;
                    }
                }
                else
                {
                    s.Direction     = Vector2.Zero;
                    s.RemainingTime = coolDown.Next(Random);
                    Status          = CycleStatus.Completed;
                }
            }
            if (s.Direction != Vector2.Zero)
            {
                float dist = host.GetSpeed((float)effectiveSpeed) * (time.ElaspedMsDelta / 1000f);
                host.ValidateAndMove(host.X + s.Direction.X * dist, host.Y + s.Direction.Y * dist);
                host.UpdateCount++;
                Status = CycleStatus.InProgress;
            }
            s.RemainingTime -= time.ElaspedMsDelta;

            state = s;
        }