private async Task <IEnumerable <PetResult> > changePetStat(InventoryItemDetails item, ItemEffect effect, int petId, User activeUser)
        {
            Pet pet = (await PetDomain.RetrievePets(petId)).FirstOrDefault();
            var arg = (ChangePetStatEffectArgument)effect.EffectParameters;

            switch (arg.Stat)
            {
            case PetStat.Food:
                await PetDomain.ChangePetFood(petId, arg.Amount, activeUser);

                break;

            case PetStat.Health:
                await PetDomain.ChangePetHealth(petId, arg.Amount, activeUser);

                break;

            default:
                break;
            }

            return(new List <PetResult>
            {
                new PetResult
                {
                    ChangedStat = arg.Stat,
                    StatChangeAmount = arg.Amount
                }
            });
        }
Example #2
0
        public async Task SubscribeAsync()
        {
            void CallBack(InventoryItemCreated data)
            {
                _logger.LogInformation($"Beginning processing of InventoryItemCreated event for AggregateId {data.Id}");
                var inventoryItem = new InventoryItemDetails(data.Id, data.Name, 0, data.Version);

                InMemoryDatabase.Details.Add(data.Id, inventoryItem);
                _logger.LogInformation($"Completed processing of InventoryItemCreated event for AggregateId {data.Id}");
            }

            await _subscriber.SubscribeAsync((Action <InventoryItemCreated>) CallBack);

            _logger.LogInformation("InventoryItemCreated subscription created");
        }
        private async Task <IEnumerable <UserResult> > changeUserStat(InventoryItemDetails item, ItemEffect effect, User activeUser)
        {
            ChangeUserStatEffectArgument arg = (ChangeUserStatEffectArgument)effect.EffectParameters;

            switch (arg.Stat)
            {
            case UserStat.Cash:
                await UserDomain.ChangeUserCash(arg.Amount, activeUser);

                break;

            default:
                break;
            }

            return(new List <UserResult>
            {
                new UserResult
                {
                    ChangedStat = arg.Stat,
                    StatChangeAmount = arg.Amount
                }
            });
        }
        private async Task <IEnumerable <ItemResult> > transform(InventoryItemDetails item, ItemEffect effect, User activeUser)
        {
            TransformEffectArgument arg      = (TransformEffectArgument)effect.EffectParameters;
            List <ItemResult>       response = new List <ItemResult>();

            if (arg.To != null)
            {
                foreach (var itemToCreate in arg.To)
                {
                    var newItemIds = await InventoryRepo.CreateItems(itemToCreate.ItemTypeId, activeUser.Id, itemToCreate.Quantity);

                    var itemsDetails = await InventoryRepo.RetrieveFullItemsByIds(newItemIds.ToArray());

                    foreach (InventoryItemDetails itemDetails in itemsDetails)
                    {
                        response.Add(new ItemResult
                        {
                            ItemId  = itemDetails.Item.Id,
                            Deleted = false,
                            NewItem = itemDetails
                        });
                    }
                }
            }

            if (arg.ToRandom?.Count() > 0)
            {
                var totalGenerated = 0;
                foreach (var itemToCreate in arg.ToRandom)
                {
                    int generationQty = Math.Max(Utilities.Extensions.Random.Next(itemToCreate.MinimumQuantity ?? 0, itemToCreate.MaximumQuantity ?? 0), 1);
                    if (arg.RandomTotalMaximumQuantity.HasValue)
                    {
                        generationQty = Math.Min(arg.RandomTotalMaximumQuantity.Value - (totalGenerated + generationQty), generationQty);
                    }
                    if (generationQty <= 0)
                    {
                        break;
                    }
                    totalGenerated += generationQty;

                    var newItemIds = await InventoryRepo.CreateItems(itemToCreate.ItemTypeId, activeUser.Id, generationQty);

                    var itemsDetails = await InventoryRepo.RetrieveFullItemsByIds(newItemIds.ToArray());

                    foreach (InventoryItemDetails itemDetails in itemsDetails)
                    {
                        response.Add(new ItemResult
                        {
                            ItemId  = itemDetails.Item.Id,
                            Deleted = false,
                            NewItem = itemDetails
                        });
                    }
                }
            }

            if (arg.DeleteOnUse)
            {
                await InventoryRepo.DestroyItem(item.Item.Id, activeUser.Id);

                response.Add(new ItemResult
                {
                    ItemId  = item.Item.Id,
                    Deleted = true
                });
            }

            return(response);
        }
        private Task <IEnumerable <ItemResult> > changeItemStat(InventoryItemDetails item, ItemEffect effect, User activeUser)
        {
            var arg = (ChangeItemStatEffectArgument)effect.EffectParameters;

            return(null);
        }