//-----------------------------------------------------------------------------
// Inn.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.IO;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace RolePlaying.Data
{
///
/// An inn in the game world, where the party can rest and restore themselves.
///
public class Inn : WorldObject
{
///
/// The amount that the party has to pay for each member to stay.
///
private int chargePerPlayer;
///
/// The amount that the party has to pay for each member to stay.
///
public int ChargePerPlayer
{
get { return chargePerPlayer; }
set { chargePerPlayer = value; }
}
///
/// The message shown when the player enters the inn.
///
private string welcomeMessage;
///
/// The message shown when the player enters the inn.
///
public string WelcomeMessage
{
get { return welcomeMessage; }
set { welcomeMessage = value; }
}
///
/// The message shown when the party successfully pays to stay the night.
///
private string paidMessage;
///
/// The message shown when the party successfully pays to stay the night.
///
public string PaidMessage
{
get { return paidMessage; }
set { paidMessage = value; }
}
///
/// The message shown when the party tries to stay but lacks the funds.
///
private string notEnoughGoldMessage;
///
/// The message shown when the party tries to stay but lacks the funds.
///
public string NotEnoughGoldMessage
{
get { return notEnoughGoldMessage; }
set { notEnoughGoldMessage = value; }
}
///
/// The content name of the texture for the shopkeeper.
///
private string shopkeeperTextureName;
///
/// The content 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; }
}
///
/// Reads an Inn object from the content pipeline.
///
public class InnReader : ContentTypeReader
{
protected override Inn Read(ContentReader input, Inn existingInstance)
{
Inn inn = existingInstance;
if (inn == null)
{
inn = new Inn();
}
input.ReadRawObject(inn as WorldObject);
inn.ChargePerPlayer = input.ReadInt32();
inn.WelcomeMessage = input.ReadString();
inn.PaidMessage = input.ReadString();
inn.NotEnoughGoldMessage = input.ReadString();
inn.ShopkeeperTextureName = input.ReadString();
inn.shopkeeperTexture = input.ContentManager.Load(Path.Combine("Textures", "Characters", "Portraits", inn.ShopkeeperTextureName));
return inn;
}
}
internal static Inn Load(string contentName, ContentManager contentManager)
{
var asset = XmlHelper.GetAssetElementFromXML(contentName);
var inn = new Inn
{
AssetName = contentName,
Name = asset.Element("Name").Value,
ChargePerPlayer = int.Parse(asset.Element("ChargePerPlayer").Value),
WelcomeMessage = asset.Element("WelcomeMessage").Value,
PaidMessage = asset.Element("PaidMessage").Value,
NotEnoughGoldMessage = asset.Element("NotEnoughGoldMessage").Value,
ShopkeeperTextureName = asset.Element("ShopkeeperTextureName").Value,
ShopkeeperTexture = contentManager.Load(
System.IO.Path.Combine("Textures", "Characters", "Portraits",
asset.Element("ShopkeeperTextureName").Value)),
};
return inn;
}
}
}