Пример #1
0
        public static LivingUnit NearedTarget(Game game, World world, Wizard self)
        {
            StrategyStorage.nearedTargets.Clear();
            StrategyStorage.nearedTargets = ActiveUnits(world);

            LivingUnit player         = null;
            LivingUnit target         = null;
            double     playerDistance = double.MaxValue;
            double     minDistance    = double.MaxValue;

            foreach (var neardTarget in StrategyStorage.nearedTargets)
            {
                double distance = self.GetDistanceTo(neardTarget);

                if (neardTarget.Faction == StrategyStorage.badGuyFaction)
                {
                    if (neardTarget is Wizard && distance < self.CastRange && distance < playerDistance)
                    {
                        playerDistance = distance;
                        player         = neardTarget;
                    }

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        target      = neardTarget;
                    }
                }
            }

            return(player != null ? player : target);
        }
Пример #2
0
        public virtual void CheckCollision(Game game, World world, Wizard self, Move move)
        {
            if (StrategyStorage.collisionObject != null)
            {
                /* Если мы "воткнулись", но не можем разрушить, пытаемся обойти */
                if (StrategyStorage.collisionObject is Tree)
                {
                    if (self.GetDistanceTo(StrategyStorage.collisionObject) < (game.StaffRange - StrategyStorage.collisionObject.Radius))
                    {
                        move.Action = ActionType.Staff;
                    }
                    else
                    {
                        move.Action    = ActionType.MagicMissile;
                        move.CastAngle = self.GetAngleTo(StrategyStorage.collisionObject);
                    }

                    StrategyHelper.Log("\tCollise with tree");
                }
                else if (StrategyStorage.collisionObject is Building)
                {
                    double angle = Math.Round(self.GetAngleTo(StrategyStorage.collisionObject));
                    StrategyStorage.currentStrafe = (angle >= 0 ? -1 : 1) * game.WizardStrafeSpeed;
                    StrategyHelper.Log("\tCollise with build");
                }
                else
                {
                    double angle = Math.Round(self.GetAngleTo(StrategyStorage.collisionObject));
                    StrategyStorage.currentStrafe = (angle >= 0 ? -1 : 1) * game.WizardStrafeSpeed;
                    //StrategyStorage.currentTurn = (random.Next(2) > 0 ? 2 : -1) * self.GetAngleTo(StrategyStorage.collisionObject);
                    StrategyHelper.Log("\tCollise with other unit");
                }
            }
        }
Пример #3
0
        public static bool CheckBadSituation(Wizard self, World world)
        {
            int enemyCount  = 0;
            int friendCount = 0;

            foreach (var unit in ActiveUnits(world))
            {
                double distance = self.GetDistanceTo(unit);
                if (distance < StrategyStorage.visionRange)
                {
                    if (unit.Faction == StrategyStorage.badGuyFaction)
                    {
                        enemyCount += unit is Minion ? (int)UnitWeight.EnemyMinion : unit is Building ? (int)UnitWeight.EnemyBuilding : (int)UnitWeight.EnemyWizard;
                    }
                    else if (unit.Faction == self.Faction)
                    {
                        if (unit.Id == StrategyStorage.mainBase.Id)
                        {
                            friendCount += (int)UnitWeight.FriendBase;
                        }

                        friendCount += unit is Minion ? (int)UnitWeight.FriendMinion : unit is Building ? (int)UnitWeight.FriendBuilding : (int)UnitWeight.FriendWizard;
                    }
                }
            }

            return((enemyCount > friendCount) || (StrategyStorage.target is Building && friendCount <= NEEDKILLBUILDFRIEND));
        }
Пример #4
0
        public static LivingUnit CollizedObject(Wizard self, World world)
        {
            StrategyStorage.nearedStaticObject.Clear();
            StrategyStorage.nearedStaticObject = ActiveUnits(world);
            StrategyStorage.nearedStaticObject.AddRange(world.Trees);

            LivingUnit collizedObject      = null;
            LivingUnit collizedTree        = null;
            double     minDistanceToTree   = double.MaxValue;
            double     minDistanceToObject = double.MaxValue;

            foreach (var neardTarget in StrategyStorage.nearedStaticObject)
            {
                double distance = self.GetDistanceTo(neardTarget) - neardTarget.Radius - self.Radius;
                if (neardTarget.Id != StrategyStorage.myId && distance < self.Radius)
                {
                    if (neardTarget is Tree && distance < minDistanceToTree)
                    {
                        minDistanceToTree = distance;
                        collizedTree      = neardTarget;
                    }
                    else if (distance < minDistanceToObject)
                    {
                        minDistanceToObject = distance;
                        collizedObject      = neardTarget;
                    }
                }
            }

            return(collizedTree != null ? collizedTree : collizedObject);
        }
Пример #5
0
        public static Bonus NearedBonus(World world, Wizard self)
        {
            Bonus  target      = null;
            double minDistance = double.MaxValue;

            foreach (var bonus in world.Bonuses)
            {
                double distance = self.GetDistanceTo(bonus);
                if (distance < (self.VisionRange * 3) && distance < minDistance)
                {
                    minDistance = distance;
                    target      = bonus;
                }
            }

            return(target);
        }
Пример #6
0
 public virtual void InitSpeed(Game game, World world, Wizard self, Move move, double multiple = 1)
 {
     /*
      * Если нужно отступать врубаем обратную максимальную скорость, иначе если нет цели или дистанция
      * больше безопасной движемся вперед, иначе отступаем
      */
     if (self.Life < StrategyStorage.halfLife || StrategyHelper.CheckBadSituation(self, world))
     {
         StrategyStorage.needRun      = true;
         StrategyStorage.currentSpeed = -(game.WizardBackwardSpeed * multiple);
     }
     else if (!(StrategyStorage.target is LivingUnit) || (self.GetDistanceTo(StrategyStorage.target) > (StrategyStorage.safeDistance - StrategyStorage.target.Radius - game.MagicMissileRadius)))
     {
         StrategyStorage.currentSpeed = game.WizardForwardSpeed * multiple;
     }
     else
     {
         StrategyStorage.currentSpeed = -(game.WizardBackwardSpeed * multiple);
     }
 }
Пример #7
0
        public static int CountEnemyInCastRange(World world, Wizard self)
        {
            int count = 0;

            List <LivingUnit> units = new List <LivingUnit>();

            units.AddRange(world.Minions);
            units.AddRange(world.Wizards);

            foreach (var unit in units)
            {
                double distance = self.GetDistanceTo(unit);
                if (unit.Faction == StrategyStorage.badGuyFaction && distance < self.CastRange)
                {
                    count++;
                }
            }

            return(count);
        }
Пример #8
0
        public virtual void CheckNeedAttack(Game game, World world, Wizard self, Move move)
        {
            if (StrategyStorage.target != null)
            {
                double distance = self.GetDistanceTo(StrategyStorage.target);
                if (distance <= self.CastRange)
                {
                    double angle = self.GetAngleTo(StrategyStorage.target);
                    if (Math.Abs(angle) < (game.StaffSector / 2.0D))
                    {
                        if (distance < (game.StaffRange - StrategyStorage.target.Radius))
                        {
                            move.Action = ActionType.Staff;
                            StrategyHelper.Log("\tStaff attack");
                        }
                        else
                        {
                            LivingUnit blockUnit = StrategyHelper.CheckBlockAttack(world, self);
                            if (blockUnit != null)
                            {
                                StrategyStorage.currentStrafe = (Math.Round(self.GetAngleTo(blockUnit)) >= 0 ? -1 : 1) * game.WizardStrafeSpeed;
                            }
                            else
                            {
                                StrategyStorage.currentStrafe = (random.Next(2) > 0 ? 1 : -1) * game.WizardStrafeSpeed;
                            }

                            move.Action          = ActionType.MagicMissile;
                            move.CastAngle       = angle;
                            move.MinCastDistance = distance - StrategyStorage.target.Radius + game.MagicMissileRadius;
                            StrategyHelper.Log("\tMagic attack");
                        }
                    }
                }
            }
        }
Пример #9
0
        public virtual void Tick(Game game, World world, Wizard self, Move move)
        {
            if (world.TickIndex == 0)
            {
                StrategyStorage.Init(game, world, self);
            }
            else
            {
                StrategyStorage.Tick(game, world, self);
            }

            Bonus bonus = StrategyHelper.NearedBonus(world, self);

            if (bonus != null)
            {
                StrategyStorage.target      = null;
                StrategyStorage.currentTurn = self.GetAngleTo(bonus);
            }
            else
            {
                StrategyStorage.target = StrategyHelper.NearedTarget(game, world, self);
            }

            if (self.SpeedX == 0 && self.SpeedY == 0 && (StrategyStorage.target == null || (self.GetDistanceTo(StrategyStorage.target) > self.CastRange)))
            {
                StrategyStorage.collisionObject = StrategyHelper.CollizedObject(self, world);
            }

            this.Run(game, world, self, move);

            if (StrategyStorage.target != null && (StrategyStorage.collisionObject == null || (self.GetDistanceTo(StrategyStorage.target) > self.CastRange)))
            {
                StrategyStorage.currentTurn = self.GetAngleTo(StrategyStorage.target);
            }

            if (StrategyStorage.collisionObject != null && (StrategyStorage.target == null || (self.GetDistanceTo(StrategyStorage.target) > self.CastRange)))
            {
                StrategyStorage.currentTurn = self.GetAngleTo(StrategyStorage.collisionObject);
            }

            if (StrategyStorage.needRun)
            {
                StrategyStorage.currentStrafe = 0;
            }

            move.StrafeSpeed = StrategyStorage.currentStrafe;
            if (move.StrafeSpeed == 0)
            {
                move.Speed = StrategyStorage.currentSpeed;
                move.Turn  = StrategyStorage.currentTurn;
            }
        }