using System;
using System.Data;
namespace Woodpecker.Game.Items
{
///
/// Represents the definition of an item, containing information about the item's appearance, interaction types etc.
///
public class itemDefinition
{
#region Fields
///
/// The item definition ID of this item definition.
///
public int ID;
///
/// The directory ID of the cast file (.cct) of this item in the hof_furni directory on the webserver.
///
public int directoryID;
///
/// The sprite of this item definition.
///
public string Sprite;
///
/// The color string of this item. ('0,0,0' or 'null' is default)
///
public string Color;
///
/// The length of this item.
///
public byte Length;
///
/// The width of this item.
///
public byte Width;
///
/// The height the 'top' of this item is located at. Affects the sitheight for seats etc. If this field holds 0.0, then no items can be placed ontop of this item.
///
public float topHeight;
///
/// A set of booleans indicating what kind of item this is, how interaction can happen with this item etc.
///
public itemBehaviourContainer Behaviour = new itemBehaviourContainer();
///
/// True if this item can hold custom data.
///
public bool canContainCustomData
{
get
{
return
this.Behaviour.customDataNumericOnOff
|| this.Behaviour.customDataTrueFalse
|| this.Behaviour.customDataNumericState
|| this.Behaviour.customDataOnOff
|| this.Behaviour.isDoor;
}
}
///
/// The ingame name of this item definition, as expressed in external_texts.
///
public string Name
{
get
{
return Engine.Game.Items.getItemName(this, 0);
}
}
///
/// The ingame description of this item definition, as expressed in external_texts.
///
public string Description
{
get
{
return Engine.Game.Items.getItemDescription(this, 0);
}
}
public bool isInteractiveStance
{
get
{
return
this.Behaviour.canSitOnTop
|| this.Behaviour.canLayOnTop;
}
}
#endregion
#region Methods
///
/// Parses a complete System.Data.DataRow of an item definition to a full itemDefinition object. Null is returned on errors.
///
/// The System.Data.DataRow with all the required fields.
public static itemDefinition Parse(DataRow dRow)
{
itemDefinition ret = new itemDefinition();
ret.ID = (int)dRow["id"];
ret.directoryID = (int)dRow["cast_directory"];
ret.Sprite = (string)dRow["sprite"];
ret.Color = (string)dRow["color"];
ret.Length = byte.Parse(dRow["length"].ToString());
ret.Width = byte.Parse(dRow["width"].ToString());
ret.topHeight = float.Parse(dRow["topheight"].ToString());
ret.Behaviour = itemBehaviourContainer.Parse(dRow["behaviour"].ToString());
return ret;
}
#endregion
#region Subclasses
///
/// A container of booleans, indicating what can be done with an item, what kind of type the item is etc.
///
public class itemBehaviourContainer
{
#region Fields
#region Primitive types
///
/// True if this item can be placed on walls.
///
public bool isWallItem;
///
/// True if this item can be placed on the floor and is solid.
///
public bool isSolid;
///
/// True if this item can be placed on the floor and allows room units to sit on it.
///
public bool canSitOnTop;
///
/// True if this item can be placed on the floor and allows room units to lay on it.
///
public bool canLayOnTop;
///
/// True if this item can be placed on the floor and allows room units to stand on it.
///
public bool canStandOnTop;
///
/// True if other items can be stacked on top of this item.
///
public bool canStackOnTop;
///
/// True if this item can be placed on the floor and behaves as a roller. (moving room units and items located on it every 2000ms)
///
public bool isRoller;
///
/// True if this item can be placed on the floor, and can only appear in public spaces.
///
public bool isPublicSpaceObject;
///
/// True if this item is invisible to room users.
///
public bool isInvisible;
#endregion
#region Interaction requirements
///
/// True if this item requires a room user to have room rights to interact with the item.
///
public bool requiresRightsForInteraction;
///
/// True if this item can be placed on the floor and requires a room user to stand one tile removed from the item to interact with the item.
///
public bool requiresTouchingForInteraction;
#endregion
#region Custom data usage
///
/// True if the custom data of this item can only hold 'TRUE' or 'FALSE'. Mostly used for items that have a temporarily status, such as an opening and closing fridge.
///
public bool customDataTrueFalse;
///
/// True if the custom data of this item can only hold 'ON' or 'OFF'. Mostly used for items that can have a status until it is changed again, such as TVs etc.
///
public bool customDataOnOff;
///
/// True if the custom data of this item can only hold '1' (off) or '2' on.
///
public bool customDataNumericOnOff;
///
/// True if the custom data of this item can only hold an integer between 1 and 6.
///
public bool customDataNumericState;
#endregion
#region Item usage
///
/// True if this item can be used to decorate the walls/floor of a user flat.
///
public bool isDecoration;
///
/// True if this item is a wall item and behaves as a post.it item. ('sticky')
///
public bool isPostIt;
///
/// True if this item can be placed on the floor and can be opened/closed. Open items allow room units to walk through them, closed items do not.
///
public bool isDoor;
///
/// True if this item can be placed on the floor and can teleport room units to other teleporter items. BEAM ME UP SCOTTY FFS!!11oneone
///
public bool isTeleporter;
///
/// True if this item can be placed on the floor and can be opened and closed, and 'rolled' to a random number.
///
public bool isDice;
///
/// True if this item can be placed on the floor and can hold a user-given message as 'inscription'.
///
public bool isPrizeTrophy;
///
/// True if this item can be redeemed for credits.
///
public bool isRedeemable;
///
/// True if this item can be placed on the floor and behaves as a soundmachine. Soundmachines play user-composed music in user flats and they accept the input of sound sample items.
///
public bool isSoundMachine;
///
/// True if this item can be placed on the floor and can be inserted into soundmachines to compose music.
///
public bool isSoundMachineSampleSet;
#endregion
#endregion
#region Methods
///
/// Returns a string representation of the behaviour flags of this item behaviour container.
///
///
public override string ToString()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (this.isWallItem)
sb.Append('W');
if (this.isSolid)
sb.Append('S');
if (this.canSitOnTop)
sb.Append('C');
if (this.canLayOnTop)
sb.Append('B');
if (this.canStandOnTop)
sb.Append('K');
if (this.isRoller)
sb.Append('R');
if (this.isPublicSpaceObject)
sb.Append('P');
if (this.isInvisible)
sb.Append('I');
if (this.requiresRightsForInteraction)
sb.Append('G');
if (this.requiresTouchingForInteraction)
sb.Append('T');
if (this.customDataTrueFalse)
sb.Append('U');
if (this.customDataOnOff)
sb.Append('O');
if (this.customDataNumericOnOff)
sb.Append('M');
if (this.customDataNumericState)
sb.Append('Z');
if (this.canStackOnTop)
sb.Append('H');
if (this.isDecoration)
sb.Append('V');
if (this.isPostIt)
sb.Append('J');
if (this.isDoor)
sb.Append('D');
if (this.isTeleporter)
sb.Append('X');
if (this.isDice)
sb.Append('F');
if (this.isPrizeTrophy)
sb.Append('Y');
if (this.isRedeemable)
sb.Append('Q');
if (this.isSoundMachine)
sb.Append('A');
if (this.isSoundMachineSampleSet)
sb.Append('N');
return sb.ToString();
}
///
/// Parses a item behaviour flag string to a itemBehaviourContainer object.
///
/// The item behavious flag string.
public static itemBehaviourContainer Parse(string s)
{
itemBehaviourContainer Container = new itemBehaviourContainer();
foreach (char c in s) // Loop through all 'flags'
{
switch (c) // Determine and set 'flag'
{
#region Primitive types
case 'W':
Container.isWallItem = true;
break;
case 'S':
Container.isSolid = true;
break;
case 'C':
Container.canSitOnTop = true;
break;
case 'B':
Container.canLayOnTop = true;
break;
case 'K':
Container.canStandOnTop = true;
break;
case 'R':
Container.isRoller = true;
break;
case 'P':
Container.isPublicSpaceObject = true;
break;
case 'I':
Container.isInvisible = true;
break;
#endregion
#region Interaction requirements
case 'G':
Container.requiresRightsForInteraction = true;
break;
case 'T':
Container.requiresTouchingForInteraction = true;
break;
#endregion
#region Custom data usage
case 'U':
Container.customDataTrueFalse = true;
break;
case 'O':
Container.customDataOnOff = true;
break;
case 'M':
Container.customDataNumericOnOff = true;
break;
case 'Z':
Container.customDataNumericState = true;
break;
#endregion
#region Item usage
case 'H':
Container.canStackOnTop = true;
break;
case 'V':
Container.isDecoration = true;
break;
case 'J':
Container.isPostIt = true;
break;
case 'D':
Container.isDoor = true;
break;
case 'X':
Container.isTeleporter = true;
break;
case 'F':
Container.isDice = true;
break;
case 'Y':
Container.isPrizeTrophy = true;
break;
case 'Q':
Container.isRedeemable = true;
break;
case 'A':
Container.isSoundMachine = true;
break;
case 'N':
Container.isSoundMachineSampleSet = true;
break;
#endregion
}
}
return Container;
}
#endregion
}
#endregion
}
}