public static IStrategyState GetState(World world, Wizard self) { /* Основная логика игры */ StrategyStates strategyState = StrategyStates.Game; if (self.Life == 0) { /* Жизней 0 - мертв */ strategyState = StrategyStates.None; } else if (StrategyStorage.prepareTick < StrategyStorage.waitTimer) { strategyState = StrategyStates.Prepare; } else if (StrategyStorage.prevLife == 0 && self.Life > 0) { StrategyHelper.Log(String.Format("RESPAWN, tick {0}", world.TickIndex)); int enemyCount = StrategyHelper.CountEnemyInCastRange(world, self); StrategyStorage.priorityLane = null; strategyState = enemyCount == 0 ? StrategyStates.Prepare : StrategyStates.Game; StrategyHelper.Log(String.Format("\tEnemyCount: {0}, work strategy: {1}", Enum.GetName(typeof(StrategyStates), strategyState))); } StrategyHelper.Log(String.Format("strategy {0}, tick: {1}", Enum.GetName(typeof(StrategyStates), strategyState).ToUpper(), world.TickIndex)); return(StrategyStateManager.strategyStates[strategyState]); }
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"); } } }
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; } }
public static void Init(Game game, World world, Wizard self) { myId = self.Id; waitTimer = game.TickCount / TIMEOUTDELUMETER; safeDistance = self.CastRange / DISTANCEDELUMETER; halfLife = self.MaxLife / 2; visionRange = self.VisionRange / 2; spawnPointX = self.X; spawnPointY = self.Y; mainBase = StrategyHelper.MainBase(world, self); prevLife = self.Life; positionTop = self.Y < (world.Height / 2); badGuyFaction = self.Faction == Faction.Academy ? Faction.Renegades : Faction.Academy; }
public override void Run(Game game, World world, Wizard self, Move move) { StrategyStorage.prepareTick++; if (StrategyStorage.priorityLane == null) { switch (random.Next(3)) { case 0: StrategyStorage.waitTimer = game.TickCount / 15; StrategyStorage.priorityLane = LaneType.Bottom; break; case 1: StrategyStorage.waitTimer = game.TickCount / 30; StrategyStorage.priorityLane = LaneType.Middle; break; case 2: default: StrategyStorage.waitTimer = game.TickCount / 15; StrategyStorage.priorityLane = LaneType.Top; break; } // TODO: Пока ходим только по миду //StrategyStorage.priorityLane = LaneType.Middle; StrategyHelper.Log(String.Format("\tChosen line: {0}", StrategyStorage.priorityLane)); } else { if (StrategyStorage.priorityLane == LaneType.Bottom) { StrategyStorage.currentTurn = self.GetAngleTo(StrategyStorage.positionTop ? 0 : world.Width, self.Y); } else if (StrategyStorage.priorityLane == LaneType.Middle) { StrategyStorage.currentTurn = self.GetAngleTo(StrategyStorage.mainBase.Y, StrategyStorage.mainBase.X); } else if (StrategyStorage.priorityLane == LaneType.Top) { StrategyStorage.currentTurn = self.GetAngleTo(self.X, StrategyStorage.positionTop ? world.Height : 0); } } this.InitSpeed(game, world, self, move, 0.7); this.CheckCollision(game, world, self, move); }
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); } }
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"); } } } } }