Exemple #1
0
 public CombatResult(ICombatResult result)
 {
     CombatId = result.CombatId;
     m_Rounds = new List <CombatRoundResult>();
     foreach (ICombatRoundResult roundResult in result.Rounds)
     {
         m_Rounds.Add(new CombatRoundResult(roundResult));
     }
 }
        static public void IsArmyResult(Guid regionId, UInt32 numberOfSurvivedRounds, UInt32 expectedTroopLoss, ICombatResult result)
        {
            UInt32 roundsSurvived = 0;
            UInt32 troopsLost     = 0;

            foreach (ICombatRoundResult round in result.Rounds)
            {
                var armyResults = round.ArmyResults.Where(armyResult => armyResult.OriginRegionId == regionId).FirstOrDefault();
                if (roundsSurvived == numberOfSurvivedRounds)
                {
                    Assert.IsNull(armyResults);
                }
                else
                {
                    Assert.IsNotNull(armyResults);
                    troopsLost     += armyResults.TroopsLost;
                    roundsSurvived += 1;
                }
            }

            Assert.AreEqual(expectedTroopLoss, troopsLost);
        }
        static public void IsResultValid(UInt32 numberOfRounds, ICombat sourceCombat, ICombatResult result)
        {
            Assert.AreEqual(numberOfRounds, (UInt32)result.Rounds.Count());
            Assert.AreEqual(sourceCombat.InvolvedArmies.Where(army => army.NumberOfTroops > 0).Count(), result.Rounds.First().ArmyResults.Count());

            foreach (ICombatRoundResult round in result.Rounds)
            {
                foreach (ICombatArmy army in sourceCombat.InvolvedArmies)
                {
                    var armyResults = round.ArmyResults.Where(armyResult => armyResult.OriginRegionId == army.OriginRegionId).FirstOrDefault();
                    if (armyResults != null)
                    {
                        Assert.IsNotNull(armyResults.RolledResults);
                        Assert.AreEqual(army.OwnerUserId, armyResults.OwnerUserId);
                        if (army.ArmyMode == CombatArmyMode.Defending)
                        {
                            Assert.IsTrue(2 >= armyResults.RolledResults.Count() && 1 <= armyResults.RolledResults.Count(), "Defender can only roll 1 or 2 dice");
                        }
                        else
                        {
                            Assert.IsTrue(3 >= armyResults.RolledResults.Count() && 1 <= armyResults.RolledResults.Count(), "Attacker can only roll 1, 2 or 3 dice");
                        }

                        switch (sourceCombat.ResolutionType)
                        {
                        case CombatType.BorderClash:
                            Assert.IsTrue(3 >= armyResults.TroopsLost, "An army cannot lose more than three troops in a round");
                            break;

                        case CombatType.Invasion:
                            Assert.IsTrue(2 >= armyResults.TroopsLost, "An army cannot lose more than two troops in a round");
                            break;
                        }
                    }
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// The log attack.
 /// </summary>
 /// <param name="attack">
 /// The attack.
 /// </param>
 /// <param name="result">
 /// The result.
 /// </param>
 public void LogAttack(IAttackCommand attack, ICombatResult result)
 {
     this.logCounter++;
     string logMessage = string.Format("{0} performed {1} on {2} with the result: \n\r {3}.", attack.Attacker.Name, attack.Description, attack.Target.Name, result.ResultDescription());
     Log.Info("log4net: " + logMessage);
     this.LastMessage = logMessage;
     this.InvokeLogMessage(logMessage);
 }