Example #1
0
        public EvaluationData AddQuantity(int resourceId, long addAmount)
        {
            var resource = GetSingleResourceFromList(_evaluationDataController.Get(new[] { resourceId }));

            var value = long.Parse(resource.Value) + addAmount;

            if (value < 0)
            {
                value = 0;
            }
            resource.Value = (value).ToString();

            _evaluationDataController.Update(resource);

            _logger.LogInformation($"{resource.Id} with Amount: {addAmount}");

            return(resource);
        }
Example #2
0
        public bool AddReward(int actorId, int gameId, Reward reward)
        {
            var evaluationDataController = new EvaluationDataController(EvaluationDataLogger, ContextFactory, reward.EvaluationDataCategory);

            var evaluationData = new EvaluationData {
                Key                = reward.EvaluationDataKey,
                GameId             = gameId,
                ActorId            = actorId,
                Category           = reward.EvaluationDataCategory,
                EvaluationDataType = reward.EvaluationDataType,
                Value              = reward.Value
            };

            if (reward.EvaluationDataCategory == Common.EvaluationDataCategory.Resource)
            {
                var current = evaluationDataController.Get(gameId, actorId, new[] { reward.EvaluationDataKey });
                if (current.Any())
                {
                    evaluationData.Value = (long.Parse(reward.Value) + long.Parse(current.Single().Value)).ToString();

                    evaluationDataController.Update(evaluationData);
                }
                else
                {
                    evaluationDataController.Add(evaluationData);
                }
            }
            else
            {
                evaluationDataController.Add(evaluationData);
            }

            _logger.LogInformation($"Game Data: {evaluationData.Id} for ActorId: {actorId}, GameId: {gameId}, Reward: {reward.Id}");

            return(true);
        }