示例#1
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int index;
            if (state == null) index = -1;
            else index = (int) state;

            if (index < 0) //select
            {
                index = 0;
                for (int i = 0; i < children.Length; i++)
                {
                    children[i].Tick(host, time);
                    if (children[i].Status == CycleStatus.InProgress)
                    {
                        index = i;
                        break;
                    }
                }
            }
            else //run a cycle
            {
                children[index].Tick(host, time);
                if (children[index].Status == CycleStatus.Completed ||
                    children[index].Status == CycleStatus.NotStarted)
                    index = -1;
            }

            state = index;
        }
 protected override void TickCore(Entity host, RealmTime time, ref object state)
 {
     Pet pet;
     if (!isValidPet(host, out pet)) return;
     if (Pet == null) Pet = pet;
     TickCore(pet, time, ref state);
 }
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     Entity[] ens = host.GetNearestEntities(dist).ToArray();
     foreach (Entity e in ens)
         if (e.ObjectType == host.Manager.GameData.IdToObjectType[children])
             host.Owner.LeaveWorld(e);
 }
        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;
        }
示例#5
0
 protected override void TickCore(Entity host, RealmTime time, ref object state)
 {
     condition.Tick(host, time);
     if (condition.Result)
         foreach (var i in behaviors)
             i.Tick(host, time);
 }
示例#6
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            var 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;
        }
        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(ConditionEffectIndex.Paralyzed)) return;

            Player 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;
        }
示例#8
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 OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     if (host.GetNearestEntity(100, 0x5e4b) != null) return;
     Entity opener = Entity.Resolve(host.Manager, "Realm Portal Opener");
     host.Owner.EnterWorld(opener);
     opener.Move(host.X, host.Y);
 }
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     if ((host as Enemy).AltTextureIndex != index)
     {
         (host as Enemy).AltTextureIndex = index;
         host.UpdateCount++;
     }
 }
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     host.ApplyConditionEffect(new ConditionEffect
     {
         Effect = effect,
         DurationMS = -1
     });
 }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            Entity entity = Entity.Resolve(host.Manager, target);

            entity.Move(host.X, host.Y);
            host.Owner.EnterWorld(entity);
            host.Owner.LeaveWorld(host);
        }
 protected override bool TickCore(Entity host, RealmTime time, ref object state)
 {
     if (host.GetNearestEntity(dist, target) == null && host.GetNearestEntity(dist, target2) == null)
     {
         return true;
     }
     return false;
 }
示例#14
0
 protected override void TickCore(Entity host, RealmTime time, ref object state)
 {
     if (targetState == null)
         targetState = FindState(host.Manager.Behaviors.Definitions[(ushort) children].Item1, targetStateName);
     foreach (Entity i in host.GetNearestEntities(range, children))
         if (!i.CurrentState.Is(targetState))
             i.SwitchTo(targetState);
 }
 private bool isValidPet(Entity host, out Pet p)
 {
     p = null;
     if (!(host is Pet)) return false;
     var pet = (Pet)host;
     if (PlayerOwnerRequired && pet.PlayerOwner == null) return false;
     p = pet;
     return true;
 }
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     if (host is Enemy)
     {
         foreach (Entity i in host.GetNearestEntities(radius, children))
             if (i is Enemy)
                 if ((i as Enemy).LootState != (host as Enemy).LootState)
                     (i as Enemy).LootState = (host as Enemy).LootState;
     }
 }
示例#17
0
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     host.Owner.BroadcastPacket(new ShowEffectPacket
     {
         EffectType = EffectType.Flashing,
         PosA = new Position {X = flashPeriod, Y = flashRepeats},
         TargetId = host.Id,
         Color = new ARGB(color)
     }, null);
 }
示例#18
0
 public static float GetSpeed(Entity entity, float stat)
 {
     var ret = 4 + 5.6f*(stat/75f);
     if (entity.HasConditionEffect(ConditionEffects.Speedy))
         ret *= 1.5f;
     if (entity.HasConditionEffect(ConditionEffects.Slowed))
         ret = 4;
     if (entity.HasConditionEffect(ConditionEffects.Paralyzed))
         ret = 0;
     return ret;
 }
        public void Move(Entity entity, double x, double y)
        {
            int hash = HashPosition(entity.X, entity.Y);
            ConcurrentDictionary<int, Entity> bucket = store.GetOrAdd(hash, _ => new ConcurrentDictionary<int, Entity>());
            Entity dummy;
            bucket.TryRemove(entity.Id, out dummy);

            hash = HashPosition(x, y);
            bucket = store.GetOrAdd(hash, _ => new ConcurrentDictionary<int, Entity>());
            bucket[entity.Id] = entity;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int)state;

            if (cool <= 0)
                host.Owner.LeaveWorld(host);
            else
                cool -= time.thisTickTimes;

            state = cool;
        }
 protected override void OnStateExit(Entity host, RealmTime time, ref object state)
 {
     if (!perm)
     {
         host.ApplyConditionEffect(new ConditionEffect
         {
             Effect = effect,
             DurationMS = 0
         });
     }
 }
 protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
 {
     foreach (var i in host.GetNearestEntities(25, null).OfType<Player>())
     {
         i.Client.SendPacket(new PlaySoundPacket
         {
             OwnerId = host.Id,
             SoundId = soundId
         });
     }
 }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int index;
            if (state == null) index = 0;
            else index = (int) state;

            children[index].Tick(host, time);
            if (children[index].Status == CycleStatus.Completed ||
                children[index].Status == CycleStatus.NotStarted)
            {
                index++;
                if (index == children.Length) index = 0;
            }

            state = index;
        }
示例#24
0
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            if (state != null && cooldown.CoolDown == 0) return; //cooldown = 0 -> once per state entry

            int c;
            if (state == null) c = cooldown.Next(Random);
            else c = (int) state;

            c -= time.thisTickTimes;
            state = c;
            if (c > 0) return;

            c = cooldown.Next(Random);
            state = c;

            if (Random.NextDouble() >= probability) return;

            string taunt = text.Length == 1 ? text[0] : text[Random.Next(text.Length)];
            if (taunt.Contains("{PLAYER}"))
            {
                Entity player = host.GetNearestEntity(10, null);
                if (player == null) return;
                taunt = taunt.Replace("{PLAYER}", player.Name);
            }
            taunt = taunt.Replace("{HP}", (host as Enemy).HP.ToString());
            taunt = taunt.Replace("{DEF}", (host as Enemy).Defense.ToString());

            var packet = new TextPacket
            {
                Name = "#" + (host.ObjectDesc.DisplayId ?? host.ObjectDesc.ObjectId),
                ObjectId = host.Id,
                Stars = -1,
                BubbleTime = 5,
                Recipient = "",
                Text = taunt,
                CleanText = ""
            };
            if (broadcast)
                host.Owner.BroadcastPacket(packet, null);
            else
                foreach (Entity i in host.Owner.PlayersCollision.HitTest(host.X, host.Y, 15))
                {
                    if (host.Dist(i) < 15 && !(i is
                        Decoy))
                        (i as Player).Client.SendPacket(packet);
                }
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            SpawnState spawn = (SpawnState)state;

            if (spawn.RemainingTime <= 0 && spawn.CurrentNumber < maxChildren)
            {
                Entity entity = Entity.Resolve(host.Manager, children[Random.Next(children.Length)]);

                entity.Move(host.X, host.Y);
                (entity as Enemy).Terrain = (host as Enemy).Terrain;
                host.Owner.EnterWorld(entity);
                spawn.RemainingTime = coolDown.Next(Random);
                spawn.CurrentNumber++;
            }
            else
                spawn.RemainingTime -= time.thisTickTimes;
        }
        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;
            //}

            float dist;
            if (state == null) dist = distance;
            else dist = (float)state;

            Status = CycleStatus.NotStarted;

            if (host.HasConditionEffect(ConditionEffectIndex.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;
        }
        protected override void TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool = (int)state;
            if (cool <= 0)
            {
                var entities = host.GetNearestEntities(6);

                Enemy en = null;
                foreach (Entity e in entities)
                    if (e is Enemy)
                    {
                        en = e as Enemy;
                        break;
                    }

                if (en != null & en.ObjectDesc.Enemy)
                {
                    en.Owner.BroadcastPacket(new ShowEffectPacket
                    {
                        EffectType = EffectType.AreaBlast,
                        Color = new ARGB(0xEEEE73),
                        TargetId = en.Id,
                        PosA = new Position { X = 1, }
                    }, null);
                    en.Owner.BroadcastPacket(new ShowEffectPacket
                    {
                        EffectType = EffectType.Trail,
                        TargetId = host.Id,
                        PosA = new Position { X = en.X, Y = en.Y },
                        Color = new ARGB(0xEEEE73)
                    }, null);
                    en.ApplyConditionEffect(new ConditionEffect
                    {
                        Effect = ConditionEffectIndex.Bleeding,
                        DurationMS = 10000
                    });
                }

                cool = 1000;
            }
            else
                cool -= time.thisTickTimes;

            state = cool;
        }
        protected override void OnStateEntry(Entity host, RealmTime time, ref object state)
        {
            state = new SpawnState
            {
                CurrentNumber = initialSpawn,
                RemainingTime = coolDown.Next(Random)
            };
            for (int i = 0; i < initialSpawn; i++)
            {
                Entity entity = Entity.Resolve(host.Manager, children[Random.Next(children.Length)]);

                entity.Move(
                    host.X + (float)(Random.NextDouble() * 0.5),
                    host.Y + (float)(Random.NextDouble() * 0.5));
                (entity as Enemy).Terrain = (host as Enemy).Terrain;
                host.Owner.EnterWorld(entity);
            }
        }
示例#29
0
        public static float GetDefenseDamage(Entity host, int dmg, int def)
        {
            if (host.HasConditionEffect(ConditionEffects.Armored))
                def *= 2;
            if (host.HasConditionEffect(ConditionEffects.ArmorBroken))
                def = 0;

            var limit = dmg*0.15f;

            float ret;
            if (dmg - def < limit) ret = limit;
            else ret = dmg - def;

            if (host.HasConditionEffect(ConditionEffects.Invulnerable) ||
                host.HasConditionEffect(ConditionEffects.Invincible))
                ret = 0;
            return ret;
        }
        protected override bool TickCore(Entity host, RealmTime time, ref object state)
        {
            int cool;
            if (state == null) cool = randomized ? Random.Next(this.time) : this.time;
            else cool = (int) state;

            bool ret = false;
            if (cool <= 0)
            {
                ret = true;
                cool = this.time;
            }
            else
                cool -= time.thisTickTimes;

            state = cool;
            return ret;
        }