/* Like Handletake, HandleDrop checks for an item's existence, but in this case it has to be in the
         * requesting user's inventory.
         * if item exists, remove it from the user inventory's list of refs and add to the room's Items instead
         */
        void HandleDrop(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            int  roomId = CommandUtils.GetCurrentRoomId(sender, Map);
            Item target = sender.Inventory.Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));

            if (target == null)
            {
                HandleHoldDrop(sender, e);
                return;
            }

            if (!target.Commands.Contains("drop"))
            {
                sender.Connection.SendMessage("You cannot drop that.");
                return;
            }

            XMLReference <Item> item = new XMLReference <Item> {
                Actual = target
            };

            sender.Player.Drop(target);
            sender.Inventory.setCurrentLoweredCapacity(target.Weight);
            sender.Inventory.RemoveFromInventory(target);
            Map.Rooms[roomId].Items.Add(item);
        }
        void HandleHold(User sender, string e)
        {
            var target = sender.Inventory.Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));

            if (target == null)
            {
                sender.Connection.SendMessage("You must have the object in your inventory.");
                return;
            }

            if (target.Commands.Contains("hold"))
            {
                if (sender.Player.Held.Count == 2)
                {
                    sender.Connection.SendMessage("You have no free hands.");
                    return;
                }

                sender.Inventory.RemoveFromInventory(target);
                sender.Inventory.setCurrentLoweredCapacity(target.Weight);
                CommandUtils.ChangeStats(target, sender);
                sender.Player.Hold(target);
                return;
            }

            sender.Connection.SendMessage("You cannot hold that.");
        }
        void HandleDrink(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            var target = sender.Inventory.Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));

            if (!target.IsConsumable)
            {
                sender.Connection.SendMessage("You cannot drink that.");
                return;
            }
            if (!CommandUtils.FuzzyEquals(target.ConsumableType, "drink"))
            {
                sender.Connection.SendMessage("You cannot drink that.");
                return;
            }
            if (target == null)
            {
                sender.Connection.SendMessage("You must have the object in your inventory.");
                return;
            }

            sender.Inventory.RemoveFromInventory(target);
            CommandUtils.ChangeStats(target, sender);
            sender.Inventory.setCurrentLoweredCapacity(target.Weight);
            return;
        }
Example #4
0
 public void GetFlavorText()
 {
     if (CommandUtils.FuzzyEquals(Target.AttackSpeed, "fast"))
     {
         AttackSuccessFlavor  = $"The {Target.Name} attacks quickly!";
         AttackFailFlavor     = $"The {Target.Name} tries to strike fast, but misses!";
         AttackCriticalFlavor = $"The {Target.Name} strikes with brutal speed!";
         AttackWeakFlavor     = $"The {Target.Name} just nicks you!";
         BlockFlavor          = $"The {Target.Name} blocks your attack!";
         LowHealthFlavor      = $"The {Target.Name} looks weak!";
         return;
     }
     if (CommandUtils.FuzzyEquals(Target.AttackSpeed, "slow"))
     {
         AttackSuccessFlavor  = $"The {Target.Name} attacks slowly!";
         AttackFailFlavor     = $"The {Target.Name} tries to strike, but is too slow!";
         AttackCriticalFlavor = $"The {Target.Name} slams you into the ground!";
         AttackWeakFlavor     = $"The {Target.Name} barely hits you!";
         BlockFlavor          = $"The {Target.Name} casually blocks your attack!";
         LowHealthFlavor      = $"The {Target.Name} looks like it might pass out!";
         return;
     }
     if (CommandUtils.FuzzyEquals(Target.AttackSpeed, "mid"))
     {
         AttackSuccessFlavor  = $"The {Target.Name} attacks!";
         AttackFailFlavor     = $"The {Target.Name} tries to strike, but misses!";
         AttackCriticalFlavor = $"The {Target.Name} lands a brutal blow!";
         AttackWeakFlavor     = $"The {Target.Name} strikes weakly!";
         BlockFlavor          = $"The {Target.Name} blocks your attack!";
         LowHealthFlavor      = $"The {Target.Name} looks weak!";
         return;
     }
 }
Example #5
0
        public void UseContainer(User sender)
        {
            string action = "";

            while (!CommandUtils.FuzzyEquals(action, "e"))
            {
                sender.Connection.SendMessage(@"What would you like to do?
t : take an item
a : add an item
p : pick up container
tc: take container
e : exit");
                action = sender.Connection.ReadMessage();
                if (CommandUtils.FuzzyEquals(action, "t"))
                {
                    TakeFromContainer(sender);
                }
                if (CommandUtils.FuzzyEquals(action, "a"))
                {
                    AddToContainer(sender);
                }
                if (CommandUtils.FuzzyEquals(action, "p"))
                {
                    PickUpContainer(sender);
                }
                if (CommandUtils.FuzzyEquals(action, "tc"))
                {
                    TakeContainer(sender);
                }
                if (CommandUtils.FuzzyEquals(action, "e"))
                {
                    return;
                }
            }
        }
        void HandleEquip(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            var  target    = sender.Inventory.Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));
            bool isWearing = false;

            if (!target.IsWearable)
            {
                sender.Connection.SendMessage("You cannot wear that.");
                return;
            }

            if (target == null)
            {
                sender.Connection.SendMessage("You must have the object in your inventory.");
                return;
            }

            if (target.IsWearable)
            {
                if (sender.Player.Equipped.Count == 6)
                {
                    sender.Connection.SendMessage("You have no other room to wear that.");
                    return;
                }

                foreach (Item item in sender.Player.Equipped)
                {
                    if (target.Slot == item.Slot)
                    {
                        sender.Connection.SendMessage($"You are already wearing a {target.Slot} item.");
                        isWearing = true;
                        break;
                    }
                }

                if (!isWearing)
                {
                    sender.Inventory.RemoveFromInventory(target);
                    sender.Player.Equip(target);
                    CommandUtils.ChangeStats(target, sender);
                    sender.Inventory.setCurrentLoweredCapacity(target.Weight);
                    return;
                }
            }
        }
        void HandleContainerExamine(User sender, string e)
        {
            int       roomId    = CommandUtils.GetCurrentRoomId(sender, Map);
            Container container = Map.Rooms[roomId].Containers.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Actual.Name, e))?.Actual;

            if (container == null)
            {
                // If it's not an npc, item, or container, it's unexaminable
                sender.Connection.SendMessage("That does not exist here!");
                return;
            }
            sender.Connection.SendMessage($"You examine the {e}.");
            sender.Connection.SendMessage($"{container.Description}");
        }
        /* HandleExamine allows a user to examine an object or themselves
         * 'examine self' returns a description of the user's player npc, including what they're wearing and appearance.
         * 'examine <item>' returns the description of the item. The item can be either in the room or in the user's inventory.
         * If the item is in neither, there is no description.
         */
        void HandleExamine(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            if (e == null)
            {
                sender.Connection.SendMessage("Examine what?");
                return;
            }

            if (CommandUtils.FuzzyEquals(e, "self"))
            {
                sender.Connection.SendMessage("You look yourself over.");
                if (sender.Player.Equipped.Count > 0)
                {
                    sender.Connection.SendMessage($"Equipped: {string.Join(", ", sender.Player.Equipped)}");
                }
                if (sender.Player.Held.Count > 0)
                {
                    sender.Connection.SendMessage($"Held: {string.Join(", ", sender.Player.Held)}");
                }
                sender.Connection.SendMessage($"Health: {sender.Player.Stats.CurrHealth}; Defense: {sender.Player.Stats.Defense}");
                return;
            }

            int  roomId = CommandUtils.GetCurrentRoomId(sender, Map);
            Item item   = Map.Rooms[roomId].Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Actual.Name, e))?.Actual ?? sender.Inventory.Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));

            if (item == null)
            {
                // If it's not a item, try and see if the target is an npc
                HandleNPCExamine(sender, e);
                return;
            }
            if (!item.Commands.Contains("examine"))
            {
                sender.Connection.SendMessage("You cannot examine that.");
                return;
            }

            sender.Connection.SendMessage($"You examine the {e}.");
            sender.Connection.SendMessage($"{item.Description}");
        }
        void HandleNPCExamine(User sender, string e)
        {
            int roomId = CommandUtils.GetCurrentRoomId(sender, Map);
            NPC npc    = Map.Rooms[roomId].NPCs.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Actual.Name, e))?.Actual;

            if (npc == null)
            {
                // If it's not an npc or a item, try and see if the target is a container
                HandleContainerExamine(sender, e);
                return;
            }
            if (!npc.Commands.Contains("examine"))
            {
                sender.Connection.SendMessage("You cannot examine that.");
                return;
            }
            sender.Connection.SendMessage($"You examine the {e}.");
            sender.Connection.SendMessage($"{npc.Description}");
        }
Example #10
0
 public void GetFlavorText()
 {
     if (CommandUtils.FuzzyEquals(Subject.Faction, "ally"))
     {
         GreetingFlavor = $"Hello, {Sender.Name}!";
         WhoFlavor      = $"I'm {Subject.Name}";
         NewsFlavor     = $"I got some news just recently!";
         TradeFlavor    = $"With you? Always.";
         QuestFlavor    = $"There was someitem I could use your help on.";
         ByeFlavor      = $"See you around, {Sender.Name}!";
         return;
     }
     if (CommandUtils.FuzzyEquals(Subject.Faction, "neutral"))
     {
         GreetingFlavor = $"Who are you?";
         WhoFlavor      = $"I am {Subject.Name}.";
         NewsFlavor     = $"Let me think...";
         TradeFlavor    = $"We might come to a deal.";
         QuestFlavor    = $"Let me think...";
         ByeFlavor      = $"Goodbye, stranger.";
         return;
     }
     if (CommandUtils.FuzzyEquals(Subject.Faction, "hostile"))
     {
         GreetingFlavor = $"Who are you?";
         WhoFlavor      = $"I don't trust you enough to tell you who I am.";
         NewsFlavor     = $"Go find out on your own.";
         TradeFlavor    = $"With the likes of you?";
         QuestFlavor    = $"You don't have any skills of use to me.";
         ByeFlavor      = $"Good riddance.";
         return;
     }
     if (CommandUtils.FuzzyEquals(Subject.Faction, "wildlife"))
     {
         GreetingFlavor = $"The {Subject.Name} gives you a suspicious look.";
         WhoFlavor      = $"The {Subject.Name} hisses at you.";
         NewsFlavor     = $"The {Subject.Name} clearly mistrusts you.";
         TradeFlavor    = $"The {Subject.Name} is very territorial of its belongings.";
         QuestFlavor    = $"The {Subject.Name} has no interests that you could resolve.";
         ByeFlavor      = $"The {Subject.Name} seems relieved you are leaving.";
         return;
     }
 }
        /* HandleTake and HandleDrop are relatively similar functions that just perform the inverses of each other
         * HandleTake checks if the item a user wants to take exists in the context of the room they are in.
         * if item exists, remove it from the room's list of references and add it to the player's inventory list instead
         */
        void HandleTake(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            int roomId = CommandUtils.GetCurrentRoomId(sender, Map);
            var target = Map.Rooms[roomId].Items.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Actual.Name, e));

            if (target == null)
            {
                sender.Connection.SendMessage("No such object exists.");
                return;
            }

            if (!target.Actual.Commands.Contains("take"))
            {
                sender.Connection.SendMessage("You cannot take that.");
                return;
            }

            // Prevent the chance that two users try to take the same item at the same time.
            lock (Map.Rooms[roomId].Items)
            {
                if (Map.Rooms[roomId].Items.Remove(target))
                {
                    sender.Inventory.setCurrentRaisedCapacity(target.Actual.Weight);
                    if (sender.Inventory.CurrentCapacity <= sender.Inventory.CarryCapacity)
                    {
                        sender.Inventory.AddToInventory(target.Actual);
                        sender.Connection.SendMessage($"You add the {e} to your inventory.");
                        return;
                    }
                    sender.Connection.SendMessage("You're carrying too much to take that.");
                }
                else
                {
                    sender.Connection.SendMessage("That item is no longer there.");
                }
            }
        }
Example #12
0
        public void AddToContainer(User sender)
        {
            if (CurrentCapacity <= Capacity)
            {
                sender.Connection.SendMessage("You have: ");
                foreach (Item i in sender.Inventory.Items)
                {
                    sender.Connection.SendMessage($"{i.Name} - Weight: {i.Weight}");
                }
                sender.Connection.SendMessage($"The {Name} can hold {Capacity - CurrentCapacity} more units.");

                sender.Connection.SendMessage("What would you like to put in the container?");
                string addItem = sender.Connection.ReadMessage();
                Item   item    = sender.Inventory.Items.Find(t => CommandUtils.FuzzyEquals(t.Name, addItem));

                if (item.Weight + CurrentCapacity > Capacity)
                {
                    sender.Connection.SendMessage($"The {Name} cannot hold that!");
                }
                else
                {
                    sender.Inventory.RemoveFromInventory(item);
                    CurrentCapacity += item.Weight;

                    XMLReference <Item> xmlItem = new XMLReference <Item> {
                        Actual = item
                    };

                    Contents.Add(xmlItem);

                    sender.Connection.SendMessage($"The {item.Name} has been added to the {Name}.");

                    return;
                }
            }
            else
            {
                sender.Connection.SendMessage($"The {Name} is full.");
                return;
            }
        }
        void HandleHoldDrop(User sender, string e)
        {
            int roomID = CommandUtils.GetCurrentRoomId(sender, Map);
            var target = sender.Player.Held.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));

            if (target == null)
            {
                sender.Connection.SendMessage("You are not holding that.");
                return;
            }

            if (!target.Commands.Contains("drop"))
            {
                sender.Connection.SendMessage("You cannot drop that.");
                return;
            }
            sender.Player.Drop(target);
            sender.Inventory.setCurrentRaisedCapacity(target.Weight);
            CommandUtils.RemoveItemChangeStats(target, sender);
            sender.Inventory.AddToInventory(target);
        }
        void HandleRemove(User sender, string e)
        {
            var target = sender.Player.Equipped.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Name, e));

            if (target == null)
            {
                sender.Connection.SendMessage("You are not wearing that.");
                return;
            }

            if (target.Commands.Contains("remove"))
            {
                sender.Player.Unequip(target);
                sender.Inventory.setCurrentRaisedCapacity(target.Weight);
                CommandUtils.RemoveItemChangeStats(target, sender);
                sender.Inventory.AddToInventory(target);
                return;
            }

            sender.Connection.SendMessage("You cannot remove that.");
        }
Example #15
0
        public void TakeFromContainer(User sender)
        {
            List <Item> dc = DecodeContents();

            if (Contents.Count > 0)
            {
                sender.Connection.SendMessage("The container has: ");
                foreach (Item i in dc)
                {
                    sender.Connection.SendMessage($"{i.Name}");
                }
                sender.Connection.SendMessage("What would you like to take?");
                string takeItem = sender.Connection.ReadMessage();
                var    item     = Contents.Find(t => CommandUtils.FuzzyEquals(t.Actual.Name, takeItem));

                if (item == null)
                {
                    sender.Connection.SendMessage($"There is no {item.Actual.Name} in the container.");
                }

                else
                {
                    sender.Inventory.AddToInventory(item.Actual);
                    sender.Connection.SendMessage($"The {item.Actual.Name} has been added to your inventory.");
                    CurrentCapacity -= item.Actual.Weight;
                    Contents.Remove(item);
                }
            }
            else
            {
                sender.Connection.SendMessage($"The {Name} is empty.");
            }

            if (CurrentCapacity < 0)
            {
                CurrentCapacity = 0;
            }
        }
        void HandleOpen(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }

            int roomId = CommandUtils.GetCurrentRoomId(sender, Map);
            var target = Map.Rooms[roomId].Containers.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Actual.Name, e));

            if (target == null)
            {
                sender.Connection.SendMessage("No such container exists.");
                return;
            }

            if (!target.Actual.IsUnlocked)
            {
                sender.Connection.SendMessage("This container is locked.");
                return;
            }

            lock (Map.Rooms[roomId].Containers)
            {
                sender.Connection.SendMessage($"You open the {target.Actual.Name}.");
                if (target.Actual.Contents.Count != 0)
                {
                    sender.Connection.SendMessage($"The {target.Actual.Name} contains some items!");
                }
                else
                {
                    sender.Connection.SendMessage($"The {target.Actual.Name} is empty.");
                }
                target.Actual.UseContainer(sender);
            }
        }
Example #17
0
        // Who gets a list of players currently in the sender's room.
        public void HandleWhoEvent(object sender, EventArgs e)
        {
            User        s            = sender as User;
            List <User> currentUsers = new List <User>();

            lock (Users)
            {
                foreach (User user in Users)
                {
                    if (CommandUtils.GetCurrentRoomId(user, Map) == CommandUtils.GetCurrentRoomId(s, Map))
                    {
                        currentUsers.Add(user);
                    }
                }
                currentUsers.Remove(s);
            }
            // if there is one player
            if (currentUsers.Count == 1)
            {
                s.Connection.SendMessage($"You see your ally, {string.Join(", ", currentUsers.Select(t => t.Name))}.");
            }
            // if there are multiple players
            else if (currentUsers.Count > 1)
            {
                s.Connection.SendMessage($"You see your allies, {string.Join(", ", currentUsers.Select(t => t.Name))}.");
            }
            // if there are no other players
            else
            {
                s.Connection.SendMessage("You have no allies nearby.");
            }
            if (CommandUtils.HasNPCs(s, Map))
            {
                List <NPC> friendlies       = new List <NPC>();
                List <NPC> meanies          = new List <NPC>();
                List <NPC> sneakies         = new List <NPC>();
                List <NPC> detectedSneakies = new List <NPC>();
                foreach (var i in Map.Rooms[CommandUtils.GetCurrentRoomId(s, Map)].NPCs)
                {
                    // each i is a reference to an entity
                    if (CommandUtils.FuzzyEquals(i.Actual.Faction, "enemy"))
                    {
                        if (i.Actual.IsHidden)
                        {
                            sneakies.Add(i.Actual);
                        }
                        else
                        {
                            meanies.Add(i.Actual);
                        }
                    }
                    else
                    {
                        friendlies.Add(i.Actual);
                    }
                }
                if (friendlies.Count > 0)
                {
                    s.Connection.SendMessage($"You can see: {string.Join(", ", friendlies.Select(t => t.Name))}");
                }
                if (meanies.Count > 0)
                {
                    s.Connection.SendMessage($"You can see some enemies: {string.Join(", ", meanies.Select(t => t.Name))}");
                }
                if (sneakies.Count > 0)
                {
                    // sender.Player.Stats.Dexterity >= directionGone.Actual.minDexterity
                    foreach (NPC entity in sneakies)
                    {
                        if (s.Player.Stats.Perception >= entity.minPerception)
                        {
                            detectedSneakies.Add(entity);
                        }
                    }
                    if (detectedSneakies.Count > 0)
                    {
                        s.Connection.SendMessage($"Although they are trying to be stealthy, you can see some enemies lurking in the shadows: {string.Join(", ", detectedSneakies.Select(t => t.Name))}");
                        return;
                    }
                    s.Connection.SendMessage("You don't see anyone new, but you sense a strange presence.");
                    return;
                }
            }
        }
Example #18
0
        public void Trade()
        {
            Sender.Player.IsTrading = true;
            List <Item> TradeItemsTo   = new List <Item>();
            List <Item> TradeItemsFrom = new List <Item>();

            Sender.Connection.SendMessage(TradeFlavor);
            while (Sender.Player.IsTrading)
            {
                Sender.Connection.SendMessage(@"What would you like to do?
ao: Add item to trade pool from your inventory
at: Add item to trade pool from entity's inventory
ro: Remove item from your trade pool
rt: Remove item from entity's trade pool
v: View current trade pools
s: Submit trade
q: Quit trading");
                string action = Sender.Connection.ReadMessage();
                if (CommandUtils.FuzzyEquals(action, "ao"))
                {
                    Sender.Connection.SendMessage("You have: ");
                    foreach (Item item in Sender.Inventory.Items)
                    {
                        Sender.Connection.SendMessage($"{item.Name} - Value: {item.Value}");
                    }
                    Sender.Connection.SendMessage("What would you like to trade?");
                    string tradeItem = Sender.Connection.ReadMessage();
                    var    trade     = Sender.Inventory.Items.Find(t => CommandUtils.FuzzyEquals(t.Name, tradeItem));
                    if (trade == null)
                    {
                        Sender.Connection.SendMessage($"You do not have a {trade.Name} to offer.");
                    }
                    else
                    {
                        TradeItemsTo.Add(trade);
                        Sender.Inventory.RemoveFromInventory(trade);
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "at"))
                {
                    Sender.Connection.SendMessage($"{Subject.Name} has: ");
                    foreach (Item item in Subject.Inventory.Items)
                    {
                        Sender.Connection.SendMessage($"{item.Name} - Value: {item.Value}");
                    }
                    Sender.Connection.SendMessage("What would you like to request?");
                    string tradeItem = Sender.Connection.ReadMessage();
                    var    trade     = Subject.Inventory.Items.Find(t => CommandUtils.FuzzyEquals(t.Name, tradeItem));
                    if (trade == null)
                    {
                        Sender.Connection.SendMessage($"{Subject.Name} does not have a {trade.Name}.");
                    }
                    else
                    {
                        TradeItemsFrom.Add(trade);
                        Subject.Inventory.RemoveFromInventory(trade);
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "ro"))
                {
                    Sender.Connection.SendMessage("You offered: ");
                    foreach (Item item in TradeItemsTo)
                    {
                        Sender.Connection.SendMessage($"{item.Name} - Value: {item.Value}");
                    }
                    Sender.Connection.SendMessage("What would you like to remove from the offers?");
                    string removeItem = Sender.Connection.ReadMessage();
                    var    remove     = TradeItemsTo.Find(t => CommandUtils.FuzzyEquals(t.Name, removeItem));
                    if (remove == null)
                    {
                        Sender.Connection.SendMessage($"You never offered a {remove.Name} to {Subject.Name}.");
                    }
                    else
                    {
                        TradeItemsTo.Remove(remove);
                        Sender.Inventory.AddToInventory(remove);
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "rt"))
                {
                    Sender.Connection.SendMessage("You requested: ");
                    foreach (Item item in TradeItemsFrom)
                    {
                        Sender.Connection.SendMessage($"{item.Name} - Value: {item.Value}");
                    }
                    Sender.Connection.SendMessage($"What would you like to return to {Subject.Name}?");
                    string removeItem = Sender.Connection.ReadMessage();
                    var    remove     = TradeItemsFrom.Find(t => CommandUtils.FuzzyEquals(t.Name, removeItem));
                    if (remove == null)
                    {
                        Sender.Connection.SendMessage($"You never requested a {remove.Name} from {Subject.Name}");
                    }
                    else
                    {
                        TradeItemsFrom.Remove(remove);
                        Subject.Inventory.AddToInventory(remove);
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "v"))
                {
                    Sender.Connection.SendMessage("Current trade pools:");
                    foreach (Item item in TradeItemsTo)
                    {
                        Sender.Connection.SendMessage($"Giving {item.Name} to {Subject.Name} (Value: {item.Value})");
                    }
                    foreach (Item item in TradeItemsFrom)
                    {
                        Sender.Connection.SendMessage($"Getting {item.Name} from {Subject.Name} (Value: {item.Value})");
                    }
                    int TradeToValue   = TradeItemsTo.Sum(t => t.Value);
                    int TradeFromValue = TradeItemsFrom.Sum(t => t.Value);
                    Sender.Connection.SendMessage($"Total value trading to {Subject.Name} is {TradeToValue}");
                    Sender.Connection.SendMessage($"Total value taking from {Subject.Name} is {TradeFromValue}");
                }
                if (CommandUtils.FuzzyEquals(action, "s"))
                {
                    if (TradeItemsTo.Sum(t => t.Value) >= TradeItemsFrom.Sum(t => t.Value))
                    {
                        if (TradeItemsFrom.Sum(t => t.Weight) <= Sender.Inventory.CurrentCapacity)
                        {
                            foreach (Item item in TradeItemsFrom)
                            {
                                Sender.Inventory.setCurrentRaisedCapacity(item.Weight);
                                Sender.Inventory.AddToInventory(item);
                            }
                            foreach (Item item in TradeItemsTo)
                            {
                                Sender.Inventory.setCurrentLoweredCapacity(item.Weight);
                                Subject.Inventory.AddToInventory(item);
                            }
                            Sender.Connection.SendMessage("Trade succesful.");
                            TradeItemsFrom.Clear();
                            TradeItemsTo.Clear();
                            break;
                        }
                        Sender.Connection.SendMessage("Trade failed - you're trying to take more than you can carry!");
                    }
                    else
                    {
                        Sender.Connection.SendMessage("Trade failed - you're trying to take more than you're giving!");
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "q"))
                {
                    foreach (Item item in TradeItemsTo)
                    {
                        Sender.Inventory.AddToInventory(item);
                    }

                    foreach (Item item in TradeItemsFrom)
                    {
                        Subject.Inventory.AddToInventory(item);
                    }
                    Sender.Connection.SendMessage("Trade cancelled.");
                    TradeItemsFrom.Clear();
                    TradeItemsTo.Clear();
                    break;
                }
            }
        }
Example #19
0
        public void Attack(User current)
        {
            // first roll:
            int hit = Roll(100);

            hit = hit + current.Player.Stats.Accuracy;
            // Check and see if the attack actually hits
            if (hit < Target.MinStrike)
            {
                current.Connection.SendMessage("Miss!");
                return;
            }
            int damage = current.Player.Stats.Damage;
            // if the attack does hit, determine if the attack is a critical hit.
            int crit = Roll(100);

            crit = crit + (current.Player.Stats.Luck);
            // A critical hit does base damage + 1/2 the base damage value.
            if (crit >= Target.CritChance)
            {
                damage = damage + (damage / 2);
                current.Connection.SendMessage($"Critical hit!");
            }

            /* Next, determine attack bonuses.
             * Attack bonuses come from multiple sources:
             *  - Players who do not have a weapon equipped get a damage modifier based on strength
             *  - Players who have "fast" weapons such as daggers get a damage modifier based on dex
             *  - Players who have "slow" weapons such as swords get damage modifiers based on strength
             *  - Players who have "spell" weapons such as staves get damage modifiers based on knowledge
             *  - Players who have "ranged" weapons such as bows get damage modifiers based on dex and agility
             *  - Spell status : Some spells will buff damage
             *  - Consumable status : Some consumables have damage modifiers
             *  - Equipment bonus : Some equipment will modify damage
             *  However, because all of these factors directly change stats on impact, we just check stat bonuses here.
             */
            if (current.Player.Held.Count != 0)
            {
                foreach (Item item in current.Player.Held)
                {
                    if (item.IsWeapon)
                    {
                        if (CommandUtils.FuzzyEquals(item.WeaponType, "slow"))
                        {
                            damage = damage + (current.Player.Stats.Strength / 2);
                            current.Connection.SendMessage($"Bonus: Slow Weapon - {damage} damage!");
                        }
                        if (CommandUtils.FuzzyEquals(item.WeaponType, "fast"))
                        {
                            damage = damage + (current.Player.Stats.Dexterity / 2);
                            current.Connection.SendMessage($"Bonus: Fast Weapon - {damage} damage!");
                        }
                        if (CommandUtils.FuzzyEquals(item.WeaponType, "spell"))
                        {
                            damage = damage + (current.Player.Stats.Knowledge / 2);
                            current.Connection.SendMessage($"Bonus: Magic - {damage} damage!");
                        }
                        if (CommandUtils.FuzzyEquals(item.WeaponType, "ranged"))
                        {
                            damage = damage + (current.Player.Stats.Dexterity / 2) + (current.Player.Stats.Agility / 2);
                            current.Connection.SendMessage($"Bonus: Ranged - {damage} damage!");
                        }
                    }
                }
            }
            // otherwise assume that the player is not holding a weapon
            else
            {
                damage = damage + current.Player.Stats.Strength;
                current.Connection.SendMessage($"Bonus: Pugilist - {damage} damage!");
            }
            // Finally, consider enemy's defense level:
            damage = damage - (Target.Defense);
            if (damage < 0)
            {
                damage = 0;
            }
            // and deal damage:
            Target.Health = Target.Health - damage;
            CombatSay($"{current.Name} dealt {damage} to {Target.Name}!");
            if (Target.Health <= 0)
            {
                Target.IsDead = true;
                CombatSay($"{Target.Name} has been defeated by {current.Name}!");
                return;
            }
            foreach (User user in Combatants)
            {
                user.Connection.SendMessage($"{Target.Name} has {Target.Health} health left");
            }
        }
        /* HandleGo handles moving between rooms.
         * TODO: Find a better way to handle the RoomsIConnect list - currently, in the XML, rooms must be
         * placed in the order of CURRENT ROOM in index 0 and CONNECTING ROOM in index 1
         * there's probably a better way to handle this situation.
         */
        void HandleGo(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            if (CommandUtils.FuzzyEquals(e, "north"))
            {
                e = "n";
            }
            if (CommandUtils.FuzzyEquals(e, "south"))
            {
                e = "s";
            }
            if (CommandUtils.FuzzyEquals(e, "east"))
            {
                e = "e";
            }
            if (CommandUtils.FuzzyEquals(e, "west"))
            {
                e = "w";
            }
            int currentRoomId = CommandUtils.GetCurrentRoomId(sender, Map);
            int numDoors      = Map.Rooms[currentRoomId].Doors.Select(t => t.Actual).Count();
            var directionGone = Map.Rooms[currentRoomId].Doors.FirstOrDefault(t => CommandUtils.FuzzyEquals(t.Actual.Direction, e))?.Actual;

            if (numDoors == 0)
            {
                sender.Connection.SendMessage("There are no doors here. You cannot go anywhere.");
                return;
            }

            if (directionGone == null)
            {
                sender.Connection.SendMessage("There is no door there.");
                return;
            }

            void proceed()
            {
                sender.CurrRoomId = directionGone.RoomsIConnect[1];
            }

            if (!directionGone.Locked)
            {
                proceed();
                return;
            }

            if (sender.Player.Stats.Dexterity >= directionGone.minDexterity)
            {
                sender.Connection.SendMessage("Although the door is locked, you are deft enough to pick your way in.");
                proceed();
                directionGone.Locked = false;
                return;
            }

            if (directionGone.HasKey)
            {
                if (CommandUtils.OwnsItem(sender, "key"))
                {
                    proceed();
                    return;
                }
                sender.Connection.SendMessage("This door is locked and has a key. Look around!");
            }
            else
            {
                sender.Connection.SendMessage("You are unable to open the door.");
            }
        }
        // Talk to an NPC
        void HandleTalkTo(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            int currRoom = CommandUtils.GetCurrentRoomId(sender, Map);
            NPC target   = CommandUtils.GetTarget(currRoom, e, Map);

            if (target == null)
            {
                sender.Connection.SendMessage("You babble to no one in particular for a moment.");
                return;
            }
            if (CommandUtils.FuzzyEquals(target.Faction, "enemy"))
            {
                sender.Connection.SendMessage("While talking your way out of confrontation is admirable, it won't work in this situation.");
                HandleAttack(sender, e);
                return;
            }
            if (CommandUtils.FuzzyEquals(target.Faction, "dead"))
            {
                sender.Connection.SendMessage("He's dead, Jim.");
                return;
            }
            target.Conversation        = new Conversation(target, sender);
            sender.Player.Conversation = target.Conversation;

            target.Conversation.Greeting();

            while (target.Conversation != null && sender.Player.Conversation != null)
            {
                sender.Connection.SendMessage(@"w: Who
n: News
t: Trade
q: Quest
b: Bye");
                string action = sender.Connection.ReadMessage();
                if (CommandUtils.FuzzyEquals(action, "w"))
                {
                    target.Conversation.Who();
                }
                if (CommandUtils.FuzzyEquals(action, "n"))
                {
                    target.Conversation.News();
                    sender.Connection.SendMessage("News placeholder");
                }
                if (CommandUtils.FuzzyEquals(action, "t"))
                {
                    if (CommandUtils.FuzzyEquals(target.Faction, "ally") || CommandUtils.FuzzyEquals(target.Faction, "neutral"))
                    {
                        target.Conversation.Trade();
                    }
                    else
                    {
                        sender.Connection.SendMessage(target.Conversation.TradeFlavor);
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "q"))
                {
                    if (CommandUtils.FuzzyEquals(target.Faction, "ally") || (CommandUtils.FuzzyEquals(target.Faction, "neutral")))
                    {
                        if (target.HasQuest)
                        {
                            target.Conversation.Quest();
                        }
                        else
                        {
                            sender.Connection.SendMessage($"{target.Name} does not have a quest for you.");
                        }
                    }
                    else
                    {
                        sender.Connection.SendMessage(target.Conversation.QuestFlavor);
                    }
                }
                if (CommandUtils.FuzzyEquals(action, "b"))
                {
                    target.Conversation.Bye();
                    break;
                }
            }
            target.Conversation        = null;
            sender.Player.Conversation = null;
        }
        // Attack an enemy
        void HandleAttack(User sender, string e)
        {
            if (sender.Player.IsDead)
            {
                sender.Connection.SendMessage("You cannot do that while defeated!");
                return;
            }
            int currRoom = CommandUtils.GetCurrentRoomId(sender, Map);
            NPC target   = CommandUtils.GetTarget(currRoom, e, Map);

            // Make sure the target is actually attackable
            if (target == null)
            {
                sender.Connection.SendMessage("You cannot attack that.");
                return;
            }
            if (CommandUtils.FuzzyEquals(target.Faction, "ally"))
            {
                sender.Connection.SendMessage("You cannot attack friendly people!");
                return;
            }
            if (CommandUtils.FuzzyEquals(target.Faction, "dead"))
            {
                sender.Connection.SendMessage("You cannot attack dead bodies!");
                return;
            }
            // If these checks pass, then there is an available target to fight
            // Check and see if the target is already engaged : if so, join the target session
            //  RoomSay($"{sender.Name} is attacking the {target.Name}!", sender);
            if (target.Combat == null)
            {
                target.Combat = new Combat(target);
            }
            target.Combat.Combatants.Add(sender);
            sender.Player.Combat = target.Combat;

            // Pre-emptively get the direction to run in in case the user decides to try to run.
            var runDir = Map.Rooms[CommandUtils.GetCurrentRoomId(sender, Map)].Doors.Where(d => !d.Actual.Locked).FirstOrDefault()?.Actual;

            // Combat loop: check turns
            while (target.Combat != null && sender.Player.Combat != null)
            {
                sender.Player.IsBlocking = false;
                sender.Connection.SendMessage(@"a: Attack
d: Defend
h: Heal
r: Run");
                if (sender.Player.Stats.CurrHealth <= 0)
                {
                    break;
                }
                else
                {
                    string action = sender.Connection.ReadMessage();
                    if (CommandUtils.FuzzyEquals(action, "a"))
                    {
                        target.Combat.Attack(sender);
                    }
                    if (CommandUtils.FuzzyEquals(action, "d"))
                    {
                        target.Combat.Defend(sender);
                    }
                    if (CommandUtils.FuzzyEquals(action, "h"))
                    {
                        sender.Connection.SendMessage("Consume what?");
                        var consumables = sender.Inventory.Items.Where(t => t.IsConsumable);
                        foreach (Item item in consumables)
                        {
                            sender.Connection.SendMessage(item.Name);
                        }
                        string choice = sender.Connection.ReadMessage();
                        HandleEat(sender, choice);
                    }
                    if (CommandUtils.FuzzyEquals(action, "r"))
                    {
                        target.Combat.Run(sender, runDir);
                        target.Combat = null;
                        break;
                    }
                }
                if (target.Health <= 0)
                {
                    break;
                }
                target.Combat.EnemyTurn();
            }

            if (sender.Player.Stats.CurrHealth <= 0)
            {
                sender.Player.Combat = null;
                target.Combat        = null;
                sender.Connection.SendMessage("You have been defeated!");
                if (Users.Count > 2)
                {
                    sender.Connection.SendMessage("Would you like to wait for a revive? (y/n)");
                    string action = sender.Connection.ReadMessage();
                    if (CommandUtils.FuzzyEquals(action, "y"))
                    {
                        sender.Player.IsDead = true;
                        return;
                    }
                }
                sender.Connection.SendMessage("As you were the only soul in this place, you have been sent back to the start.");
                foreach (Item items in sender.Inventory.Items.ToList())
                {
                    sender.Inventory.RemoveFromInventory(items);
                    XMLReference <Item> item = new XMLReference <Item> {
                        Actual = items
                    };
                    Map.Rooms[CommandUtils.GetCurrentRoomId(sender, Map)].Items.Add(item);
                }
                sender.Player.Stats.CurrHealth = sender.Player.Stats.MaxHealth;
                sender.CurrRoomId = 0001;
                return;
            }
            // After this loop, the target is dead. Remove them from the npc list and add them to the dead list/faction.
            target.Faction = "dead";

            // Upon death, an npc's inventory gets dropped to the room.

            /* foreach(Item items in target.Inventory.Items.ToList())
             * {
             *  target.Inventory.RemoveFromInventory(items);
             *  XMLReference<Item> item = new XMLReference<Item> { Actual = items };
             *  Map.Rooms[CommandUtils.GetCurrentRoomId(sender, Map)].Items.Add(item);
             * } */

            foreach (var i in Map.Rooms[CommandUtils.GetCurrentRoomId(sender, Map)].NPCs.ToList())
            {
                if (i.Actual.Name == target.Name)
                {
                    Map.Rooms[CommandUtils.GetCurrentRoomId(sender, Map)].NPCs.Remove(i);
                    Map.Rooms[CommandUtils.GetCurrentRoomId(sender, Map)].DeadNPCs.Add(i);
                }
            }

            sender.Connection.SendMessage("Send 'q' to exit combat.");
            sender.Player.Combat = null;
            target.Combat        = null;
        }