Ejemplo n.º 1
0
        private void buyItem(string search, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            Item item = items.getItemByName(search);

            if (item != null)
            {
                int sellPrice = item.value * 2;
                if (player.gold > sellPrice)
                {
                    player.items.addToInventory(item);
                    gold += sellPrice;
                    player.gold -= sellPrice;
                    buffer.AppendFormat("\r\n%BYou purchase %W{0} %Bfor %Y{1} %Bgold.", item.description, sellPrice);
                    say("Thank you for your business.");
                    player.client.send(buffer.ToString());
                }
                else
                {
                    say("Please, don't waste my time. Come back when you have some coin.");
                }
            }
            else
            {
                say("I apologize, I am fresh out of " + search);
            }
        }
Ejemplo n.º 2
0
        private void doDrop(string[] args, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (args.Length == 1)
            {
                player.client.send("Drop what?");
            }
            else
            {
                Item item = player.items.getItemByName(args[1].TrimEnd('\r', '\n'));

                if (item != null)
                {
                    player.items.removeFromInventory(item);
                    player.room.addItem(item);
                    buffer.AppendFormat("You drop a {0} onto the ground.", item.description);
                    player.client.send(buffer.ToString());
                }
                else
                {
                    player.client.send("I can't find that item.");
                }
            }
        }
Ejemplo n.º 3
0
        private void doKill(string[] args, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (args.Length == 1)
            {
                player.client.send("Kill whom?");
                return;
            }

            Character target = player.room.getCharacterByName(args[1]);

            if (target == player)
            {
                buffer.AppendLine("\r\nYou kill yourself!");
                buffer.AppendLine("Do you want your possessions identified?");
            }
            else if (target != null)
            {
                buffer.AppendFormat("You attack {0} with all your might!", target.name);
                player.combat.target = target;
                player.combat.isFighting = true;
            }
            else
            {
                buffer.AppendLine("I do not see anybody by that name here.");
            }

            player.client.send(buffer.ToString());
        }
Ejemplo n.º 4
0
        //TODO: Clean this up
        private void doCreate(string[] args, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (args.Length == 1)
            {
                player.parser.parse("create --help");
                return;
            }

            if (args[1] == "mob")
            {
                player.client.send("I don't know how to create mob yet.");
            }
            else if (args[1] == "item")
            {
                if (args.ElementAtOrDefault(2) != null)
                {
                    if (args[2].Length > 10)
                    {
                        player.client.send("please select a shorter name.");
                        return;
                    }

                    Item newItem = new Item(args[2].TrimEnd('\r', '\n'), "", 5, "none", 1);
                    player.items.addToInventory(newItem);
                    buffer.AppendFormat("{0} creates a {1} out of thin air!", player.name, newItem.name);
                    player.room.sendToRoom(buffer.ToString());
                }
            }
            else
            {
                player.parser.parse("create --help");
            }
        }
Ejemplo n.º 5
0
        private void doPickup(string[] args, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (args.Length == 1)
            {
                player.client.send("Pickup what?");
            }
            else
            {
                Item item = player.room.getItemByName(args[1].TrimEnd('\r', '\n'));

                if (item != null)
                {
                    buffer.AppendFormat("You pick up {0}, off the ground.", item.description);
                    player.client.send(buffer.ToString());
                    player.room.removeItem(item);
                    player.items.addToInventory(item);
                }
                else
                {
                    player.client.send("I don't see that anywhere.");
                }
            }
        }
Ejemplo n.º 6
0
 private void doTime(string[] args, Player player)
 {
     StringBuilder buffer = new StringBuilder();
     buffer.AppendFormat("\r\n%c{0}\r\n%C{1}\r\n",
                         player.world.worldTime.ToShortTimeString(),
                         player.world.worldTime.ToLongDateString());
     player.client.send(buffer.ToString());
 }
Ejemplo n.º 7
0
 private void doLook(string[] args, Player player)
 {
     if (args.Length > 1)
     {
         lookAt(player, args[1]);
     }
     else
     {
         lookAll(player);
     }
 }
Ejemplo n.º 8
0
        private void doHelp(string[] args, Player player)
        {
            Commands commands = new Commands();
            StringBuilder buffer = new StringBuilder();

            buffer.AppendLine("Available Commands:\r\n");
            foreach (Command c in commands.all)
            {
                buffer.AppendFormat("    [ {0,12} ] {1}\r\n", c.name, c.description);
            }
            player.client.send(buffer.ToString());
        }
Ejemplo n.º 9
0
        private void lookAll(Player player)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.AppendFormat("%W{0}\r\n{1}\r\n%w{2}\r\n%R{3}\r\n%B{4}\r\n%M{5}",
                                 player.room.name,
                                 player.room.exitsToString(),
                                 player.room.description,
                                 player.room.NPCsToString(),
                                 player.room.itemsToString(),
                                 player.room.playersToString(player));

            player.client.send(buffer.ToString().TrimEnd('\r', '\n'));
        }
Ejemplo n.º 10
0
        private void doChat(string[] args, Player player)
        {
            StringBuilder text = new StringBuilder();

            if (args.Length == 0)
            {
                player.client.send("chat what?\r\n");
            }

            foreach (string s in args.Skip(1))
            {
                text.Append(s);
                text.Append(" ");
            }

            player.client.sendToAll("%W[%Cchat %y" + player.name + "%w:%W]%x \"" + text.ToString().Trim() + "%x.\"\r\n");
        }
Ejemplo n.º 11
0
        private void doSay(string[] args, Player player)
        {
            StringBuilder text = new StringBuilder();

            if (args.Length == 0)
            {
                player.client.send("say what?\r\n");
            }

            foreach (string s in args.Skip(1))
            {
                text.Append(s);
                text.Append(" ");
            }

            player.client.send("%Byou say \"%W" + text.ToString().Trim() + ".%B\"%x\r\n");
            player.room.sendToRestRoom("\n%B" + player.name + " says \"%W" + text.ToString().Trim() + ".%B\"%x\r\n", player);
        }
Ejemplo n.º 12
0
        private void doWalk(string[] args, Player player)
        {
            Movement movement = new Movement();

            if (player.combat.isFighting)
            {
                player.client.send("Not while fighting!");
                return;
            }

            if (movement.walk(Direction.shortDirectionToInt(args[0].TrimEnd('\r', '\n')), player))
            {
                player.parser.parse("look");
            }
            else
            {
                player.client.send("You can't go that way!");
            }
        }
Ejemplo n.º 13
0
        private void doClone(string[] args, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (args.Length == 1)
            {
                player.parser.parse("clone --help");
                return;
            }

            if (args[1] == "mob")
            {
                if (args.ElementAtOrDefault(2) != null)
                {
                    NPC clone = player.world.findNPC(args[2].TrimEnd('\r', '\n'));
                    if (clone != null)
                    {
                        buffer.AppendFormat("{0} creates {1} out of thin air!", player.name, clone.description);
                        player.room.addNPC(clone);
                        player.world.mobs.Add(clone);
                        player.room.sendToRoom(buffer.ToString());
                    }
                    else
                    {
                        player.client.send("I dont know how to clone that mob!");
                    }
                }
                else
                {
                    player.client.send("Clone which mob?");
                }
            }
            else if (args[1] == "item")
            {
                player.client.send("I don't know how to clone items yet.");
            }
            else
            {
                player.parser.parse("clone --help");
            }
        }
Ejemplo n.º 14
0
        private void doRemove(string[] args, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (args.Length == 1)
            {
                player.client.send("Remove what?");
            }
            else
            {
                Item item = player.items.removeFromEquipped(args[1].TrimEnd('\r', '\n'));

                if (item != null)
                {
                    buffer.AppendFormat("Removed {0} from {1}.", item.description, item.wearLocation);
                    player.client.send(buffer.ToString());
                }
                else
                {
                    player.client.send("I don't know how to remove that.");
                }
            }
        }
Ejemplo n.º 15
0
        public bool walk(int direction, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            if (player.room.hasExit(direction))
            {
                player.room.removePlayer(player);
                buffer.AppendFormat("\r\n{0} exits the room to the {1}.\r\n",
                                    player.name, Direction.directionToName(direction));
                player.room.sendToRestRoom(buffer.ToString(), player);

                buffer.Clear();
                player.room.exits[direction].addPlayer(player);
                buffer.AppendFormat("\r\n{0} has entered the room from the {1}.\r\n",
                                    player.name, Direction.directionToName(Direction.oppositeExit(direction)));
                player.room.sendToRestRoom(buffer.ToString(), player);
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 16
0
        public override bool shop(string[] args, Player player)
        {
            if (args.Length > 1)
            {
                if (args[1].TrimEnd('\r', '\n') == "buy")
                {
                    if (args.ElementAtOrDefault(2) != null)
                    {
                        buyItem(args[2].TrimEnd('\r', '\n'), player);
                    }
                    else
                    {
                        say("What would you like to purchase?");
                        player.client.send(listBuy());
                    }
                }
                else if (args[1].TrimEnd('\r', '\n') == "sell")
                {
                    if (args.ElementAtOrDefault(2) != null)
                    {
                        sellItem(args[2].TrimEnd('\r', '\n'), player);
                    }
                    else
                    {
                        say("I can give you these prices for your stuff.");
                        player.client.send(listSell(player));
                    }
                }
            }
            else
            {
                say("Hello! please have a look at my merchandise.");
                player.client.send(listBuy());
            }

            return true;
        }
Ejemplo n.º 17
0
        private void lookAt(Player player, string what)
        {
            StringBuilder buffer = new StringBuilder();

            Character c = player.room.getCharacterByName(what);
            if (c != null)
            {
                buffer.AppendFormat("You look at {0}.\r\n{1}\r\n\n{2}",
                                    c.name,
                                    c.description,
                                    c.items.equippedToString());
            }

            Item item = player.room.getItemByName(what);
            if (item != null)
            {
                buffer.AppendFormat("\r\nYou look at {0}.\r\n{1}\r\n", item.name, item.description);
            }

            if (buffer.ToString().Length < 1)
                player.client.send("You do not see that here!");
            else
                player.client.send(buffer.ToString());
        }
Ejemplo n.º 18
0
        private void sellItem(string search, Player player)
        {
            StringBuilder buffer = new StringBuilder();

            Item item = player.items.getItemByName(search);

            if (item != null)
            {
                if (gold > item.value)
                {
                    player.items.removeFromInventory(item);
                    items.addToInventory(item);
                    player.gold += item.value;
                    gold -= item.value;
                    buffer.AppendFormat("\r\n%BYou sell %W{0} to {1}, %Bfor %Y{2} %Bgold.", item.description, name, item.value);
                    say("Thank you for your business.");
                    player.client.send(buffer.ToString());
                }
                else
                {
                    say("I can't purchase that at the moment, I'm a little short.");
                }
            }
            else
            {
                player.client.send("I can't find that item");
            }
        }
Ejemplo n.º 19
0
        private string listSell(Player player)
        {
            StringBuilder buffer = new StringBuilder();
            int x = 1;

            buffer.AppendLine("\r\n%YYou can sell:");
            foreach (Item i in player.items.inventory)
            {
                buffer.AppendFormat("\r\n\t%B{0}%W) %w{1,3}%Yg %W[ %w{2,8}%W ]  %B{3}%x",
                                    x++,
                                    i.value,
                                    i.name,
                                    i.description);
            }

            return buffer.ToString();
        }
Ejemplo n.º 20
0
 private void doQuit(string[] args, Player player)
 {
     player.client.sendToRest(player.name + " has left the game!");
     player.client.send("thank you, come again!");
     player.client.disconnect();
 }
Ejemplo n.º 21
0
 public virtual bool shop(string[] args, Player player)
 {
     return false;
 }
Ejemplo n.º 22
0
 public void addPlayer(Player player)
 {
     players.Add(player);
     characters.Add(player);
     player.room = this;
 }
Ejemplo n.º 23
0
        public void sendToRestRoom(string message, Player player)
        {
            for (int x = 0; x < players.Count; x++)
            {
                Player p = players.ElementAtOrDefault(x);

                if (p != null && p != player)
                    p.client.send(message);
            }
        }
Ejemplo n.º 24
0
 public void removePlayer(Player player)
 {
     characters.Remove(player);
     players.Remove(player);
 }
Ejemplo n.º 25
0
        public string playersToString(Player player)
        {
            StringBuilder buffer = new StringBuilder();

            foreach (Player p in players)
            {
                if (p != player)
                {
                    if (p != null && !p.client.isPlaying)
                    {
                        buffer.Append("%w( %rdisconnected%w )%x ");
                    }
                    buffer.AppendFormat("{0} is standing here.\r\n", p.name);
                }
            }

            return buffer.ToString().TrimEnd('\r', '\n');
        }
Ejemplo n.º 26
0
        public void findShop(string[] args, Player player)
        {
            bool result = false;

            foreach (NPC n in npcs)
            {
                result = n.shop(args, player);
                if (result)
                    break;
            }

            if (!result)
            {
                player.client.send("There is no merchant around.");
            }
        }
Ejemplo n.º 27
0
 private void doShop(string[] args, Player player)
 {
     player.room.findShop(args, player);
 }
Ejemplo n.º 28
0
        private void doWear(string[] args, Player player)
        {
            if (args.Length == 1)
            {
                player.client.send("Wear what?");
            }
            else
            {
                Item item = player.items.getItemByName(args[1].TrimEnd('\r', '\n'));

                if (item != null)
                {
                    if (player.items.addToEquipped(item.wearLocation, item))
                    {
                        player.client.send("You equip " + item.description + ".");
                    }
                    else
                    {
                        player.client.send("You can't wear that there!");
                    }
                }
            }
        }
Ejemplo n.º 29
0
        private void doDig(string[] args, Player player)
        {
            if (args.Length == 1)
            {
                player.parser.parse("dig --help");
                return;
            }

            int direction = Direction.directionToNumber(args[1]);

            if (direction >= 0 && direction < 4)
            {
                if (!player.world.newExit(direction, player.room))
                {
                    player.client.send("Can't dig that way!");
                }
                else
                {
                    player.client.send("Dug " + args[1]);
                }
            }
            else
            {
                player.client.send("I don't know how to dig that direction!");
            }
        }
Ejemplo n.º 30
0
 public void dispatch(string[] args, Player player)
 {
     this.method.Invoke(args, player);
 }