public void AbsorbShade(Shade shade) { ShadeAbsorbedEventArgs e = new ShadeAbsorbedEventArgs(shade); OnShadeAbsorbed(e); FullyHeal(); IncrementMalevolenceCounter(shade._malevolenceCounter); StatType statBonus = ChanceService.WhichEventOccurs(AbsorptionBonuses); //TODO: move into a method int increaseAmount; switch (statBonus) { case StatType.Speed: case StatType.Defense: increaseAmount = shade.ShadeExperience; break; case StatType.Evade: increaseAmount = shade.ShadeExperience * 5; break; default: throw new Exception($"Shade.AbsorbShade() does not know how to handle a boost to the '{statBonus}' stat"); } RaiseStat(statBonus, increaseAmount); ShadeExperience += shade.ShadeExperience; shade.CurrentHealth = 0; }
public override BattleMove SelectMove(Team ownTeam, Team enemyTeam) { double[] chancesArray = GenerateMoveChances(); int whichMoveIndex = ChanceService.WhichEventOccurs(chancesArray); BattleMove ret = AvailableMoves[whichMoveIndex]; return(ret); }
public MockChanceService() { _realChanceService = new ChanceService(); _eventOccursReturnValues = new List <bool>(); _whichEventOccursReturnValues = new List <int>(); _eventOccursIndex = 0; _whichEventOccursIndex = 0; LastChanceVals = new List <double>(); _shuffleIndices = new List <int>(); }
public override BattleMove SelectMove(Team ownTeam, Team enemyTeam) { BattleMove ret; if (ChanceService.EventOccurs(0.75)) { ret = _availableMoves.Single(m => m.Description == "goblin punch"); } else { ret = _availableMoves.Single(m => m.Description == "attack"); } return(ret); }
private void LayEgg(Team ownTeam, IOutput output) { var typeIndex = ChanceService.WhichEventOccurs(Globals.EggMagicTypes.Length); var type = Globals.EggMagicTypes[typeIndex]; var prefix = "a"; if (type == MagicType.Ice) { prefix += "n"; } var egg = (Egg)FighterFactory.GetFighter(FighterType.Egg, 1, null, type); egg.Killed += OnEggKilled; ownTeam.Add(egg); _eggs.Add(egg); output.WriteLine($"{DisplayName} laid {prefix} {egg.BaseName}!"); }
public override BattleMove SelectMove(Team ownTeam, Team enemyTeam) { var index = 0; List <BattleMove> executableMoves = GetExecutableMoves(enemyTeam); int executableMovesCount = executableMoves.Count; if (executableMovesCount > 1) { if (executableMoves.Contains(_chargeMove)) { double[] chances = new double[executableMovesCount]; for (var i = 0; i < executableMovesCount; ++i) { chances[i] = 1.0 / executableMovesCount; } double combinedChance = chances[0] * 2; double attackChance = (combinedChance * _malevolenceCounter) / MaxMalevolenceLevel; double chargeChance = combinedChance - attackChance; int chargeIndex = executableMoves.IndexOf(_chargeMove); int attackIndex = executableMoves.IndexOf(_malevolenceAttackMove); chances[chargeIndex] = chargeChance; chances[attackIndex] = attackChance; index = ChanceService.WhichEventOccurs(chances); } else { index = ChanceService.WhichEventOccurs(executableMovesCount); } } var move = executableMoves[index]; return(move); }
public void StatusScreenCorrectlyDisplaysTerrainInteractableInformation_Bells() { ChanceService chanceService = new ChanceService(); MenuFactory menuFactory = new MenuFactory(); List <TerrainInteractable> bells = new List <TerrainInteractable> { new Bell("copper bell", BellType.Copper, menuFactory, chanceService), new Bell("silver bell", BellType.Silver, menuFactory, chanceService) }; SetUpAndBuildMenu(true, terrainInteractable: bells); _menuInput.Push("status"); _menuInput.Push("back"); _menu.GetInput(); var outputs = _menuOutput.GetOutputs(); var clearIndices = _menuOutput.GetClearIndices(); var expectedLength = _fullMenuPromptLength * 2; //times 2 because it's displayed twice expectedLength += FighterStatusPromptLength; //no spells expectedLength += 2; //"Foes" header and one foe listed expectedLength += 3; //"Other" header and both bells listed Assert.AreEqual(expectedLength, outputs.Length); Assert.AreEqual(5, clearIndices.Length); //once for each main menu, once after each human fighter (just 1), one after enemy display, one after bells displayed var index = _fullMenuPromptLength + FighterStatusPromptLength + 2; //2 for the foes and enemy display information Assert.AreEqual("Other details:\n", outputs[index++].Message); foreach (TerrainInteractable bell in bells) { Assert.AreEqual($"{bell.GetFullDisplayString()}\n", outputs[index++].Message); } }
private void _setReviveCounter(object sender, KilledEventArgs e) { ReviveCounter = ChanceService.WhichEventOccurs(3) + 2; }
//TODO: this should have return type void and print messages should queue off events, not a return value public bool ExecuteMove(BattleMoveWithTarget battleMoveWithTarget) { bool moveSucceeded = false; BellMove bellMove = battleMoveWithTarget.Move as BellMove; if (bellMove == null) { throw new InvalidOperationException($"Bell.ExecuteMove() was erroneously called for a move that was not a Bell move. Movetype: {battleMoveWithTarget.Move.MoveType}"); } Shade targetAsShade = battleMoveWithTarget.Target as Shade; if (targetAsShade == null) { throw new InvalidOperationException($"Bell.ExecuteMove() was given a target that was not a shade! target: {battleMoveWithTarget.Target}"); } int healthDiff = targetAsShade.MaxHealth - targetAsShade.CurrentHealth; double healthPercentage = ((double)targetAsShade.CurrentHealth) / targetAsShade.MaxHealth; double chance = 1.0 / 3; if (healthDiff > 0) { if (healthPercentage < 0.26) { chance = 0.8; } else if (healthPercentage < 0.51) { chance = 0.65; } else if (healthPercentage < 0.76) { chance = 0.5; } } if (targetAsShade.ShadeExperience > 1) { int levelDiff = targetAsShade.ShadeExperience - 1; chance -= 0.1 * levelDiff; //minimum chance is 10% that it works chance = Math.Max(.1, chance); } if (bellMove.BellMoveType == BellMoveType.ControlMove) { BattleMoveWithTargetAndNumberInput moveWithNumber = battleMoveWithTarget as BattleMoveWithTargetAndNumberInput; if (moveWithNumber == null) { throw new InvalidOperationException("Bell.ExecuteMove() should be supplied a BattleMoveWIthTargetAndNUmberInput if the move was a control type Bell move"); } int bloodAmount = moveWithNumber.NumberValue; chance += bloodAmount * 0.05; } if ((BellType == BellType.Silver && bellMove.BellMoveType == BellMoveType.SealMove) || (BellType == BellType.Copper && bellMove.BellMoveType == BellMoveType.ControlMove)) { chance += .25; } if (ChanceService.EventOccurs(chance)) { int healAmount = targetAsShade.CurrentHealth; targetAsShade.Seal(); moveSucceeded = true; if (bellMove.BellMoveType == BellMoveType.SealMove) { battleMoveWithTarget.Owner.Heal(healAmount); } else if (bellMove.BellMoveType == BellMoveType.ControlMove) { battleMoveWithTarget.Owner.RaiseMaxHealth(targetAsShade.ShadeExperience); } } return(moveSucceeded); }
public override BattleMove SelectMove(Team ownTeam, Team enemyTeam) { List <IFighter> targetableAllies = ownTeam.Fighters.Where(f => f.IsAlive()).ToList(); int totalNumberOfAllies = targetableAllies.Count; int numberOfAlliesWithShields = CountAlliesWithShields(targetableAllies); int numberOfAlliesWithShieldsMissingHealth = CountAlliesWithShieldsMissingHealth(targetableAllies); List <BattleMove> movesToSelect = new List <BattleMove> { _basicAttack }; List <double> chances = new List <double> { 0.2 }; if (numberOfAlliesWithShields < totalNumberOfAllies) { movesToSelect.Add(_ironShieldMove); } if (numberOfAlliesWithShields > 0) { movesToSelect.Add(_fortifyShield); } if (numberOfAlliesWithShieldsMissingHealth > 0) { movesToSelect.Add(_healShield); } switch (movesToSelect.Count) { case 4: //all four moves chances.Add(.4); //Iron Shield chances.Add(.2); //fortify chances.Add(.2); //heal break; case 3: if (movesToSelect.Contains(_ironShieldMove)) { chances.Add(.6); //iron shield chances.Add(.2); //whatever the other move is } else { chances.Add(.4); chances.Add(.4); } break; case 2: chances.Add(.8); break; } int selectedIndex = ChanceService.WhichEventOccurs(chances.ToArray()); return(movesToSelect[selectedIndex]); }
public void TearDown() { _chanceService = null; }
public void SetUp() { _chanceService = new ChanceService(); }