Exemple #1
0
        public override Handler DoGet(ParsedInput input)
        {
            // take <item> from <container>
            if (input.Words.Length == 4)
            {
                return(DoGetExtended(input));
            }

            // take <item>
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, input.Words[0].ToSentenceCase().ToParagraph()));
            }

            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            ItemContainer container = null;
            MESSAGE_ENUM  message   = MESSAGE_ENUM.PLAYER_GET;

            // find item in current room
            Item item = CurrentRoom.Items.Find(input.Words[1]);

            if (item == null)
            {
                // find item in a room container
                List <Item> containers = CurrentRoom.Items.GetItemsOfType(ITEM_TYPE.CONTAINER_ANY);
                for (int i = containers.Count() - 1; i >= 0; i--)
                {
                    container = containers[i] as ItemContainer;
                    item      = container.Items.Find(input.Words[1]);
                    if (item != null)
                    {
                        message = MESSAGE_ENUM.PLAYER_GET_FROM_ROOM_CONTAINER;
                        break;
                    }
                }
            }
            if (item == null)
            {
                message = MESSAGE_ENUM.PLAYER_GET_FROM_CONTAINER;

                foreach (EntityHand hand in Hands.Hands)
                {
                    if (hand.Item == null)
                    {
                        continue;
                    }
                    if (hand.Item.IsType(ITEM_TYPE.CONTAINER_ANY))
                    {
                        item = container.Items.Find(input.Words[1]);
                        if (item != null)
                        {
                            break;
                        }
                    }
                }
            }
            if (item == null)
            {
                item = ContainerSlots.FindItem(input.Words[1]);
            }
            if (item == null)
            {
                // item not found
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM));
            }

            // item found; attempt to put in hands
            if (Hands.Full)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_HANDS_ARE_FULL));
            }

            EntityHand emptyHand = Hands.GetEmptyHand();

            emptyHand.Item = item;

            // if we found in a container, remove from container
            if (container != null)
            {
                container.Items.RemoveItem(item);
            }
            // otherwise, remove from room
            else
            {
                CurrentRoom.Items.Remove(item);
            }

            return(Handler.HANDLED(message, item.NameWithIndefiniteArticle, container == null ? null : container.NameAsParagraph));
        }
Exemple #2
0
        public override Handler DoAttack(ParsedInput input)
        {
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, input.Words[0].ToSentenceCase().ToParagraph()));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            string strNPCName = "";
            int    ordinal    = 0;

            if (input.Words.Length == 2)
            {
                strNPCName = input.Words[1];
            }
            else if (input.Words.Length == 3)
            {
                if (!Statics.OrdinalStringToInt.TryGetValue(input.Words[1], out ordinal))
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }
                strNPCName = input.Words[2];
            }

            EntityNPCBase npc = CurrentRoom.NPCs.FindLiving(strNPCName, ordinal);

            if (npc == null)
            {
                npc = CurrentRoom.NPCs.Find(strNPCName, ordinal);
            }
            if (npc == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (npc.IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NPC_ALREADY_DEAD, npc.NameBaseAsParagraph));
            }

            Item weapon = Hands.GetAnyItem(ITEM_TYPE.WEAPON);

            // TODO: fix this
            if (weapon == null)
            {
                if (Hands.Hands[0].Item != null)
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_ATTACKS_BAD_WEAPON, Hands.Hands[0].Item.NameAsParagraph));
                }
                else if (Hands.Hands[1].Item != null)
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_ATTACKS_BAD_WEAPON, Hands.Hands[1].Item.NameAsParagraph));
                }
            }

            Paragraph pWeapon = weapon == null ? "fist".ToParagraph() : weapon.NameAsParagraph;

            // calculate damage
            MESSAGE_ENUM message = MESSAGE_ENUM.PLAYER_ATTACKS_NPC;
            int          damage  = AttackPower - npc.Body.DefensePower;

            npc.Attributes.CurrentHealth -= damage;
            if (npc.IsDead)
            {
                Paragraph xpPara = Game.Player.ProcessExperience(npc);
                return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_KILLS_NPC, npc.NameBaseAsParagraph, pWeapon, damage.ToString().ToParagraph(), xpPara));
            }

            return(Handler.HANDLED(message, npc.NameBaseAsParagraph, pWeapon, damage.ToString().ToParagraph()));
        }
Exemple #3
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));
                }
            }
        }
Exemple #4
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));
                }
            }
        }
Exemple #5
0
        public override Handler DoBuy(ParsedInput input)
        {
            // if (input.Words.Length == 1) { return Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Buy".ToParagraph()); }
            if (input.Words.Length > 2)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (IsDead)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_PLAYER_IS_DEAD));
            }

            RoomShop shop = CurrentRoom as RoomShop;

            if (shop == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NOT_A_SHOP));
            }

            // "buy" lists items for sale
            if (input.Words.Length == 1)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.BASE_STRING, shop.SoldItemsParagraph));
            }

            // scenario 1: buy <number>
            // <number> corresponds with the list obtained through SoldItemsString
            // attempt to parse second word as number
            int  itemIndex;
            Item boughtItem = null;
            int  nPrice     = -1;

            if (int.TryParse(input.Words[1], out itemIndex))
            {
                if (itemIndex < 1 || itemIndex > shop.SoldItems.Count)
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
                }

                nPrice = (int)(shop.SoldItems[itemIndex - 1].Value * shop.SellsAt);
                if (Gold < nPrice)
                {
                    return(Handler.HANDLED(MESSAGE_ENUM.ERROR_NOT_ENOUGH_GOLD, shop.SoldItems[itemIndex - 1].NameAsParagraph));
                }

                boughtItem = shop.SoldItems[itemIndex - 1].Clone();
            }

            // TODO: scenario 2: parse second word as item keyword
            // TODO: find item with merged input
            // MergeInput(int nStartingIndex)
            // FindItem(string, bool bMultiWord = false)
            // - if true, match string to full item name

            if (boughtItem == null)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT));
            }
            if (Hands.Full)
            {
                return(Handler.HANDLED(MESSAGE_ENUM.ERROR_HANDS_ARE_FULL));
            }

            EntityHand hand = Hands.GetEmptyHand();

            hand.Item = boughtItem;

            Gold -= nPrice;
            return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_BUY, boughtItem.NameWithIndefiniteArticle, nPrice.ToString().ToParagraph()));
        }