예제 #1
0
 static string GetMotionName(ConsumableEntity template)
 {
     if (template.Projectile > 0)
     {
         return "Throw01";
     }
     return string.Empty;
 }
예제 #2
0
        /// <summary>
        /// Inserts a consumable entity into the database which gets <c>offerId</c> as foreign key for the offer entity it relates to.
        /// </summary>
        /// <param name="offerId">The unique id of the offer</param>
        /// <param name="consumable">The consumable from which the entity is created</param>
        /// <returns></returns>
        private async Task InsertAsync(int offerId, Consumable consumable)
        {
            var consumableEntity = new ConsumableEntity().Build(consumable);

            consumableEntity.offer_id = offerId;
            await consumableEntity.InsertAsync(_context);

            consumable.id = consumableEntity.id;
        }
예제 #3
0
    public ItemCommand(ConsumableEntity template)
        : base(GetMotionName(template), template.ActionPattern, template.Priority, 0, template.GlobalCooldownTime, false, (template.ConsumableGroupType == E_CousumableGroupType.Scroll) ? IsPuzzleReady : (FireCondition)null)
    {
        this.template = template;

        string type = template.ConsumableGroupType.ToString();
        type = type.Replace("Attack", "").Replace("StatusEffect", "Buff");
        this.name = string.Format("item{0}\n{1}", template.ConsumableID, type);
        if (template.Projectile > 0)
        {
            name += "\nProjectile";
        }
    }
예제 #4
0
 public Consumable build(ConsumableEntity c)
 {
     NullCheck.ThrowIfNull <ConsumableEntity>(c);
     id           = c.id;
     category     = c.category;
     name         = c.name;
     manufacturer = c.manufacturer;
     ordernumber  = c.ordernumber;
     amount       = c.amount;
     unit         = c.unit;
     annotation   = c.annotation;
     return(this);
 }
예제 #5
0
        public async Task MarkConsumableAsDeletedAsync(string token, int consumableId, string reason)
        {
            NullCheck.ThrowIfNull <string>(reason);

            if (reason.Trim().Length == 0)
            {
                throw new ArgumentException(FailureCodes.InvalidReason);
            }

            // Get consumable from database
            var query =
                from o in _context.offer as IQueryable <OfferEntity>
                join c in _context.consumable on o.id equals c.offer_id
                where token == o.token && c.id == consumableId
                select new { c, o };

            var foundConsumables = await query.ToListAsync();

            if (foundConsumables.Count == 0)
            {
                throw new DataNotFoundException(FailureCodes.NotFoundConsumable);
            }

            ConsumableEntity consumableEntity = foundConsumables[0].c;
            OfferEntity      offerEntity      = foundConsumables[0].o;

            consumableEntity.is_deleted = true;
            await consumableEntity.UpdateAsync(_context);

            await new ChangeEntity()
            {
                change_type      = ChangeEntityChangeType.DeleteResource,
                element_id       = consumableEntity.id,
                element_type     = ChangeEntityElementType.Consumable,
                element_category = consumableEntity.category,
                element_name     = consumableEntity.name,
                diff_amount      = consumableEntity.amount,
                reason           = reason,
                timestamp        = DateTime.Now,
                region           = offerEntity.region
            }.InsertAsync(_context);
        }
예제 #6
0
        public async IAsyncEnumerable <OfferResource <Consumable> > QueryOffersAsync(Consumable con, string region)
        {
            NullCheck.ThrowIfNull <Consumable>(con);

            var consumable        = new ConsumableEntity().Build(con);
            var maxDistance       = con.kilometer;
            var consumableAddress = con.address;
            var location          = new AddressEntity().build(consumableAddress);

            _addressMaker.SetCoordinates(location);

            var query = from o in _context.offer as IQueryable <OfferEntity>
                        join c in _context.consumable on o.id equals c.offer_id
                        join ap in _context.address on o.address_id equals ap.Id
                        where consumable.category == c.category && !c.is_deleted && o.region == region
                        select new { o, c, ap };

            if (!string.IsNullOrEmpty(consumable.name))
            {
                query = query.Where(collection => consumable.name == collection.c.name);
            }
            if (!string.IsNullOrEmpty(consumable.manufacturer))
            {
                query = query.Where(collection => consumable.manufacturer == collection.c.manufacturer);;
            }
            if (consumable.amount > 0)
            {
                query = query.Where(collection => consumable.amount <= collection.c.amount);
            }

            List <OfferResource <Consumable> > resources = new List <OfferResource <Consumable> >();
            var results = await query.ToListAsync();

            foreach (var data in results)
            {
                var resource = new Consumable().build(data.c);

                var yLatitude  = data.ap.Latitude;
                var yLongitude = data.ap.Longitude;
                var distance   = DistanceCalculator.computeDistance(location.Latitude, location.Longitude, yLatitude, yLongitude);
                if (distance > maxDistance && maxDistance != 0)
                {
                    continue;
                }
                resource.kilometer = (int)Math.Round(distance);

                var provider        = new Provider().Build(data.o);
                var providerAddress = new Address().Build(data.ap);

                provider.address = providerAddress;

                var offer = new OfferResource <Consumable>()
                {
                    resource = resource
                };

                // ---- HOTFIX
                // Vorerst sollen keine persönliche Daten veröffentlicht werden.
                provider.ispublic = false;
                // ---- END HOTFIX

                if (provider.ispublic)
                {
                    offer.provider = provider;
                }

                yield return(offer);
            }
        }
예제 #7
0
        public async Task ChangeConsumableAmountAsync(string token, int consumableId, int newAmount, string reason)
        {
            NullCheck.ThrowIfNull <string>(token);
            NullCheck.ThrowIfNull <string>(reason);

            // Get consumable from database
            var query =
                from o in _context.offer as IQueryable <OfferEntity>
                join c in _context.consumable on o.id equals c.offer_id
                where token == o.token && c.id == consumableId
                select new { c, o };
            var foundConsumables = await query.ToListAsync();

            if (foundConsumables.Count == 0)
            {
                throw new DataNotFoundException(FailureCodes.NotFoundConsumable);
            }
            ConsumableEntity consumable = foundConsumables[0].c;
            OfferEntity      offer      = foundConsumables[0].o;

            // If amount has not changed: do nothing
            if (consumable.amount == newAmount)
            {
                return;
            }

            int diffAmount = Math.Abs(newAmount - consumable.amount);

            // If amount has increased: no reason required
            if (consumable.amount < newAmount)
            {
                consumable.amount = newAmount;
                await consumable.UpdateAsync(_context);

                // Add log
                await new ChangeEntity()
                {
                    change_type      = "INCREASE_AMOUNT",
                    element_id       = consumable.id,
                    element_type     = "consumable",
                    element_category = consumable.category,
                    element_name     = consumable.name,
                    diff_amount      = diffAmount,
                    reason           = reason,
                    timestamp        = DateTime.Now,
                    region           = offer.region
                }.InsertAsync(_context);

                return;
            }

            // If amount has decreased: ensure that a reason is provided
            if (reason.Trim().Length == 0)
            {
                throw new ArgumentException(FailureCodes.InvalidReason);
            }
            if (newAmount < 1)
            {
                throw new ArgumentException(FailureCodes.InvalidAmountConsumable);
            }
            consumable.amount = newAmount;
            await consumable.UpdateAsync(_context);

            // Add log
            await new ChangeEntity()
            {
                change_type      = "DECREASE_AMOUNT",
                element_id       = consumable.id,
                element_type     = "consumable",
                element_category = consumable.category,
                element_name     = consumable.name,
                diff_amount      = diffAmount,
                reason           = reason,
                timestamp        = DateTime.Now,
                region           = offer.region
            }.InsertAsync(_context);
        }