public void IncrementItemCount(ArmamentType itemType, SquadModel squadModel) { var targetItemArmament = squadModel.Items.Where(a => a.ArmamentType == itemType).FirstOrDefault(); if (targetItemArmament != null) { var squads = _gameState.Game.Players.Where(p => p.PlayerId == squadModel.PlayerId).FirstOrDefault().Squads; var itemArmamentList = squads.SelectMany(s => s.Items.Where(a => a.ArmamentType == itemType).ToList()); var existingItemArmament = itemArmamentList.Where(a => a.Count > 0).FirstOrDefault(); if (existingItemArmament != null) { if (!targetItemArmament.Equals(existingItemArmament)) { existingItemArmament.SetCount(0); targetItemArmament.SetCount(1); CalculateSquadStats(squadModel); } else { _errorMessage.OnNext(ErrorType.InvalidAbilityCount.ToDescription()); } } else { targetItemArmament.SetCount(1); CalculateSquadStats(squadModel); } } }
public void ToggleSelected(SquadModel squadModel) { squadModel.IsSelected = !squadModel.IsSelected; _selectedSquadsUpdate.OnNext(_selectedSquads); SumSelectedSquadStats(); _squadUpdate.OnNext(squadModel); }
public void CalculateSquadStats(SquadModel squadModel) { // Named and Faceless Henchmen squadModel.Stats.Combat.SetValue(squadModel.Armaments.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Combat.Value)); squadModel.Stats.Stealth.SetValue(squadModel.Armaments.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Stealth.Value)); squadModel.Stats.Cunning.SetValue(squadModel.Armaments.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Cunning.Value)); squadModel.Stats.Diplomacy.SetValue(squadModel.Armaments.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Diplomacy.Value)); //Abilities squadModel.Stats.Combat.SetValue(squadModel.Stats.Combat.Value + squadModel.Abilities.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Combat.Value)); squadModel.Stats.Stealth.SetValue(squadModel.Stats.Stealth.Value + squadModel.Abilities.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Stealth.Value)); squadModel.Stats.Cunning.SetValue(squadModel.Stats.Cunning.Value + squadModel.Abilities.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Cunning.Value)); squadModel.Stats.Diplomacy.SetValue(squadModel.Stats.Diplomacy.Value + squadModel.Abilities.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Diplomacy.Value)); //Items squadModel.Stats.Combat.SetValue(squadModel.Stats.Combat.Value + squadModel.Items.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Combat.Value)); squadModel.Stats.Stealth.SetValue(squadModel.Stats.Stealth.Value + squadModel.Items.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Stealth.Value)); squadModel.Stats.Cunning.SetValue(squadModel.Stats.Cunning.Value + squadModel.Items.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Cunning.Value)); squadModel.Stats.Diplomacy.SetValue(squadModel.Stats.Diplomacy.Value + squadModel.Items.Where(a => a.Count > 0).Sum(a => a.Count * a.Stats.Diplomacy.Value)); if (squadModel.IsSelected) { var selectedSquads = _gameState.Game.Players.SelectMany(player => player.Squads.Where(squad => squad.IsSelected)).ToList(); _selectedSquadsUpdate.OnNext(selectedSquads); } _squadUpdate.OnNext(squadModel); if (squadModel.IsSelected) { _selectedSquadsUpdate.OnNext(_selectedSquads); SumSelectedSquadStats(); } }
public void DecrementArmamentCount(ArmamentType armamentType, SquadModel squadModel) { var armament = squadModel.Armaments.Where(a => a.ArmamentType == armamentType).FirstOrDefault(); if (armament != null) { if (armament.Count - 1 >= 0) { armament.SetCount(armament.Count - 1); CalculateSquadStats(squadModel); } else { if (armament.ArmamentType == _gameState.Game.PlayerId) { _errorMessage.OnNext(ErrorType.InvalidNamedHenchmanCount.ToDescription()); } else { _errorMessage.OnNext(ErrorType.InvalidArmamentCount.ToDescription()); } } } else { _errorMessage.OnNext(ErrorType.InvalidArmamentType.ToDescription()); } }
public void IncrementArmamentCount() { var playerArmamentType = ArmamentType.ArchibaldKluge; var otherArmamentType = ArmamentType.Hacker; var playerId = ((int)playerArmamentType).ToString(); var thisSquad = new SquadModel { PlayerId = playerId, SquadId = "TEST" }; thisSquad.Armaments.Add(new Armament(playerArmamentType, new ArmamentStats(0, 1, 3, 1))); var game = new GameModel { GameId = "ABCDEF", PlayerId = playerId, PlayerType = playerArmamentType, Players = new List <PlayerModel> { new PlayerModel { PlayerId = playerId, PlayerName = playerArmamentType.ToDescription(), PlayerType = playerArmamentType, Squads = new List <SquadModel> { thisSquad, new SquadModel { PlayerId = playerId, SquadId = "OTHER" } } } } }; var otherSquad = game.Players.Select(p => p.Squads.Where(s => s.SquadId == "OTHER").FirstOrDefault()).FirstOrDefault(); otherSquad.Armaments.Add(new Armament(playerArmamentType, new ArmamentStats(0, 1, 3, 1))); var otherSquadPlayerArmament = otherSquad.Armaments.Where(a => a.ArmamentType == playerArmamentType).FirstOrDefault(); var otherSquadHackerArmament = otherSquad.Armaments.Where(a => a.ArmamentType == otherArmamentType).FirstOrDefault(); var thisSquadPlayerArmament = thisSquad.Armaments.Where(a => a.ArmamentType == playerArmamentType).FirstOrDefault(); var thisSquadHackerArmament = thisSquad.Armaments.Where(a => a.ArmamentType == otherArmamentType).FirstOrDefault(); otherSquadPlayerArmament.SetCount(1); otherSquadHackerArmament.SetCount(1); _mockGameService.Setup(c => c.Game).Returns(game); var squadService = Container.Resolve <ISquadService>(); squadService.IncrementArmamentCount(playerArmamentType, thisSquad); squadService.IncrementArmamentCount(otherArmamentType, thisSquad); var successfulPlayerArmamentIncrement = thisSquadPlayerArmament.Count == 1 && otherSquadPlayerArmament.Count == 0; var successfulOtherArmamentIncrement = thisSquadHackerArmament.Count == 1 && otherSquadHackerArmament.Count == 1; Assert.True(successfulPlayerArmamentIncrement && successfulOtherArmamentIncrement); }
public void IncrementItemCount() { var playerArmamentType = ArmamentType.ArchibaldKluge; var explosiveRounds = ArmamentType.ExplosiveRounds; var hypnoticSpray = ArmamentType.HypnoticSpray; var playerId = ((int)playerArmamentType).ToString(); var thisSquad = new SquadModel { PlayerId = playerId, SquadId = "TEST" }; var game = new GameModel { GameId = "ABCDEF", PlayerId = playerId, PlayerType = playerArmamentType, Players = new List <PlayerModel> { new PlayerModel { PlayerId = playerId, PlayerName = playerArmamentType.ToDescription(), PlayerType = playerArmamentType, Squads = new List <SquadModel> { thisSquad, new SquadModel { PlayerId = playerId, SquadId = "OTHER" } } } } }; var otherSquad = game.Players.Select(p => p.Squads.Where(s => s.SquadId == "OTHER").FirstOrDefault()).FirstOrDefault(); var otherSquadExplosiveRounds = otherSquad.Items.Where(a => a.ArmamentType == explosiveRounds).FirstOrDefault(); var otherSquadHypnoticSpray = otherSquad.Items.Where(a => a.ArmamentType == hypnoticSpray).FirstOrDefault(); otherSquadExplosiveRounds.SetCount(1); otherSquadHypnoticSpray.SetCount(1); var thisSquadExplosiveRounds = thisSquad.Items.Where(a => a.ArmamentType == explosiveRounds).FirstOrDefault(); var thisSquadHypnoticSpray = thisSquad.Items.Where(a => a.ArmamentType == hypnoticSpray).FirstOrDefault(); _mockGameService.Setup(c => c.Game).Returns(game); var squadService = Container.Resolve <ISquadService>(); squadService.IncrementItemCount(explosiveRounds, thisSquad); squadService.IncrementItemCount(hypnoticSpray, thisSquad); var successfulExplosiveRoundsIncrement = thisSquadExplosiveRounds.Count == 1 && otherSquadExplosiveRounds.Count == 0; var successfulHypnoticSprayIncrement = thisSquadHypnoticSpray.Count == 1 && otherSquadHypnoticSpray.Count == 0; Assert.True(successfulExplosiveRoundsIncrement && successfulHypnoticSprayIncrement); }
public void IncrementArmamentCount(ArmamentType armamentType, SquadModel squadModel) { var targetArmament = squadModel.Armaments.Where(a => a.ArmamentType == armamentType).FirstOrDefault(); var validTotalArmamentCount = 6; var totalArmamentCount = squadModel.Armaments.Sum(a => a.Count); if (targetArmament != null) { if (totalArmamentCount + 1 <= validTotalArmamentCount) { var playerArmamentType = _gameState.Game.PlayerId; if (targetArmament.ArmamentType == _gameState.Game.PlayerId) { var playerId = _gameState.Game.PlayerId; var squads = _gameState.Game.Players.Where(p => p.PlayerId == playerId).FirstOrDefault().Squads; var playerArmamentList = squads.SelectMany(s => s.Armaments.Where(a => a.ArmamentType == armamentType).ToList()); var existingNamedHenchmanArmament = playerArmamentList.Where(a => a.Count > 0).FirstOrDefault(); if (existingNamedHenchmanArmament != null) { if (!targetArmament.Equals(existingNamedHenchmanArmament)) { existingNamedHenchmanArmament.SetCount(0); targetArmament.SetCount(1); CalculateSquadStats(squadModel); } else { _errorMessage.OnNext(ErrorType.InvalidNamedHenchmanCount.ToDescription()); } } else { targetArmament.SetCount(1); CalculateSquadStats(squadModel); } } else { targetArmament.SetCount(targetArmament.Count + 1); CalculateSquadStats(squadModel); } } else { _errorMessage.OnNext(ErrorType.InvalidSquadSize.ToDescription()); } } else { _errorMessage.OnNext(ErrorType.InvalidArmamentType.ToDescription()); } }
public void DecrementItemCount() { var squadService = Container.Resolve <ISquadService>(); var itemType = ArmamentType.ExplosiveRounds; var squadModel = new SquadModel(); var item = squadModel.Items.Where(a => a.ArmamentType == ArmamentType.ExplosiveRounds).FirstOrDefault(); item.SetCount(1); squadService.DecrementItemCount(itemType, squadModel); Assert.True(item.Count == 0); }
public void DecrementArmamentCount() { var squadService = Container.Resolve <ISquadService>(); var armamentType = ArmamentType.Thief; var squadModel = new SquadModel(); var armament = squadModel.Armaments.Where(a => a.ArmamentType == ArmamentType.Thief).FirstOrDefault(); armament.SetCount(1); squadService.DecrementArmamentCount(armamentType, squadModel); Assert.True(armament.Count == 0); }
public void DecrementAbilityCount() { var squadService = Container.Resolve <ISquadService>(); var abilityType = ArmamentType.UgoCombat; var squadModel = new SquadModel(); var ability = squadModel.Abilities.Where(a => a.ArmamentType == ArmamentType.UgoCombat).FirstOrDefault(); ability.SetCount(1); squadService.DecrementAbilityCount(abilityType, squadModel); Assert.True(ability.Count == 0); }
public void IncrementAbilityCount() { var abilityType = ArmamentType.UgoStealth; var ugoPlayerId = ((int)ArmamentType.UgoDottore).ToString(); var squadModel = new SquadModel { PlayerId = ugoPlayerId, SquadId = "TEST" }; var game = new GameModel { GameId = "ABCDEF", PlayerId = ugoPlayerId, PlayerType = ArmamentType.UgoDottore, Players = new List <PlayerModel> { new PlayerModel { PlayerId = ugoPlayerId, PlayerName = ArmamentType.UgoDottore.ToDescription(), PlayerType = ArmamentType.UgoDottore, Squads = new List <SquadModel> { squadModel, new SquadModel { PlayerId = ugoPlayerId, SquadId = "OTHER" } } } } }; var otherSquad = game.Players.Select(p => p.Squads.Where(s => s.SquadId == "OTHER").FirstOrDefault()).FirstOrDefault(); var otherSquadAbility = otherSquad.Abilities.Where(a => a.ArmamentType == abilityType).FirstOrDefault(); otherSquadAbility.SetCount(1); var ability = squadModel.Abilities.Where(a => a.ArmamentType == abilityType).FirstOrDefault(); _mockGameService.Setup(c => c.Game).Returns(game); var squadService = Container.Resolve <ISquadService>(); squadService.IncrementAbilityCount(abilityType, squadModel); Assert.True(ability.Count == 1 && otherSquadAbility.Count == 0); }
public void CalculateSquadStats() { var squadService = Container.Resolve <ISquadService>(); var inputSquadModel = new SquadModel(); var playerArmament = new Armament(ArmamentType.ArchibaldKluge, new ArmamentStats(0, 1, 3, 1)); playerArmament.SetCount(1); inputSquadModel.Armaments.Add(playerArmament); squadService.CalculateSquadStats(inputSquadModel); var combatResult = inputSquadModel.Stats.Combat.Value; var stealthResult = inputSquadModel.Stats.Stealth.Value; var cunningResult = inputSquadModel.Stats.Cunning.Value; var diplomacyResult = inputSquadModel.Stats.Diplomacy.Value; Assert.True(combatResult == 0 && stealthResult == 1 && cunningResult == 3 && diplomacyResult == 1); }
public void DecrementAbilityCount(ArmamentType abilityType, SquadModel squadModel) { var ability = squadModel.Abilities.Where(a => a.ArmamentType == abilityType).FirstOrDefault(); if (ability != null) { if (ability.Count - 1 >= 0) { ability.SetCount(ability.Count - 1); CalculateSquadStats(squadModel); } else { _errorMessage.OnNext(ErrorType.InvalidAbilityCount.ToDescription()); } } else { _errorMessage.OnNext(ErrorType.InvalidAbilityType.ToDescription()); } }
public void DecrementItemCount(ArmamentType itemType, SquadModel squadModel) { var item = squadModel.Items.Where(a => a.ArmamentType == itemType).FirstOrDefault(); if (item != null) { if (item.Count - 1 >= 0) { item.SetCount(item.Count - 1); CalculateSquadStats(squadModel); } else { _errorMessage.OnNext(ErrorType.InvalidAbilityCount.ToDescription()); } } else { _errorMessage.OnNext(ErrorType.InvalidItemType.ToDescription()); } }
public void IncrementAbilityCount(ArmamentType abilityType, SquadModel squadModel) { ArmamentType playerArmamentType = _gameState.Game.PlayerId; if (playerArmamentType == ArmamentType.UgoDottore) { var targetAbilityArmament = squadModel.Abilities.Where(a => a.ArmamentType == abilityType).FirstOrDefault(); if (targetAbilityArmament != null) { var squads = _gameState.Game.Players.Where(p => p.PlayerId == squadModel.PlayerId).FirstOrDefault().Squads; var abilityArmamentList = squads.SelectMany(s => s.Abilities.Where(a => a.ArmamentType == abilityType).ToList()); var existingAbilityArmament = abilityArmamentList.Where(a => a.Count > 0).FirstOrDefault(); if (existingAbilityArmament != null) { if (!targetAbilityArmament.Equals(existingAbilityArmament)) { existingAbilityArmament.SetCount(0); targetAbilityArmament.SetCount(1); CalculateSquadStats(squadModel); } else { _errorMessage.OnNext(ErrorType.InvalidAbilityCount.ToDescription()); } } else { targetAbilityArmament.SetCount(1); CalculateSquadStats(squadModel); } } } else { _errorMessage.OnNext(ErrorType.InvalidNamedHenchmanType.ToDescription()); } }
public void ToggleSelected() { var startSelected = new SquadModel { IsSelected = true, Stats = new SquadStats(1, 1, 1, 1) }; var startNotSelected = new SquadModel { IsSelected = false, Stats = new SquadStats(2, 2, 2, 2) }; var game = new GameModel { GameId = "ABCDEF", Players = new List <PlayerModel> { new PlayerModel { Squads = new List <SquadModel> { startSelected, startNotSelected } } }, SelectedSquadStats = new SquadStats() }; _mockGameService.Setup(c => c.Game).Returns(game); var squadService = Container.Resolve <ISquadService>(); squadService.ToggleSelected(startSelected); squadService.ToggleSelected(startNotSelected); Assert.True(!startSelected.IsSelected && startNotSelected.IsSelected); }
private PlayerModel PlayerToModel(PlayerDTO playerDTO) { var squadModels = new List <SquadModel>(); foreach (SquadDTO squadDTO in playerDTO.Squads) { var squadModel = new SquadModel { PlayerId = playerDTO.PlayerId, SquadId = squadDTO.SquadId, Armaments = squadDTO.Armaments, Stats = squadDTO.Stats }; squadModels.Add(squadModel); } var playerModel = new PlayerModel { PlayerId = playerDTO.PlayerId, Squads = squadModels }; return(playerModel); }