using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace Chop.Game.Rooms.Units { internal abstract class RoomUnit { private Room _room; private ushort ID; private string name; private string motto; private string figure; internal byte x; internal byte y; internal byte destinationX; internal byte destinationY; private float height; private byte bodyRotation; private byte headRotation; public bool mIsWalking; public bool mCanWalk = true; public bool mStatusUpdated; private Dictionary animations; public delegate void StatusDelegate(string pKey, bool pUpdateInRoom, int pSleepTime); public void AddStatus(string pKey, object pValue, bool pUpdateInRoom) { // Remove existing if (animations.ContainsKey(pKey)) animations.Remove(pKey); animations.Add(pKey, pValue); if (pUpdateInRoom) mStatusUpdated = true; } public void AddStatus(string pKey, object pValue, bool pUpdateInRoom, int pSleepTime) { // Remove existing if (animations.ContainsKey(pKey)) animations.Remove(pKey); animations.Add(pKey, pValue); if (pUpdateInRoom) mStatusUpdated = true; if (pSleepTime > 0) new StatusDelegate(RemoveStatus).BeginInvoke(pKey, pUpdateInRoom, pSleepTime, null, null); } public void AddStatus(string pKey, bool pUpdateInRoom, int pSleepTime) { // Remove existing if (animations.ContainsKey(pKey)) animations.Remove(pKey); animations.Add(pKey, ""); if (pUpdateInRoom) mStatusUpdated = true; if (pSleepTime > 0) new StatusDelegate(RemoveStatus).BeginInvoke(pKey, pUpdateInRoom, pSleepTime, null, null); } public void RemoveStatus(string pKey, bool pUpdateInRoom) { // Status exists if (animations.ContainsKey(pKey)) animations.Remove(pKey); if (pUpdateInRoom) mStatusUpdated = true; } public void RemoveStatus(string pKey, bool pUpdateInRoom, int pSleepTime) { Thread.Sleep(pSleepTime); // Status exists if (animations.ContainsKey(pKey)) animations.Remove(pKey); if (pUpdateInRoom) mStatusUpdated = true; } internal RoomUnit(Room room) { _room = room; animations = new Dictionary(); // TODO should be a capacity } internal abstract void Whisper(ushort ID, string message); internal abstract void Talk(string message); internal abstract void Shout(string message); internal abstract void Move(byte x, byte y, bool warp = false); //internal virtual ResponseBuilder ToShockwaveProtocol() //{ // ResponseBuilder sResponse = new ResponseBuilder(); // sResponse.Append("i:"); // sResponse.AppendString(ID, 13); // sResponse.Append("n:"); // sResponse.AppendString(name, 13); // sResponse.Append("f:"); // sResponse.AppendString(figure, 13); // sResponse.Append("l:"); // sResponse.AppendString(x, ' '); // sResponse.AppendString(y, ' '); // sResponse.AppendString(height, 13); // sResponse.Append("c:"); // sResponse.AppendString(motto, 13); // return sResponse; //} //internal ResponseBuilder ToShockwaveAnimationProtocol() //{ // ResponseBuilder sBuilder = new ResponseBuilder(); // sBuilder.AppendString(ID, ' '); // sBuilder.AppendString(x, ','); // sBuilder.AppendString(y, ','); // sBuilder.AppendString(height, ','); // sBuilder.AppendString(bodyRotation, ','); // sBuilder.AppendString(headRotation, '/'); // foreach (string sKey in animations.Keys) // { // sBuilder.Append(sKey); // if (animations[sKey].ToString() != "") // sBuilder.Append(" " + animations[sKey]); // sBuilder.Append('/'); // } // return sBuilder; //} } }