//----------------------------------------------------------------------------- // Store.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace RolePlaying.Data { /// /// A gear store, where the party can buy and sell gear, organized into categories. /// public class Store : WorldObject { /// /// A purchasing multiplier applied to the price of all gear. /// private float buyMultiplier; /// /// A purchasing multiplier applied to the price of all gear. /// public float BuyMultiplier { get { return buyMultiplier; } set { buyMultiplier = value; } } /// /// A sell-back multiplier applied to the price of all gear. /// private float sellMultiplier; /// /// A sell-back multiplier applied to the price of all gear. /// public float SellMultiplier { get { return sellMultiplier; } set { sellMultiplier = value; } } /// /// The categories of gear in this store. /// private List storeCategories = new List(); /// /// The categories of gear in this store. /// public List StoreCategories { get { return storeCategories; } set { storeCategories = value; } } /// /// The message shown when the party enters the store. /// private string welcomeMessage; /// /// The message shown when the party enters the store. /// public string WelcomeMessage { get { return welcomeMessage; } set { welcomeMessage = value; } } /// /// The content path and name of the texture for the shopkeeper. /// private string shopkeeperTextureName; /// /// The content path and name of the texture for the shopkeeper. /// public string ShopkeeperTextureName { get { return shopkeeperTextureName; } set { shopkeeperTextureName = value; } } /// /// The texture for the shopkeeper. /// private Texture2D shopkeeperTexture; /// /// The texture for the shopkeeper. /// [ContentSerializerIgnore] public Texture2D ShopkeeperTexture { get { return shopkeeperTexture; } set { shopkeeperTexture = value; } } internal static Store Load(string contentName, ContentManager contentManager) { var asset = XmlHelper.GetAssetElementFromXML(contentName); var store = new Store { AssetName = contentName, Name = asset.Element("Name").Value, BuyMultiplier = float.Parse(asset.Element("BuyMultiplier").Value), SellMultiplier = float.Parse(asset.Element("SellMultiplier").Value), WelcomeMessage = asset.Element("WelcomeMessage").Value, ShopkeeperTextureName = asset.Element("ShopkeeperTextureName").Value, ShopkeeperTexture = contentManager.Load(Path.Combine("Textures", "Characters", "Portraits", asset.Element("ShopkeeperTextureName").Value)), StoreCategories = asset.Element("StoreCategories") .Elements("Item") .Select(storeCategory => StoreCategory.Load(storeCategory, contentManager)).ToList(), }; return store; } /// /// Reads an Store object from the content pipeline. /// public class StoreReader : ContentTypeReader { protected override Store Read(ContentReader input, Store existingInstance) { Store store = existingInstance; if (store == null) { store = new Store(); } input.ReadRawObject(store as WorldObject); store.BuyMultiplier = input.ReadSingle(); store.SellMultiplier = input.ReadSingle(); store.StoreCategories.AddRange(input.ReadObject>()); store.WelcomeMessage = input.ReadString(); store.ShopkeeperTextureName = input.ReadString(); store.shopkeeperTexture = input.ContentManager.Load(Path.Combine("Textures", "Characters", "Portraits", store.ShopkeeperTextureName)); return store; } } } }