public void Guard() { // Determine how much we're blocking int GuardValue = DiceRoller.RollDiceAgainstThreshold((int)(CurrentPlayer.myStats.Endurance.Value * 1.5)).Hits; RollResults MonsterDamage = DiceRoller.RollDiceAgainstThreshold((int)CurrentMonster.StrengthAttackPower); // If monster is still alive, let the monster attack int damageToPlayer = (MonsterDamage.Hits + (2 * MonsterDamage.Crits)) - GuardValue / 2; if (damageToPlayer <= 0) { RaiseMessage("The monster attacks, but you block it!"); } else { CurrentPlayer.CurrentHealth -= damageToPlayer; RaiseMessage($"The {CurrentMonster.Name} hit you for {damageToPlayer} points."); } // If player is killed, move them back to their home. if (CurrentPlayer.CurrentHealth <= 0) { RaiseMessage(""); RaiseMessage($"The {CurrentMonster.Name} defeated you..."); CurrentSession.CurrentLocation = CurrentSession.CurrentWorld.LocationAt(0, -1); // Player's home CurrentPlayer.CurrentHealth = CurrentPlayer.MaxHealth; // Completely heal the player CurrentSession.ButtonContext = new ExploreButtonContext(CurrentSession); } }
/// <summary> /// Validate and Record Rollings /// </summary> /// <param name="pins">Number of Pins knocked down in a roll</param> public void RecordRolling(int pins) { ValidateRoll(pins); RollResults.Add(pins); _remainingPins -= pins; ResetPinsForLastFrame(); IsFrameClosed = SetFrameClosed(); if (IsFrameClosed) { if (RollResults.Count == 1) { TotalPins = RollResults.First(); } if (RollResults.Count == 2) { TotalPins = RollResults.First() + RollResults.Last(); } if (RollResults.Count == 3) { TotalPins = RollResults.First() + RollResults[1]; BonusPins = RollResults.Last(); } } }
public void ValidateData(int score, RollResults rollResult, int currentFrameCounter, List <IFrame> frames) { if (score > MaxScore) { ThrowException(string.Format(MessageFactory.GetMessage("WrongInput"), MaxScore)); } if (currentFrameCounter >= FramesPerMatch) { ThrowException((MessageFactory.GetMessage("NoMoreFrames"))); } if (currentFrameCounter >= frames.Count) { return; } if (frames.Count <= 0 || frames[currentFrameCounter].RollScore == null || rollResult == RollResults.Bonus) { return; } if (frames[currentFrameCounter].RollScore.Sum(x => x.Score) + score > MaxScore) { ThrowException(string.Format(MessageFactory.GetMessage("TotalScoreError"), MaxScore)); } }
private RollResults RollExpanded(string expression) { if (!ValidateDiceExpression(expression)) { return(new RollResults { Arithmetic = string.Empty, Result = 0, Valid = false, TextResult = $"Invalid: {expression}" }); } int diceCount = 1; int numSides = 0; int modifier = 0; var match = _regex.Match(expression); if (!string.IsNullOrWhiteSpace(match.Groups["numdice"]?.Value)) { diceCount = int.Parse(match.Groups["numdice"].Value); } if (!string.IsNullOrWhiteSpace(match.Groups["numsides"]?.Value)) { numSides = int.Parse(match.Groups["numsides"].Value); } if (!string.IsNullOrWhiteSpace(match.Groups["modifier"]?.Value)) { modifier = int.Parse(match.Groups["modifier"]?.Value); } var result = new RollResults(); for (int i = 1; i <= diceCount; i++) { int roll = numSides == 0 ? numSides : _rand.Next(numSides) + 1; result.Arithmetic += $"{roll}"; result.Result += roll; if (i < diceCount) { result.Arithmetic += " + "; } } if (modifier != 0) { result.Result += modifier; result.Arithmetic += modifier < 0 ? $" - {Math.Abs(modifier)}" : $" + {modifier}"; result.Arithmetic += $" = {result.Result}"; } else { result.Arithmetic += $" = {result.Result}"; } result.Valid = true; result.TextResult = NumberToText(result.Result); return(result); }
static void RollIsComplete(CardDto card, RollResults stopRollingData) { OnViewerDieRollComplete(null, new ViewerDieRollStoppedEventArgs(card, stopRollingData)); }
public void AttackCurrentMonster() { // Determine damage to monster RollResults PlayerDamage = DiceRoller.RollDiceAgainstThreshold((int)CurrentPlayer.StrengthAttackPower); RollResults MonsterToughness = DiceRoller.RollDiceAgainstThreshold((int)CurrentMonster.myStats.Toughness.Value); int damageToMonster = (PlayerDamage.Hits + (2 * PlayerDamage.Crits)) - MonsterToughness.Hits / 2; if (damageToMonster == 0) { RaiseMessage($"You missed {CurrentMonster.Name}."); } else { CurrentMonster.CurrentHealth -= damageToMonster; RaiseMessage($"You hit {CurrentMonster.Name} for {damageToMonster} points."); } // If monster if killed, collect rewards and loot if (CurrentMonster.CurrentHealth <= 0) { RaiseMessage(""); RaiseMessage($"You defeated {CurrentMonster.Name}!"); CurrentPlayer.Experience += CurrentMonster.RewardExperiencePoints; RaiseMessage($"You receive {CurrentMonster.RewardExperiencePoints} experience points."); CurrentPlayer.Gold += CurrentMonster.RewardGold; RaiseMessage($"You receive {CurrentMonster.RewardGold} gold."); CurrentSession.ButtonContext = new ExploreButtonContext(CurrentSession); } else { RollResults MonsterDamage = DiceRoller.RollDiceAgainstThreshold((int)CurrentMonster.StrengthAttackPower); RollResults PlayerToughness = DiceRoller.RollDiceAgainstThreshold((int)CurrentPlayer.myStats.Toughness.Value); // If monster is still alive, let the monster attack int damageToPlayer = (MonsterDamage.Hits + (2 * MonsterDamage.Crits)) - PlayerToughness.Hits; if (damageToPlayer <= 0) { RaiseMessage("The monster attacks, but misses you."); } else { CurrentPlayer.CurrentHealth -= damageToPlayer; RaiseMessage($"{CurrentMonster.Name} hit you for {damageToPlayer} points."); } // If player is killed, move them back to their home. if (CurrentPlayer.CurrentHealth <= 0) { RaiseMessage(""); RaiseMessage($"The {CurrentMonster.Name} defeated you..."); CurrentSession.CurrentLocation = CurrentSession.CurrentWorld.LocationAt(0, -1); // Player's home CurrentPlayer.CurrentHealth = CurrentPlayer.MaxHealth; // Completely heal the player CurrentSession.ButtonContext = new ExploreButtonContext(CurrentSession); } } }
public ViewerDieRollStoppedEventArgs(CardDto card, RollResults stopRollingData) { StopRollingData = stopRollingData; Card = card; }
public void Play(int score, IGameCalculator gameCalculator, int currentFrameCounter, RollResults rollResult, Guid currentGameId) { Logger.Info("BowlingPlayer :: Play"); _currentFrameCounter = currentFrameCounter; ValidateData(score, rollResult); try { if (rollResult == RollResults.Bonus) { HandleBonusRoll(score, gameCalculator, currentGameId); return; } if (ShouldCreateFrame()) { Frames.Add(new Frame(_currentFrameCounter)); } CurrentFrame = Frames[_currentFrameCounter]; if (HandleStrikeFrame(currentGameId, gameCalculator, score)) { return; } CurrentFrame.RollScore.Add(new RollScore(score)); if (HandleSpareFrame(currentFrameCounter)) { return; } HandleFullFrame(currentGameId, gameCalculator, score); } catch (Exception e) { Logger.Error(e); throw e; } }
public void ValidateData(int score, RollResults rollResult) { Logger.Info("BowlingPlayer :: ValidateData"); _gameRules.ValidateData(score, rollResult, _currentFrameCounter, Frames); }
private void PlayerOnFramesCompleted() { GameCalculator.CalculateTotalScore(_currentPlayer.PlayerId); RollResults = RollResults.GameOver; }
private void PlayerOnBonusLastFramesEvent() { RollResults = RollResults.Bonus; RollRound(); RollResults = RollResults.None; }
private void PlayerOnRunAdditionalRoll() { RollRound(); RollResults = RollResults.PlayAdditional; }
private void PlayerOnFrameComplete(IFrame obj) { RollResults = RollResults.FrameIsFull; }