protected override void Subscribed() { if (_labyrinthData != null) { return; } var assets = Resolve <IAssetManager>(); _labyrinthData = assets.LoadLabyrinthData(_mapData.LabDataId); if (_labyrinthData == null) { TileSize = Vector3.One * 512; return; } TileSize = new Vector3(_labyrinthData.EffectiveWallWidth, _labyrinthData.WallHeight, _labyrinthData.EffectiveWallWidth); _selection = AttachChild(new Selection3D()); AttachChild(new MapRenderable3D(MapId, _mapData, _labyrinthData, TileSize)); AttachChild(new ScriptManager()); if (!_labyrinthData.BackgroundId.IsNone) { AttachChild(new Skybox(_labyrinthData.BackgroundId)); } var palette = assets.LoadPalette(_mapData.PaletteId); uint backgroundColour = palette.GetPaletteAtTime(0)[_labyrinthData.BackgroundColour]; _backgroundRed = (backgroundColour & 0xff) / 255.0f; _backgroundGreen = (backgroundColour & 0xff00 >> 8) / 255.0f; _backgroundBlue = (backgroundColour & 0xff0000 >> 16) / 255.0f; //if(_labyrinthData.CameraHeight != 0) // Debugger.Break(); //if(_labyrinthData.Unk12 != 0) // 7=1|2|4 (Jirinaar), 54=32|16|4|2, 156=128|16|8|2 (Tall town) // Debugger.Break(); var maxObjectHeightRaw = _labyrinthData.ObjectGroups.Max(x => x.SubObjects.Max(y => (int?)y.Y)); float objectYScaling = TileSize.Y / _labyrinthData.WallHeight; if (maxObjectHeightRaw > _labyrinthData.WallHeight * 1.5f) { objectYScaling /= 2; // TODO: Figure out the proper way to handle this. } Raise(new LogEvent(LogEvent.Level.Info, $"WallHeight: {_labyrinthData.WallHeight} MaxObj: {maxObjectHeightRaw} EffWallWidth: {_labyrinthData.EffectiveWallWidth}")); foreach (var npc in _mapData.Npcs.Values) { if (npc.SpriteOrGroup.Id >= _labyrinthData.ObjectGroups.Count) { CoreUtil.LogWarn($"[3DMap] Tried to load object group {npc.SpriteOrGroup.Id}, but the max group id is {_labyrinthData.ObjectGroups.Count-1}."); continue; } var objectData = _labyrinthData.ObjectGroups[npc.SpriteOrGroup.Id]; // TODO: Verify SpriteOrGroup is an ObjectGroup // TODO: Build proper NPC objects with AI, sound effects etc foreach (var subObject in objectData.SubObjects) { AttachChild(BuildMapObject(npc.Waypoints[0].X, npc.Waypoints[0].Y, subObject, objectYScaling)); } } for (int y = 0; y < _mapData.Height; y++) { for (int x = 0; x < _mapData.Width; x++) { var contents = _mapData.Contents[y * _mapData.Width + x]; if (contents == 0 || contents >= _labyrinthData.ObjectGroups.Count) { continue; } var objectInfo = _labyrinthData.ObjectGroups[contents - 1]; foreach (var subObject in objectInfo.SubObjects) { AttachChild(BuildMapObject(x, y, subObject, objectYScaling)); } } } Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue)); }
protected override void Subscribed() { if (_labyrinthData != null) { Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue, 1.0f)); return; } var assets = Resolve <IAssetManager>(); var state = Resolve <IGameState>(); var factory = Resolve <ICoreFactory>(); _labyrinthData = assets.LoadLabyrinthData(_mapData.LabDataId); if (_labyrinthData == null) { return; } _logicalMap = new LogicalMap3D(_mapData, _labyrinthData, state.TemporaryMapChanges, state.PermanentMapChanges); var properties = new TilemapRequest { Id = MapId, Width = (uint)_logicalMap.Width, Scale = _labyrinthData.TileSize, Origin = _labyrinthData.TileSize.Y / 2 * Vector3.UnitY, HorizontalSpacing = _labyrinthData.TileSize * Vector3.UnitX, VerticalSpacing = _labyrinthData.TileSize * Vector3.UnitZ, AmbientLightLevel = _labyrinthData.Lighting, FogColor = _labyrinthData.FogColor, ObjectYScaling = _labyrinthData.ObjectYScaling, Pipeline = DungeonTilemapPipeline.Normal }; _selection = AttachChild(new Selection3D()); AttachChild(new MapRenderable3D(_logicalMap, _labyrinthData, properties)); AttachChild(new ScriptManager()); AttachChild(new Collider3D(_logicalMap)); if (!_labyrinthData.BackgroundId.IsNone) { var background = assets.LoadTexture(_labyrinthData.BackgroundId); _skybox = factory.CreateSkybox(background); } var palette = assets.LoadPalette(_logicalMap.PaletteId); uint backgroundColour = palette.GetPaletteAtTime(0)[_labyrinthData.BackgroundColour]; _backgroundRed = (backgroundColour & 0xff) / 255.0f; _backgroundGreen = (backgroundColour & 0xff00 >> 8) / 255.0f; _backgroundBlue = (backgroundColour & 0xff0000 >> 16) / 255.0f; //if(_labyrinthData.CameraHeight != 0) // Debugger.Break(); //if(_labyrinthData.Unk12 != 0) // 7=1|2|4 (Jirinaar), 54=32|16|4|2, 156=128|16|8|2 (Tall town) // Debugger.Break(); // Raise(new LogEvent(LogEvent.Level.Info, $"WallHeight: {_labyrinthData.WallHeight} MaxObj: {maxObjectHeightRaw} EffWallWidth: {_labyrinthData.EffectiveWallWidth}")); foreach (var npc in _logicalMap.Npcs) { if (npc.SpriteOrGroup.IsNone) { continue; } if (npc.SpriteOrGroup.Type != AssetType.ObjectGroup) { Warn($"[3DMap] Tried to load npc with object group of incorrect type: {npc.SpriteOrGroup}"); continue; } if (npc.SpriteOrGroup.Id >= _labyrinthData.ObjectGroups.Count) { Warn($"[3DMap] Tried to load object group {npc.SpriteOrGroup.Id}, but the max group id is {_labyrinthData.ObjectGroups.Count-1}."); continue; } var objectData = _labyrinthData.ObjectGroups[npc.SpriteOrGroup.Id]; // TODO: Verify SpriteOrGroup is an ObjectGroup // TODO: Build proper NPC objects with AI, sound effects etc foreach (var subObject in objectData.SubObjects) { AttachChild(MapObject.Build(npc.Waypoints[0].X, npc.Waypoints[0].Y, _labyrinthData, subObject, properties)); } } for (int y = 0; y < _logicalMap.Height; y++) { for (int x = 0; x < _logicalMap.Width; x++) { var group = _logicalMap.GetObject(x, y); if (group == null) { continue; } foreach (var subObject in group.SubObjects) { AttachChild(MapObject.Build(x, y, _labyrinthData, subObject, properties)); } } } Raise(new SetClearColourEvent(_backgroundRed, _backgroundGreen, _backgroundBlue, 1.0f)); }