public override Handler DoRemove(ParsedInput input) { if (input.Words.Length == 1) { return(Handler.HANDLED(MESSAGE_ENUM.ERROR_WHAT, "Remove".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)); } EntityHand hand = Hands.GetEmptyHand(); if (hand == null) { return(Handler.HANDLED(MESSAGE_ENUM.ERROR_HANDS_ARE_FULL)); } REMOVE_RESULT result = Body.DoRemove(input.Words[1], hand); if (result == REMOVE_RESULT.NOT_REMOVED) { result = ContainerSlots.DoRemove(input.Words[1], hand); } if (result == REMOVE_RESULT.NOT_REMOVED) { return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_INPUT)); } MESSAGE_ENUM message = Statics.ItemTypeToRemoveMessage[hand.Item.Type]; return(Handler.HANDLED(message, hand.Item.NameAsParagraph)); }
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)); }
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())); }