/// <summary> /// Converts GDLE spawn map -> ACE landblock instances /// /// This will not alter the Guid. To sanitize the Guid for ACE usage, you should use GDLELoader.TryLoadWorldSpawnsConverted() instead. /// </summary> public static bool TryConvert(Models.Landblock input, out List <LandblockInstance> results, out List <LandblockInstanceLink> links) { try { results = new List <LandblockInstance>(); links = new List <LandblockInstanceLink>(); foreach (var value in input.value.weenies) { var result = new LandblockInstance(); result.Guid = value.id; // Collisions and other errors can be caused by invalid input. Data should be sanitized by the running ACE server. //result.Landblock = input.key; ACE uses a virtual column here of (result.ObjCellId >> 16) result.WeenieClassId = value.wcid; result.ObjCellId = value.pos.objcell_id; result.OriginX = value.pos.frame.origin.x; result.OriginY = value.pos.frame.origin.y; result.OriginZ = value.pos.frame.origin.z; result.AnglesW = value.pos.frame.angles.w; result.AnglesX = value.pos.frame.angles.x; result.AnglesY = value.pos.frame.angles.y; result.AnglesZ = value.pos.frame.angles.z; results.Add(result); } if (input.value.links != null) { foreach (var value in input.value.links) { var result = new LandblockInstanceLink(); result.ParentGuid = value.target; result.ChildGuid = value.source; links.Add(result); } } // reguid if needed var landblockId = (ushort)(input.key >> 16); ReGuidAndConvertLandblocks(results, links, landblockId); return(true); } catch { results = null; links = null; return(false); } }
public static bool TryLoadLandblock(string[] lines, out Models.Landblock result) { try { result = JsonConvert.DeserializeObject <Models.Landblock>(string.Join("\n", lines)); return(true); } catch { result = null; return(false); } }
/// <summary> /// This will not alter the Guid. To sanitize the Guid for ACE usage, you should use GDLELoader.TryLoadWorldSpawnsConverted() instead. /// </summary> public static bool TryConvert(Models.Landblock input, out List <Database.Models.World.LandblockInstance> results, out List <Database.Models.World.LandblockInstanceLink> links) { try { results = new List <LandblockInstance>(); links = new List <LandblockInstanceLink>(); foreach (var value in input.Value.Weenies) { var result = new LandblockInstance(); result.Guid = value.Id; // Collisions and other errors can be caused by invalid input. Data should be sanitized by the running ACE server. //result.Landblock = input.key; ACE uses a virtual column here of (result.ObjCellId >> 16) result.WeenieClassId = value.WCID; result.ObjCellId = value.Position.ObjCellId; result.OriginX = (float)value.Position.Frame.Origin.X; result.OriginY = (float)value.Position.Frame.Origin.Y; result.OriginZ = (float)value.Position.Frame.Origin.Z; result.AnglesW = (float)value.Position.Frame.Angles.W; result.AnglesX = (float)value.Position.Frame.Angles.X; result.AnglesY = (float)value.Position.Frame.Angles.Y; result.AnglesZ = (float)value.Position.Frame.Angles.Z; results.Add(result); } if (input.Value.Links != null) { foreach (var value in input.Value.Links) { var result = new LandblockInstanceLink(); result.ParentGuid = value.Target; result.ChildGuid = value.Source; links.Add(result); } } return(true); } catch { results = null; links = null; return(false); } }
public static bool TryLoadLandblock(string file, out Models.Landblock result) { try { var fileText = File.ReadAllText(file); result = JsonConvert.DeserializeObject <Models.Landblock>(fileText); return(true); } catch { result = null; return(false); } }
/// <summary> /// Converts ACE landblock instances -> GDLE landblock instances /// </summary> public static bool TryConvert(List <LandblockInstance> input, out Models.Landblock result) { var instanceWcids = new Dictionary <uint, uint>(); foreach (var instance in input) { instanceWcids.Add(instance.Guid, instance.WeenieClassId); } result = new Models.Landblock(); if (input.Count == 0) { return(true); } result.key = (uint)input[0].Landblock << 16; result.value = new Models.LandblockValue(); result.desc = $"{result.key}({input[0].Landblock:X4})"; foreach (var lbi in input) { if (result.value.weenies == null) { result.value.weenies = new List <Models.LandblockWeenie>(); } var weenie = new Models.LandblockWeenie(); weenie.id = lbi.Guid; weenie.wcid = lbi.WeenieClassId; if (WeenieNames != null && WeenieClassNames != null) { WeenieNames.TryGetValue(lbi.WeenieClassId, out var weenieName); WeenieClassNames.TryGetValue(lbi.WeenieClassId, out var weenieClassName); weenie.desc = $"{weenieName}({weenieClassName})"; } // fix this ***, write it properly. var pos = new Models.Position(); pos.objcell_id = lbi.ObjCellId; var frame = new Models.Frame(); frame.origin = new Models.Origin(); frame.origin.x = lbi.OriginX; frame.origin.y = lbi.OriginY; frame.origin.z = lbi.OriginZ; frame.angles = new Models.Angles(); frame.angles.w = lbi.AnglesW; frame.angles.x = lbi.AnglesX; frame.angles.y = lbi.AnglesY; frame.angles.z = lbi.AnglesZ; pos.frame = frame; weenie.pos = pos; result.value.weenies.Add(weenie); if (lbi.LandblockInstanceLink != null) { foreach (var link in lbi.LandblockInstanceLink) { if (result.value.links == null) { result.value.links = new List <Models.LandblockLink>(); } var _link = new Models.LandblockLink(); _link.target = link.ParentGuid; _link.source = link.ChildGuid; if (WeenieNames != null && WeenieClassNames != null) { WeenieNames.TryGetValue(lbi.WeenieClassId, out var targetName); WeenieClassNames.TryGetValue(lbi.WeenieClassId, out var targetClassName); if (instanceWcids.TryGetValue(link.ChildGuid, out var sourceWcid)) { WeenieNames.TryGetValue(sourceWcid, out var sourceName); WeenieClassNames.TryGetValue(sourceWcid, out var sourceClassName); _link.desc = $"{sourceName}({sourceClassName})(wcid: {sourceWcid}) -> {targetClassName}(wcid: {lbi.WeenieClassId})"; } } result.value.links.Add(_link); } } } return(true); }