Esempio n. 1
0
        protected override Handler DoLook(string strWord1, string strWord2, string strWord3)
        {
            // TODO: strWord2 could be ordinal OR "my"
            if (strWord1 == "at")
            {
                return(DoLook(strWord2, strWord3));
            }
            if (strWord1 == "in")
            {
                int ordinal;
                if (Statics.OrdinalStringToInt.TryGetValue(strWord2, out ordinal))
                {
                    return(DoLookInContainer(strWord3, ordinal));
                }
                else if (strWord2 == "my")
                {
                    // TODO: fix GetItem to look for BOTH types of container here
                    EntityHand hand = Hands.GetHandWithItem(strWord3);
                    if (hand.Item != null)
                    {
                        if ((hand.Item.Type & ITEM_TYPE.CONTAINER_ANY) != hand.Item.Type)
                        {
                            // matched input with a hand, but hand is not holding a container
                            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                        }

                        // hand is holding requested container
                        ItemContainer handContainer = hand.Item as ItemContainer;
                        if (handContainer.Closed)
                        {
                            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_CLOSED, handContainer.NameAsParagraph));
                        }

                        return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, handContainer.ItemsParagraph));
                    }

                    // hands didn't work; check container slots
                    ItemContainer equippedContainer = ContainerSlots.GetContainer(strWord3);
                    if (equippedContainer != null)
                    {
                        if (equippedContainer.Closed)
                        {
                            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_CONTAINER_CLOSED, equippedContainer.NameAsParagraph));
                        }
                        return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, equippedContainer.ItemsParagraph));
                    }

                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
            }
            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
        }
Esempio n. 2
0
        public override Handler DoEquip(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Equip".ToParagraph()));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            string strItemToEquip = input.Words[1];

            // equip my <item>; strip 'my'
            if (input.Words.Length == 3 && input.Words[1] == "my")
            {
                strItemToEquip = input.Words[2];
            }

            EntityHand hand = Hands.GetHandWithItem(strItemToEquip);

            if (hand == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if ((hand.Item.Type & ITEM_TYPE.ARMOR_ANY) == hand.Item.Type)
            {
                return(Body.DoEquip(hand));
            }
            if ((hand.Item.Type & ITEM_TYPE.CONTAINER_ANY) == hand.Item.Type)
            {
                return(ContainerSlots.DoEquip(hand));
            }

            return(Handler.HANDLED(MESSAGE_ENUM.ERROR_ITEM_NOT_EQUIPPABLE));
        }
Esempio n. 3
0
        public override Handler DoDrink(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Drink".ToParagraph()));
            }
            else if (input.Words.Length > 2)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            EntityHand hand = Hands.GetHandWithItem(input.Words[1], ITEM_TYPE.DRINK);

            if (hand != null)
            {
                MESSAGE_ENUM message = MESSAGE_ENUM.PLAYER_DRINK;

                // hand is holding a drink
                ItemDrink drink = hand.Item as ItemDrink;
                if (drink.NumberOfDrinks == 1)
                {
                    message   = MESSAGE_ENUM.PLAYER_DRINK_LAST;
                    hand.Item = null;
                }
                else
                {
                    drink.NumberOfDrinks--;
                }

                return(Handler.HANDLED(message, drink.NameAsParagraph, drink.MagicPerDrink.ToString().ToParagraph(), drink.NumberOfDrinks.ToString().ToParagraph()));
            }
            else
            {
                // not holding a drink; check room
                ItemDrink drink = CurrentRoom.Items.Find(input.Words[1], ITEM_TYPE.DRINK) as ItemDrink;
                if (drink != null)
                {
                    MESSAGE_ENUM message = MESSAGE_ENUM.PLAYER_DRINK_GROUND_ITEM;

                    if (drink.NumberOfDrinks == 1)
                    {
                        message = MESSAGE_ENUM.PLAYER_DRINK_LAST_GROUND_ITEM;
                        CurrentRoom.Items.Remove(drink);
                    }
                    else
                    {
                        drink.NumberOfDrinks--;
                    }

                    return(Handler.HANDLED(message, drink.NameAsParagraph, drink.MagicPerDrink.ToString().ToParagraph(), drink.NumberOfDrinks.ToString().ToParagraph()));
                }
                else
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
            }
        }
Esempio n. 4
0
        public override Handler DoEat(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Eat".ToParagraph()));
            }
            else if (input.Words.Length > 2)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            EntityHand hand = Hands.GetHandWithItem(input.Words[1], ITEM_TYPE.FOOD);

            if (hand != null)
            {
                MESSAGE_ENUM message = MESSAGE_ENUM.PLAYER_EAT;

                // hand is holding food
                ItemFood food = hand.Item as ItemFood;
                if (food.NumberOfBites == 1)
                {
                    message   = MESSAGE_ENUM.PLAYER_EAT_LAST;
                    hand.Item = null;
                }
                else
                {
                    food.NumberOfBites--;
                }

                return(Handler.HANDLED(message, food.NameAsParagraph, food.HealthPerBite.ToString().ToParagraph(), food.NumberOfBites.ToString().ToParagraph()));
            }
            else
            {
                // not holding food; check room
                ItemFood food = CurrentRoom.Items.Find(input.Words[1], ITEM_TYPE.FOOD) as ItemFood;
                if (food != null)
                {
                    MESSAGE_ENUM message = MESSAGE_ENUM.PLAYER_EAT_GROUND_ITEM;

                    if (food.NumberOfBites == 1)
                    {
                        message   = MESSAGE_ENUM.PLAYER_EAT_LAST_GROUND_ITEM;
                        hand.Item = null;
                    }
                    else
                    {
                        food.NumberOfBites--;
                    }

                    return(Handler.HANDLED(message, food.NameAsParagraph, food.HealthPerBite.ToString().ToParagraph(), food.NumberOfBites.ToString().ToParagraph()));
                }
                else
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
            }
        }