public IMapData Serdes(IMapData existing, AssetInfo config, AssetMapping mapping, ISerializer s) { if (config == null) { throw new ArgumentNullException(nameof(config)); } return(BaseMapData.Serdes(config, existing, mapping, s)); }
public IMapData Serdes(IMapData existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } return(BaseMapData.Serdes(info, existing, mapping, s)); }
public static IEnumerable <ObjectGroup> BuildTriggers( BaseMapData map, int tileWidth, int tileHeight, Dictionary <ushort, string> functionsByEventId, ref int nextObjectGroupId, ref int nextObjectId) { var objectGroups = new List <ObjectGroup>(); var regions = TriggerZoneBuilder.BuildZones(map); if (map.GlobalZones.Count > 0) { var globalRegions = new List <(ZoneKey, Geometry.Polygon)>(); for (var index = 0; index < map.GlobalZones.Count; index++) { var global = map.GlobalZones[index]; var(x, y) = DiagonalLayout.GetPositionForIndex(index); var polygon = new Geometry.Polygon { OffsetX = -x - 1, OffsetY = -y - 1, Points = new List <(int, int)> { (0, 0), (1, 0), (1, 1), (0, 1) } }; globalRegions.Add((new ZoneKey(global), polygon)); } objectGroups.Add(BuildTriggerObjectGroup( nextObjectGroupId++, "T:Global", globalRegions, tileWidth, tileHeight, functionsByEventId, ref nextObjectId)); } var groupedByTriggerType = regions .Where(x => !x.Item1.Global) .GroupBy(x => x.Item1.Trigger) .OrderBy(x => x.Key); foreach (var polygonsForTriggerType in groupedByTriggerType) { objectGroups.Add(BuildTriggerObjectGroup( nextObjectGroupId++, $"T:{polygonsForTriggerType.Key}", polygonsForTriggerType, tileWidth, tileHeight, functionsByEventId, ref nextObjectId)); if (polygonsForTriggerType.Key == TriggerTypes.Examine) { objectGroups[^ 1].Hidden = true;
public void Init(BaseMapData mapData) { _mapData = (KrbMapData)mapData; _mapHelper = new RectGridMap(_mapData.DistanceStrategy); // Instantiate selectively from data _palette = new Dictionary <KrbTileType, KrbTile>(); foreach (var entry in _mapData.Palette) { var castTile = (KrbTile)entry; _palette.Add(castTile.TileType, castTile); } }
public static IList <(ZoneKey, Geometry.Polygon)> BuildZonesSimple(BaseMapData map) { if (map == null) { throw new ArgumentNullException(nameof(map)); } var zones = new List <(ZoneKey, Geometry.Polygon)>(); foreach (var zone in map.Zones) { zones.Add((new ZoneKey(zone), new Geometry.Polygon { Points = new[]
public static IList <(ZoneKey, Geometry.Polygon)> BuildZones(BaseMapData map) { if (map == null) { throw new ArgumentNullException(nameof(map)); } // Render zones to a grid var zoneMap = new MapEventZone[map.Width * map.Height]; Array.Copy(map.Zones, zoneMap, zoneMap.Length); var regions = new List <(ZoneKey key, IList <(int, int)> region)>(); for (int index = 0; index < zoneMap.Length; index++) { var current = zoneMap[index]; if (current == null) { continue; } FillZone(regions, zoneMap, map.Width, current, index); } RemoveVoids(regions); var edgeSets = regions.Select(x => (x.key, FindRegionEdges(x.region))).ToList(); // zoneMap should be empty now ApiUtil.Assert(zoneMap.All(x => x == null)); // Stitch edges together for (int i = 0; i < edgeSets.Count; i++) { edgeSets[i] = (edgeSets[i].Item1, MergeEdges(edgeSets[i].Item2)); } // Follow edges clockwise to build poly return(edgeSets .SelectMany(x => BuildPolygonsFromSortedEdges(x.Item2) .Select(y => (x.Item1, y))) .ToList()); }
public static void ReadMapProperties(BaseMapData albionMap, Map tiledMap) { albionMap.CombatBackgroundId = PropId(tiledMap, Prop.CombatBackground); albionMap.SongId = PropId(tiledMap, Prop.Song); if (albionMap is MapData2D map2d) { map2d.Flags = Enum.Parse <MapFlags>(PropString(tiledMap, Prop.Flags, true)); map2d.FrameRate = (byte)(PropInt(tiledMap, Prop.FrameRate) ?? 0); map2d.Sound = (byte)(PropInt(tiledMap, Prop.Sound) ?? 0); } if (albionMap is MapData3D map3d) { map3d.AmbientSongId = PropId(tiledMap, Prop.Ambient); map3d.Flags = Enum.Parse <MapFlags>(PropString(tiledMap, Prop.Flags, true)); } }
protected LogicalMap(BaseMapData mapData, MapChangeCollection tempChanges, MapChangeCollection permChanges) { _mapData = mapData ?? throw new ArgumentNullException(nameof(mapData)); TempChanges = tempChanges ?? throw new ArgumentNullException(nameof(tempChanges)); PermChanges = permChanges ?? throw new ArgumentNullException(nameof(permChanges)); // Clear out temp changes for other maps for (int i = 0; i < tempChanges.Count;) { if (TempChanges[i].MapId != mapData.Id) { TempChanges.RemoveAt(i); } else { i++; } } }
public static List <ObjectGroup> BuildObjectGroups( BaseMapData map, int tileWidth, int tileHeight, NpcMapping.GetTileFunc getTileFunc, Dictionary <ushort, string> functionsByEventId, ref int nextObjectGroupId, ref int nextObjectId) { var results = new[] { TriggerMapping.BuildTriggers(map, tileWidth, tileHeight, functionsByEventId, ref nextObjectGroupId, ref nextObjectId), NpcMapping.BuildNpcs(map, tileWidth, tileHeight, getTileFunc, functionsByEventId, ref nextObjectGroupId, ref nextObjectId), }.SelectMany(x => x); if (map is MapData3D map3d) { results = results.Concat(AutomapMapping.BuildMarkers(map3d, tileWidth, tileHeight, ref nextObjectGroupId, ref nextObjectId)); } return(results.ToList()); }
public static List <TiledProperty> BuildMapProperties(BaseMapData map) { var props = new List <TiledProperty>(); props.Add(new(Prop.Palette, map.PaletteId.ToString())); if (map.SongId != SongId.None) { props.Add(new(Prop.Song, map.SongId.ToString())); } if (map.CombatBackgroundId != SpriteId.None) { props.Add(new(Prop.CombatBackground, map.CombatBackgroundId.ToString())); } if (map is MapData2D map2d) { props.Add(new(Prop.Flags, map2d.Flags.ToString())); props.Add(new(Prop.Tileset, map2d.TilesetId.ToString())); if (map2d.FrameRate > 0) { props.Add(new(Prop.FrameRate, map2d.FrameRate)); } if (map2d.Sound > 0) { props.Add(new(Prop.Sound, map2d.Sound)); } } if (map is MapData3D map3d) { props.Add(new(Prop.Ambient, map3d.AmbientSongId.ToString())); props.Add(new(Prop.Flags, map3d.Flags.ToString())); props.Add(new(Prop.Labyrinth, map3d.LabDataId.ToString())); } return(props); }
public static IEnumerable <ObjectGroup> BuildNpcs( BaseMapData map, int tileWidth, int tileHeight, GetTileFunc getTileFunc, Dictionary <ushort, string> functionsByEventId, ref int nextObjectGroupId, ref int nextObjectId) { int nextId = nextObjectId; int npcGroupId = nextObjectGroupId++; var waypointGroups = new List <ObjectGroup>(); var npcPathIndices = new Dictionary <int, int>(); for (var index = 0; index < map.Npcs.Count; index++) { var npc = map.Npcs[index]; if (!npc.HasWaypoints(map.Flags)) { continue; } if (npc.SpriteOrGroup == AssetId.None) // Unused 2D slots { continue; } if (npc.SpriteOrGroup == new AssetId(AssetType.ObjectGroup, 1) && npc.Id.IsNone) // unused 3D slots { continue; } int firstWaypointObjectId = nextId; npcPathIndices[index] = firstWaypointObjectId; waypointGroups.Add(new ObjectGroup { Id = nextObjectGroupId++, Name = $"NPC{index} Path", Objects = NpcPathBuilder.Build(index, npc.Waypoints, tileWidth, tileHeight, ref nextId), Hidden = true, }); } var group = new ObjectGroup { Id = npcGroupId, Name = "NPCs", Objects = map.Npcs.Select((x, i) => BuildNpcObject( tileWidth, tileHeight, functionsByEventId, getTileFunc, npcPathIndices, i, x, ref nextId)) .ToList(), }; nextObjectId = nextId; return(new[] { group }.Concat(waypointGroups)); }