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)); } } }
public ShopItem(ShopItemTypes shopItemType, int price, int probability, bool isSingleton) { ShopItemType = shopItemType; Price = price; Probability = probability; IsSingleton = isSingleton; ShopItemID = GenerateShopItemID(); }
public static ShopItem Deserialize(DataStream reader) { ShopItemTypes shopItemType = (ShopItemTypes)reader.ReadSInt32(); int price = reader.ReadSInt32(); int probability = reader.ReadSInt32(); bool isSingleton = reader.ReadByte() == 0x01; int shopItemID = reader.ReadSInt32(); ShopItem si = null; switch (shopItemType) { case ShopItemTypes.Card: { int rareLevel = reader.ReadSInt32(); int generateCardID = reader.ReadSInt32(); si = new ShopItem_Card(price, rareLevel, probability, isSingleton); ((ShopItem_Card)si).GenerateCardID = generateCardID; break; } case ShopItemTypes.Budget: { int budget = reader.ReadSInt32(); si = new ShopItem_Budget(price, budget, probability, isSingleton); break; } case ShopItemTypes.LifeUpperLimit: { int lifeUpperLimit = reader.ReadSInt32(); si = new ShopItem_LifeUpperLimit(price, lifeUpperLimit, probability, isSingleton); break; } case ShopItemTypes.EnergyUpperLimit: { int energyUpperLimit = reader.ReadSInt32(); si = new ShopItem_EnergyUpperLimit(price, energyUpperLimit, probability, isSingleton); break; } } si.ShopItemID = shopItemID; return(si); }
public Handler DoPriceItem(Item item, string strKeyword) { if (item == null) { return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM)); } if (!item.IsKeyword(strKeyword)) { return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_ITEM)); } if (!ShopItemTypes.HasFlag(item.Type)) { return(Handler.HANDLED(MESSAGE_ENUM.ERROR_BAD_SHOP)); } // shop will buy this item type int nPrice = (int)(item.Value * BuysAt); return(Handler.HANDLED(MESSAGE_ENUM.PLAYER_PRICE_ITEM, item.NameAsParagraph, nPrice.ToString().ToParagraph())); }
public static ShopItem GenerateShopItemFromXML(XmlNode node_ShopItem, out bool needRefresh) { needRefresh = false; ShopItemTypes type = (ShopItemTypes)Enum.Parse(typeof(ShopItemTypes), node_ShopItem.Attributes["shopItemType"].Value); int price = int.Parse(node_ShopItem.Attributes["price"].Value); int probability = int.Parse(node_ShopItem.Attributes["probability"].Value); bool isSingleton = node_ShopItem.Attributes["isSingleton"].Value == "True"; switch (type) { case ShopItemTypes.Card: { int rareLevel = int.Parse(node_ShopItem.Attributes["cardRareLevel"].Value); return(new ShopItem_Card(price, rareLevel, probability, isSingleton)); } case ShopItemTypes.Budget: { int budget = int.Parse(node_ShopItem.Attributes["budget"].Value); return(new ShopItem_Budget(price, budget, probability, isSingleton)); } case ShopItemTypes.LifeUpperLimit: { int lifeUpperLimit = int.Parse(node_ShopItem.Attributes["lifeUpperLimit"].Value); return(new ShopItem_LifeUpperLimit(price, lifeUpperLimit, probability, isSingleton)); } case ShopItemTypes.EnergyUpperLimit: { int energyUpperLimit = int.Parse(node_ShopItem.Attributes["energyUpperLimit"].Value); return(new ShopItem_EnergyUpperLimit(price, energyUpperLimit, probability, isSingleton)); } } return(null); }