ModernUO/Scripts/Items/Body Parts/Head.cs
2018-09-14 13:07:43 -07:00

127 lines
No EOL
2.5 KiB
C#

using System;
namespace Server.Items
{
public enum HeadType
{
Regular,
Duel,
Tournament
}
public class Head : Item
{
private string m_PlayerName;
private HeadType m_HeadType;
[CommandProperty( AccessLevel.GameMaster )]
public string PlayerName
{
get => m_PlayerName;
set => m_PlayerName = value;
}
[CommandProperty( AccessLevel.GameMaster )]
public HeadType HeadType
{
get => m_HeadType;
set => m_HeadType = value;
}
public override string DefaultName
{
get
{
if ( m_PlayerName == null )
return base.DefaultName;
switch ( m_HeadType )
{
default:
return $"the head of {m_PlayerName}";
case HeadType.Duel:
return $"the head of {m_PlayerName}, taken in a duel";
case HeadType.Tournament:
return $"the head of {m_PlayerName}, taken in a tournament";
}
}
}
[Constructible]
public Head()
: this( null )
{
}
[Constructible]
public Head( string playerName )
: this( HeadType.Regular, playerName )
{
}
[Constructible]
public Head( HeadType headType, string playerName )
: base( 0x1DA0 )
{
m_HeadType = headType;
m_PlayerName = playerName;
}
public Head( Serial serial )
: base( serial )
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 1 ); // version
writer.Write( (string) m_PlayerName );
writer.WriteEncodedInt( (int) m_HeadType );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
case 1:
m_PlayerName = reader.ReadString();
m_HeadType = (HeadType) reader.ReadEncodedInt();
break;
case 0:
string format = Name;
if ( format != null )
{
if ( format.StartsWith( "the head of " ) )
format = format.Substring( "the head of ".Length );
if ( format.EndsWith( ", taken in a duel" ) )
{
format = format.Substring( 0, format.Length - ", taken in a duel".Length );
m_HeadType = HeadType.Duel;
}
else if ( format.EndsWith( ", taken in a tournament" ) )
{
format = format.Substring( 0, format.Length - ", taken in a tournament".Length );
m_HeadType = HeadType.Tournament;
}
}
m_PlayerName = format;
Name = null;
break;
}
}
}
}