Example #1
0
        public override void Execute(Session session, CommandContext context)
        {
            try
            {
                PlayerItem container;
                PlayerItem putItem      = null;
                bool       itemFound    = false;
                string     argContainer = context.Arguments[1];
                string     argItem      = context.Arguments[0];
                var        room         = RoomHelper.GetPlayerRoom(session.Player.Location);

                // item in inevntory?
                foreach (var key in session.Player.Inventory.Keys)
                {
                    putItem = Server.Current.Database.Get <PlayerItem>(key);
                    if (putItem != null &&
                        putItem.Keywords.Contains(argItem))
                    {
                        itemFound = true;
                        break;
                    }
                }

                if (!itemFound)
                {
                    session.WriteLine("Can't find item: {0}", argItem);
                    return;
                }

                // container in inventory?
                container = ItemHelper.FindInventoryItem(session.Player, argContainer, true);

                // container on floor?
                if (container == null)
                {
                    container = ItemHelper.FindFloorItem(room, argContainer);
                }

                if (container == null)
                {
                    session.WriteLine("Can't find container: {0}", argContainer);
                    return;
                }

                // move item
                session.Player.Inventory.Remove(putItem.Key);
                container.ContainedItems.Add(putItem.Key, putItem.Name);
                Server.Current.Database.Save(session.Player);
                session.WriteLine("You put {0} in {1}", putItem.Name, container.Name);
                return;
            }
            catch
            {
                PrintSyntax(session);
            }

            session.WriteLine("Put what in what?");
        }
Example #2
0
        public override void Execute(Session session, CommandContext context)
        {
            var room = RoomHelper.GetPlayerRoom(session.Player);

            // find item
            var item = ItemHelper.FindFloorItem(room, context.ArgumentString);

            if (item == null)
            {
                session.WriteLine("You couldn't find that.");
                return;
            }

            // remove from room
            room.RemoveItem(item);

            // notify player/room
            session.WriteLine("You sacrifice {0}.", item.Name);
            room.SendPlayers(string.Format("{0} sacrifices {1}.", session.Player.Forename, item.Name),
                             session.Player, null, session.Player);

            // delete from db
            ItemHelper.DeleteItem(item.Key);
        }
Example #3
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrWhiteSpace(context.ArgumentString))
            {
                PrintSyntax(session);
                return;
            }

            var room = RoomHelper.GetPlayerRoom(session.Player.Location);

            // 1 argument, "get all", "get x.item", "get gold" must be on ground
            var arg1 = context.Arguments[0];

            if (context.Arguments.Count == 1)
            {
                if (arg1.ToLower() == "gold")
                {
                    if (room.Gold > 0)
                    {
                        pickupGold(session, room);
                        return;
                    }

                    session.WriteLine("There are no coins here.");
                    return;
                }

                PlayerItem itemToPickup = null;

                if (arg1 == "all") // "get all"
                {
                    // attempt to get gold
                    pickupGold(session, room);

                    var pickedUpAnything = false;
                    foreach (var key in room.Items.Keys)
                    {
                        itemToPickup = ItemHelper.FindFloorItem(room, key);
                        if (itemToPickup != null &&
                            session.Player.Inventory.Count + 1 < session.Player.MaxInventory && // not over inventory
                            session.Player.Weight + itemToPickup.Weight < session.Player.MaxWeight)    // not over weight
                        {
                            // move item from floor to inventory
                            room.RemoveItem(itemToPickup);
                            session.Player.Inventory.Add(itemToPickup.Key, itemToPickup.Name);
                            session.WriteLine("You pick up {0}", itemToPickup.Name);
                            pickedUpAnything = true;
                        }
                        else
                        {
                            session.WriteLine("You picked up all you could.");
                        }
                    }

                    if (pickedUpAnything)
                    {
                        Server.Current.Database.Save(session.Player);
                        room.SendPlayers("%d picked up some items.", session.Player, null, session.Player);
                    }
                    return;
                }

                if (arg1.ToLower() == "coin" || arg1.ToLower() == "coins" || arg1.ToLower() == "gold")
                {
                    if (room.Gold > 0)
                    {
                        pickupGold(session, room);
                        return;
                    }

                    session.WriteLine("There are no coins here.");
                    return;
                }

                // arg1 is x.item, and it's on the floor
                itemToPickup = ItemHelper.FindFloorItem(room, arg1);
                if (itemToPickup != null)
                {
                    if (session.Player.Inventory.Count + 1 < session.Player.MaxInventory && // not over inventory
                        session.Player.Weight + itemToPickup.Weight < session.Player.MaxWeight) // not over weight
                    {
                        // move item from floor to inventory
                        room.RemoveItem(itemToPickup);
                        session.Player.Inventory.Add(itemToPickup.Key, itemToPickup.Name);
                        Server.Current.Database.Save(session.Player);
                        session.WriteLine("You pick up {0}", itemToPickup.Name);
                        room.SendPlayers("%d picked up some something.", session.Player, null, session.Player);
                        return;
                    }

                    session.WriteLine("You couldn't pick that up.");
                    return;
                }

                session.WriteLine("You coulnd't find that.");
                return;
            }

            // 2 arguments, "all x.container", "x.item x.container", "gold corpse"
            var        arg2 = context.Arguments[1];
            var        inventoryContainer = ItemHelper.FindInventoryItem(session.Player, arg2, true);
            var        groundContainer    = ItemHelper.FindFloorItem(room, arg2, true);
            PlayerItem itemLookup         = null;

            if (arg1 == "all")
            {
                if (arg2 == "coin")
                {
                    if (room.Gold > 0)
                    {
                        var amountOfGold = room.Gold;
                        room.Gold            = 0;
                        session.Player.Gold += amountOfGold;
                        Server.Current.Database.Save(room);
                        session.WriteLine("You pick up {0} coin{1}", amountOfGold, amountOfGold > 1 ? "s" : string.Empty);
                        room.SendPlayers("%d picked up some gold.", session.Player, null, session.Player);
                    }

                    session.WriteLine("There is no gold here.");
                    return;
                }
                else // arg2 is x.container
                {
                    if (inventoryContainer != null)
                    {
                        if (inventoryContainer.ContainedItems.Count == 0)
                        {
                            session.WriteLine("There is nothing in there.");
                            return;
                        }

                        // get gold from container
                        if (inventoryContainer.Gold > 0)
                        {
                            int gold = inventoryContainer.Gold;
                            inventoryContainer.Gold = 0;
                            session.Player.Gold    += gold;
                            session.WriteLine("`YYou get {0} coin{1} from {2}", gold, gold > 1 ? "s" : string.Empty,
                                              inventoryContainer.Name);
                        }

                        foreach (var containerItem in inventoryContainer.ContainedItems.ToArray())
                        {
                            // room in inventory?
                            if (session.Player.Inventory.Count + 1 <= session.Player.MaxInventory)
                            {
                                // move item from container to inventory
                                session.Player.Inventory.Add(containerItem.Key, containerItem.Value);
                                inventoryContainer.ContainedItems.Remove(containerItem.Key);
                                session.WriteLine("You get {0} from {1}.", containerItem.Value, inventoryContainer.Name);
                                room.SendPlayers(string.Format("%d gets {0} from %o {1}.", containerItem.Value,
                                                               inventoryContainer.Name), session.Player, null,
                                                 session.Player);
                            }
                            else
                            {
                                session.WriteLine("Your hands are full.");
                            }
                        }

                        Server.Current.Database.Save(inventoryContainer);
                        Server.Current.Database.Save(session.Player);
                        return;
                    }

                    if (groundContainer == null)
                    {
                        session.WriteLine("You can't find that.");
                        return;
                    }

                    if (groundContainer.Gold <= 0 && groundContainer.ContainedItems.Count <= 0)
                    {
                        session.WriteLine("There's nothing in there.");
                        return;
                    }

                    // get gold from container
                    if (groundContainer.Gold > 0)
                    {
                        int gold = groundContainer.Gold;
                        groundContainer.Gold = 0;
                        session.Player.Gold += gold;
                        session.WriteLine("`YYou get {0} coin{1} from {2}", gold, gold > 1 ? "s" : string.Empty,
                                          groundContainer.Name);
                    }

                    // use ground container and check weight
                    foreach (var containerItem in groundContainer.ContainedItems.ToArray())
                    {
                        itemLookup = Server.Current.Database.Get <PlayerItem>(containerItem.Key);

                        if (session.Player.Weight + itemLookup.Weight > session.Player.MaxWeight)
                        {
                            session.WriteLine("You can't carry that much weight.");
                            break;
                        }

                        if (session.Player.Inventory.Count + 1 > session.Player.MaxInventory)
                        {
                            session.WriteLine("Your hands are full.");
                            break;
                        }

                        if (itemLookup.WearLocation == Wearlocation.Corpse &&
                            !itemLookup.AllowedToLoot.Contains(session.Player.Key))
                        {
                            session.WriteLine("You can't get anything from there.");
                            break;
                        }

                        groundContainer.ContainedItems.Remove(containerItem.Key);
                        session.Player.Inventory.Add(containerItem.Key, containerItem.Value);
                        session.WriteLine("You get {0} from {1}.", containerItem.Value, groundContainer.Name);
                        room.SendPlayers(
                            string.Format("%d gets {0} from %o {1}.", containerItem.Value, groundContainer.Name),
                            session.Player, null, session.Player);
                    }

                    Server.Current.Database.Save(groundContainer);
                    Server.Current.Database.Save(session.Player);
                    return;
                }
            }

            // assume corpse/container
            if (arg1 == "gold")
            {
                var corpse = ItemHelper.FindFloorItem(room, arg2);
                if (corpse == null)
                {
                    session.WriteLine("Can't find that.");
                    return;
                }

                if (corpse.Gold <= 0)
                {
                    session.WriteLine("There are no coins in there.");
                    return;
                }

                var gold = corpse.Gold;
                corpse.Gold          = 0;
                session.Player.Gold += gold;
                session.WriteLine("You pick up {0} coin{1}.", gold, gold > 1 ? "s" : string.Empty);
                return;
            }

            // must be "get x.item x.container"
            if (inventoryContainer != null)
            {
                if (inventoryContainer.ContainedItems.Count == 0)
                {
                    session.WriteLine("There is nothing in there.");
                    return;
                }

                itemLookup = ItemHelper.FindItemInContainer(inventoryContainer, arg1);
                if (itemLookup == null)
                {
                    session.WriteLine("You can't find that.");
                    return;
                }

                inventoryContainer.ContainedItems.Remove(itemLookup.Key);
                session.Player.Inventory.Add(itemLookup.Key, itemLookup.Name);
                session.WriteLine("You get {0} from {1}.", itemLookup.Name, inventoryContainer.Name);
                room.SendPlayers(string.Format("%d gets {0} from %o {1}.", itemLookup.Name, inventoryContainer.Name),
                                 session.Player, null, session.Player);

                Server.Current.Database.Save(inventoryContainer);
                Server.Current.Database.Save(session.Player);
                return;
            }

            if (groundContainer == null)
            {
                session.WriteLine("You can't find that.");
                return;
            }

            if (groundContainer.ContainedItems.Count == 0)
            {
                session.WriteLine("There is nothing in there.");
                return;
            }

            itemLookup = ItemHelper.FindItemInContainer(groundContainer, arg1);
            if (itemLookup == null)
            {
                session.WriteLine("You can't find that.");
                return;
            }

            if (session.Player.Weight + itemLookup.Weight > session.Player.MaxWeight)
            {
                session.WriteLine("You can't carry that much weight.");
                return;
            }

            if (session.Player.Inventory.Count + 1 > session.Player.MaxInventory)
            {
                session.WriteLine("Your hands are full.");
                return;
            }

            if (itemLookup.WearLocation == Wearlocation.Corpse && !itemLookup.AllowedToLoot.Contains(session.Player.Key))
            {
                session.WriteLine("You can't get anything from there.");
                return;
            }

            groundContainer.ContainedItems.Remove(itemLookup.Key);
            session.Player.Inventory.Add(itemLookup.Key, itemLookup.Name);
            session.WriteLine("You get {0} from {1}.", itemLookup.Name, groundContainer.Name);
            room.SendPlayers(string.Format("%d gets {0} from {1}.", itemLookup.Name, groundContainer.Name),
                             session.Player, null, session.Player);

            Server.Current.Database.Save(groundContainer);
            Server.Current.Database.Save(session.Player);
            return;
        }