public static void LoadObjectGroups(AssetInfo info, Map map, int tileWidth, int tileHeight, EventLayout eventLayout, List <TriggerInfo> triggers, List <MapNpc> npcs, List <MapEventZone> zones, List <AutomapInfo> markers, List <byte> markerTiles) { ushort ResolveEntryPoint(string name) { var(isChain, id) = ScriptConstants.ParseEntryPoint(name); return(isChain ? eventLayout.Chains[id] : id); } var mapObjects = map.ObjectGroups.SelectMany(x => x.Objects); var pathParser = NpcPathBuilder.BuildParser(mapObjects, tileWidth, tileHeight); foreach (var objectGroup in map.ObjectGroups) { foreach (var obj in objectGroup.Objects) { if (TypeName.Trigger.Equals(obj.Type, StringComparison.OrdinalIgnoreCase)) { triggers.Add(TriggerMapping.ParseTrigger(obj, tileWidth, tileHeight, ResolveEntryPoint)); } if (TypeName.Npc.Equals(obj.Type, StringComparison.OrdinalIgnoreCase)) { npcs.Add(NpcMapping.ParseNpc(obj, tileWidth, tileHeight, ResolveEntryPoint, pathParser)); } if (TypeName.Marker.Equals(obj.Type, StringComparison.OrdinalIgnoreCase)) { var(marker, tile) = AutomapMapping.ParseMarker(obj, tileWidth, tileHeight); markers.Add(marker); markerTiles.Add(tile); } } } TriggerMapping.LoadZones(zones, info.AssetId, triggers, map); }
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)); }