private GameStatus CalculateNext(GameStatus gameStatus, PlayEvent playEvent) { var properties = PlayEventProperties.GetByType(playEvent.Type); var eventType = playEvent.Type; var additionalScore = gameStatus.PlayerStatus.GetAdditionalPlayEventScore(playEvent, gameStatus); var newStatus = gameStatus .WithScore(gameStatus.Score + _eventStatusScoreCalculator.CalculateScoreForEvent(playEvent, gameStatus) + additionalScore) .WithScorePerSecond(gameStatus.ScoreRate + _eventStatusScoreCalculator.CalculateScoreForTick(playEvent, gameStatus)); var withAdditionalEffects = properties.AdditionalEffects(newStatus); return(withAdditionalEffects); }
private bool Validate(GameStatus gameStatus, PlayEvent playEvent) { var properties = PlayEventProperties.GetByType(playEvent.Type); var eventType = playEvent.Type; var canBuy = gameStatus.Score + _eventStatusScoreCalculator.CalculateScoreForEvent(playEvent, gameStatus) >= 0; var additionalValidation = properties.AdditionalValidation(gameStatus); var isValid = canBuy && additionalValidation; if (!isValid) { _logger.LogInformation("Play event is invalid for current game status", gameStatus, playEvent); } return(canBuy && additionalValidation); }
private bool CheckActionsInTick(IReadOnlyCollection <PlayEvent> events) { var cookieClicks = events .Where(e => e.Type == PlayEventType.CookieClicked) .ToArray(); var otherEventTypes = events .Select(e => e.Type) .Distinct() .Where(t => t != PlayEventType.CookieClicked && !PlayEventProperties.GetByType(t).Automatic) .ToArray(); var clickedCookieAndOtherEvent = cookieClicks.Any() && otherEventTypes.Any(); var tooManyCookieClicks = cookieClicks.Length >= 10; var valid = !clickedCookieAndOtherEvent && !tooManyCookieClicks; return(valid); }