예제 #1
0
        public void FireAbility_TargetConditionFalse_DoesNotResolve()
        {
            bool hasfired = false;
            bool resolvesEventTriggered = false;
            bool targetBecomesInvalid   = true;

            Ability abi = new MockAbility(() => hasfired = true);

            abi.EventManager = this.EventManager;


            this.EventManager.Register(new Trigger <AbilityResolvesEvent>(_ => resolvesEventTriggered    = true));
            this.EventManager.Register(new Trigger <AbilityTargetInvalidEvent>(_ => targetBecomesInvalid = true));

            UnitEntity unit = new MockUnit();

            abi.SetTarget(0, new XmasUniversal[] { unit });

            abi.SetTargetCondition(0, _ => false);


            this.ActionManager.Queue(abi);
            this.ActionManager.ExecuteActions();



            Assert.IsFalse(hasfired);
            Assert.IsFalse(resolvesEventTriggered);
            Assert.IsTrue(targetBecomesInvalid);
        }
예제 #2
0
        protected static IUnit FindUnit()
        {
            var unit = new MockUnit
            {
                Name        = "Mandragora",
                ClaimedId   = 0,
                Distance    = 3.0,
                HasAggroed  = false,
                HppCurrent  = 100,
                Id          = 200,
                IsActive    = true,
                IsClaimed   = false,
                IsDead      = false,
                IsPet       = false,
                IsRendered  = true,
                MyClaim     = false,
                NpcType     = NpcType.Mob,
                PartyClaim  = false,
                Status      = Status.Standing,
                YDifference = 2.0,
                IsValid     = true
            };

            return(unit);
        }
예제 #3
0
        public void NotSee_WhenLineOfSight_IsOutsideMapBounds()
        {
            // Arrange
            var Matrix = new Map(1, 3).Matrix;

            var mockWall = new Mock <ITile>();
            var mockAir  = new Mock <ITile>();

            mockWall.SetupGet(w => w.BlocksSight).Returns(true);
            mockAir.SetupGet(w => w.BlocksSight).Returns(false);
            Matrix[0][0].Tile = mockAir.Object;
            Matrix[0][0].Tile = mockAir.Object;
            Matrix[0][2].Tile = mockAir.Object;

            var mockMap = new Mock <Map>();
            var map     = mockMap.Object;

            map.Matrix = Matrix;
            var unit = new MockUnit(Matrix[0][0], mockMap.Object);

            // these Coordinates could be mocked
            var lineOfSightOutOfBounds =
                new List <ICoordinates> {
                new Coordinates(0, 0), new Coordinates(0, 1), new Coordinates(0, 2), new Coordinates(0, 3)
            };

            // TODO: Refracto can see function to be independent of unit, pass 2 coordinates and a map rather than depending on the unit
            // Act
            Assert.IsFalse(unit.CanSee(lineOfSightOutOfBounds));
        }
예제 #4
0
 public UnitFilterTests()
 {
     mob    = FindBasicMob();
     sut    = new UnitFilters();
     config = FindConfig();
     api    = new MockGameAPI();
 }
예제 #5
0
 public UnitFilterTests()
 {
     mob     = FindBasicMob();
     mockApi = new MockEliteAPI();
     api     = mockApi.AsMemoryApi();
     sut     = new UnitFilters();
     config  = FindConfig();
 }
예제 #6
0
 public void ApplyMockAttack(MockUnit target)
 {
     int dmgTaken = target.Buffs.Exists (b => b is DeathTouchBuff) ? int.MaxValue : target.Attack;
     if(Buffs.Exists(b => b is RangedBuff)) { Buffs.RemoveAll(b => b is ForceFieldBuff); dmgTaken = 0; }
     int dmgInflicted = Buffs.Exists(b => b is ForceFieldBuff) ? 0 : Buffs.Exists(b => b is DeathTouchBuff) ? int.MaxValue : Attack;
     if(target.Buffs.Exists(b => b is RangedBuff)) { target.Buffs.RemoveAll(b => b is ForceFieldBuff); dmgInflicted = 0; }
     CurrentHealth -= dmgTaken;
     target.CurrentHealth -= dmgInflicted;
 }
예제 #7
0
        public void TestTarget_NoTargetCondition_TargetAccepted()
        {
            int      firstTarget = 0;
            MockCard card        = new MockCard();
            MockUnit someUnit    = new MockUnit();

            bool result = card.TestTarget(firstTarget, someUnit);

            Assert.IsTrue(result);
        }
예제 #8
0
        public void TestTarget_ValidTarget_TargetAccepted()
        {
            int      firstTarget = 0;
            MockCard card        = new MockCard();
            MockUnit someUnit    = new MockUnit();

            card.SetTargetCondition(firstTarget, unit => unit is UnitEntity);
            bool result = card.TestTarget(firstTarget, someUnit);

            Assert.IsTrue(result);
        }
 public override int MockOnPlay(MockUnit mo, HexEvaluator he)
 {
     if(mo.CurrentHealth < mo.MaxHealth) {
         if(mo.MaxHealth - mo.CurrentHealth < 5) {
             mo.CurrentHealth = mo.MaxHealth;
         } else {
             mo.CurrentHealth += 5;
         }
     }
     return mo.Value(he);
 }
예제 #10
0
        public void ZeroProgressAtMaxCapacity()
        {
            Building testBuilding = BuildingUpgradeTests.GetTestBuilding();
            IUnit    unit         = new MockUnit(.111f);

            testBuilding.Unit = unit;

            testBuilding.Tick(new TimeSpan(1, 0, 0));

            Assert.AreEqual(0, testBuilding.NextUnitProgress);
            testBuilding.Dispose();
        }
예제 #11
0
        private static MockUnit FindBasicMob()
        {
            var mob = new MockUnit()
            {
                IsActive   = true,
                ClaimedId  = 0,
                IsRendered = true,
                NpcType    = NpcType.Mob,
                IsPet      = false,
            };

            return(mob);
        }
예제 #12
0
        public void UnitsGeneratedFromTick(TimeSpan i_timeSpan)
        {
            Building testBuilding = BuildingUpgradeTests.GetTestBuilding();
            IUnit    unit         = new MockUnit(1);

            testBuilding.Unit = unit;
            int unitsBeforeTick = testBuilding.NumUnits;

            testBuilding.Tick(i_timeSpan);

            Assert.AreNotSame(unitsBeforeTick, testBuilding.NumUnits);
            testBuilding.Dispose();
        }
예제 #13
0
        public void Targets_HasOneOnFirstTargetZeroOnSecondTargetTwoOnThirdTarget_ReturnsCorrectTargets()
        {
            UnitEntity first = new MockUnit();

            UnitEntity Third1 = new MockUnit();
            UnitEntity Third2 = new MockUnit();
            Ability    abi    = new MockAbility(null);

            abi.SetTarget(0, new object[] { first });
            abi.SetTarget(2, new object[] { Third1, Third2 });

            var targets     = abi.Targets;
            int secondcount = 0;

            Assert.AreEqual(first, targets[0][0]);
            Assert.AreEqual(secondcount, targets[1].Length);
            Assert.AreEqual(Third1, targets[2][0]);
            Assert.AreEqual(Third2, targets[2][1]);
        }
예제 #14
0
        public void Should_DealDamageWhen_NegativeRegen(double variance)
        {
            // Arrange
            var mockLocation = new Mock <ICoordinates>();

            var mockMap = new Mock <Map>();

            var unit = new MockUnit(mockLocation.Object, mockMap.Object);

            unit.CurrentHealth      = 100;
            unit.HealthRegenPerTurn = variance;
            // mockUnit.SetupGet(u => u.CurrentHealth)

            // Act
            unit.RegenarateHP();

            // Assert
            Assert.IsTrue(100 + variance == unit.CurrentHealth);
        }
예제 #15
0
        public void Regenerate_ShouldCap_AtMxHP(double variance)
        {
            var mockLocation = new Mock <ICoordinates>();

            var mockMap = new Mock <Map>();

            // Arrange
            var unit = new MockUnit(mockLocation.Object, mockMap.Object);

            unit.CurrentHealth      = 0;
            unit.MaximumHealth      = 10;
            unit.HealthRegenPerTurn = variance;
            // mockUnit.SetupGet(u => u.CurrentHealth)

            // Act
            unit.RegenarateHP();

            // Assert
            Assert.IsTrue(unit.CurrentHealth == unit.MaximumHealth);
        }
예제 #16
0
        public void FireAbility_HasValidTarget_Resolves()
        {
            bool hasfired = false;
            bool resolvesEventTriggered = false;

            Ability abi = new MockAbility(() => hasfired = true);

            abi.EventManager = this.EventManager;

            this.EventManager.Register(new Trigger <AbilityResolvesEvent>(_ => resolvesEventTriggered = true));

            UnitEntity unit = new MockUnit();

            abi.SetTarget(0, new XmasUniversal[] { unit });

            this.ActionManager.Queue(abi);
            this.ActionManager.ExecuteActions();

            Assert.IsTrue(hasfired);
            Assert.IsTrue(resolvesEventTriggered);
        }
예제 #17
0
        public void NotSeeWhen_LineOfSight_IsBroken()
        {
            // Arrange

            // TODO: do the matrix creaion here without relying on map constuctor

            // Altho it brakes the isolation map used because  its initialise method creates
            // AND MAPS!! postion x,y  leaving us only to fill them with tiles

            // Creates a map off 3 tiles and puts a wall in the middle

            var Matrix = new Map(1, 3).Matrix;

            var mockWall = new Mock <ITile>();
            var mockAir  = new Mock <ITile>();

            mockWall.SetupGet(w => w.BlocksSight).Returns(true);
            mockAir.SetupGet(w => w.BlocksSight).Returns(false);
            Matrix[0][1].Tile = mockWall.Object;
            Matrix[0][0].Tile = mockAir.Object;
            Matrix[0][2].Tile = mockAir.Object;

            var mockMap = new Mock <Map>();
            var map     = mockMap.Object;

            map.Matrix = Matrix;

            var unit = new MockUnit(Matrix[0][0], mockMap.Object);
            // These Coordinates could be mocked
            var lineOfSight =
                new List <ICoordinates> {
                new Coordinates(0, 0), new Coordinates(0, 1), new Coordinates(0, 2)
            };

            // TODO Refracto can see function to be independent of unit, pass 2 coordinates and a map rather than depending on the unit or added as utility method in Map

            // Act
            Assert.IsFalse(unit.CanSee(lineOfSight));
        }
예제 #18
0
    public int MockAttack(MockUnit target, HexEvaluator he)
    {
        int oldValue = Value (he);
        int oldTargetValue = target.Value (he);
        int dmgTaken = target.Buffs.Exists (b => b is DeathTouchBuff) ? int.MaxValue : target.Attack;
        if(Buffs.Exists(b => b is RangedBuff)) { Buffs.RemoveAll(b => b is ForceFieldBuff); dmgTaken = 0; }
        int dmgInflicted = Buffs.Exists(b => b is ForceFieldBuff) ? 0 : Buffs.Exists(b => b is DeathTouchBuff) ? int.MaxValue : Attack;
        if(target.Buffs.Exists(b => b is RangedBuff)) { target.Buffs.RemoveAll(b => b is ForceFieldBuff); dmgInflicted = 0; }
        if(dmgTaken > CurrentHealth) {
            // I die
            if(dmgInflicted > target.CurrentHealth) {
                // Target dies
                return 10 * (oldValue - oldTargetValue);
            } else {
                // Target survives
                return 10 * (dmgInflicted - oldValue);
            }
        } else {
            // I survive
            if(dmgInflicted > target.CurrentHealth) {
                // Target dies
                return 10 * (oldTargetValue -
                        (oldValue - Value(he)) - // Change in my value
                        (he(target.Hex) - he(Hex)) - // Change in value of hex
                        dmgTaken); // Damage taken;
            } else {
                // Target survives
                return 10 * ((oldTargetValue - target.Value (he)) + // Change in target value (from buffs etc)
                        dmgInflicted - // Damage taken by target
                        (oldValue - Value(he)) - // Change in my value
                        (he(Hex) - he(target.Hex)) - // Change in value of hex
                        dmgTaken); // Damage taken
            }

        }
    }
예제 #19
0
    bool MoveLeftOvers()
    {
        if(untouchedUnits.Count < 1) {
            return false;
        }
        Say(untouchedUnits.Count + " untouched units left");
        Unit unit = untouchedUnits.First();
        MockUnit thisMock = new MockUnit(unit);
        List<Hex> targets = PathFinder.BreadthFirstSearch(thisMock.Hex, GameControl.gameControl.GridControl.Map, unit.MovementLeft(), player.Team);
        Hex target = thisMock.Hex;
        int oldValue = CalculateHexValue(target);
        foreach(Hex h in targets) {
            if(target == null || h.Unit == null && CalculateHexValue(h) > oldValue) {
                target = h;
                oldValue = CalculateHexValue(h);
            } else if(h.Unit != null && h.Unit.Team != player.Team) {
                MockUnit targetMock = new MockUnit(h.Unit);
                if(targetMock.CurrentHealth > 0) {
                    int value = thisMock.MockAttack(targetMock, CalculateHexValue);
                    if(value > oldValue) {
                        target = h;
                        oldValue = value;
                    }
                }
            }
        }
        if(target != thisMock.Hex) {
            Say ("Moving " + unit.UnitName + " from " + unit.Hex.GridPosition + " to " + target.GridPosition);
            unit.PrepareMove(target);
        } else {
            Say ("Not moving " + unit.UnitName);
        }
        untouchedUnits.Remove(unit);

        return true;
    }
예제 #20
0
 private void SetPartyClaimed(MockUnit mob)
 {
     mob.IsClaimed = true;
 }
예제 #21
0
 private static void SetAggroedMob(MockUnit mob)
 {
     mob.Status    = Status.Fighting;
     mob.IsClaimed = false;
 }
 public override int MockOnPlay(MockUnit mo, HexEvaluator he)
 {
     return 9;
 }
예제 #23
0
    int SpellOnHexValue(SpellCard sCard, Hex hex)
    {
        if(hex.Unit != null) {
            MockUnit mo = new MockUnit(hex.Unit);
            int originValue = mo.Value(CalculateHexValue);

            int newValue = sCard.MockOnPlay(mo, CalculateHexValue);
            if(mo.Team == player.Team) {
                return ((originValue - newValue) * -1);
            } else {
                return ((originValue - newValue));
            }
        }
        return -1;
    }
예제 #24
0
 public override int MockOnPlay(MockUnit mo, HexEvaluator he)
 {
     int draw = mo.Buffs.Count * 3;
     mo.Buffs = new List<UnitBuff>();
     return mo.Value(he) - draw;
 }
예제 #25
0
 public virtual int MockOnPlay(MockUnit mo, HexEvaluator he)
 {
     Debug.LogError("MockOnPlay attempted called on card without it implemented. This probably means an AI is trying to use a card that is not meant for AI");
     return 0;
 }
 public override int MockOnPlay(MockUnit mo, HexEvaluator he)
 {
     mo.Movement = 1;
     return mo.Value(he);
 }
 public override int MockOnPlay(MockUnit mo, HexEvaluator he)
 {
     mo.CurrentHealth -= 3;
     return mo.Value (he);
 }