Exemplo n.º 1
0
        public async Task CreateNewItem(string itemName, string itemDescription, int itemCost, int maxAllowed, int levelRequired, decimal defenseBuff, decimal attackBuff, bool allowHeist = false)
        {
            using var context = new RPGContext(_options);

            var existingItems = GetAllRobbingItems();

            if (existingItems.Exists(x => x.Name.ToLower() == itemName.ToLower()))
            {
                throw new Exception("An item with that name already exists.");
            }

            if (itemCost < 0)
            {
                throw new Exception("You cannot have a negative value for the item cost.");
            }

            if (maxAllowed < 1)
            {
                throw new Exception("The minimum max allowed is 1.");
            }

            if (defenseBuff > 0.5M)
            {
                throw new Exception("The defense buff is really high, please use a lower value.");
            }

            if (defenseBuff < -0.5M)
            {
                throw new Exception("The defense buff is really low, please use a higher value.");
            }

            if (attackBuff > 0.5M)
            {
                throw new Exception("The attack buff is really high, please use a lower value.");
            }

            if (attackBuff < -0.5M)
            {
                throw new Exception("The attack buff is really low, please use a higher value.");
            }

            var item = new RobbingItems
            {
                Name        = itemName,
                Cost        = itemCost,
                Description = itemDescription,
                LvlRequired = levelRequired,
                AllowHeist  = allowHeist,
                MaxAllowed  = maxAllowed,
                AttackBuff  = attackBuff,
                DefenseBuff = defenseBuff
            };

            context.Add(item);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task GiveUserItem(Profile profile, Profile botProfile, string itemName)
        {
            using var context = new RPGContext(_options);

            RobbingItems item = context.RobbingItems.First(x => x.Name.ToLower() == itemName.ToLower());

            if (profile.Gold < item.Cost)
            {
                throw new Exception("User cannot afford the item.");
            }

            if (profile.Level < item.LvlRequired)
            {
                throw new Exception("User is not the right level");
            }

            ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson);

            string newItemsJson;

            if (itemsJson.Robbing.Exists(x => x.Id == item.Id))
            {
                if (itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count >= item.MaxAllowed)
                {
                    throw new Exception("user already owns max amount of items.");
                }


                itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count++;

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }
            else
            {
                Robbing newRobbing = new Robbing {
                    Id = item.Id, Count = 1
                };

                itemsJson.Robbing.Add(newRobbing);

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }



            profile.ItemJson = newItemsJson;
            profile.Gold    -= item.Cost;

            context.Profiles.Update(profile);

            botProfile.Gold += item.Cost;

            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Exemplo n.º 3
0
        public async Task GiveUserItem(Profile profile, Profile botProfile, int itemId)
        {
            using var context = new RPGContext(_options);

            RobbingItems item = context.RobbingItems.SingleOrDefault(x => x.Id == itemId);

            if (profile.Gold < item.Cost)
            {
                throw new InvalidOperationException("The user cannot afford to purchase this item.");
            }

            if (profile.Level < item.LvlRequired)
            {
                throw new InvalidOperationException("The user is not the correct level to purchase this item.");
            }

            ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson);

            if (itemsJson.Robbing.SingleOrDefault(x => x.Id == itemId).Count >= item.MaxAllowed)
            {
                throw new InvalidOperationException("The user already owns the maximum number of items allowed.");
            }

            string newItemsJson;

            if (itemsJson.Robbing.Exists(x => x.Id == itemId))
            {
                itemsJson.Robbing.SingleOrDefault(x => x.Id == itemId).Count++;

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }
            else
            {
                Robbing newRobbing = new Robbing {
                    Id = itemId, Count = 1
                };

                itemsJson.Robbing.Add(newRobbing);

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }

            profile.ItemJson = newItemsJson;
            profile.Gold    -= item.Cost;

            context.Profiles.Update(profile);

            botProfile.Gold += item.Cost;

            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Exemplo n.º 4
0
        public async Task RemoveUserItemById(Profile profile, int itemId, bool refundGold)
        {
            using var context = new RPGContext(_options);

            ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson);

            RobbingItems item = context.RobbingItems.SingleOrDefault(x => x.Id == itemId);

            itemsJson.Robbing[itemId].Count--;

            if (refundGold)
            {
                profile.Gold = +item.Cost;
            }

            string newItemsJson = JsonConvert.SerializeObject(itemsJson);

            profile.ItemJson = newItemsJson;

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Exemplo n.º 5
0
 public void ModifyItem(int itemId, RobbingItems modifiedItem)
 {
     throw new NotImplementedException("This is not yet implemented.");
 }