public void Combat_RemoveCombatantInDifferentRoom() { Mock <IMobileObject> mob1 = new Mock <IMobileObject>(); Mock <IMobileObject> mob2 = new Mock <IMobileObject>(); PropertyInfo info = combat.GetType().GetProperty("combatants", BindingFlags.Instance | BindingFlags.NonPublic); ConcurrentDictionary <IMobileObject, CombatPair> combatants = (ConcurrentDictionary <IMobileObject, CombatPair>)info.GetValue(combat); CombatPair pair = new CombatPair(); Mock <IRoom> room1 = new Mock <IRoom>(); Mock <IRoom> room2 = new Mock <IRoom>(); mob1.Setup(e => e.Health).Returns(1); mob1.Setup(e => e.Room).Returns(room1.Object); mob2.Setup(e => e.Health).Returns(1); mob2.Setup(e => e.Room).Returns(room2.Object); pair.Attacker = mob1.Object; pair.Defender = mob2.Object; combatants.TryAdd(mob1.Object, pair); pair = new CombatPair(); pair.Attacker = mob2.Object; pair.Defender = mob1.Object; combatants.TryAdd(mob2.Object, pair); combat.ProcessCombatRound(); Assert.AreEqual(0, combatants.Count); }
/// <summary> /// Version that is used for internal that will not try to add the opposite attack order /// </summary> /// <param name="attacker"></param> /// <param name="defender"></param> private void AddCombatPairInternal(IMobileObject attacker, IMobileObject defender) { if (!Combatants.Keys.Contains(attacker)) { CombatPair pair = new CombatPair(); pair.Attacker = attacker; pair.Defender = defender; Combatants.TryAdd(attacker, pair); } }
private void ProcessAttack(IMobileObject mob) { CombatPair pair = Combatants[mob]; bool invalidComabatPair = RemoveInvalidCombatant(mob, pair); if (!invalidComabatPair) { ProcessWeapons(pair.Attacker, pair.Defender); AddCombatPairInternal(pair.Defender, pair.Attacker); } }
private bool RemoveInvalidCombatant(IMobileObject mob, CombatPair pair) { if ((pair.Attacker.Health <= 0 || pair.Defender.Health <= 0) || (pair.Attacker.Room != pair.Defender.Room) || pair.Attacker.Room.Attributes.Contains(Room.Room.RoomAttribute.Peaceful)) { Combatants.TryRemove(mob, out pair); return(true); } return(false); }
public void Combat_ProcessWeapons_() { Mock <IMobileObject> mob1 = new Mock <IMobileObject>(); Mock <IMobileObject> mob2 = new Mock <IMobileObject>(); Mock <IRoom> room = new Mock <IRoom>(); PropertyInfo info = combat.GetType().GetProperty("combatants", BindingFlags.Instance | BindingFlags.NonPublic); ConcurrentDictionary <IMobileObject, CombatPair> combatants = (ConcurrentDictionary <IMobileObject, CombatPair>)info.GetValue(combat); CombatPair pair = new CombatPair(); Mock <IWeapon> weapon = new Mock <IWeapon>(); List <IWeapon> weapons = new List <IWeapon>() { weapon.Object, weapon.Object }; Mock <IDamage> damage = new Mock <IDamage>(); Mock <IDice> dice = new Mock <IDice>(); List <IDamage> damages = new List <IDamage>() { damage.Object }; Mock <IEngine> engine = new Mock <IEngine>(); Mock <IEvent> evnt = new Mock <IEvent>(); mob1.Setup(e => e.Health).Returns(1); mob2.Setup(e => e.Health).Returns(1); mob1.Setup(e => e.Room).Returns(room.Object); mob2.Setup(e => e.Room).Returns(room.Object); room.Setup(e => e.Attributes).Returns(new List <RoomAttribute>()); pair.Attacker = mob1.Object; pair.Defender = mob2.Object; combatants.TryAdd(mob1.Object, pair); weapon.Setup(e => e.Speed).Returns(1); mob1.Setup(e => e.EquipedWeapon).Returns(weapons); damage.Setup(e => e.Dice).Returns(dice.Object); weapon.Setup(e => e.DamageList).Returns(damages); engine.Setup(e => e.Event).Returns(evnt.Object); GlobalReference.GlobalValues.Engine = engine.Object; combat.ProcessCombatRound(); weapon.Verify(e => e.DamageList, Times.Exactly(2)); mob1.Verify(e => e.CalculateDamage(damage.Object), Times.Exactly(2)); evnt.Verify(e => e.DamageDealtBeforeDefense(mob1.Object, mob2.Object, 0)); evnt.Verify(e => e.DamageDealtAfterDefense(mob1.Object, mob2.Object, 0)); }
public IResult AddCombatPair(IMobileObject attacker, IMobileObject defender) { CombatPair pair; if (Combatants.TryGetValue(attacker, out pair)) { return(new Result(string.Format("You are already attacking {0}.", pair.Defender.KeyWords.FirstOrDefault()), true)); } else { pair = new CombatPair(); pair.Attacker = attacker; pair.Defender = defender; Combatants.TryAdd(attacker, pair); //add the defender attacking the attacker AddCombatPairInternal(defender, attacker); return(new Result(string.Format("You begin to attack {0}.", defender.KeyWords.FirstOrDefault()), false)); } }
public void Combat_ProcessAttack_AddDefendingMobToCombat() { Mock <IMobileObject> mob1 = new Mock <IMobileObject>(); Mock <IMobileObject> mob2 = new Mock <IMobileObject>(); Mock <IRoom> room = new Mock <IRoom>(); PropertyInfo info = combat.GetType().GetProperty("combatants", BindingFlags.Instance | BindingFlags.NonPublic); ConcurrentDictionary <IMobileObject, CombatPair> combatants = (ConcurrentDictionary <IMobileObject, CombatPair>)info.GetValue(combat); CombatPair pair = new CombatPair(); room.Setup(e => e.Attributes).Returns(new List <RoomAttribute>()); mob1.Setup(e => e.Health).Returns(1); mob2.Setup(e => e.Health).Returns(1); mob1.Setup(e => e.Room).Returns(room.Object); mob2.Setup(e => e.Room).Returns(room.Object); pair.Attacker = mob1.Object; pair.Defender = mob2.Object; combatants.TryAdd(mob1.Object, pair); combat.ProcessCombatRound(); Assert.AreEqual(2, combatants.Count); }