using System;
using System.Collections.Generic;
using Woodpecker.Specialized.Text;
using Woodpecker.Game.Items;
using Woodpecker.Game.Items.Pets;
namespace Woodpecker.Game.Store
{
///
/// Represents an item (package) that is being sold in the catalogue.
///
public class storeCatalogueSale
{
#region Fields
///
/// The purchase name/code of this sale, used to identify this sale.
///
private string _saleCode;
///
/// The purchase name/code of this sale, used to identify this sale.
///
public string saleCode
{
get { return _saleCode; }
}
///
/// Holds true if this sale object is a package.
///
private bool _isPackage;
///
/// True if this sale object is a package. (multiple items in one buy)
///
public bool isPackage
{
get { return _isPackage; }
}
///
/// The amount of Credits this sale costs.
///
private int _Price;
///
/// The amount of Credits this sale costs.
///
public int Price
{
get { return _Price; }
}
#region Single-item sale
///
/// The item definition of the item that is sold with this single-item sale. Null if this sale is a package of items.
///
public itemDefinition pItem;
///
/// The special sprite ID that holds the sprite ID of items such as 'poster'.
///
public int pItemSpecialSpriteID;
#endregion
///
/// An array of storeCataloguePackageItem objects, representing the package items that are included and their quantity.
///
private List pPackageItems;
///
/// The sale item type character ('d', 'i' or 's') as a string.
///
public string saleItemType
{
get
{
if(this.isPackage)
return "d";
else
{
if(this.pItem.Behaviour.isWallItem)
return "i";
else
return "s";
}
}
}
///
/// The icon of item in this sale. If this sale is a package, then there is no special icon, and the client will display the package icon.
///
private string itemIcon
{
get
{
if (this.isPackage)
return null;
else
return Engine.Game.Items.generateSpecialSprite(ref this.pItem.Sprite, this.pItemSpecialSpriteID);
}
}
///
/// The size of the item in this sale. If this sale is a package or is a wall item, then there is no size.
///
private string itemSize
{
get
{
if (this.isPackage || this.pItem.Behaviour.isWallItem)
return null;
else
return "0";
}
}
///
/// The dimensions of the item in this sale. If this sale is a package or is a wall item, then there are no dimensions.
///
private string itemDimensions
{
get
{
if (this.isPackage || this.pItem.Behaviour.isWallItem)
return null;
else
return pItem.Length + "," + pItem.Width;
}
}
///
/// The name of this sale. If this sale is a package, the internal name value will be returned. Otherwise, the matching value from the external_texts will be returned.
///
public string Name
{
get
{
if (this.isPackage)
return _packageName;
else
return Engine.Game.Items.getItemName(pItem, pItemSpecialSpriteID);
}
}
///
/// The description of this sale. If this sale is a package, the internal description value will be returned. Otherwise, the matching value from the external_texts will be returned.
///
public string Description
{
get
{
if (this.isPackage)
return _packageDescription;
else
return Engine.Game.Items.getItemDescription(pItem, pItemSpecialSpriteID);
}
}
///
///Holds the name of this package as a string. If this sale is not a package, then this field holds null.
///
private string _packageName = null;
///
/// Holds the description of this package as a string. If this sale is not a package, then this field holds null.
///
private string _packageDescription = null;
#endregion
#region Constructors
///
/// Constructs a blank catalogue sale with a given sale code and a given price.
///
/// The sale code of this sale.
/// The amount of Credits this sale costs.
public storeCatalogueSale(string saleCode, int Price)
{
this._saleCode = saleCode;
this._Price = Price;
}
#endregion
#region Methods
///
/// Set the item definition that ships with this sale.
///
/// The itemDefinition of the item to set.
public void setItem(itemDefinition Item, int specialSpriteID)
{
if(!this.isPackage)
{
this.pItem = Item;
this.pItemSpecialSpriteID = specialSpriteID;
}
}
///
/// Marks this sale as a package, sets the given name and description and constructs an empty List of the type storeCataloguePackageItem.
///
/// The name of this package.
/// The description of this package.
public void setPackage(string packageName, string packageDescription)
{
this._isPackage = true;
this._packageName = packageName;
this._packageDescription = packageDescription;
this.pPackageItems = new List();
}
///
/// Adds a given itemDefinition item with a given quantity to the package sale.
///
/// The itemDefinition object of the item to add to the package.
/// The amount of times this item should be added to the package.
public void addPackageItem(itemDefinition Item, int Amount, int specialSpriteID)
{
if (!this.isPackage)
return;
storeCataloguePackageItem pPackageItem = new storeCataloguePackageItem(Item, Amount, specialSpriteID);
this.pPackageItems.Add(pPackageItem);
}
public void factorizeItems(int receivingUserID, string extraInformation)
{
}
public stripItem[] getItemInstances()
{
List Items = new List();
if (!isPackage)
{
Items.Add(Engine.Game.Items.createItemFromDefinition(this.pItem, this.pItemSpecialSpriteID));
}
else
{
foreach(storeCataloguePackageItem lPackageItem in this.pPackageItems)
{
for(int i = 0; i < lPackageItem.pAmount; i++)
{
Items.Add(Engine.Game.Items.createItemFromDefinition(lPackageItem.pItem, lPackageItem.specialSpriteID));
}
}
}
return Items.ToArray();
}
public List getPackageItems()
{
if (this.pPackageItems == null)
return new List();
else
return this.pPackageItems;
}
///
/// Returns 'true' if two storeCatalogueSale objects have the same salecode.
///
/// The storeCatalogueSale object to compare against this storeCatalogueSale.
public override bool Equals(object obj)
{
return (this.saleCode == ((storeCatalogueSale)obj).saleCode);
}
///
/// Returns the hashcode of l u l z.
///
public override int GetHashCode()
{
return base.GetHashCode();
}
///
/// Converts this catalogue page sale representation to a string and returns it.
///
public override string ToString()
{
try
{
fuseStringBuilder szSaleDetails = new fuseStringBuilder();
szSaleDetails.appendTabbedValue(this.Name);
szSaleDetails.appendTabbedValue(this.Description);
szSaleDetails.appendTabbedValue(this.Price.ToString());
szSaleDetails.appendTabbedValue(null);
szSaleDetails.appendTabbedValue(this.saleItemType); // 'i', 's', 'd' etc
szSaleDetails.appendTabbedValue(this.itemIcon);
szSaleDetails.appendTabbedValue(this.itemSize);
szSaleDetails.appendTabbedValue(this.itemDimensions);
szSaleDetails.appendTabbedValue(this.saleCode);
if (this.isPackage || this.pItem.Sprite == "poster")
szSaleDetails.appendTabbedValue(null);
if (this.isPackage)
{
szSaleDetails.appendTabbedValue(this.pPackageItems.Count.ToString());
foreach (storeCataloguePackageItem lPackageItem in this.pPackageItems)
{
szSaleDetails.appendTabbedValue(Engine.Game.Items.generateSpecialSprite(ref lPackageItem.pItem.Sprite, lPackageItem.specialSpriteID));
szSaleDetails.appendTabbedValue(lPackageItem.pAmount.ToString());
szSaleDetails.appendTabbedValue(lPackageItem.pItem.Color);
}
}
else
{
if (!this.pItem.Behaviour.isWallItem) // Wall items do not have colors
szSaleDetails.appendTabbedValue(this.pItem.Color);
}
return szSaleDetails.ToString();
}
catch { return ""; }
}
#endregion
}
///
/// Represents an item + a quantity, of an item sold in a package sale.
///
public struct storeCataloguePackageItem
{
#region Fields
///
/// The item that is for sale.
///
public itemDefinition pItem;
///
/// The amount of instances this item ships with.
///
public int pAmount;
///
/// The ID for items with sprites such as 'poster' and 'wallpaper'.
///
public int specialSpriteID;
#endregion
#region Constructors
///
/// Constructs a storeCataloguePackageItem instance with a given item and quantity.
///
/// The itemDefinition object of the item.
/// The amount of times this item appears in the package.
public storeCataloguePackageItem(itemDefinition pItemDefinition, int pItemAmount, int specialSpriteID)
{
this.pItem = pItemDefinition;
this.pAmount = pItemAmount;
this.specialSpriteID = specialSpriteID;
}
#endregion
}
}