public async Task EquipArmour(string armourName)
        {
            var activeCharacter =
                _stewardContext.PlayerCharacters
                .Include(c => c.DefaultMeleeWeapon)
                .Include(c => c.DefaultRangedWeapon)
                .SingleOrDefault(c => c.DiscordUserId == Context.User.Id.ToString() && c.YearOfDeath == null);

            var valkFinderArmour =
                _stewardContext.ValkFinderArmours.FirstOrDefault(w => w.ArmourName == armourName);

            if (valkFinderArmour == null)
            {
                await ReplyAsync($"Could not find Armour.");

                return;
            }

            if (!_inventoryService.CheckInv(activeCharacter, valkFinderArmour.ArmourName, "armour", 1))
            {
                await ReplyAsync($"You do not have a {valkFinderArmour.ArmourName} in your inventory");

                return;
            }

            activeCharacter.EquippedArmour = valkFinderArmour;

            _stewardContext.PlayerCharacters.Update(activeCharacter);
            await _stewardContext.SaveChangesAsync();

            await ReplyAsync($"{valkFinderArmour.ArmourName} has been equipped.");
        }
Example #2
0
        public async Task SetDefaultWeapon(string weaponName)
        {
            var activeCharacter =
                _stewardContext.PlayerCharacters
                .Include(c => c.DefaultMeleeWeapon)
                .Include(c => c.DefaultRangedWeapon)
                .SingleOrDefault(c => c.DiscordUserId == Context.User.Id.ToString() && c.YearOfDeath == null);

            var valkFinderWeapon =
                _stewardContext.ValkFinderWeapons.FirstOrDefault(w => w.WeaponName == weaponName);

            if (valkFinderWeapon == null)
            {
                await ReplyAsync($"Could not find weapon.");

                return;
            }

            if (!_inventoryService.CheckInv(activeCharacter, valkFinderWeapon.WeaponName, "weapon", 1))
            {
                await ReplyAsync($"You do not have a {valkFinderWeapon.WeaponName} in your inventory");

                return;
            }

            if (valkFinderWeapon.IsRanged)
            {
                activeCharacter.DefaultRangedWeapon = valkFinderWeapon;
            }
            else
            {
                activeCharacter.DefaultMeleeWeapon = valkFinderWeapon;
            }

            _stewardContext.PlayerCharacters.Update(activeCharacter);
            await _stewardContext.SaveChangesAsync();

            await ReplyAsync($"{valkFinderWeapon.WeaponName} has been equipped.");
        }
        public async Task Transfer(string itemName, string type, SocketGuildUser mention, int amount = 1)//add item to mentioned player
        {
            //check wheter ItemID of type exists
            //check wheter player has item
            //give player item
            var commandUser = _stewardContext.DiscordUsers
                              .Include(du => du.Characters)
                              .SingleOrDefault(u => u.DiscordId == Context.User.Id.ToString());

            var activeCharacter = commandUser.Characters.Find(c => c.IsAlive());

            if (activeCharacter == null)
            {
                await ReplyAsync("Could not find a living character.");

                return;
            }
            var discordUser = _stewardContext.DiscordUsers
                              .Include(du => du.Characters)
                              .SingleOrDefault(u => u.DiscordId == mention.Id.ToString());

            var receivingCharacter = discordUser.Characters.Find(c => c.IsAlive());

            if (receivingCharacter == null)
            {
                await ReplyAsync($"Could not find a living character for {_client.GetUser(ulong.Parse(discordUser.DiscordId)).ToString()}.");

                return;
            }
            object item;

            switch (type)
            {
            case "weapon":
                item = _stewardContext.ValkFinderWeapons.FirstOrDefault(w => w.WeaponName == itemName);
                break;

            case "armour":
                item = _stewardContext.ValkFinderArmours.FirstOrDefault(w => w.ArmourName == itemName);
                break;

            case "item":
                item = _stewardContext.ValkFinderItems.FirstOrDefault(w => w.ItemName == itemName);
                break;

            default:
                await ReplyAsync($"{type} is not a valid item type. Types are armour/weapon/item.");

                return;
            }
            if (item == null)
            {
                await ReplyAsync($"{itemName} either does not exist or is not a {type}");

                return;
            }

            //does sender have enough items?
            if (!_inventoryService.CheckInv(activeCharacter, itemName, type, amount))
            {
                await ReplyAsync($"You don't have enough of {itemName} in you inventory to give {amount} away.");

                return;
            }

            await _inventoryService.GiveItem(receivingCharacter, itemName, type, amount); //gives item to reciever

            await _inventoryService.TakeItem(activeCharacter, itemName, type, amount);    //takes item with sender inventory

            await ReplyAsync($"{amount} of the {type} {itemName} has been given to {receivingCharacter.CharacterName}");
        }