Beispiel #1
0
        public override void Execute(Session session, CommandContext context)
        {
            string argContainer = context.Arguments[0];

            // find container
            PlayerItem container = ItemHelper.FindInventoryItem(session.Player, argContainer, true);

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

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

            // toss on floor
            foreach (var item in container.ContainedItems.ToArray())
            {
                container.ContainedItems.Remove(item.Key);
                room.Items.Add(item.Key, item.Value);
            }

            Server.Current.Database.Save(session.Player);
            session.WriteLine("You empty {0}", container.Name);
            room.SendPlayers(string.Format("%d empties %o {0}", container.Name), session.Player, null, session.Player);
        }
Beispiel #2
0
        public override void Execute(Session session, CommandContext context)
        {
            string argContainer = context.Arguments[0];

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

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

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

            // add items from room, with weight checks
            foreach (var key in room.Items.Keys.ToArray())
            {
                // get item
                var roomItem = Server.Current.Database.Get <PlayerItem>(key);
                if (roomItem != null && session.Player.Weight + roomItem.Weight <= session.Player.MaxWeight)
                {
                    room.Items.Remove(roomItem.Key);
                    container.ContainedItems[roomItem.Key] = roomItem.Name;
                }
            }

            Server.Current.Database.Save(session.Player);
            session.WriteLine("You filled your {0}", container.Name);
            room.SendPlayers(string.Format("%d filled %o {0}.", container.Name), session.Player, null, session.Player);
        }
Beispiel #3
0
        internal void Start()
        {
            if (fighters.Count < 1 || mobs.Count < 1)
            {
                throw new Exception("Cannot start combat. 1 Player, 1 NonPlayer required.");
            }

            foreach (var fighter in fighters)
            {
                if (room == null)
                {
                    room = RoomHelper.GetPlayerRoom(fighter.Location);
                }

                fighter.Status = GameStatus.Fighting;
            }

            foreach (var mob in mobs)
            {
                if (room == null)
                {
                    room = RoomHelper.GetPlayerRoom(mob.Location);
                }

                // if at least one mob is aggro, the whole fight is 'aggro' i.e. mob gets first hit each round
                if (mob.Aggro)
                {
                    isAggro = true;
                }

                mob.Status = GameStatus.Fighting;
            }
        }
Beispiel #4
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?");
        }
Beispiel #5
0
        public virtual void Unequip(Session session)
        {
            session.Player.Equipped.Remove(WearLocation);
            session.Player.Inventory[Key] = Name;

            session.WriteLine("You remove {0}", Name);
            RoomHelper.GetPlayerRoom(session.Player)
            .SendPlayers(string.Format("%d removes {0}", Name), session.Player, null, session.Player);
        }
Beispiel #6
0
        public string Whois()
        {
            var result = new StringBuilder();

            result.AppendLine(string.Format("{0} is a {1} year old, level {2} player.", Forename, Age, Level));
            result.AppendLine(string.Format("{0} is currently in {1}.",
                                            Gender == PlayerGender.Male
                                                ? "He"
                                                : Gender == PlayerGender.Female ? "She" : "It",
                                            RoomHelper.GetPlayerRoom(Location).Title));

            return(result.ToString());
        }
Beispiel #7
0
        public override void Execute(Session session, CommandContext context)
        {
            try
            {
                var room = RoomHelper.GetPlayerRoom(session.Player.Location);

                // dropping gold
                if (context.Arguments.Count == 2 && context.Arguments[1].ToLower() == "coin")
                {
                    int gold = 0;
                    if (int.TryParse(context.Arguments[0], out gold))
                    {
                        if (session.Player.Gold < gold)
                        {
                            session.WriteLine("You don't have that much.");
                            return;
                        }

                        session.Player.Gold -= gold;
                        room.Gold           += gold;
                        session.WriteLine("`YYou drop {0} coin{1}.", gold, gold > 1 ? "s" : string.Empty);
                        room.SendPlayers("%d drops some coins.", session.Player, null, session.Player);
                        Server.Current.Database.Save(session.Player);
                        return;
                    }

                    PrintSyntax(session);
                    return;
                }

                // does player have item?
                PlayerItem item = ItemHelper.FindInventoryItem(session.Player, context.Arguments[0]);
                if (item == null)
                {
                    session.WriteLine("Can't find item: {0}", context.Arguments[0]);
                    return;
                }

                // remove from player inventory
                session.Player.Inventory.Remove(item.Key);
                Server.Current.Database.Save(session.Player);

                room.AddItem(item); // this saves the room
                session.WriteLine("You drop {0}.", item.Name);
                room.SendPlayers("%d drops something.", session.Player, null, session.Player);
            }
            catch
            {
                PrintSyntax(session);
            }
        }
Beispiel #8
0
        public virtual void Equip(Session session)
        {
            // don't equip .None or .Key
            if (WearLocation == Wearlocation.None ||
                WearLocation == Wearlocation.Key ||
                WearLocation == Wearlocation.Container)
            {
                session.WriteLine("You can't equip that.");
                return;
            }

            if (session.Player.Equipped.ContainsKey(WearLocation))
            {
                session.WriteLine("You've already equipped that slot.");
                return;
            }

            // can't equip both hands if either single hand is equipped
            if (WearLocation == Wearlocation.BothHands &&
                (session.Player.Equipped.ContainsKey(Wearlocation.LeftHand) ||
                 session.Player.Equipped.ContainsKey(Wearlocation.RightHand)))
            {
                session.WriteLine("You can't hold a two-handed weapon with any other weapons.");
                return;
            }

            // can't eqiup either hand if both hands is equipped
            if ((WearLocation == Wearlocation.RightHand || WearLocation == Wearlocation.LeftHand) &&
                session.Player.Equipped.ContainsKey(Wearlocation.BothHands))
            {
                session.WriteLine("You're already using both hands.");
                return;
            }

            session.Player.Equipped[WearLocation] = new WearSlot()
            {
                Key  = Key,
                Name = Name
            };

            // remove from inventory
            session.Player.Inventory.Remove(Key);

            session.WriteLine("You don {0}.", Name);
            RoomHelper.GetPlayerRoom(session.Player)
            .SendPlayers(string.Format("%d dons {0}", Name), session.Player, null, session.Player);
        }
Beispiel #9
0
        public void DieForReal()
        {
            Status    = GameStatus.Sitting;
            HitPoints = 1;

            var deathRoom = RoomHelper.GetPlayerRoom(Location);

            deathRoom.RemovePlayer(this);

            // create corpse
            var corpse      = Server.Current.Database.Get <Template>("corpse");
            var dupedCorpse = Mapper.Map <PlayerItem>(corpse);
            var corpseName  = string.Format("The corpse of {0}", Forename);

            dupedCorpse.AllowedToLoot = Key; // this should be the only place this is used
            dupedCorpse.Name          = corpseName;
            dupedCorpse.Description   = corpseName;
            dupedCorpse.Keywords      = new [] { "corpse", Forename };
            dupedCorpse.WearLocation  = Wearlocation.Corpse;
            Console.WriteLine("NEW CORPSE: {0}", dupedCorpse.Key);
            deathRoom.CorpseQueue[dupedCorpse.Key] = DateTime.Now.AddMilliseconds(Server.CorpseDecayTime);

            // copy player items to corpse
            foreach (var item in Inventory
                     .Select(x => new { Key = x.Key, Value = x.Value })
                     .Union(Equipped.Values.Select(x => new { Key = x.Key, Value = x.Name })
                            .ToArray()))
            {
                dupedCorpse.ContainedItems.Add(item.Key, item.Value);
            }

            // clear inventory/equipped
            Inventory.Clear();
            Equipped.Clear();

            // cache, don't save
            Server.Current.Database.Put(dupedCorpse);
            deathRoom.AddItem(dupedCorpse);

            var room = RoomHelper.GetPlayerRoom(RespawnRoom);

            Location = RespawnRoom;
            room.AddPlayer(this);

            Server.Current.Database.Save(this);
        }
Beispiel #10
0
        public override void Execute(Session session, CommandContext context)
        {
            // validate item arg
            if (string.IsNullOrWhiteSpace(context.ArgumentString))
            {
                session.WriteLine("Sell what?");
                return;
            }

            PlayerItem itemToSell = ItemHelper.FindInventoryItem(session.Player, context.ArgumentString, false, false);

            if (itemToSell == null)
            {
                session.WriteLine("You don't have that to sell.");
                return;
            }

            // get shopkeeper in room
            var       room       = RoomHelper.GetPlayerRoom(session.Player.Location);
            NonPlayer shopkeeper = null;

            foreach (var npc in room.GetNpcs())
            {
                if (npc.IsShopkeeper)
                {
                    shopkeeper = npc;
                    break;
                }
            }

            if (shopkeeper == null)
            {
                session.WriteLine("You can't sell that here.");
                return;
            }

            // destroy item, remove from inventory, give gold, save player
            var sellPrice = itemToSell.Value / 2;

            session.Player.Gold += sellPrice;
            session.Player.Inventory.Remove(itemToSell.Key);
            Server.Current.Database.Save(session.Player); // save so they can't try to sell again
            session.WriteLine("You sold {0} for {1} gold.", itemToSell.Name, sellPrice);
            Server.Current.Database.Delete <PlayerItem>(itemToSell.Key);
        }
Beispiel #11
0
        public override void Execute(Session session, CommandContext context)
        {
            // find shopkeeper
            var room       = RoomHelper.GetPlayerRoom(session.Player.Location);
            var shopkeeper = room.GetNpcs().FirstOrDefault(s => s.IsShopkeeper);

            if (shopkeeper == null)
            {
                session.WriteLine("There is notihng to buy here.");
                return;
            }

            foreach (var key in shopkeeper.Inventory.Keys)
            {
                var item = Server.Current.Database.Get <PlayerItem>(key);
                session.WriteLine("`G{0,-15}{1}", "[" + item.Value + "]", item.Name);
            }
        }
Beispiel #12
0
        public override void Execute(Session session, CommandContext context)
        {
            // get room
            var room = RoomHelper.GetPlayerRoom(session.Player.Location);

            if (room == null)
            {
                Server.Current.Log(LogType.Error, "WhereCommand: couldn't find room");
                return;
            }

            // get area
            var area = RoomHelper.GetArea(room.Area);

            if (area == null)
            {
                Server.Current.Log(LogType.Error, "WhereCommand: couldn't find area");
                return;
            }

            Dictionary <string, string> players = new Dictionary <string, string>();

            // for each room in area, add players to list
            foreach (var roomKey in area.Rooms)
            {
                var theRoom = RoomHelper.GetRoom(roomKey);
                foreach (var playerInRoom in theRoom.GetPlayers())
                {
                    if (!players.ContainsKey(playerInRoom.Forename))
                    {
                        // get proper room name
                        var playerRoomName = RoomHelper.GetRoom(playerInRoom.Location);
                        players.Add(playerInRoom.Forename, playerRoomName.Title);
                    }
                }
            }

            session.WriteLine("Players in {0}:", area.Name);

            foreach (var player in players)
            {
                session.WriteLine(string.Format("{0,-20}{1}", player.Key, player.Value));
            }
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public override void Execute(Session session, CommandContext context)
        {
            if (string.IsNullOrWhiteSpace(context.ArgumentString))
            {
                session.WriteLine("Buy what?");
                return;
            }

            // find shopkeeper
            var room       = RoomHelper.GetPlayerRoom(session.Player.Location);
            var shopkeeper = room.GetNpcs().FirstOrDefault(s => s.IsShopkeeper);

            if (shopkeeper == null)
            {
                session.WriteLine("There is notihng to buy here.");
                return;
            }

            int qty = 1;

            if (!int.TryParse(context.Arguments[0], out qty))
            {
                qty = 1;
            }
            else
            {
                context.Arguments.RemoveAt(0);
            }

            // get item
            PlayerItem item = null;

            foreach (var key in shopkeeper.Inventory.Keys)
            {
                var template = Server.Current.Database.Get <PlayerItem>(key);
                if (template.Keywords.Contains(context.Arguments[0].ToLower()))
                {
                    item = template;
                    break;
                }
            }

            if (item == null)
            {
                session.WriteLine("They don't sell that here.");
                return;
            }

            // calculate price
            var price = item.Value * qty;

            if (session.Player.Gold < price)
            {
                session.WriteLine("You can't afford that much.");
                return;
            }

            session.Player.Gold -= price;

            // duplicate in inventory, minding inventory and weight limits
            // if over weight/inventory, dump on the floor
            for (int i = 0; i < qty; i++)
            {
                var dupedItem = item.Copy();
                if (session.Player.Inventory.Count + 1 <= session.Player.MaxInventory &&
                    session.Player.Weight + dupedItem.Weight <= session.Player.MaxWeight)
                {
                    session.Player.Inventory[dupedItem.Key] = dupedItem.Name;
                }
                else
                {
                    room.AddItem(dupedItem);
                }

                Server.Current.Database.Save(dupedItem);
                Server.Current.Database.Save(session.Player);
            }

            session.WriteLine("You buy {0} {1}", qty, item.Name);
            room.SendPlayers("%d buys something.", session.Player, null, session.Player);
        }
Beispiel #15
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;
        }
Beispiel #16
0
        public override void Execute(Session session, CommandContext context)
        {
            try
            {
                bool givingGold = context.Arguments[1] == "coin";
                context.Arguments.Remove("coin");

                var target = Server.Current.Database.Get <Player>(context.Arguments[1]);
                if (target == null)
                {
                    session.WriteLine("Who is {0}?", context.Arguments[1]);
                    return;
                }

                var room = RoomHelper.GetPlayerRoom(session.Player.Location);
                if (room == null)
                {
                    throw new Exception();
                }

                // players must be in the same room
                if (target.Location != room.Key)
                {
                    session.WriteLine("{0} is not here.", target.Forename);
                    return;
                }

                if (givingGold)
                {
                    long gold = Convert.ToInt64(context.Arguments[0]);
                    if (session.Player.Gold < gold)
                    {
                        session.WriteLine("You don't have that much...");
                        return;
                    }

                    // remove gold from session player
                    session.Player.Gold -= gold;
                    // give gold to target player
                    target.Gold += gold;
                }
                else
                {
                    // find item
                    var item = ItemHelper.FindInventoryItem(session.Player, context.Arguments[0]);

                    if (item == null)
                    {
                        session.WriteLine("Couldn't find {0}.", context.Arguments[0]);
                        return;
                    }

                    // weight check
                    if (target.Inventory.Count >= target.MaxInventory || target.Weight + item.Weight > target.MaxWeight)
                    {
                        session.WriteLine("{0} can't carry that much.", target.Forename);
                        return;
                    }

                    // remove from player inventory
                    session.Player.Inventory.Remove(item.Key);

                    // messages
                    session.WriteLine("You give {0} to {1}.", item.Name, target.Forename);
                    target.Send(string.Format("{0} gives you {1}.", session.Player.Forename, item.Name), session.Player, target);
                    room.SendPlayers("%d gives something to %D.", session.Player, target, new[] { session.Player, target });

                    // add to target inventory
                    target.Inventory.Add(item.Key, item.Name);
                }

                Server.Current.Database.Save(session.Player);
                Server.Current.Database.Save(target);
            }
            catch
            {
                PrintSyntax(session);
            }
        }
Beispiel #17
0
        private void TryExecuteCommand(string input)
        {
            if (input.ToLower() == "exitmapping")
            {
                Session.PopState();
                return;
            }

            var room = RoomHelper.GetPlayerRoom(Session.Player);

            if (_status == MappingStatus.Walking)
            {
                var direction = DirectionHelper.GetDirectionWord(input);

                if (string.IsNullOrEmpty(direction))
                {
                    Session.WriteLine("That's not a direction.");
                    return;
                }

                if (room.HasExit(direction))
                {
                    var commandInfo = Server.Current.CommandLookup.FindCommand(direction, Session.Player);
                    commandInfo.Command.Execute(Session, CommandContext.Create(direction));
                    return;
                }

                // set mode to request title
                Session.WriteLine("`RCreating exit, Please enter a title...");
                _status    = MappingStatus.NeedsTitle;
                _direction = direction;
            }
            else
            {
                // user is inputting a title
                var checkRoom     = Server.Current.Database.Get <Room>(input.ToLower());
                var calculatedKey = input.ToLower();

                if (checkRoom != null)
                {
                    calculatedKey = RoomHelper.GenerateKey(input);
                    Session.WriteLine("`RRoom already exists. Using title: `G{0}`R.", calculatedKey);
                }

                var newRoom = new Room()
                {
                    Area        = room.Area,
                    Description = RoomHelper.GetDefaultRoomDescription(),
                    Key         = calculatedKey.ToLower(),
                    Title       = input,
                };

                newRoom.Exits.Add(DirectionHelper.GetOppositeDirection(_direction), new RoomExit()
                {
                    IsDoor  = false,
                    IsOpen  = true,
                    LeadsTo = room.Key
                });

                Server.Current.Database.Save(newRoom);

                room.Exits.Add(_direction, new RoomExit()
                {
                    IsDoor  = false,
                    IsOpen  = true,
                    LeadsTo = newRoom.Key
                });

                Server.Current.Database.Save(room);

                var commandInfo = Server.Current.CommandLookup.FindCommand(_direction, Session.Player);
                commandInfo.Command.Execute(Session, CommandContext.Create(_direction));
                _status = MappingStatus.Walking;
            }
        }