public static byte[] Convert(XmlData data, string json) { var obj = JsonConvert.DeserializeObject <json_dat>(json); byte[] dat = ZlibStream.UncompressBuffer(obj.data); var tileDict = new Dictionary <short, TerrainTile>(); for (int i = 0; i < obj.dict.Length; i++) { loc o = obj.dict[i]; tileDict[(short)i] = new TerrainTile { TileId = o.ground == null ? (ushort)0xff : data.IdToTileType[o.ground], TileObj = o.objs == null ? null : o.objs[0].id, Name = o.objs == null ? "" : o.objs[0].name ?? "", Terrain = TerrainType.None, Region = o.regions == null ? TileRegion.None : (TileRegion)Enum.Parse(typeof(TileRegion), o.regions[0].id.Replace(' ', '_')) }; } var tiles = new TerrainTile[obj.width, obj.height]; using (var rdr = new NReader(new MemoryStream(dat))) for (int y = 0; y < obj.height; y++) { for (int x = 0; x < obj.width; x++) { tiles[x, y] = tileDict[rdr.ReadInt16()]; } } return(WorldMapExporter.Export(tiles)); }
//public void SaveEntities(IEnumerable<Entity> entities) //{ // List<Tuple<Position, obj>> list = new List<Tuple<Position, obj>>(); // foreach (var i in entities) // { // var o = new obj() { id = Objects.type2id[(short)i.ObjectType] }; // string s = ""; // if (!string.IsNullOrEmpty(i.Name)) // s += ";name:" + i.Name; // if (i.Size != 100) // s += ";size:" + i.Size; // if (i.ConditionEffects != 0) // s += ";eff:0x" + ((int)i.ConditionEffects).ToString("X8"); // if (i is ConnectedObject) // s += ";conn:0x" + (i as ConnectedObject).Connection.ToString("X8"); // //if (en.Stats.ContainsKey(StatsType.MerchantMerchandiseType)) // // s += ";mtype:" + en.Stats[StatsType.MerchantMerchandiseType]; // //if (en.Stats.ContainsKey(StatsType.MerchantRemainingCount)) // // s += ";mcount:" + en.Stats[StatsType.MerchantRemainingCount]; // //if (en.Stats.ContainsKey(StatsType.MerchantRemainingMinute)) // // s += ";mtime:" + en.Stats[StatsType.MerchantRemainingMinute]; // //if (en.Stats.ContainsKey(StatsType.NameChangerStar)) // // s += ";nstar:" + en.Stats[StatsType.NameChangerStar]; // o.name = s.Trim(';'); // list.Add(new Tuple<Position, obj>(new Position() { X = (int)(i.X - 0.5), Y = (int)(i.Y - 0.5) }, o)); // } // descs = list.ToArray(); //} MapTileDesc loc2Tile(loc loc, List<obj> objs) { MapTileDesc ret = new MapTileDesc(); if (loc.ground != null) ret.Tile = (Tile)Grounds.id2type[loc.ground]; else ret.Tile = (Tile)0xff; if (loc.objs != null) { foreach (var z in loc.objs) { ObjectDesc desc; if (Objects.objectDescs.TryGetValue(Objects.id2type[z.id], out desc)) { if (desc.Static && !desc.Enemy) { ret.ObjType = desc.ObjectType; ret.Name = z.name; } else objs.Add(z); } else objs.Add(z); } } if (loc.regions != null) ret.Region = (TileRegion)Enum.Parse(typeof(TileRegion), loc.regions[0].id.Replace(' ', '_')); return ret; }
public string ToJson() { var obj = new json_dat(); obj.width = Width; obj.height = Height; var locs = new List <loc>(); var ms = new MemoryStream(); using (var wtr = new NWriter(ms)) for (int y = 0; y < obj.height; y++) { for (int x = 0; x < obj.width; x++) { var loc = new loc(); loc.ground = dat.TileTypeToId[(byte)Tiles[x][y]]; loc.objs = new obj[Entities[x][y].Length]; for (int i = 0; i < loc.objs.Length; i++) { ObjectDef en = Entities[x][y][i]; var o = new obj { id = dat.ObjectTypeToId[en.ObjectType] }; string s = ""; var vals = new Dictionary <StatsType, object>(); foreach (var z in en.Stats.Stats) { vals.Add(z.Key, z.Value); } if (vals.ContainsKey(StatsType.Name)) { s += ";name:" + vals[StatsType.Name]; } if (vals.ContainsKey(StatsType.Size)) { s += ";size:" + vals[StatsType.Size]; } if (vals.ContainsKey(StatsType.ObjectConnection)) { s += ";conn:0x" + ((int)vals[StatsType.ObjectConnection]).ToString("X8"); } if (vals.ContainsKey(StatsType.MerchantMerchandiseType)) { s += ";mtype:" + vals[StatsType.MerchantMerchandiseType]; } if (vals.ContainsKey(StatsType.MerchantRemainingCount)) { s += ";mcount:" + vals[StatsType.MerchantRemainingCount]; } if (vals.ContainsKey(StatsType.MerchantRemainingMinute)) { s += ";mtime:" + vals[StatsType.MerchantRemainingMinute]; } if (vals.ContainsKey(StatsType.NameChangerStar)) { s += ";nstar:" + vals[StatsType.NameChangerStar]; } o.name = s.Trim(';'); loc.objs[i] = o; } int ix = -1; for (int i = 0; i < locs.Count; i++) { if (locs[i].ground != loc.ground) { continue; } if (!((locs[i].objs != null && loc.objs != null) || (locs[i].objs == null && loc.objs == null))) { continue; } if (locs[i].objs != null) { if (locs[i].objs.Length != loc.objs.Length) { continue; } bool b = false; for (int j = 0; j < loc.objs.Length; j++) { if (locs[i].objs[j].id != loc.objs[j].id || locs[i].objs[j].name != loc.objs[j].name) { b = true; break; } } if (b) { continue; } } ix = i; break; } if (ix == -1) { ix = locs.Count; locs.Add(loc); } wtr.Write((short)ix); } } obj.data = ZlibStream.CompressBuffer(ms.ToArray()); obj.dict = locs.ToArray(); return(JsonConvert.SerializeObject(obj)); }
public static byte[] ConvertMakeWalls(RealmManager manager, string json) { json_dat obj = JsonConvert.DeserializeObject <json_dat>(json); byte[] dat = ZlibStream.UncompressBuffer(obj.data); Dictionary <ushort, TerrainTile> tileDict = new Dictionary <ushort, TerrainTile>(); for (int i = 0; i < obj.dict.Length; i++) { loc o = obj.dict[i]; tileDict[(ushort)i] = new TerrainTile { TileId = o.ground == null ? (ushort)0xff : manager.GameData.IdToObjectType[o.ground], TileObj = o.objs == null ? null : o.objs[0].id, Name = o.objs == null ? "" : o.objs[0].name ?? "", Terrain = TerrainType.None, Region = o.regions == null ? TileRegion.None : (TileRegion)Enum.Parse(typeof(TileRegion), o.regions[0].id.Replace(' ', '_')) }; } TerrainTile[,] tiles = new TerrainTile[obj.width, obj.height]; using (NReader rdr = new NReader(new MemoryStream(dat))) for (int y = 0; y < obj.height; y++) { for (int x = 0; x < obj.width; x++) { tiles[x, y] = tileDict[(ushort)rdr.ReadInt16()]; tiles[x, y].X = x; tiles[x, y].Y = y; } } foreach (TerrainTile i in tiles) { if (i.TileId == 0xff && i.TileObj == null) { bool createWall = false; for (int ty = -1; ty <= 1; ty++) { for (int tx = -1; tx <= 1; tx++) { try { if (tiles[i.X + tx, i.Y + ty].TileId != 0xff) { createWall = true; } } catch { } } } if (createWall) { tiles[i.X, i.Y].TileObj = "Grey Wall"; } } } return(WorldMapExporter.Export(tiles)); }
port = parseInt(loc.port)+1
public static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; int CASES = int.Parse(Console.ReadLine()); for (int CASE = 1; CASE <= CASES; CASE++) { Console.Error.WriteLine("Case " + CASE); string[] ps = Console.ReadLine().Split(); int R = int.Parse(ps[0]); int C = int.Parse(ps[1]); int N = 2 * (R + C); int[] perm = new int[N]; ps = Console.ReadLine().Split(); for (int i = 0; i < N; i++) { perm[i] = int.Parse(ps[i]); } int[] loves = new int[N]; for (int i = 0; i < perm.Length; i += 2) { loves[perm[i] - 1] = perm[i + 1] - 1; loves[perm[i + 1] - 1] = perm[i] - 1; } bool possible = true; char[][] grid = new char[R][]; for (int i = 0; i < R; i++) { grid[i] = new char[C]; } bool[] conn = new bool[N]; while (true) { int p1 = -1; int p2 = -1; bool have = false; for (int i = 0; i < N; i++) { if (conn[i]) { continue; } have = true; for (int j = i + 1; j < N; j++) { if (loves[i] == j) { p1 = i; p2 = j; } else if (!conn[j]) { break; } } } if (p1 == -1) { if (have) { possible = false; } break; } // connect p1 and p2 loc loc = getLoc(R, C, p1); int px = loc.x; int py = loc.y; int d = loc.d; // top, right, down, left while (!(px < 0 || py < 0 || px >= C || py >= R)) { if (grid[py][px] == 0) { if (d == 0 || d == 2) { grid[py][px] = '\\'; } if (d == 1 || d == 3) { grid[py][px] = '/'; } } // oh, the horror, there must be a bug here somewhere... if (d == 0 && grid[py][px] == '/') { px--; d = 1; } else if (d == 0 && grid[py][px] == '\\') { px++; d = 3; } else if (d == 1 && grid[py][px] == '/') { py++; d = 0; } else if (d == 1 && grid[py][px] == '\\') { py--; d = 2; } else if (d == 2 && grid[py][px] == '/') { px++; d = 3; } else if (d == 2 && grid[py][px] == '\\') { px--; d = 1; } else if (d == 3 && grid[py][px] == '/') { py--; d = 2; } else if (d == 3 && grid[py][px] == '\\') { py++; d = 0; } else { throw new Exception("Oh man..."); } } // todo: check if pos is ok loc loc2 = getLoc(R, C, p2); int[] dy = { -1, 0, 1, 0 }; int[] dx = { 0, 1, 0, -1 }; if (loc2.x + dx[loc2.d] != px || loc2.y + dy[loc2.d] != py) { possible = false; break; } conn[p1] = conn[p2] = true; } // fill in random chars for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { if (grid[i][j] == 0) { grid[i][j] = '/'; // randomly chosen by me } } } // print Console.WriteLine("Case #" + CASE + ":"); if (possible) { for (int i = 0; i < R; i++) { Console.WriteLine(new string(grid[i])); } } else { Console.WriteLine("IMPOSSIBLE"); } } }
select(loc, kv.Key));
public string ToJson() { var obj = new json_dat(); obj.width = Width; obj.height = Height; List <loc> locs = new List <loc>(); MemoryStream ms = new MemoryStream(); using (PacketWriter wtr = new PacketWriter(ms)) for (int y = 0; y < obj.height; y++) { for (int x = 0; x < obj.width; x++) { var loc = new loc(); loc.ground = Tiles[x][y] != -1 ? GetTileId((ushort)Tiles[x][y]) : null; loc.objs = new obj[Entities[x][y].Length]; for (int i = 0; i < loc.objs.Length; i++) { var en = Entities[x][y][i]; obj o = new obj() { id = GetEntityId(en.ObjectType) }; string s = ""; Dictionary <StatsType, object> vals = new Dictionary <StatsType, object>(); foreach (var z in en.Status.Data) { vals.Add(z.Id, z.IsStringData() ? (object)z.StringValue : (object)z.IntValue); } if (vals.ContainsKey(StatsType.Name)) { s += ";name:" + vals[StatsType.Name]; } if (vals.ContainsKey(StatsType.Size)) { s += ";size:" + vals[StatsType.Size]; } if (vals.ContainsKey(StatsType.ObjectConnection)) { s += ";conn:0x" + ((int)vals[StatsType.ObjectConnection]).ToString("X8"); } if (vals.ContainsKey(StatsType.MerchandiseType)) { s += ";mtype:" + vals[StatsType.MerchandiseType]; } if (vals.ContainsKey(StatsType.MerchandiseRemainingCount)) { s += ";mcount:" + vals[StatsType.MerchandiseRemainingCount]; } if (vals.ContainsKey(StatsType.MerchandiseRemainingMinutes)) { s += ";mtime:" + vals[StatsType.MerchandiseRemainingMinutes]; } if (vals.ContainsKey(StatsType.RankRequired)) { s += ";nstar:" + vals[StatsType.RankRequired]; } o.name = s.Trim(';'); loc.objs[i] = o; } int ix = -1; for (int i = 0; i < locs.Count; i++) { if (locs[i].ground != loc.ground) { continue; } if (!((locs[i].objs != null && loc.objs != null) || (locs[i].objs == null && loc.objs == null))) { continue; } if (locs[i].objs != null) { if (locs[i].objs.Length != loc.objs.Length) { continue; } bool b = false; for (int j = 0; j < loc.objs.Length; j++) { if (locs[i].objs[j].id != loc.objs[j].id || locs[i].objs[j].name != loc.objs[j].name) { b = true; break; } } if (b) { continue; } } ix = i; break; } if (ix == -1) { ix = locs.Count; locs.Add(loc); } wtr.Write((short)ix); } } obj.data = ZlibStream.CompressBuffer(ms.ToArray()); obj.dict = locs.ToArray(); var settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; return(JsonConvert.SerializeObject(obj, settings)); }
public string ToJson() { var obj = new json_dat(); obj.width = Width; obj.height = Height; var locs = new List<loc>(); var ms = new MemoryStream(); using (var wtr = new NWriter(ms)) for (int y = 0; y < obj.height; y++) for (int x = 0; x < obj.width; x++) { var loc = new loc(); loc.ground = dat.TileTypeToId[(byte) Tiles[x][y]]; loc.objs = new obj[Entities[x][y].Length]; for (int i = 0; i < loc.objs.Length; i++) { ObjectDef en = Entities[x][y][i]; var o = new obj { id = dat.ObjectTypeToId[en.ObjectType] }; string s = ""; var vals = new Dictionary<StatsType, object>(); foreach (var z in en.Stats.Stats) vals.Add(z.Key, z.Value); if (vals.ContainsKey(StatsType.Name)) s += ";name:" + vals[StatsType.Name]; if (vals.ContainsKey(StatsType.Size)) s += ";size:" + vals[StatsType.Size]; if (vals.ContainsKey(StatsType.ObjectConnection)) s += ";conn:0x" + ((int) vals[StatsType.ObjectConnection]).ToString("X8"); if (vals.ContainsKey(StatsType.MerchantMerchandiseType)) s += ";mtype:" + vals[StatsType.MerchantMerchandiseType]; if (vals.ContainsKey(StatsType.MerchantRemainingCount)) s += ";mcount:" + vals[StatsType.MerchantRemainingCount]; if (vals.ContainsKey(StatsType.MerchantRemainingMinute)) s += ";mtime:" + vals[StatsType.MerchantRemainingMinute]; if (vals.ContainsKey(StatsType.NameChangerStar)) s += ";nstar:" + vals[StatsType.NameChangerStar]; o.name = s.Trim(';'); loc.objs[i] = o; } int ix = -1; for (int i = 0; i < locs.Count; i++) { if (locs[i].ground != loc.ground) continue; if (!((locs[i].objs != null && loc.objs != null) || (locs[i].objs == null && loc.objs == null))) continue; if (locs[i].objs != null) { if (locs[i].objs.Length != loc.objs.Length) continue; bool b = false; for (int j = 0; j < loc.objs.Length; j++) if (locs[i].objs[j].id != loc.objs[j].id || locs[i].objs[j].name != loc.objs[j].name) { b = true; break; } if (b) continue; } ix = i; break; } if (ix == -1) { ix = locs.Count; locs.Add(loc); } wtr.Write((short) ix); } obj.data = ZlibStream.CompressBuffer(ms.ToArray()); obj.dict = locs.ToArray(); return JsonConvert.SerializeObject(obj); }
public string ToJson() { var obj = new json_dat(); obj.width = Width; obj.height = Height; List<loc> locs = new List<loc>(); MemoryStream ms = new MemoryStream(); using (PacketWriter wtr = new PacketWriter(ms)) for (int y = 0; y < obj.height; y++) for (int x = 0; x < obj.width; x++) { var loc = new loc(); loc.ground = Tiles[x][y] != -1 ? GetTileId((ushort)Tiles[x][y]) : null; loc.objs = new obj[Entities[x][y].Length]; for (int i = 0; i < loc.objs.Length; i++) { var en = Entities[x][y][i]; obj o = new obj() { id = GetEntityId(en.ObjectType) }; string s = ""; Dictionary<StatsType, object> vals = new Dictionary<StatsType, object>(); foreach (var z in en.Status.Data) vals.Add(z.Id, z.IsStringData() ? (object)z.StringValue : (object)z.IntValue); if (vals.ContainsKey(StatsType.Name)) s += ";name:" + vals[StatsType.Name]; if (vals.ContainsKey(StatsType.Size)) s += ";size:" + vals[StatsType.Size]; if (vals.ContainsKey(StatsType.ObjectConnection)) s += ";conn:0x" + ((int)vals[StatsType.ObjectConnection]).ToString("X8"); if (vals.ContainsKey(StatsType.MerchandiseType)) s += ";mtype:" + vals[StatsType.MerchandiseType]; if (vals.ContainsKey(StatsType.MerchandiseRemainingCount)) s += ";mcount:" + vals[StatsType.MerchandiseRemainingCount]; if (vals.ContainsKey(StatsType.MerchandiseRemainingMinutes)) s += ";mtime:" + vals[StatsType.MerchandiseRemainingMinutes]; if (vals.ContainsKey(StatsType.RankRequired)) s += ";nstar:" + vals[StatsType.RankRequired]; o.name = s.Trim(';'); loc.objs[i] = o; } int ix = -1; for (int i = 0; i < locs.Count; i++) { if (locs[i].ground != loc.ground) continue; if (!((locs[i].objs != null && loc.objs != null) || (locs[i].objs == null && loc.objs == null))) continue; if (locs[i].objs != null) { if (locs[i].objs.Length != loc.objs.Length) continue; bool b = false; for (int j = 0; j < loc.objs.Length; j++) if (locs[i].objs[j].id != loc.objs[j].id || locs[i].objs[j].name != loc.objs[j].name) { b = true; break; } if (b) continue; } ix = i; break; } if (ix == -1) { ix = locs.Count; locs.Add(loc); } wtr.Write((short)ix); } obj.data = ZlibStream.CompressBuffer(ms.ToArray()); obj.dict = locs.ToArray(); var settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; return JsonConvert.SerializeObject(obj, settings); }
// ------------ Convert to UDL format ------------- // public static byte[] ConvertUDL(string json) { var obj = JsonConvert.DeserializeObject <json_dat>(json); byte[] dat = ZlibStream.UncompressBuffer(obj.data); var rand = new Random(); var tileDict = new Dictionary <short, TerrainTile>(); for (int i = 0; i < obj.dict.Length; i++) { loc o = obj.dict[i]; tileDict[(short)i] = new TerrainTile { TileId = o.ground == null ? (short)0xff : XmlDatas.IdToType[o.ground], TileObj = o.objs == null ? null : o.objs[0].id, Name = o.objs == null ? "" : o.objs[0].name ?? "", Terrain = TerrainType.None, Region = o.regions == null ? TileRegion.None : (TileRegion)Enum.Parse(typeof(TileRegion), o.regions[0].id.Replace(' ', '_')) }; } var tiles = new TerrainTile[obj.width, obj.height]; using (var rdr = new NReader(new MemoryStream(dat))) for (int y = 0; y < obj.height; y++) { for (int x = 0; x < obj.width; x++) { tiles[x, y] = tileDict[rdr.ReadInt16()]; tiles[x, y].X = x; tiles[x, y].Y = y; } } foreach (TerrainTile i in tiles) { if (i.TileId == 0xff && i.TileObj == null) { bool createWall = false; for (int ty = -1; ty <= 1; ty++) { for (int tx = -1; tx <= 1; tx++) { try { if (tiles[i.X + tx, i.Y + ty].TileId != 0xff && tiles[i.X + tx, i.Y + ty].TileId != 0xfe && tiles[i.X + tx, i.Y + ty].TileId != 0xfd && tiles[i.X + tx, i.Y + ty].TileId != 0xe8) { createWall = true; } } catch { } } } if (createWall) { tiles[i.X, i.Y].TileObj = rand.Next(1, 5) == 1 ? "Grey Torch Wall" : "Grey Wall"; } } else if (i.TileId == XmlDatas.IdToType["Grey Closed"] && rand.Next(1, 4) == 1) { tiles[i.X, i.Y].TileId = XmlDatas.IdToType["Grey Quad"]; } } return(WorldMapExporter.Export(tiles)); }
public player(int n, loc l) { this.playernumber = n; this.playerloc = l; }
public tile(int c, int r) { this.tilestate = ' '; this.tileloc = new loc(c, r); }
{ "N9030A", (loc, idn) => new Analyzer(loc, idn) },