#region
using System;
using System.Collections.Generic;
using System****;
using Ionic.Zlib;
using Newtonsoft.Json;
#endregion
namespace wServer.realm.terrain
{
public class Json2Wmap
{
public static void Convert(RealmManager manager, string from, string to)
{
byte[] x = Convert(manager, File.ReadAllText(from));
File.WriteAllBytes(to, x);
}
public static byte[] Convert(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.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(' ', '_'))
};
}
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()];
}
return WorldMapExporter.Export(tiles);
}
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);
}
// ------------ Convert to UDL format ------------- //
public static byte[] ConvertUDL(RealmManager manager, string json)
{
json_dat obj = JsonConvert.DeserializeObject<json_dat>(json);
byte[] dat = ZlibStream.UncompressBuffer(obj.data);
Random rand = new Random();
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 && 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 == manager.GameData.IdToObjectType["Grey Closed"] && rand.Next(1, 4) == 1)
{
tiles[i.X, i.Y].TileId = manager.GameData.IdToObjectType["Grey Quad"];
}
}
return WorldMapExporter.Export(tiles);
}
private struct json_dat
{
public byte[] data { get; set; }
public loc[] dict { get; set; }
public int height { get; set; }
public int width { get; set; }
}
private struct loc
{
public string ground { get; set; }
public obj[] objs { get; set; }
public obj[] regions { get; set; }
}
private struct obj
{
public string id { get; set; }
public string name { get; set; }
}
}
}
namespace terrain
namespace wServer.realm.terrain
internal enum TileRegion : byte
public enum TileRegion : byte
public int X { get; set; }
public int Y { get; set; }
public TerrainType Terrain;
public ushort TileId;
public string TileObj;
public enum TileRegion : byte
{
None,
Spawn,
Realm_Portals,
Store_1,
Store_2,
Store_3,
Store_4,
Store_5,
Store_6,
Store_7,
Store_8,
Store_9,
Vault,
Loot,
Defender,
Hallway,
Hallway_1,
Hallway_2,
Hallway_3,
Enemy,
}
protected void LoadMap(string embeddedResource, MapType type)
{
if (embeddedResource == null) return;
var stream = typeof(RealmManager).Assembly.GetManifestResourceStream(embeddedResource);
if (stream == null) throw new ArgumentException("Resource not found", nameof(embeddedResource));
switch (type)
{
case MapType.Wmap:
FromWorldMap(stream);
break;
case MapType.Json:
FromWorldMap(new MemoryStream(Json2Wmap.Convert(Manager, new StreamReader(stream).ReadToEnd())));
break;
default:
throw new ArgumentException("Invalid MapType");
}
}
protected void LoadMap(string json)
{
FromWorldMap(new MemoryStream(Json2Wmap.Convert(Manager, json)));
}
public enum MapType
{
Wmap,
Json
}
public virtual void Tick(RealmTime time)
{
if (IsLimbo) return;
if (disposable)
{
if (Players.Count <= 0 && !isDisposing)
{
isDisposing = true;
if (RemovalMS < 1000)
{
log.WarnFormat("World \"{0}\" does not have a valid RemovalMS: {1}! Please allow at least 10 seconds. Default: 10000 ms", Name, RemovalMS);
RemovalMS = 10000;
}
log.InfoFormat("World {0}, ID:{1} is unused and will dispose in {2}MS.", Name, Id, RemovalMS);
WorldTimer timer = new WorldTimer(RemovalMS, (w, t) =>
{
manager.RemoveWorld(w);
});
Timers.Add(timer);
}
else if (isDisposing && Players.Count >= 1)
{
isDisposing = false;
log.InfoFormat("World {0}, ID:{1} is in use and has cancelled disposal.", Name, Id);
}
}
if (Timers != null && Timers.Count > 0)
{
for (int i = 0; i < Timers.Count; i++)
if (Timers[i].Tick(this, time) && Timers.Count > 0)
{
Timers.RemoveAt(i);
i--;
}
}
try //entity ticking now, possible huge range of issues that i can't yet remove the try catch - jade
{
foreach (var i in Players)
i.Value.Tick(time);
if (isDisposing) return;
if (EnemiesCollision != null)
{
foreach (Entity i in EnemiesCollision.GetActiveChunks(PlayersCollision))
i.Tick(time);
foreach (var i in StaticObjects.Where(x => x.Value is Decoy))
i.Value.Tick(time);
}
else
{
foreach (var i in Enemies)
i.Value.Tick(time);
foreach (var i in StaticObjects)
i.Value.Tick(time);
}
foreach (var i in Projectiles)
i.Value.Tick(time);
}
catch (Exception e)
{
log.Error(e);
}
}
using System****;
using terrain;
namespace wServer.realm.worlds
{
public class Test : World
{
public string js = null;
public Test()
{
Id = TEST_ID;
Name = "Editor";
Background = 0;
Difficulty = 5;
SetMusic("Island");
SetRemovalMS(10 * 60 * 1000);
}
public void LoadJson(string json)
{
js = json;
LoadMap(json);
}
}
}

protected override void Init()
{
base.FromWorldMap(typeof (RealmManager).Assembly.GetManifestResourceStream("wServer.realm.worlds.EventArena.wmap"));
}
protected override void Init()
{
LoadMap("wServer.realm.worlds.YOURMAP.jm", MapType.Json);
}
public const string YOURMAP = "wServer.realm.worlds.YOURMAP.jm";
public class YOURWORLD : World
LoadMap(YOURMAP, MapType.Json);
#region using System; using System.Collections.Generic; using System****; using Ionic.Zlib; using Newtonsoft.Json; #endregion
using System,IO; //replace , with .