public void TestWhichEventOccurs_AtLeastOneEventOccurs() { double[] chanceEvents = { .1, .3, .6 }; double[] occurances = { 0, 0, 0 }; for (var i = 0; i < 10000; ++i) { var eventIndex = _chanceService.WhichEventOccurs(chanceEvents); occurances[eventIndex] += 1; } for (var i = 0; i < 3; ++i) { occurances[i] = occurances[i] / 10000; } Assert.LessOrEqual(.08, occurances[0]); Assert.GreaterOrEqual(.12, occurances[0]); Assert.LessOrEqual(.28, occurances[1]); Assert.GreaterOrEqual(.32, occurances[1]); Assert.LessOrEqual(.58, occurances[2]); Assert.GreaterOrEqual(.62, occurances[2]); }
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); }
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); }
private void _setReviveCounter(object sender, KilledEventArgs e) { ReviveCounter = ChanceService.WhichEventOccurs(3) + 2; }
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]); }