using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; namespace Chop.Game.Rooms { public class RoomTemplate { public string ModelName; public bool HC_only; public byte Door_x; public byte Door_y; public double Door_h; public byte Door_z; public string Heightmap; public string Publicroom_items; public bool Swimmingpool; public string Specialcast_emitter; public uint Specialcast_interval; public uint Specialcast_rnd_min; public uint Specialcast_rnd_max; public byte[,] mDynamicHeightmap; public float[,] mDynamicHeight; public SquareState[,] mSquares; public static RoomTemplate Parse(DataRow row) { RoomTemplate template = new RoomTemplate { ModelName = row["model"].ToString(), HC_only = row["roomomatic_subscr_only"].ToString() == "1", Door_x = Convert.ToByte(row["door_x"]), Door_y = Convert.ToByte(row["door_y"]), Door_h = Convert.ToDouble(row["door_h"]), Door_z = Convert.ToByte(row["door_z"]), Heightmap = row["heightmap"].ToString(), Publicroom_items = row["publicroom_items"].ToString(), Swimmingpool = row["swimmingpool"].ToString() == "1", Specialcast_emitter = row["specialcast_emitter"].ToString(), Specialcast_interval = Convert.ToUInt32(row["specialcast_interval"]), Specialcast_rnd_min = Convert.ToUInt32(row["specialcast_rnd_min"]), Specialcast_rnd_max = Convert.ToUInt32(row["specialcast_rnd_max"]) }; string[] sTempHeightmap = template.Heightmap.Split(Convert.ToChar(13)); int sLengthX = sTempHeightmap[0].Length; int sLengthY = sTempHeightmap.Length - 1; template.mDynamicHeightmap = new byte[sLengthX, sLengthY]; template.mDynamicHeight = new float[sLengthX, sLengthY]; template.mSquares = new SquareState[sLengthX, sLengthY]; for (int x = 0; x < sLengthX; x++) for (int y = 0; y < sLengthY; y++) if (sTempHeightmap[y] != "") { char c = sTempHeightmap[y][x]; if (c != 'x') { template.mDynamicHeightmap[x, y] = 1; template.mSquares[x, y] = SquareState.Open; if (char.IsNumber(c)) template.mDynamicHeight[x, y] = int.Parse(c.ToString()); } else { template.mDynamicHeightmap[x, y] = 0; template.mSquares[x, y] = SquareState.Closed; } } if (template.Publicroom_items != "") { string[] sItems = template.Publicroom_items.Split('\n'); template.Publicroom_items = ""; foreach (string t in sItems) { string[] sData = t.Split(' '); int sX = Convert.ToInt32(sData[2]); int sY = Convert.ToInt32(sData[3]); template.mDynamicHeightmap[sX, sY] = 0; template.mSquares[sX, sY] = SquareState.Closed; template.mDynamicHeight[sX, sY] = 1.0F; template.Publicroom_items += sData[0] + " " + sData[1] + " " + sData[2] + " " + sData[3] + " " + sData[4] + " " + sData[5] + Convert.ToChar(13); } } return template; } } }