Beispiel #1
0
        }         // AddItem()

        public async Task <bool> ChangeItemQty(Creature creature, int itemId, int qty)
        {
            Creature target = _ctx.Creatures.Find(creature.Id);

            if (target == null)
            {
                return(false);
            }

            Item item = _ctx.Items.Find(itemId);

            if (item == null)
            {
                return(false);
            }

            if (target.Items.SingleOrDefault(x => x.ItemId == itemId) == null)
            {
                return(false);
            }

            target.Items.SingleOrDefault(x => x.ItemId == itemId).Qty = qty;

            await _ctx.SaveChangesAsync();

            CalculateCreature.ItemEffect(creature, _ctx, itemId);

            return(true);
        }         // ChangeItemQty()
Beispiel #2
0
        }         // ChangeItemQty()

        public async Task <bool> DeleteItem(Creature creature, int itemId)
        {
            Creature target = _ctx.Creatures.Find(creature.Id);

            if (target == null)
            {
                return(false);
            }

            Item item = _ctx.Items.Find(itemId);

            if (item == null)
            {
                return(false);
            }

            if (target.Items.FirstOrDefault(x => x.ItemId == itemId) == null)
            {
                return(false);
            }

            target.Items.Remove(target.Items.FirstOrDefault(x => x.ItemId == itemId));

            await _ctx.SaveChangesAsync();

            CalculateCreature.ItemEffect(creature, _ctx, itemId);

            return(true);
        }         // DeleteItem()
Beispiel #3
0
        }         // UpdateArmor() updates only creature's armor

        public async Task <bool> AddItem(Creature creature, int itemId)
        {
            Creature target = _ctx.Creatures.Include(x => x.Items).ThenInclude(x => x.Item).SingleOrDefault(x => x.Id == creature.Id);

            if (target == null)
            {
                return(false);
            }

            Item item = _ctx.Items.Find(itemId);

            if (item == null)
            {
                return(false);
            }


            if (target.Items == null || target.Items.Count == 0)
            {
                target.Items = new List <CreatureItem>
                {
                    new CreatureItem
                    {
                        CreatureId = target.Id,
                        ItemId     = item.Id,
                        Qty        = 1,

                        Creature = target,
                        Item     = item
                    }
                };
            }

            else if (target.Items != null)
            {
                if (item.ItemType == Enumerators.ItemTypeEnum.AgilityBooster ||
                    item.ItemType == Enumerators.ItemTypeEnum.EnduranceBooster ||
                    item.ItemType == Enumerators.ItemTypeEnum.SpeedBooster ||
                    item.ItemType == Enumerators.ItemTypeEnum.StrengthBooster ||
                    item.ItemType == Enumerators.ItemTypeEnum.WillpowerBooster)
                {
                    var booster = target.Items.SingleOrDefault(x => x.Item.ItemType == item.ItemType);

                    if (booster != null)
                    {
                        target.Items.Remove(booster);
                    }

                    target.Items.Add(new CreatureItem
                    {
                        CreatureId = target.Id,
                        ItemId     = item.Id,
                        Qty        = 1,

                        Creature = target,
                        Item     = item
                    });
                }

                else if (target.Items.SingleOrDefault(x => x.ItemId == itemId) == null)
                {
                    target.Items.Add(new CreatureItem
                    {
                        CreatureId = target.Id,
                        ItemId     = item.Id,
                        Qty        = 1,

                        Creature = target,
                        Item     = item
                    });
                }

                else
                {
                    target.Items.FirstOrDefault(x => x.ItemId == itemId).Qty++;
                }
            }

            await _ctx.SaveChangesAsync();

            CalculateCreature.ItemEffect(creature, _ctx, itemId);

            return(true);
        }         // AddItem()