Exemplo n.º 1
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var args = e.ArgsAsList;

            if (args.Count == 1)
            {
                player.ChatClient.PostDirectMessage(player, "What would you like to attack?");
                return;
            }
            else
            {
                var victim = args[1].ToLower();

                if (player.Here(victim))
                {
                    var target = player.CurrentLocation.Items.FirstOrDefault(i => i.IsMatch(victim));

                    if (target == null)
                    {
                        var contents = player.CurrentLocation.Items.SelectMany(i => i.Contents);
                        target = contents.FirstOrDefault(i => i.IsMatch(victim));
                    }

                    if (target != null)
                    {
                        target.Attack(player, target);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private WanderingMonster GetDwarfIfPresent(IAdventurePlayer player)
        {
            foreach (var manager in Game.MonsterManagers)
            {
                if (player.Here(Item.Dwarf, manager))
                {
                    return(manager.Monsters.First(d => (d.CurrentLocation != null) &&
                                                  d.CurrentLocation.LocationId.Equals(player.CurrentLocation.LocationId) &&
                                                  (d.Group == MonsterGroup.Dwarves)));
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var args = e.ArgsAsList;

            if (args.Count == 1)
            {
                player.ChatClient.PostDirectMessage(player, "What would you like to give?");
                return;
            }

            IAdventureItem itemInInventory    = null;
            IAdventureItem potentialRecipient = null;
            var            giveTo             = string.Empty;

            if (args.Count == 2)
            {
                var itemToGive = args[1].ToLower();

                if (!player.Inventory.Has(itemToGive))
                {
                    player.ChatClient.PostDirectMessage(player, $"You don't have a {itemToGive} to give to anyone!");
                    return;
                }

                itemInInventory    = player.Inventory.GetItems().FirstOrDefault(i => i.IsMatch(itemToGive));
                potentialRecipient = player.CurrentLocation.Items.FirstOrDefault(x => x.IsCreature);
            }
            else
            {
                var potentialItem = args[1].ToLower();
                giveTo = args[2].ToLower();

                if (!player.Inventory.Has(potentialItem))
                {
                    giveTo        = args[1].ToLower();
                    potentialItem = args[2].ToLower();

                    if (!player.Inventory.Has(potentialItem))
                    {
                        player.ChatClient.PostDirectMessage(player, $"You don't have a {potentialItem} to give to anyone!");
                        player.ChatClient.PostDirectMessage(player, "Try saying, !adv give _item_ to _recipient_...");

                        return;
                    }
                    else
                    {
                        itemInInventory = player.Inventory.GetItems().FirstOrDefault(i => i.IsMatch(potentialItem));
                    }
                }
                else
                {
                    itemInInventory = player.Inventory.GetItems().FirstOrDefault(i => i.IsMatch(potentialItem));
                }
            }

            if (player.Here(giveTo) ||
                (potentialRecipient != null && player.Here(potentialRecipient.ItemId)))
            {
                var recipient = !string.IsNullOrWhiteSpace(giveTo)
                    ? player.CurrentLocation.Items.FirstOrDefault(i => i.IsMatch(giveTo))
                    : potentialRecipient;

                if (player.Here(recipient.ItemId))
                {
                    recipient.Give(player, itemInInventory, recipient);
                    return;
                }
            }

            player.ChatClient.PostDirectMessage(player, $"I'm not sure who you want to give the {itemInInventory.Name} to...");
        }
Exemplo n.º 4
0
        public override void Invoke(IAdventurePlayer player, ChatCommandEventArgs e)
        {
            var args = e.ArgsAsList;

            if (args.Count == 1)
            {
                player.ChatClient.PostDirectMessage(player, "What would you like to attack?");
                return;
            }
            else if (args.Count == 2)
            {
                var victim = args[1].ToLower();

                if (player.Here(victim))
                {
                    var target = player.CurrentLocation.Items.FirstOrDefault(i => i.IsMatch(victim));

                    if (target == null)
                    {
                        var contents = player.CurrentLocation.Items.SelectMany(i => i.Contents);
                        target = contents.FirstOrDefault(i => i.IsMatch(victim));
                    }

                    if (target != null)
                    {
                        if (target.IsCreature)
                        {
                            player.ChatClient.PostDirectMessage(player, "Do you just want to use your bare hands?");
                            var attackState = new AddPlayerItemState("attack"); // ToDo: how to guarantee this is removed?
                            attackState.Do(player, target);
                        }
                        else
                        {
                            target.Attack(player, target);
                        }
                    }

                    return;
                }
            }
            else
            {
                var victim = args[1].ToLower();
                var weapon = args[2].ToLower();

                var target = player.CurrentLocation.Items.FirstOrDefault(i => i.IsMatch(victim));

                if (target == null)
                {
                    var contents = player.CurrentLocation.Items.SelectMany(i => i.Contents);
                    target = contents.FirstOrDefault(i => i.IsMatch(victim));
                }

                if (target != null)
                {
                    if (!player.Inventory.Has(weapon))
                    {
                        player.ChatClient.PostDirectMessage(player, $"You are not carrying a {weapon}!");
                        return;
                    }

                    var weaponItem = player.Inventory.GetItems().FirstOrDefault(i => i.IsMatch(weapon));

                    if (!weaponItem.IsWeapon)
                    {
                        player.ChatClient.PostDirectMessage(player, $"You cannot fight with a {weapon}!");
                        return;
                    }

                    target.Attack(player, target, weaponItem);
                    return;
                }
            }

            player.ChatClient.PostDirectMessage(player, $"I can't see anything like that to attack!");
        }