Example #1
0
        public UseResult Use(Player player)
        {
            UseResult result = Logic.Use(player);

            if (result.success == true)
            {
                player.CurrentKingdom.Vault.RemoveItem(this);
            }

            return(result);
        }
        public async Task <UseResult> UseItem(int itemId, ItemFunctionality itemFunctionality, int entityId, User activeUser)
        {
            var item = (await InventoryRepo.RetrieveFullItemsByIds(itemId)).FirstOrDefault();

            if (item != null && item.Item.OwnerUserId == activeUser.Id)
            {
                UseResult result = new UseResult();
                using (var trans = TransactionScopeFactory.Create())
                {
                    IEnumerable <ItemEffect> effects = await getItemEffects(item.ItemType.Id, itemFunctionality);

                    foreach (ItemEffect effect in effects)
                    {
                        switch (effect.EffectType)
                        {
                        case EffectType.ChangePetStat:
                            result.PetChanges = result.PetChanges.Concat(await changePetStat(item, effect, entityId, activeUser));
                            break;

                        case EffectType.ChangeItemStat:
                            result.ItemChanges = result.ItemChanges.Concat(await changeItemStat(item, effect, activeUser));
                            break;

                        case EffectType.ChangeUserStat:
                            result.UserChanges = result.UserChanges.Concat(await changeUserStat(item, effect, activeUser));
                            break;

                        case EffectType.Transform:
                        {
                            result.ItemChanges = result.ItemChanges.Concat(await transform(item, effect, activeUser));
                            break;
                        }

                        default:
                            break;
                        }
                    }
                    trans.Complete();
                }
                return(result);
            }
            throw new CritterException($"You can't do that, its not your item!",
                                       $"Invalid item provided for use - item: {itemId}, user: {activeUser.Id}",
                                       System.Net.HttpStatusCode.BadRequest);
        }
Example #3
0
        public CommandResult Use(ItemType itype)
        {
            if (!CurrentKingdom.Vault.ContainsItem(itype))
            {
                return(new UseResult(false, ResultType.NotFound));
            }

            Item item = CurrentKingdom.Vault.Items.First(i => i.Type == itype);

            if (!item.CheckMovement())
            {
                return(new CommandResult(false, ResultType.NoMovement));
            }

            UseResult result = item.Use(this);

            return(result);
        }