Esempio n. 1
0
        private bool OnRemoveCommand(string userName, string[] pieces)
        {
            var player = FrogtownShared.GetPlayerWithName(userName);

            ItemWithCount itemWithCount = null;

            try
            {
                itemWithCount = ParseItemWithCount(pieces);
            } catch (ArgumentException e)
            {
                SendFailedLookupMessage();
                return(true);
            }

            int countPlayerHas = player.master.inventory.GetItemCount((ItemIndex)itemWithCount.index);

            itemWithCount.count = Math.Min(Math.Max(itemWithCount.count, 1), countPlayerHas);

            FrogtownShared.SendChat(string.Format("countPlayerHas = {0}\r\nitemWithCount.count = {1}", countPlayerHas, itemWithCount.count));

            if (itemWithCount.count > 0)
            {
                player.master.inventory.GiveItem((ItemIndex)itemWithCount.index, -itemWithCount.count);
                FrogtownShared.SendChat(string.Format("Took {0} items from {1}.", itemWithCount.count, userName));
            }

            return(true);
        }
Esempio n. 2
0
        private bool OnGiveCommand(string userName, string[] pieces)
        {
            var           player        = FrogtownShared.GetPlayerWithName(userName);
            ItemWithCount itemWithCount = null;

            try
            {
                itemWithCount = ParseItemWithCount(pieces);
                if (itemWithCount.index < 0 || itemWithCount.index >= (int)ItemIndex.Count)
                {
                    SendFailedLookupMessage();
                    return(true);
                }
            } catch (ArgumentException e)
            {
                SendFailedLookupMessage();
                return(true);
            }
            itemWithCount.count = Math.Max(itemWithCount.count, 1);

            player.master.inventory.GiveItem((ItemIndex)itemWithCount.index, itemWithCount.count);
            FrogtownShared.SendChat(string.Format("Gave {0} items to {1}.", itemWithCount.count, userName));

            return(true);
        }
Esempio n. 3
0
        private ItemWithCount ParseItemWithCount(string[] pieces)
        {
            int count         = 1;
            int index         = -1;
            var itemWithCount = new ItemWithCount();

            if (pieces.Length >= 2)
            {
                if (!TryParseItemIndex(pieces[1], out index))
                {
                    throw new ArgumentException(nameof(pieces));
                }
                itemWithCount.index = index;
            }
            if (pieces.Length >= 3)
            {
                Int32.TryParse(pieces[2], out count);
            }
            itemWithCount.count = count;
            return(itemWithCount);
        }