Exemple #1
0
        private double HandleOtherRobot(IHommRobot otherRobot)
        {
            var combatTriggerTime = BeginCombat(otherRobot.Player, map[robot.Player.Location], map[newLocation]);

            otherRobot.ControlTrigger.ScheduledTime = combatTriggerTime + 0.01;
            return(HommRules.Current.CombatDuration);
        }
Exemple #2
0
 public CombatHelper(IHommRobot robot)
 {
     this.robot   = robot;
     world        = robot.World;
     player       = robot.Player;
     hommEngine   = world.HommEngine;
     commonEngine = world.CommonEngine;
 }
Exemple #3
0
        private static void DoUpdateLocation(IHommRobot actor, Location newLocation)
        {
            actor.World.Round.Update(actor.Player, newLocation);

            if (actor.Player.HasNoArmy())
            {
                actor.Die();
            }
        }
Exemple #4
0
        private double HandleMovementCollision(IHommRobot collisionRobot)
        {
            robot.World.Clocks.AddTrigger(new OneTimeTrigger(collisionRobot.ControlTrigger.ScheduledTime,
                                                             () =>
            {
                var combatTriggerTime = BeginCombat(collisionRobot.Player, map[robot.Player.Location], map[newLocation]);
                collisionRobot.ControlTrigger.ScheduledTime = combatTriggerTime + 0.01;
            }));

            collisionRobot.ControlTrigger.ScheduledTime = double.PositiveInfinity;

            return(double.PositiveInfinity);
        }
Exemple #5
0
        internal double Apply(IHommRobot robot)
        {
            robot.World.HommEngine.Freeze(robot.ControllerId);
            robot.World.HommEngine.SetPosition(robot.ControllerId, robot.Player.Location.X, robot.Player.Location.Y);

            if (WaitDuration != 0)
            {
                robot.World.HommEngine.SetAnimation(robot.ControllerId, Animation.Idle);
                return(WaitDuration);
            }

            return(new MovementHelper(robot, MovementDirection).CheckForCombatAndMovePlayer());
        }
Exemple #6
0
        public MovementHelper(IHommRobot robot, Direction movementDirection)
        {
            this.robot             = robot;
            this.movementDirection = movementDirection;

            world        = robot.World;
            hommEngine   = world.HommEngine;
            commonEngine = world.CommonEngine;
            player       = robot.Player;
            map          = world.Round.Map;

            newLocation      = player.Location.NeighborAt(movementDirection);
            movementDuration = GetTravelDuration(player, map);
        }
Exemple #7
0
        private void Resolve(HommWorld world, IHommRobot first, IHommRobot second)
        {
            var currentTime    = world.Clocks.CurrentTime;
            var combatDuration = HommRules.Current.CombatDuration;

            var firstAvailable = combatQueue.ContainsKey(first) ? combatQueue[first] : currentTime;
            var otherAvailable = combatQueue.ContainsKey(second) ? combatQueue[second] : currentTime;

            var thisCombatStart = Math.Max(firstAvailable, otherAvailable);
            var thisCombatEnd   = combatQueue[first] = combatQueue[second] = thisCombatStart + combatDuration;

            world.Clocks.AddTrigger(new OneTimeTrigger(thisCombatStart, () =>
            {
                if (first.IsDisabled || second.IsDisabled)
                {
                    return;
                }

                // TODO: play combat animation

                world.Clocks.AddTrigger(new OneTimeTrigger(thisCombatEnd, () =>
                {
                    currentCombats.Remove(Tuple.Create(first, second));
                    currentCombats.Remove(Tuple.Create(second, first));

                    if (combatQueue[first] == thisCombatEnd)
                    {
                        combatQueue.Remove(first);
                    }

                    if (combatQueue[second] == thisCombatEnd)
                    {
                        combatQueue.Remove(second);
                    }

                    Combat.ResolveBattle(first.Player, second.Player);

                    if (first.Player.HasNoArmy())
                    {
                        first.Die();
                    }

                    if (second.Player.HasNoArmy())
                    {
                        second.Die();
                    }
                }));
            }));
        }
Exemple #8
0
        protected override bool TileFilter(Tile tile, IHommRobot actor, Player playerOnTile)
        {
            var scout       = actor.Player.Scout;
            var scoutRadius = HommRules.Current.ScoutRadius;

            var tileIsObservableByTileScout =
                scout.IsScoutingTile && tile.Location.EuclideanDistance(scout.TileBeingScouted) <= scoutRadius;

            var tileIsObservableByHeroScout =
                scout.IsScoutingHero && playerOnTile != null;

            var tileIsObservableByScout = tileIsObservableByTileScout || tileIsObservableByHeroScout;

            return(tileIsObservableByScout || base.TileFilter(tile, actor, playerOnTile));
        }
Exemple #9
0
        private void MakeTurn(IHommRobot robot)
        {
            hommEngine.SetRotation(robot.ControllerId, movementDirection.ToUnityAngle());

            if (world.IsEnemySpawn(newLocation, robot.ControllerId))
            {
                hommEngine.SetAnimation(robot.ControllerId, Animation.Idle);
                hommEngine.Freeze(robot.ControllerId);
                return;
            }

            player.DesiredLocation = newLocation;

            hommEngine.SetAnimation(robot.ControllerId, Animation.Gallop);
            hommEngine.Move(robot.Player.Name, movementDirection, movementDuration);

            world.Clocks.AddTrigger(new LocationTrigger(robot.World.Clocks.CurrentTime,
                                                        movementDuration, robot, newLocation));
        }
Exemple #10
0
        public double Resolve(IHommRobot actor)
        {
            var others = actor.World.Actors
                         .Where(x => x is IHommRobot)
                         .Cast <IHommRobot>()
                         .Where(x => x != actor && x.Player.Location == actor.Player.Location)
                         .Where(x => !currentCombats.Contains(Tuple.Create(actor, x)));

            double timeInCombat = 0;

            foreach (var other in others)
            {
                currentCombats.Add(Tuple.Create(actor, other));
                timeInCombat += HommRules.Current.CombatDuration;

                if (!currentCombats.Contains(Tuple.Create(other, actor)))
                {
                    Resolve(actor.World, actor, other);
                }
            }

            return(timeInCombat);
        }
Exemple #11
0
 public GarrisonBuilderUnit(IHommRobot actor)
 {
     this.actor = actor;
 }
Exemple #12
0
 protected virtual bool TileFilter(Tile tile, IHommRobot actor, Player playerOnTile) =>
 tile.Location.EuclideanDistance(actor.Player.Location) <= actor.ViewRadius;
Exemple #13
0
 protected virtual bool PlayerFilter(Player player, IHommRobot robot) =>
 player.Location.EuclideanDistance(robot.Player.Location) <= robot.ViewRadius;
Exemple #14
0
 public HexMovUnit(IHommRobot actor)
 {
     this.actor = actor;
 }
Exemple #15
0
 public ArmyInterfaceUnit(IHommRobot actor)
 {
     this.actor = actor;
 }
Exemple #16
0
 public LocationTrigger(double submitTime, double movementDuration, IHommRobot actor, Location newLocation)
     : base(submitTime + movementDuration, () => DoUpdateLocation(actor, newLocation))
 {
 }
Exemple #17
0
 public ScoutInterfaceUnit(IHommRobot actor)
 {
     this.actor = actor;
 }
Exemple #18
0
 private static void DoUpdateLocation(IHommRobot actor, Location newLocation)
 {
     actor.World.Round.Update(actor.Player, newLocation);
     actor.World.HommEngine.Freeze(actor.ControllerId);
 }
Exemple #19
0
 protected override bool PlayerFilter(Player player, IHommRobot robot)
 {
     return(robot.Player.Scout.IsScoutingHero || robot.Player.Scout.IsScoutingTile || base.PlayerFilter(player, robot));
 }