rendered paste bodyItem.cs OnSingleClick
if (ns != null)
{
if (this.Name == null)
{
if (m_Amount <= 1)
ns.Send(new AsciiMessage(this.m_Serial, this.m_ItemID, MessageType.Label, 0x3b2, 3, "", string.Format("{0} {1}", this.m_Amount, (ClilocTranslator.ClilocStringList[LabelNumber] as ClilocStringEntries).Singular)));
else
ns.Send(new AsciiMessage(this.m_Serial, this.m_ItemID, MessageType.Label, 0x3b2, 3, "", string.Format("{0} {1}", this.m_Amount, (ClilocTranslator.ClilocStringList[LabelNumber] as ClilocStringEntries).Plural)));
}
else
{
if (m_Amount <= 1)
ns.Send(new AsciiMessage(m_Serial, m_ItemID, MessageType.Label, 0x3b2, 3, "", this.Name.ToLower()));
else
{
string toDisplay = string.Format("{0} {1}", this.m_Amount, this.Name.ToLower());
if (toDisplay[toDisplay.Length - 1] != 's')
toDisplay += "s";
ns.Send(new AsciiMessage(this.m_Serial, this.m_ItemID, MessageType.Label, 0x3b2, 3, "", toDisplay));
}
}
}
Cliloc to string
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
namespace Server
{
#region Ultima SDK code + mod
public class StringList
{
private Hashtable m_Table;
private string m_Language;
public Hashtable Table { get { return m_Table; } }
public string Language { get { return m_Language; } }
private static byte[] m_Buffer = new byte[1024];
public StringList(string language)
{
m_Language = language;
m_Table = new Hashtable();
string path = string.Format("{0}cliloc.{1}",ClilocTranslator.clientPath, language);
if (path == null)
{
return;
}
using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
bin.ReadInt32();
bin.ReadInt16();
while (bin.PeekChar() != -1)
{
int number = bin.ReadInt32();
bin.ReadByte();
int length = bin.ReadInt16();
if (length > m_Buffer.Length)
m_Buffer = new byte[(length + 1023) & ~1023];
bin.Read(m_Buffer, 0, length);
m_Table[number] = new ClilocStringEntries(Encoding.UTF8.GetString(m_Buffer, 0, length));
}
}
}
}
#endregion
class ClilocTranslator
{
private static Hashtable clilocList;
private static string language = "enu";
public static string clientPath = "D:\\Program\\Ultima Online 2D\\";
public static Hashtable ClilocStringList
{
get { return clilocList; }
set { clilocList = value; }
}
public static void Start()
{
if (language == null || language == "")
language = "enu";
StringList sl = new StringList(language);
clilocList = sl.Table;
}
}
public class ClilocStringEntries
{
string singular;
string plural;
public string Singular
{
get { return singular; }
set { singular = value; }
}
public string Plural
{
get { return plural; }
set { plural = value; }
}
public ClilocStringEntries(string clilocString)
{
if (clilocString.Contains("~"))
clilocString = FormatVars(clilocString);
singular = clilocString.ToLower();
if (singular[singular.Length - 1] != 's')
plural += "s";
}
public string FormatVars(string text)
{
Regex r = new Regex("~(.+?)~");
MatchCollection mC = r.Matches(text);
for (int i = 0; i < mC.Count; i++)
text = text.Replace(mC[i].ToString(), string.Format("{{0}}",i));
return text;
}
}
}