Exemple #1
0
        private void TrySpawn()
        {
            int respawnTime = 15;

            if (Monster.LeaderID == 1)
            {
                respawnTime *= 2;
            }
            if (Monster.MonsterType == 112 || Monster.MonsterType == 187 || Monster.MonsterType == 188) // king, phx, gb
            {
                respawnTime = 3600;
            }
            if (Monster.MonsterType == 113) // emp
            {
                respawnTime = 7200;
            }

            if (DateTime.Now >= Monster.DeathTime.AddSeconds(respawnTime))
            {
                Monster.Position.X = Monster.SpawnX;
                Monster.Position.Y = Monster.SpawnY;
                Monster.CurHealth  = Monster.MaxHealth;
                Monster.Target     = null;
                Monster.Alive      = true;
                Monster.Attacking  = false;
                Monster.IsMoving   = false;
                state = MonsterAIState.Wander;
            }
        }
Exemple #2
0
        public MonsterAI(Monster monster, List<BaseEntity> surroundings)
        {
            aiTimer = new Timer();
            aiTimer.Elapsed += new ElapsedEventHandler(aiTimer_Elapsed);
            aiTimer.Disposed += new EventHandler(aiTimer_Disposed);
            aiTimer.Enabled = true;
            aiTimer.AutoReset = true;
            aiTimer.Interval = 1000; //1000 for movemetn update, or 100

            this.surroundings = surroundings;

            this.Monster = monster;
            this.state = MonsterAIState.Wander;
        }
Exemple #3
0
        public MonsterAI(Monster monster, List <BaseEntity> surroundings)
        {
            aiTimer           = new Timer();
            aiTimer.Elapsed  += new ElapsedEventHandler(aiTimer_Elapsed);
            aiTimer.Disposed += new EventHandler(aiTimer_Disposed);
            aiTimer.Enabled   = true;
            aiTimer.AutoReset = true;
            aiTimer.Interval  = 1000; //1000 for movemetn update, or 100

            this.surroundings = surroundings;

            this.Monster = monster;
            this.state   = MonsterAIState.Wander;
        }
Exemple #4
0
        private void ChaseEntity(BaseEntity ent)
        {
            UpdateTarget();

            if (Monster.Target != null)
            {
                if (TargetOnAttackRange())
                {
                    state = MonsterAIState.Attack;
                }
                else
                {
                    Position entPos = new Position(ent.Position.X, ent.Position.Y, 0);
                    MoveTo(entPos);
                }
            }
        }
Exemple #5
0
        private void DoWandering()
        {
            if (HasTarget())
            {
                state = MonsterAIState.Chase;
                return;
            }
            Position destination;

            // last action time set here
            short toX = (short)XiahRandom.Next(Monster.SpawnX - (Monster.WanderRange), Monster.SpawnX + (Monster.WanderRange));
            short toY = (short)XiahRandom.Next(Monster.SpawnY - (Monster.WanderRange), Monster.SpawnY + (Monster.WanderRange));

            destination = new Position(toX, toY, 0);


            MoveTo(destination);
        }
Exemple #6
0
        private void AttackEntity(BaseEntity ent)
        {
            UpdateTarget();

            if (Monster.Target != null)
            {
                if (!TargetOnAttackRange())
                {
                    state = MonsterAIState.Chase;
                }
                else
                {
                    Monster.Target    = ent;
                    Monster.Attacking = true;

                    MonsterAttackInfo info = GetAttackInfo(false);
                    if (MonsterAttack != null)
                    {
                        MonsterAttack(this, new MonsterAttackInfoEventArgs(info));
                    }
                }
            }
        }
Exemple #7
0
        void aiTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (Monster.Alive)
            {
                switch (state)
                {
                    case MonsterAIState.Wander:
                        if (!Monster.IsMoving && DateTime.Now >= Monster.LastMoveTime.AddSeconds(3))
                            DoWandering();
                        break;

                    case MonsterAIState.Chase:
                        if (!Monster.IsMoving && Monster.Target != null)
                            ChaseEntity(Monster.Target);
                        else
                            state = MonsterAIState.Wander;
                        break;

                    case MonsterAIState.Attack:
                        if (Monster.Target != null && DateTime.Now >= Monster.LastAttack.AddSeconds(2))
                            AttackEntity(Monster.Target);
                        else
                            state = MonsterAIState.Wander;
                        break;

                    default:
                        state = MonsterAIState.Wander;
                        break;
                }

                if (Monster.IsMoving)
                    UpdateMovement();

                if (HasTarget())
                {
                    if (state != MonsterAIState.Attack)
                        state = MonsterAIState.Chase;
                }
                else
                    state = MonsterAIState.Wander;
            }
            else
            {
                TrySpawn();
            }

            //// add logics, 3sec no mobs -> idle, if player around rape him etc
            //if (Monster.Alive)
            //{
            //    // add check if monster is too far away from spawning point, then walk back there
            //    if (!Monster.IsMoving)
            //    {
            //        if (Monster.Target != null)
            //        {
            //            UpdateTarget();

            //            if (TargetOnAttackRange())
            //                Monster.Attacking = true;
            //            else
            //                Monster.Attacking = false;
            //        }

            //        if (!Monster.Attacking && DateTime.Now >= Monster.LastMoveTime.AddSeconds(3)) // && 3 secs passed since last action
            //            DoWandering();
            //        else if (Monster.Attacking && DateTime.Now >= Monster.LastAttack.AddSeconds(2))
            //        {
            //            // do attacking stuff etc
            //            MonsterAttackInfo info = GetAttackInfo(false);
            //            if (MonsterAttack != null)
            //                MonsterAttack(this, new MonsterAttackInfoEventArgs(info));
            //        }
            //    }
            //    else if (Monster.IsMoving)
            //    {
            //        UpdateMovement();
            //    }
            //}
            //else
            //{
            //    TrySpawn();
            //}
        }
Exemple #8
0
        private void TrySpawn()
        {
            int respawnTime = 15;
            if (Monster.LeaderID == 1)
                respawnTime *= 2;
            if (Monster.MonsterType == 112 || Monster.MonsterType == 187 || Monster.MonsterType == 188) // king, phx, gb
                respawnTime = 3600;
            if (Monster.MonsterType == 113) // emp
                respawnTime = 7200;

            if (DateTime.Now >= Monster.DeathTime.AddSeconds(respawnTime))
            {
                Monster.Position.X = Monster.SpawnX;
                Monster.Position.Y = Monster.SpawnY;
                Monster.CurHealth = Monster.MaxHealth;
                Monster.Target = null;
                Monster.Alive = true;
                Monster.Attacking = false;
                Monster.IsMoving = false;
                state = MonsterAIState.Wander;
            }
        }
Exemple #9
0
        private void DoWandering()
        {
            if (HasTarget())
            {
                state = MonsterAIState.Chase;
                return;
            }
            Position destination;

            // last action time set here
            short toX = (short)XiahRandom.Next(Monster.SpawnX - (Monster.WanderRange), Monster.SpawnX + (Monster.WanderRange));
            short toY = (short)XiahRandom.Next(Monster.SpawnY - (Monster.WanderRange), Monster.SpawnY + (Monster.WanderRange));

            destination = new Position(toX, toY, 0);

            MoveTo(destination);
        }
Exemple #10
0
        private void ChaseEntity(BaseEntity ent)
        {
            UpdateTarget();

            if (Monster.Target != null)
            {
                if (TargetOnAttackRange())
                    state = MonsterAIState.Attack;
                else
                {
                    Position entPos = new Position(ent.Position.X, ent.Position.Y, 0);
                    MoveTo(entPos);
                }
            }
        }
Exemple #11
0
        private void AttackEntity(BaseEntity ent)
        {
            UpdateTarget();

            if (Monster.Target != null)
            {
                if (!TargetOnAttackRange())
                    state = MonsterAIState.Chase;
                else
                {
                    Monster.Target = ent;
                    Monster.Attacking = true;

                    MonsterAttackInfo info = GetAttackInfo(false);
                    if (MonsterAttack != null)
                        MonsterAttack(this, new MonsterAttackInfoEventArgs(info));
                }
            }
        }
Exemple #12
0
        void aiTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (Monster.Alive)
            {
                switch (state)
                {
                case MonsterAIState.Wander:
                    if (!Monster.IsMoving && DateTime.Now >= Monster.LastMoveTime.AddSeconds(3))
                    {
                        DoWandering();
                    }
                    break;

                case MonsterAIState.Chase:
                    if (!Monster.IsMoving && Monster.Target != null)
                    {
                        ChaseEntity(Monster.Target);
                    }
                    else
                    {
                        state = MonsterAIState.Wander;
                    }
                    break;

                case MonsterAIState.Attack:
                    if (Monster.Target != null && DateTime.Now >= Monster.LastAttack.AddSeconds(2))
                    {
                        AttackEntity(Monster.Target);
                    }
                    else
                    {
                        state = MonsterAIState.Wander;
                    }
                    break;

                default:
                    state = MonsterAIState.Wander;
                    break;
                }

                if (Monster.IsMoving)
                {
                    UpdateMovement();
                }

                if (HasTarget())
                {
                    if (state != MonsterAIState.Attack)
                    {
                        state = MonsterAIState.Chase;
                    }
                }
                else
                {
                    state = MonsterAIState.Wander;
                }
            }
            else
            {
                TrySpawn();
            }

            //// add logics, 3sec no mobs -> idle, if player around rape him etc
            //if (Monster.Alive)
            //{
            //    // add check if monster is too far away from spawning point, then walk back there
            //    if (!Monster.IsMoving)
            //    {
            //        if (Monster.Target != null)
            //        {
            //            UpdateTarget();

            //            if (TargetOnAttackRange())
            //                Monster.Attacking = true;
            //            else
            //                Monster.Attacking = false;
            //        }

            //        if (!Monster.Attacking && DateTime.Now >= Monster.LastMoveTime.AddSeconds(3)) // && 3 secs passed since last action
            //            DoWandering();
            //        else if (Monster.Attacking && DateTime.Now >= Monster.LastAttack.AddSeconds(2))
            //        {
            //            // do attacking stuff etc
            //            MonsterAttackInfo info = GetAttackInfo(false);
            //            if (MonsterAttack != null)
            //                MonsterAttack(this, new MonsterAttackInfoEventArgs(info));
            //        }
            //    }
            //    else if (Monster.IsMoving)
            //    {
            //        UpdateMovement();
            //    }
            //}
            //else
            //{
            //    TrySpawn();
            //}
        }