コード例 #1
0
        public void PerformRangedAttack_FiresRangedCombatWithUnitSignal()
        {
            var attackerLocation = BuildCell();
            var defenderLocation = BuildCell();

            Mock <IUnit> attackerMock;
            var          attacker = BuildUnit(3f, 100, attackerLocation, out attackerMock);
            var          defender = BuildUnit(currentMovement: 0f, currentHitpoints: 100, location: defenderLocation);

            var combatInfo = new CombatInfo();

            MockCombatInfoLogic.Setup(logic => logic.GetAttackInfo(attacker, defender, defenderLocation, CombatType.Ranged))
            .Returns(combatInfo);

            MockRangedAttackValidityLogic.Setup(logic => logic.IsRangedAttackValid(attacker, defender)).Returns(true);

            attackerMock.Setup(unit => unit.PerformMovement(false, It.IsAny <Action>()))
            .Callback <bool, Action>((ignoreMovementCosts, postMovementCallback) => postMovementCallback());

            var executer = Container.Resolve <CombatExecuter>();

            executer.PerformRangedAttack(attacker, defender);

            MockCommonCombatExecutionLogic.Verify(
                logic => logic.PerformCommonCombatTasks(attacker, defender, combatInfo), Times.Once
                );
        }
コード例 #2
0
        public void RespondToCombat_AndValidCityCapture_AttackerChangesDefendingOwnerOfDefendingCity()
        {
            var attackerOwner = BuildCivilization();

            var attacker = BuildUnit(attackerOwner, 0, UnitType.Melee);

            var cityOwner    = BuildCivilization();
            var cityLocation = BuildHexCell();

            var cityBeingCaptured = BuildCity(
                cityLocation, cityOwner, BuildUnit(cityOwner, 0, UnitType.City), new List <IUnit>()
                );

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var conquestLogic = Container.Resolve <CityConquestResponder>();

            conquestLogic.RespondToCombat(attacker, cityBeingCaptured.CombatFacade, combatInfo);

            MockCityPossessionCanon.Verify(
                canon => canon.ChangeOwnerOfPossession(cityBeingCaptured, attackerOwner),
                Times.Once, "City was not transferred to the attacker's owner as expected"
                );
        }
コード例 #3
0
        public void RespondToCombat_DoesNothingIfAttackerOwnerWasBarbaric()
        {
            var attackerOwner = BuildCivilization(true);

            var attacker = BuildUnit(attackerOwner, 0, UnitType.Melee);

            var cityOwner    = BuildCivilization();
            var cityLocation = BuildHexCell();

            var cityBeingCaptured = BuildCity(
                cityLocation, cityOwner, BuildUnit(cityOwner, 0, UnitType.City), new List <IUnit>()
                );

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var conquestLogic = Container.Resolve <CityConquestResponder>();

            conquestLogic.RespondToCombat(attacker, cityBeingCaptured.CombatFacade, combatInfo);

            MockCityPossessionCanon.Verify(
                canon => canon.ChangeOwnerOfPossession(cityBeingCaptured, attackerOwner),
                Times.Never, "City was unexpectedly transferred to the attacker's owner"
                );
        }
コード例 #4
0
        public void PerformCommonCombatTasks_CallsIntoAllPostCombatResponders()
        {
            var attacker = BuildUnit(100, false, new UnitCombatSummary());
            var defender = BuildUnit(100, false, new UnitCombatSummary());

            var combatInfo = new CombatInfo();

            BuildResponder();
            BuildResponder();
            BuildResponder();

            MockCombatCalculator.Setup(calculator => calculator.CalculateCombat(attacker, defender, combatInfo))
            .Returns(new Tuple <int, int>(0, 0));

            var executionLogic = Container.Resolve <CommonCombatExecutionLogic>();

            executionLogic.PerformCommonCombatTasks(attacker, defender, combatInfo);

            foreach (var mockResponder in MockPostCombatResponders)
            {
                mockResponder.Verify(
                    responder => responder.RespondToCombat(attacker, defender, combatInfo),
                    Times.Once, "A PostCombatResponder wasn't called into as expected"
                    );
            }
        }
コード例 #5
0
	public bool IsUnitInAttackQueue(Unit unit){
		Debug.Log ("queue Length: " + hitQueue.Count);
		for (int i=0; i<hitQueue.Count; ++i) {
			CombatInfo temp = hitQueue.ElementAt(i);
			if (temp is AttackInfo){
				AttackInfo attackInfo = (AttackInfo)temp;
				if (unit == attackInfo.attack.target || unit == attackInfo.retalition.target){
					return true;
				}
				for (int ii=0; ii<attackInfo.additionalTargets.Count; ++ii){
					if (attackInfo.additionalTargets[ii].target==unit){
						return true;
					}
					
				}
				
			}else if (temp is SpellInfo){
				SpellInfo attackInfo = (SpellInfo)temp;
				if (unit == attackInfo.target.Unit){
					return true;
				}
				for (int ii=0; ii<attackInfo.hitInfos.Count; ++ii){
					if (attackInfo.hitInfos[ii].target==unit){
						return true;
					}
				}
			}
		}
		return false;
	}
コード例 #6
0
        public void RespondToCombat_CityOwnerCannotLoseNegativeGold()
        {
            var attacker = BuildUnit(100, UnitType.Melee);
            var defender = BuildUnit(0, UnitType.City);

            var cityBeingAttacked = BuildCity(-10, defender);

            var cities = new List <ICity>()
            {
                cityBeingAttacked, BuildCity(100, null)
            };

            BuildCiv(100, new List <ICity>(), BuildCivTemplate(true), attacker);

            var defendingCiv = BuildCiv(100, cities, BuildCivTemplate(false), defender);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var responder = Container.Resolve <CitySackResponder>();

            responder.RespondToCombat(attacker, defender, combatInfo);

            Assert.AreEqual(100, defendingCiv.GoldStockpile);
        }
コード例 #7
0
        public void PerformMeleeAttack_AfterMovement_AndAttackStillValid_CallsSuccessAction()
        {
            var attackerLocation = BuildCell();
            var defenderLocation = BuildCell();

            Mock <IUnit> attackerMock;
            var          attacker = BuildUnit(3f, 100, attackerLocation, out attackerMock);
            var          defender = BuildUnit(currentMovement: 0f, currentHitpoints: 100, location: defenderLocation);

            var path = new List <IHexCell>()
            {
                BuildCell()
            };

            MockHexPathfinder.Setup(pathfinder => pathfinder.GetShortestPathBetween(
                                        attackerLocation, defenderLocation, 3f, It.IsAny <Func <IHexCell, IHexCell, float> >(),
                                        AllCells
                                        )).Returns(path);

            var combatInfo = new CombatInfo();

            MockCombatInfoLogic.Setup(logic => logic.GetAttackInfo(attacker, defender, defenderLocation, CombatType.Melee))
            .Returns(combatInfo);

            MockMeleeAttackValidityLogic.Setup(logic => logic.IsMeleeAttackValid(attacker, defender)).Returns(true);

            attackerMock.Setup(unit => unit.PerformMovement(false, It.IsAny <Action>()))
            .Callback <bool, Action>((ignoreMovementCosts, postMovementCallback) => postMovementCallback());

            var executer = Container.Resolve <CombatExecuter>();

            executer.PerformMeleeAttack(attacker, defender, () => Assert.Pass(), () => Assert.Fail("Fail action unexpectedly called"));

            Assert.Fail("Success action wasn't called as expected");
        }
コード例 #8
0
    void SetText()
    {
        CombatInfo c     = CombatInfo.Instance;
        Label      label = GetNode <Label>("Label");

        label.Text = "Round: " + c.currentRound.ToString() + " / " + c.maxRounds.ToString();
    }
        public void RespondToCombat_DefenderIsDestroyedIfTemplateIsCapturable_ButCombatTypeIsNotMelee()
        {
            var templates = new List <IUnitTemplate>()
            {
                BuildTemplate(), BuildTemplate(), BuildTemplate()
            };

            MockUnitConfig.Setup(config => config.CapturableTemplates).Returns(templates);

            Mock <IUnit> attackerMock, defenderMock;

            var attacker = BuildUnit(50, UnitType.Melee, BuildCell(), null, out attackerMock);
            var defender = BuildUnit(0, UnitType.Melee, BuildCell(), templates[1], out defenderMock);

            var attackerOwner = BuildCiv();

            MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(attacker)).Returns(attackerOwner);
            MockUnitPossessionCanon.Setup(canon => canon.CanChangeOwnerOfPossession(defender, attackerOwner)).Returns(true);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Ranged
            };

            var destructionLogic = Container.Resolve <DestructionPostCombatResponder>();

            destructionLogic.RespondToCombat(attacker, defender, combatInfo);

            MockUnitPossessionCanon.Verify(
                canon => canon.ChangeOwnerOfPossession(defender, attackerOwner),
                Times.Never, "ChangeOwnerOfPossession was unexpectedly called"
                );

            defenderMock.Verify(unit => unit.Destroy(), Times.Once, "Defender.Destroy() was not called as expected");
        }
コード例 #10
0
        public void RespondToCombat_DoesNothingIfDefenderNotACity()
        {
            var attacker = BuildUnit(100, UnitType.Melee);
            var defender = BuildUnit(0, UnitType.Melee);

            var cityBeingAttacked = BuildCity(10, defender);

            BuildCiv(100, new List <ICity>(), BuildCivTemplate(true), attacker);

            var defendingCiv = BuildCiv(
                100, new List <ICity>()
            {
                cityBeingAttacked
            }, BuildCivTemplate(false), defender
                );

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var responder = Container.Resolve <CitySackResponder>();

            responder.RespondToCombat(attacker, defender, combatInfo);

            Assert.AreEqual(100, defendingCiv.GoldStockpile);
        }
        public void RespondToCombat_DefenderIsCapturedIfTemplateIsCapturable_AndAttackerOwnerCanPossessIt()
        {
            var templates = new List <IUnitTemplate>()
            {
                BuildTemplate(), BuildTemplate(), BuildTemplate()
            };

            MockUnitConfig.Setup(config => config.CapturableTemplates).Returns(templates);

            Mock <IUnit> attackerMock, defenderMock;

            var attacker = BuildUnit(50, UnitType.Melee, BuildCell(), null, out attackerMock);
            var defender = BuildUnit(0, UnitType.Melee, BuildCell(), templates[1], out defenderMock);

            var attackerOwner = BuildCiv();

            MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(attacker)).Returns(attackerOwner);
            MockUnitPossessionCanon.Setup(canon => canon.CanChangeOwnerOfPossession(defender, attackerOwner)).Returns(true);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var destructionLogic = Container.Resolve <DestructionPostCombatResponder>();

            destructionLogic.RespondToCombat(attacker, defender, combatInfo);

            MockUnitPossessionCanon.Verify(
                canon => canon.ChangeOwnerOfPossession(defender, attackerOwner), Times.Once
                );
        }
        public void RespondToCombat_AttackerDoesNotMoveIfAttackerDead()
        {
            Mock <IUnit> attackerMock, defenderMock;

            var defenderLocation = BuildCell();

            var attacker = BuildUnit(0, UnitType.Melee, BuildCell(), null, out attackerMock);
            var defender = BuildUnit(0, UnitType.Melee, defenderLocation, null, out defenderMock);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var destructionLogic = Container.Resolve <DestructionPostCombatResponder>();

            destructionLogic.RespondToCombat(attacker, defender, combatInfo);

            Assert.Null(
                attacker.CurrentPath,
                "attacker.CurrentPath has an unexpected value"
                );

            attackerMock.Verify(
                unit => unit.PerformMovement(It.IsAny <bool>()), Times.Never,
                "attacker.PerformMovement was unexpectedly called"
                );
        }
        public void RespondToCombat_MovesAttackerOntoLocationWhenValid()
        {
            Mock <IUnit> attackerMock, defenderMock;

            var defenderLocation = BuildCell();

            var attacker = BuildUnit(50, UnitType.Melee, BuildCell(), null, out attackerMock);
            var defender = BuildUnit(0, UnitType.Melee, defenderLocation, null, out defenderMock);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var destructionLogic = Container.Resolve <DestructionPostCombatResponder>();

            destructionLogic.RespondToCombat(attacker, defender, combatInfo);

            CollectionAssert.AreEqual(
                new List <IHexCell>()
            {
                defenderLocation
            }, attacker.CurrentPath,
                "attacker.CurrentPath has an unexpected value"
                );

            attackerMock.Verify(
                unit => unit.PerformMovement(false), Times.Once,
                "attacker.PerformMovement wasn't called as expected"
                );
        }
コード例 #14
0
        public void RespondToCombat_AndCityWasCaptured_CityCaptureSignalFired()
        {
            var attackerOwner = BuildCivilization();

            Mock <IUnit> attackerMock;
            var          attacker = BuildUnit(attackerOwner, 0, UnitType.Melee, out attackerMock);

            var cityOwner    = BuildCivilization();
            var cityLocation = BuildHexCell();

            var cityBeingCaptured = BuildCity(
                cityLocation, cityOwner, BuildUnit(cityOwner, 0, UnitType.City), new List <IUnit>()
                );

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var conquestLogic = Container.Resolve <CityConquestResponder>();

            CitySignals.CityCaptured.Subscribe(delegate(CityCaptureData captureData) {
                Assert.AreEqual(cityBeingCaptured, captureData.City, "Incorrect City passed");
                Assert.AreEqual(cityOwner, captureData.OldOwner, "Incorrect OldOwner passed");
                Assert.AreEqual(attackerOwner, captureData.NewOwner, "Incorrect NewOwner passed");

                Assert.Pass();
            });

            conquestLogic.RespondToCombat(attacker, cityBeingCaptured.CombatFacade, combatInfo);

            Assert.Fail("Event not evoked");
        }
コード例 #15
0
 public Template(AgentBase agent)
     : base(agent, new string[] { "TemplateAction1ToBlock",
                                  "TemplateAction2ToBlock" },
            new string[] { "TemplateSense1ToBlock",
                           "TemplateSense2ToBlock" })
 {
     info = new CombatInfo();
 }
コード例 #16
0
    public override void _Ready()
    {
        Reset();

        Instance = this;

        Events.dinoDiedType += OnDinoDiedType;
        Events.conquestWon  += Reset; // reset after a conquest is won; this ensures that when a new round starts, currentRound is 1 (which is used in CombatArmyCreator.cs)
    }
コード例 #17
0
 public RuneMetricsProfile(string name, SkillScore overall, CombatInfo combat, QuestsInfo quests, RuneMetricsSkillScores skills, IList <AdventurersLogActivity> activities)
 {
     Name       = name;
     Overall    = overall;
     Combat     = combat;
     Quests     = quests;
     Skills     = skills;
     Activities = activities;
 }
コード例 #18
0
        public void PerformMeleeAttack_AfterMovement_FiresMeleeCombatWithUnitSignal()
        {
            var attackerLocation = BuildCell();
            var defenderLocation = BuildCell();

            Mock <IUnit> attackerMock;
            var          attacker = BuildUnit(3f, 100, attackerLocation, out attackerMock);
            var          defender = BuildUnit(currentMovement: 0f, currentHitpoints: 100, location: defenderLocation);

            var path = new List <IHexCell>()
            {
                BuildCell()
            };

            MockHexPathfinder.Setup(pathfinder => pathfinder.GetShortestPathBetween(
                                        attackerLocation, defenderLocation, 3f, It.IsAny <Func <IHexCell, IHexCell, float> >(),
                                        AllCells
                                        )).Returns(path);

            var combatInfo = new CombatInfo();

            MockCombatInfoLogic.Setup(logic => logic.GetAttackInfo(attacker, defender, defenderLocation, CombatType.Melee))
            .Returns(combatInfo);

            MockMeleeAttackValidityLogic.Setup(logic => logic.IsMeleeAttackValid(attacker, defender)).Returns(true);

            attackerMock.Setup(unit => unit.PerformMovement(false, It.IsAny <Action>()))
            .Callback <bool, Action>((ignoreMovementCosts, postMovementCallback) => postMovementCallback());

            MockCommonCombatExecutionLogic.Setup(
                logic => logic.PerformCommonCombatTasks(attacker, defender, combatInfo)
                ).Callback <IUnit, IUnit, CombatInfo>(
                (attkr, dfndr, info) => { attkr.CurrentHitpoints -= 30; dfndr.CurrentHitpoints -= 40; }
                );

            UnitSignals.MeleeCombatWithUnit.Subscribe(delegate(UnitCombatResults results) {
                Assert.AreEqual(attacker, results.Attacker, "Results had an unexpected Attacker");
                Assert.AreEqual(defender, results.Defender, "Results had an unexpected Defender");
                Assert.AreEqual(30, results.DamageToAttacker, "Results had an unexpected DamageToAttacker");
                Assert.AreEqual(40, results.DamageToDefender, "Results had an unexpected DamageToDefender");
                Assert.AreEqual(combatInfo, results.InfoOfAttack, "Results had an unexpected Attacker");
                Assert.Pass();
            });

            var executer = Container.Resolve <CombatExecuter>();

            executer.PerformMeleeAttack(attacker, defender, () => { }, () => { });

            Assert.Fail("MeleeCombatWithUnitSignal never fired");
        }
コード例 #19
0
        void combatTracker_CombatInfoUpdated(CombatInfo obj)
        {
            AddNamesToList(obj.SourceName, obj.TargetName);

            if (!String.IsNullOrEmpty(obj.SourceName) && obj.SourceName != CoreManager.Current.CharacterFilter.Name)
            {
                loadInfoForName(obj.SourceName);
            }

            if (!String.IsNullOrEmpty(obj.TargetName) && obj.TargetName != CoreManager.Current.CharacterFilter.Name)
            {
                loadInfoForName(obj.TargetName);
            }
        }
コード例 #20
0
        public void ApplyAurasToCombat_AddsAttackerAurasOfNearbyFriendlyUnitsToAttackerModifier()
        {
            var domesticCiv = BuildCiv();
            var foreignCiv  = BuildCiv();

            var attacker = BuildUnit(domesticCiv, new UnitCombatSummary());
            var defender = BuildUnit(foreignCiv, new UnitCombatSummary());

            var domesticWithinRange = BuildUnit(
                domesticCiv, new UnitCombatSummary()
            {
                auraModifiersWhenAttacking = new List <ICombatModifier>()
                {
                    BuildModifier(10f, true), BuildModifier(10f, true)
                },
            }
                );

            var foreignWithinRange = BuildUnit(
                foreignCiv, new UnitCombatSummary()
            {
                auraModifiersWhenAttacking = new List <ICombatModifier>()
                {
                    BuildModifier(12f, true)
                }
            }
                );

            var cellWithinRange = BuildCell(domesticWithinRange, foreignWithinRange);

            var attackerLocation = BuildCell(attacker);
            var defenderLocation = BuildCell(defender);

            MockUnitConfig.Setup(config => config.AuraRange).Returns(7);

            MockGrid.Setup(grid => grid.GetCellsInRadius(attackerLocation, 7)).Returns(new List <IHexCell>()
            {
                cellWithinRange
            });
            MockGrid.Setup(grid => grid.GetCellsInRadius(defenderLocation, 7)).Returns(new List <IHexCell>());

            var combatInfo = new CombatInfo();

            var auraLogic = Container.Resolve <CombatAuraLogic>();

            auraLogic.ApplyAurasToCombat(attacker, defender, combatInfo);

            Assert.AreEqual(20f, combatInfo.AttackerCombatModifier);
        }
コード例 #21
0
    // Start is called before the first frame update
    void Awake()
    {
        if (InformationController.infoController == null)
        {
            InformationController.infoController = this;
        }
        else
        {
            Destroy(this.gameObject);
        }

        DontDestroyOnLoad(this.gameObject);

        //Save info for the first iteration in the first room
        combatInfo = new CombatInfo();
    }
コード例 #22
0
        public void PerformCommonCombatTasks_ReducesParticipiantHealthFromCalculatedCombatResults()
        {
            var attacker = BuildUnit(100, false, new UnitCombatSummary());
            var defender = BuildUnit(100, false, new UnitCombatSummary());

            var combatInfo = new CombatInfo();

            MockCombatCalculator.Setup(calculator => calculator.CalculateCombat(attacker, defender, combatInfo))
            .Returns(new Tuple <int, int>(40, 55));

            var executionLogic = Container.Resolve <CommonCombatExecutionLogic>();

            executionLogic.PerformCommonCombatTasks(attacker, defender, combatInfo);

            Assert.AreEqual(60, attacker.CurrentHitpoints, "Attacker.CurrentHitpoints has an unexpected value");
            Assert.AreEqual(45, defender.CurrentHitpoints, "Defender.CurrentHitpoints has an unexpected value");
        }
コード例 #23
0
        public void ApplyCityModifiersToCombat_DoesNotApplyBonusesIfNoCityOnCell()
        {
            var cell = BuildCell();

            var attacker = BuildUnit(UnitType.City, cell);
            var defender = BuildUnit(UnitType.Melee, cell);

            var combatInfo = new CombatInfo()
            {
                AttackerCombatModifier = 1f, CombatType = CombatType.Ranged
            };

            var modifierLogic = Container.Resolve <CityCombatModifierLogic>();

            modifierLogic.ApplyCityModifiersToCombat(attacker, defender, combatInfo);

            Assert.AreEqual(1f, combatInfo.AttackerCombatModifier);
        }
        public void RespondToCombat_SetsCityHealthToOneInsteadOfDestroying()
        {
            Mock <IUnit> attackerMock, defenderMock;

            var attacker = BuildUnit(50, UnitType.Melee, BuildCell(), null, out attackerMock);
            var defender = BuildUnit(0, UnitType.City, BuildCell(), null, out defenderMock);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var destructionLogic = Container.Resolve <DestructionPostCombatResponder>();

            destructionLogic.RespondToCombat(attacker, defender, combatInfo);

            Assert.AreEqual(1, defender.CurrentHitpoints);
        }
        public void RespondToCombat_DoesNotDestroyAttackerIfHealthPositive()
        {
            Mock <IUnit> attackerMock, defenderMock;

            var attacker = BuildUnit(1, UnitType.Melee, BuildCell(), null, out attackerMock);
            var defender = BuildUnit(50, UnitType.Melee, BuildCell(), null, out defenderMock);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var destructionLogic = Container.Resolve <DestructionPostCombatResponder>();

            destructionLogic.RespondToCombat(attacker, defender, combatInfo);

            attackerMock.Verify(unit => unit.Destroy(), Times.Never, "Attacker was unexpectedly destroyed");
        }
コード例 #26
0
        void combatTracker_CombatInfoUpdated(CombatInfo obj)
        {
            updateAllRow();

            AddNamesToList(obj.SourceName, obj.TargetName);

            if (!String.IsNullOrEmpty(obj.SourceName) && obj.SourceName != CoreManager.Current.CharacterFilter.Name)
            {
                updateMonsterListRow(obj.SourceName);
            }

            if (!String.IsNullOrEmpty(obj.TargetName) && obj.TargetName != CoreManager.Current.CharacterFilter.Name)
            {
                updateMonsterListRow(obj.TargetName);
            }

            updateCombatTrackerGUIInfo();
        }
コード例 #27
0
        public void PerformCommonCombatTasks_CanAttackSetToTrue_IfCombatSummaryPermitsAttackingAfterAttacking()
        {
            var attacker = BuildUnit(100, false, new UnitCombatSummary()
            {
                CanAttackAfterAttacking = true
            });
            var defender = BuildUnit(100, false, new UnitCombatSummary());

            var combatInfo = new CombatInfo();

            MockCombatCalculator.Setup(calculator => calculator.CalculateCombat(attacker, defender, combatInfo))
            .Returns(new Tuple <int, int>(0, 0));

            var executionLogic = Container.Resolve <CommonCombatExecutionLogic>();

            executionLogic.PerformCommonCombatTasks(attacker, defender, combatInfo);

            Assert.IsTrue(attacker.CanAttack);
        }
コード例 #28
0
        public void ApplyCityModifiersToCombat_AppliesBonusesIfAttackerIsGarrisionedCity()
        {
            var city = BuildCity(0.5f);

            var cell = BuildCell(city);

            var attacker = BuildUnit(UnitType.City, cell);
            var defender = BuildUnit(UnitType.Melee, cell);

            var combatInfo = new CombatInfo()
            {
                AttackerCombatModifier = 1f, CombatType = CombatType.Ranged
            };

            var modifierLogic = Container.Resolve <CityCombatModifierLogic>();

            modifierLogic.ApplyCityModifiersToCombat(attacker, defender, combatInfo);

            Assert.AreEqual(1.5f, combatInfo.AttackerCombatModifier);
        }
コード例 #29
0
        public void RespondToCombat_AndValidCityCapture_AllOccupantsDislocatedAndDestroyed()
        {
            var attackerOwner = BuildCivilization();

            Mock <IUnit> attackerMock;
            var          attacker = BuildUnit(attackerOwner, 0, UnitType.Melee, out attackerMock);

            var cityOwner    = BuildCivilization();
            var cityLocation = BuildHexCell();

            Mock <IUnit> mockMeleeInCity;
            Mock <IUnit> mockCivilianInCity;
            Mock <IUnit> mockCombatFacade;

            var meleeInCity    = BuildUnit(cityOwner, 100, UnitType.Melee, out mockMeleeInCity);
            var civilianInCity = BuildUnit(cityOwner, 100, UnitType.Civilian, out mockCivilianInCity);
            var combatFacade   = BuildUnit(cityOwner, 0, UnitType.City, out mockCombatFacade);

            var unitsInCity = new List <IUnit>()
            {
                meleeInCity, civilianInCity, combatFacade
            };

            var cityBeingCaptured = BuildCity(cityLocation, cityOwner, combatFacade, unitsInCity);

            MockUnitPositionCanon.Setup(canon => canon.GetPossessionsOfOwner(cityLocation))
            .Returns(unitsInCity);

            var combatInfo = new CombatInfo()
            {
                CombatType = CombatType.Melee
            };

            var conquestLogic = Container.Resolve <CityConquestResponder>();

            conquestLogic.RespondToCombat(attacker, cityBeingCaptured.CombatFacade, combatInfo);

            mockMeleeInCity.Verify(unit => unit.Destroy(), Times.Once, "MeleeInCity was not destroyed");
            mockCivilianInCity.Verify(unit => unit.Destroy(), Times.Once, "CivilianInCity was not destroyed");
            mockCombatFacade.Verify(unit => unit.Destroy(), Times.Never, "CombatFacade was unexpectedly destroyed");
        }
コード例 #30
0
        public void PerformRangedAttack_PerformsCommonCombatTasks()
        {
            var attackerLocation = BuildCell();
            var defenderLocation = BuildCell();

            Mock <IUnit> attackerMock;
            var          attacker = BuildUnit(3f, 100, attackerLocation, out attackerMock);
            var          defender = BuildUnit(currentMovement: 0f, currentHitpoints: 100, location: defenderLocation);

            var combatInfo = new CombatInfo();

            MockCombatInfoLogic.Setup(logic => logic.GetAttackInfo(attacker, defender, defenderLocation, CombatType.Ranged))
            .Returns(combatInfo);

            MockRangedAttackValidityLogic.Setup(logic => logic.IsRangedAttackValid(attacker, defender)).Returns(true);

            attackerMock.Setup(unit => unit.PerformMovement(false, It.IsAny <Action>()))
            .Callback <bool, Action>((ignoreMovementCosts, postMovementCallback) => postMovementCallback());

            MockCommonCombatExecutionLogic.Setup(
                logic => logic.PerformCommonCombatTasks(attacker, defender, combatInfo)
                ).Callback <IUnit, IUnit, CombatInfo>(
                (attkr, dfndr, info) => { attkr.CurrentHitpoints -= 30; dfndr.CurrentHitpoints -= 40; }
                );

            UnitSignals.RangedCombatWithUnit.Subscribe(delegate(UnitCombatResults results) {
                Assert.AreEqual(attacker, results.Attacker, "Results had an unexpected Attacker");
                Assert.AreEqual(defender, results.Defender, "Results had an unexpected Defender");
                Assert.AreEqual(30, results.DamageToAttacker, "Results had an unexpected DamageToAttacker");
                Assert.AreEqual(40, results.DamageToDefender, "Results had an unexpected DamageToDefender");
                Assert.AreEqual(combatInfo, results.InfoOfAttack, "Results had an unexpected Attacker");
                Assert.Pass();
            });

            var executer = Container.Resolve <CombatExecuter>();

            executer.PerformRangedAttack(attacker, defender);

            Assert.Fail("RangedCombatWithUnitSignal never fired");
        }