Ejemplo n.º 1
0
        private void SelectAttack(SnakeHydra head)
        {
            var weightedList = new WeightedList <Snake.Action>();

            weightedList.Add(new Snake.ActionIdle(head), 30);
            Vector2 dist = Target.Position - Position;

            if (Heads.Count(x => x.CurrentAction is Snake.ActionBite) < 2 && dist.LengthSquared() < 90 * 90)
            {
                weightedList.Add(new Snake.ActionBite(head, 60 + Random.Next(60), 20, 60 + Random.Next(60)), 50);
            }
            if (Heads.Count(x => x.CurrentAction is Snake.ActionSpit) < 1)
            {
                weightedList.Add(new Snake.ActionSpit(head, Target, new Vector2(0, -70), 60, 20, 20, 20), 30);
            }
            if (Heads.Count(x => x.CurrentAction is Snake.ActionBreath) < 1 && Math.Abs(dist.X) < 100)
            {
                weightedList.Add(new Snake.ActionBreath(head, Target, 80, 120, 60), 30);
            }
            head.CurrentAction = weightedList.GetWeighted(Random);
        }
Ejemplo n.º 2
0
        private Potion BrewPotion(Meat meat)
        {
            Random random = new Random(meat.MeatType.GetHashCode());

            return(Potions.GetWeighted(random)());
        }
Ejemplo n.º 3
0
        public void UpdateAI()
        {
            var        viewSize = new Vector2(200, 50);
            RectangleF viewArea = new RectangleF(Position - viewSize / 2, viewSize);

            if (viewArea.Contains(World.Player.Position))
            {
                Target     = World.Player;
                TargetTime = 200;
            }
            else
            {
                TargetTime--;
                if (TargetTime <= 0)
                {
                    Target = null;
                }
            }

            if (Target != null) //Engaged
            {
                if (CurrentAction is ActionHit)
                {
                }
                else if (CurrentAction is ActionEnemyDeath)
                {
                }
                else if (CurrentAction is ActionJump)
                {
                }
                else if (CurrentAction is ActionClimb)
                {
                    OnWall = false;
                }
                else
                {
                    foreach (var weaponAI in GetWeaponAIs(Weapon))
                    {
                        weaponAI.Update(this);
                    }

                    if (DifferenceVector.X < 0)
                    {
                        Owner.Facing = HorizontalFacing.Left;
                    }
                    else if (DifferenceVector.X > 0)
                    {
                        Owner.Facing = HorizontalFacing.Right;
                    }

                    float preferredDistanceMin = 20;
                    float preferredDistanceMax = 30;
                    if (Target.Invincibility > 0)
                    {
                        preferredDistanceMin = 30;
                        preferredDistanceMax = 40;
                    }
                    if (Target.InAir)
                    {
                        preferredDistanceMin = 40;
                        preferredDistanceMax = 50;
                    }
                    if (CurrentAction is ActionMove move)
                    {
                        move.WalkingLeft  = false;
                        move.WalkingRight = false;
                    }
                    if (Math.Abs(DifferenceVector.X) > preferredDistanceMax)
                    {
                        Owner.WalkConstrained(DifferenceVector.X);
                    }
                    if (Math.Abs(DifferenceVector.X) < preferredDistanceMin)
                    {
                        Owner.WalkConstrained(-DifferenceVector.X);
                    }
                }

                AttackCooldown--;
                RangedCooldown--;
            }
            else //Idle
            {
                IdleTime--;

                switch (Idle)
                {
                case (IdleState.Wait):
                    break;

                case (IdleState.MoveLeft):
                    Owner.Facing = HorizontalFacing.Left;
                    Owner.WalkConstrained(-1);
                    break;

                case (IdleState.MoveRight):
                    Owner.Facing = HorizontalFacing.Right;
                    Owner.WalkConstrained(1);
                    break;
                }

                if (OnWall)
                {
                    if (Idle == IdleState.MoveLeft)
                    {
                        Idle = IdleState.MoveRight;
                    }
                    else if (Idle == IdleState.MoveRight)
                    {
                        Idle = IdleState.MoveLeft;
                    }
                    OnWall   = false;
                    IdleTime = 70;
                }

                if (IdleTime <= 0)
                {
                    WeightedList <IdleState> nextState = new WeightedList <IdleState>();
                    nextState.Add(IdleState.Wait, 30);
                    nextState.Add(IdleState.MoveLeft, 70);
                    nextState.Add(IdleState.MoveRight, 70);
                    IdleTime = Owner.Random.Next(50) + 20;
                    Idle     = nextState.GetWeighted(Owner.Random);
                }
            }
        }