public Handler DoBuyFromEntity(EntityBase entity, string strKeyword) { EntityHand hand = entity.Hands.GetHandWithItem(strKeyword); if (hand == null) { // no hand is holding the requested item return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM)); } else { // hand is holding the requested item if (ShopItemTypes.HasFlag(hand.Item.Type)) { // shop WILL buy this item type int nPrice = (int)(hand.Item.Value * BuysAt); Paragraph itemNameAsParagraph = hand.Item.NameAsParagraph; entity.Gold += nPrice; hand.Item = null; return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_SELL_ITEM, itemNameAsParagraph, nPrice.ToString().ToParagraph())); } else { // shop WILL NOT buy this item type return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_SHOP)); } } }
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)); }
public REMOVE_RESULT DoRemove(string strKeyword, EntityHand hand) { foreach (EntityContainerSlot slot in ContainerSlots) { if (slot.Container == null) { continue; } if (!slot.Container.IsKeyword(strKeyword)) { continue; } hand.Item = slot.Container; slot.Container = null; return(REMOVE_RESULT.REMOVED); } return(REMOVE_RESULT.NOT_REMOVED); }
// TODO: how to determine which message to display? // is returning an item ok? return status instead? public REMOVE_RESULT DoRemove(string strKeyword, EntityHand hand) { foreach (EntityBodyPart part in BodyParts) { if (part.Item == null) { continue; } if (!part.Item.IsKeyword(strKeyword)) { continue; } _defensepower -= part.Item.ArmorFactor; hand.Item = part.Item; part.Item = null; return(REMOVE_RESULT.REMOVED); } return(REMOVE_RESULT.NOT_REMOVED); }
public Handler DoEquip(EntityHand hand) { ItemContainer container = hand.Item as ItemContainer; EQUIP_RESULT bestResult = EQUIP_RESULT.NOT_EQUIPPABLE; foreach (EntityContainerSlot slot in ContainerSlots) { EQUIP_RESULT currentResult = slot.DoEquip(container); if (currentResult == EQUIP_RESULT.EQUIPPED) { hand.Item = null; return(Handler.HANDLED(Statics.ItemTypeToEquipMessage[container.Type], container.NameAsParagraph)); } else if (currentResult > bestResult) { bestResult = currentResult; } } return(Handler.HANDLED(Statics.EquipResultToMessage[bestResult])); }
// result determines message to display public Handler DoEquip(EntityHand hand) { ItemArmor armor = hand.Item as ItemArmor; EQUIP_RESULT bestResult = EQUIP_RESULT.NOT_EQUIPPABLE; foreach (EntityBodyPart part in BodyParts) { EQUIP_RESULT currentResult = part.DoEquip(armor); if (currentResult == EQUIP_RESULT.EQUIPPED) { _defensepower += armor.ArmorFactor; hand.Item = null; return(Handler.HANDLED(Statics.ItemTypeToEquipMessage[armor.Type], armor.NameAsParagraph)); } else if (currentResult > bestResult) { bestResult = currentResult; } } return(Handler.HANDLED(Statics.EquipResultToMessage[bestResult])); }
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 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)); }
// simple List wrappers public void Add(EntityHand hand) { Hands.Add(hand); }
// with dependency on entity, might make sense to move up, since entity already has hands (circular?) // otherwise, remove dependency public Paragraph NPCDisplayParagraph(EntityNPCBase entity) { // if the NPC has hands, assume two hands for now if (Hands.Count == 0) { return(null); } Paragraph p = new Paragraph(); EntityHand RightHand = Hands[0]; EntityHand LeftHand = Hands[1]; if (LeftHand.Item == null && RightHand.Item == null) { p.Inlines.Add("The ".ToRun()); p.Merge(entity.NameAsParagraph); p.Inlines.Add(" isn't holding anything.".ToRun()); return(p); } if (RightHand.Item == null) { // RightHand IS empty // LeftHand IS NOT empty p.Inlines.Add("The ".ToRun()); p.Merge(entity.NameAsParagraph); p.Inlines.Add(" is holding ".ToRun()); p.Merge(LeftHand.Item.NameWithIndefiniteArticle); p.Inlines.Add(" in its left hand.".ToRun()); return(p); } else { // RightHand IS NOT empty // LeftHand MAY OR MAY NOT BE empty p.Inlines.Add("The ".ToRun()); p.Merge(entity.NameAsParagraph); p.Inlines.Add(" is holding ".ToRun()); p.Merge(RightHand.Item.NameWithIndefiniteArticle); p.Inlines.Add(" in its right hand".ToRun()); // TODO: LeftHand switch here if (LeftHand.Item == null) { // RightHand IS NOT empty // LeftHand IS empty p.Inlines.Add(".".ToRun()); return(p); } else { // RightHand IS NOT empty // LeftHand IS NOT empty // append ...and a blah in its left hand. p.Inlines.Add(" and ".ToRun()); p.Merge(LeftHand.Item.NameWithIndefiniteArticle); p.Inlines.Add(" in its left hand.".ToRun()); return(p); } } }
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 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)); } } }
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)); } } }
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())); }