Ejemplo n.º 1
0
        public static void ResolveBattle(ICombatable p1, ICombatable p2)
        {
            double atkDmgMod = (p1.Attack - p2.Defence) * ((p1.Attack - p2.Defence > 0) ? 0.05 : 0.025);
            double defDmgMod = (p2.Attack - p1.Defence) * ((p2.Attack - p1.Defence > 0) ? 0.05 : 0.025);

            while (!p1.HasNoArmy() && !p2.HasNoArmy())
            {
                var p2NewArmy = ResolveTurn(p1, p2, atkDmgMod);
                var p1NewArmy = ResolveTurn(p2, p1, defDmgMod);

                foreach (var unitType in p1NewArmy.Keys)
                {
                    p1.Army[unitType] = p1NewArmy[unitType];
                }
                foreach (var unitType in p2NewArmy.Keys)
                {
                    p2.Army[unitType] = p2NewArmy[unitType];
                }
            }
        }
Ejemplo n.º 2
0
        public double BeginCombat(ICombatable other, Tile robotTile, Tile otherTile, Action onPlayerWin)
        {
            robotTile.BeginCombat();
            otherTile.BeginCombat();

            hommEngine.Freeze(player.Name);
            hommEngine.Freeze(other.UnityId);

            hommEngine.SetRotation(player.Name, robotTile.Location.GetDirectionTo(otherTile.Location).ToUnityAngle());
            hommEngine.SetRotation(other.UnityId, otherTile.Location.GetDirectionTo(robotTile.Location).ToUnityAngle());

            hommEngine.SetAnimation(player.Name, Animation.Attack);
            hommEngine.SetAnimation(other.UnityId, Animation.Attack);

            var combatTriggerTime = world.Clocks.CurrentTime + HommRules.Current.CombatDuration;

            world.Clocks.AddTrigger(new OneTimeTrigger(combatTriggerTime, () =>
            {
                var initialOtherArmy = new Dictionary <UnitType, int>(other.Army);

                Combat.Resolve(player, other);

                var armies = new ArmiesPair(player.Army, other.Army);
                armies.Log("after Combat.ResolveBattle");

                if (other.HasNoArmy())
                {
                    Debugger.Log("other has no army");

                    if (other is TileObject)
                    {
                        Debugger.Log("other is tile object, delete it");

                        ((TileObject)other).OnRemove();
                    }

                    if (other is Player)
                    {
                        var otherPlayer = other as Player;

                        world.Actors
                        .Where(x => x is IHommRobot)
                        .Cast <IHommRobot>()
                        .Single(x => x.Player.Name == otherPlayer.Name)
                        .Die();
                    }

                    player.OnVictoryAchieved(other, initialOtherArmy);
                }
                else
                {
                    hommEngine.SetAnimation(other.UnityId, Animation.Idle);
                }

                if (player.HasNoArmy())
                {
                    robot.Die();
                }
                else
                {
                    onPlayerWin();
                }

                robotTile.EndCombat();
                otherTile.EndCombat();
            }));

            return(combatTriggerTime);
        }