mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-13 04:46:38 -05:00
Fixed map loading to work with any valid map id!
This commit is contained in:
parent
7d0715e97f
commit
3e1c52449b
16
OpenDiablo2.Common/Enums/eLevelId.cs
Normal file
16
OpenDiablo2.Common/Enums/eLevelId.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Enums
|
||||
{
|
||||
public enum eLevelId
|
||||
{
|
||||
None,
|
||||
Act1_Town = 1,
|
||||
Act4_Fortress = 103,
|
||||
Act5_Baal_Entrance = 120
|
||||
}
|
||||
}
|
@ -11,5 +11,6 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
List<LevelPreset> LevelPresets { get; }
|
||||
List<LevelType> LevelTypes { get; }
|
||||
List<LevelDetail> LevelDetails { get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
{
|
||||
ImageSet GetImageSet(string resourcePath);
|
||||
MPQFont GetMPQFont(string resourcePath);
|
||||
MPQDS1 GetMPQDS1(string resourcePath, int definition, int act);
|
||||
MPQDS1 GetMPQDS1(string resourcePath, LevelPreset level, LevelDetail levelDetail, LevelType levelType);
|
||||
MPQDT1 GetMPQDT1(string resourcePath);
|
||||
Palette GetPalette(string paletteName);
|
||||
}
|
||||
|
180
OpenDiablo2.Common/Models/LevelDetail.cs
Normal file
180
OpenDiablo2.Common/Models/LevelDetail.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
public sealed class LevelDetail
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
public int Pal { get; set; }
|
||||
public int Act { get; set; }
|
||||
public int Layer { get; set; }
|
||||
public int SizeX { get; set; }
|
||||
public int SizeY { get; set; }
|
||||
public int OffsetX { get; set; }
|
||||
public int OffsetY { get; set; }
|
||||
public int Depend { get; set; }
|
||||
public int Rain { get; set; }
|
||||
public int Mud { get; set; }
|
||||
public int NoPer { get; set; }
|
||||
public int LOSDraw { get; set; }
|
||||
public int FloorFilter { get; set; }
|
||||
public int BlankScreen { get; set; }
|
||||
public int DrawEdges { get; set; }
|
||||
public int IsInside { get; set; }
|
||||
public int DrlgType { get; set; }
|
||||
public int LevelType { get; set; }
|
||||
public int SubType { get; set; }
|
||||
public int SubTheme { get; set; }
|
||||
public int SubWaypoint { get; set; }
|
||||
public int SubShrine { get; set; }
|
||||
public int Vis0 { get; set; }
|
||||
public int Vis1 { get; set; }
|
||||
public int Vis2 { get; set; }
|
||||
public int Vis3 { get; set; }
|
||||
public int Vis4 { get; set; }
|
||||
public int Vis5 { get; set; }
|
||||
public int Vis6 { get; set; }
|
||||
public int Vis7 { get; set; }
|
||||
public int Warp0 { get; set; }
|
||||
public int Warp1 { get; set; }
|
||||
public int Warp2 { get; set; }
|
||||
public int Warp3 { get; set; }
|
||||
public int Warp4 { get; set; }
|
||||
public int Warp5 { get; set; }
|
||||
public int Warp6 { get; set; }
|
||||
public int Warp7 { get; set; }
|
||||
public int Intensity { get; set; }
|
||||
public int Red { get; set; }
|
||||
public int Green { get; set; }
|
||||
public int Blue { get; set; }
|
||||
public int Portal { get; set; }
|
||||
public int Position { get; set; }
|
||||
public int SaveMonsters { get; set; }
|
||||
public int Quest { get; set; }
|
||||
public int WarpDist { get; set; }
|
||||
public int MonLvl1 { get; set; }
|
||||
public int MonLvl2 { get; set; }
|
||||
public int MonLvl3 { get; set; }
|
||||
public int MonDen { get; set; }
|
||||
public int MonUMin { get; set; }
|
||||
public int MonUMax { get; set; }
|
||||
public int MonWndr { get; set; }
|
||||
public int MonSpcWalk { get; set; }
|
||||
public int Mtot { get; set; }
|
||||
public int[] M1_25 { get; set; }
|
||||
public int[] S1_25 { get; set; }
|
||||
public int Utot { get; set; }
|
||||
public int[] U1_25 { get; set; }
|
||||
public int[] C1_5 { get; set; }
|
||||
public int[] CA1_5 { get; set; }
|
||||
public int[] CD1_5 { get; set; }
|
||||
public int Themes { get; set; }
|
||||
public int SoundEnv { get; set; }
|
||||
public int Waypoint { get; set; }
|
||||
public string LevelName { get; set; }
|
||||
public string LevelWarp { get; set; }
|
||||
public string EntryFile { get; set; }
|
||||
public int[] ObjGrp0_7 { get; set; }
|
||||
public int[] ObjPrb0_7 { get; set; }
|
||||
public bool Beta { get; set; }
|
||||
}
|
||||
|
||||
public static class LevelDetailHelper
|
||||
{
|
||||
public static LevelDetail ToLevelDetail(this string[] v)
|
||||
{
|
||||
var result = new LevelDetail();
|
||||
int i = 0;
|
||||
result.Name = v[i++];
|
||||
result.Id = Convert.ToInt32(v[i++]);
|
||||
result.Pal = Convert.ToInt32(v[i++]);
|
||||
result.Act = Convert.ToInt32(v[i++]);
|
||||
result.Layer = Convert.ToInt32(v[i++]);
|
||||
result.SizeX = Convert.ToInt32(v[i++]);
|
||||
result.SizeY = Convert.ToInt32(v[i++]);
|
||||
result.OffsetX = Convert.ToInt32(v[i++]);
|
||||
result.OffsetY = Convert.ToInt32(v[i++]);
|
||||
result.Depend = Convert.ToInt32(v[i++]);
|
||||
result.Rain = Convert.ToInt32(v[i++]);
|
||||
result.Mud = Convert.ToInt32(v[i++]);
|
||||
result.NoPer = Convert.ToInt32(v[i++]);
|
||||
result.LOSDraw = Convert.ToInt32(v[i++]);
|
||||
result.FloorFilter = Convert.ToInt32(v[i++]);
|
||||
result.BlankScreen = Convert.ToInt32(v[i++]);
|
||||
result.DrawEdges = Convert.ToInt32(v[i++]);
|
||||
result.IsInside = Convert.ToInt32(v[i++]);
|
||||
result.DrlgType = Convert.ToInt32(v[i++]);
|
||||
result.LevelType = Convert.ToInt32(v[i++]);
|
||||
result.SubType = Convert.ToInt32(v[i++]);
|
||||
result.SubTheme = Convert.ToInt32(v[i++]);
|
||||
result.SubWaypoint = Convert.ToInt32(v[i++]);
|
||||
result.SubShrine = Convert.ToInt32(v[i++]);
|
||||
result.Vis0 = Convert.ToInt32(v[i++]);
|
||||
result.Vis1 = Convert.ToInt32(v[i++]);
|
||||
result.Vis2 = Convert.ToInt32(v[i++]);
|
||||
result.Vis3 = Convert.ToInt32(v[i++]);
|
||||
result.Vis4 = Convert.ToInt32(v[i++]);
|
||||
result.Vis5 = Convert.ToInt32(v[i++]);
|
||||
result.Vis6 = Convert.ToInt32(v[i++]);
|
||||
result.Vis7 = Convert.ToInt32(v[i++]);
|
||||
result.Warp0 = Convert.ToInt32(v[i++]);
|
||||
result.Warp1 = Convert.ToInt32(v[i++]);
|
||||
result.Warp2 = Convert.ToInt32(v[i++]);
|
||||
result.Warp3 = Convert.ToInt32(v[i++]);
|
||||
result.Warp4 = Convert.ToInt32(v[i++]);
|
||||
result.Warp5 = Convert.ToInt32(v[i++]);
|
||||
result.Warp6 = Convert.ToInt32(v[i++]);
|
||||
result.Warp7 = Convert.ToInt32(v[i++]);
|
||||
result.Intensity = Convert.ToInt32(v[i++]);
|
||||
result.Red = Convert.ToInt32(v[i++]);
|
||||
result.Green = Convert.ToInt32(v[i++]);
|
||||
result.Blue = Convert.ToInt32(v[i++]);
|
||||
result.Portal = Convert.ToInt32(v[i++]);
|
||||
result.Position = Convert.ToInt32(v[i++]);
|
||||
result.SaveMonsters = Convert.ToInt32(v[i++]);
|
||||
result.Quest = Convert.ToInt32(v[i++]);
|
||||
result.WarpDist = Convert.ToInt32(v[i++]);
|
||||
result.MonLvl1 = Convert.ToInt32(v[i++]);
|
||||
result.MonLvl2 = Convert.ToInt32(v[i++]);
|
||||
result.MonLvl3 = Convert.ToInt32(v[i++]);
|
||||
result.MonDen = Convert.ToInt32(v[i++]);
|
||||
result.MonUMin = Convert.ToInt32(v[i++]);
|
||||
result.MonUMax = Convert.ToInt32(v[i++]);
|
||||
result.MonWndr = Convert.ToInt32(v[i++]);
|
||||
result.MonSpcWalk = Convert.ToInt32(v[i++]);
|
||||
result.Mtot = Convert.ToInt32(v[i++]);
|
||||
result.M1_25 = new int[25];
|
||||
for (int j = 0; j < 25; j++) result.M1_25[j] = Convert.ToInt32(v[i++]);
|
||||
result.S1_25 = new int[25];
|
||||
for (int j = 0; j < 25; j++) result.S1_25[j] = Convert.ToInt32(v[i++]);
|
||||
result.Utot = Convert.ToInt32(v[i++]);
|
||||
result.U1_25 = new int[25];
|
||||
for (int j = 0; j < 25; j++) result.U1_25[j] = Convert.ToInt32(v[i++]);
|
||||
result.C1_5 = new int[5];
|
||||
for (int j = 0; j < 5; j++) result.C1_5[j] = Convert.ToInt32(v[i++]);
|
||||
result.CA1_5 = new int[5];
|
||||
for (int j = 0; j < 5; j++) result.CA1_5[j] = Convert.ToInt32(v[i++]);
|
||||
result.CD1_5 = new int[5];
|
||||
for (int j = 0; j < 5; j++) result.CD1_5[j] = Convert.ToInt32(v[i++]);
|
||||
result.Themes = Convert.ToInt32(v[i++]);
|
||||
result.SoundEnv = Convert.ToInt32(v[i++]);
|
||||
result.Waypoint = Convert.ToInt32(v[i++]);
|
||||
result.LevelName = v[i++];
|
||||
result.LevelWarp = v[i++];
|
||||
result.EntryFile = v[i++];
|
||||
result.ObjGrp0_7 = new int[8];
|
||||
for (int j = 0; j < 5; j++) result.ObjGrp0_7[j] = Convert.ToInt32(v[i++]);
|
||||
result.ObjPrb0_7 = new int[8];
|
||||
for (int j = 0; j < 5; j++) result.ObjPrb0_7[j] = Convert.ToInt32(v[i++]);
|
||||
result.Beta = Convert.ToInt32(v[i++]) == 1;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -85,9 +85,9 @@ namespace OpenDiablo2.Common.Models
|
||||
public MPQDS1Group[] Groups { get; internal set; }
|
||||
|
||||
// TODO: DI magic please
|
||||
public MPQDS1(Stream stream, string fileName, int definition, int act, IEngineDataManager engineDataManager, IResourceManager resourceManager)
|
||||
public MPQDS1(Stream stream, LevelPreset level, LevelDetail levelDetail, LevelType levelType, IEngineDataManager engineDataManager, IResourceManager resourceManager)
|
||||
{
|
||||
log.Debug($"Loading {fileName} (Act {act}) Def {definition}");
|
||||
log.Debug($"Loading {level.Name} (Act {levelDetail.Act})...");
|
||||
var br = new BinaryReader(stream);
|
||||
Version = br.ReadInt32();
|
||||
Width = br.ReadInt32() + 1;
|
||||
@ -320,26 +320,9 @@ namespace OpenDiablo2.Common.Models
|
||||
}*/
|
||||
|
||||
|
||||
LevelPreset levelPreset;
|
||||
if (definition == -1)
|
||||
{
|
||||
levelPreset = engineDataManager.LevelPresets.First(x =>
|
||||
x.File1.ToLower() == fileName.ToLower()
|
||||
|| x.File2.ToLower() == fileName.ToLower()
|
||||
|| x.File3.ToLower() == fileName.ToLower()
|
||||
|| x.File4.ToLower() == fileName.ToLower()
|
||||
|| x.File5.ToLower() == fileName.ToLower()
|
||||
|| x.File6.ToLower() == fileName.ToLower());
|
||||
}
|
||||
else
|
||||
{
|
||||
levelPreset = engineDataManager.LevelPresets.First(x => x.Def == definition);
|
||||
}
|
||||
|
||||
var dt1Mask = levelPreset.Dt1Mask;
|
||||
var levelType = engineDataManager.LevelTypes.First(x => x.Id == levelPreset.LevelId && x.Act == act);
|
||||
|
||||
|
||||
var dt1Mask = level.Dt1Mask;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
var tilePath = levelType.File[i];
|
||||
|
@ -72,6 +72,7 @@
|
||||
<Compile Include="Attributes\SceneAttribute.cs" />
|
||||
<Compile Include="Enums\eButtonType.cs" />
|
||||
<Compile Include="Enums\eHero.cs" />
|
||||
<Compile Include="Enums\eLevelId.cs" />
|
||||
<Compile Include="Enums\eMPQFormatVersion.cs" />
|
||||
<Compile Include="Enums\eRenderCellType.cs" />
|
||||
<Compile Include="Interfaces\IEngineDataManager.cs" />
|
||||
@ -95,6 +96,7 @@
|
||||
<Compile Include="Interfaces\ITextLabel.cs" />
|
||||
<Compile Include="Models\BitStream.cs" />
|
||||
<Compile Include="Models\ButtonLayout.cs" />
|
||||
<Compile Include="Models\LevelDetail.cs" />
|
||||
<Compile Include="Models\LevelPreset.cs" />
|
||||
<Compile Include="Models\LevelType.cs" />
|
||||
<Compile Include="Models\MPQDS1.cs" />
|
||||
|
@ -113,9 +113,8 @@ namespace OpenDiablo2.Common
|
||||
public static string ExpansionStringTable = "data\\local\\lng\\eng\\expansionstring.tbl";
|
||||
public static string LevelPreset = "data\\global\\excel\\LvlPrest.txt";
|
||||
public static string LevelType = "data\\global\\excel\\LvlTypes.txt";
|
||||
public static string LevelDetails = "data\\global\\excel\\Levels.txt";
|
||||
|
||||
// --- Maps ---
|
||||
public static string MapAct1TownE1 = "data\\global\\tiles\\ACT1\\Town\\townE1.ds1";
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace OpenDiablo2.Core
|
||||
|
||||
public List<LevelPreset> LevelPresets { get; internal set; }
|
||||
public List<LevelType> LevelTypes { get; internal set; }
|
||||
public List<LevelDetail> LevelDetails { get; internal set; }
|
||||
|
||||
public EngineDataManager(IMPQProvider mpqProvider)
|
||||
{
|
||||
@ -22,6 +23,7 @@ namespace OpenDiablo2.Core
|
||||
|
||||
LoadLevelPresets();
|
||||
LoadLevelTypes();
|
||||
LoadLevelDetails();
|
||||
}
|
||||
|
||||
private void LoadLevelTypes()
|
||||
@ -51,5 +53,19 @@ namespace OpenDiablo2.Core
|
||||
|
||||
LevelPresets = new List<LevelPreset>(data);
|
||||
}
|
||||
|
||||
private void LoadLevelDetails()
|
||||
{
|
||||
var data = mpqProvider
|
||||
.GetTextFile(ResourcePaths.LevelDetails)
|
||||
.Skip(1)
|
||||
.Where(x => !String.IsNullOrWhiteSpace(x))
|
||||
.Select(x => x.Split('\t'))
|
||||
.Where(x => x.Count() > 80 && x[0] != "Expansion")
|
||||
.ToArray()
|
||||
.Select(x => x.ToLevelDetail());
|
||||
|
||||
LevelDetails = new List<LevelDetail>(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace OpenDiablo2.Core.GameState_
|
||||
private readonly ISceneManager sceneManager;
|
||||
private readonly IResourceManager resourceManager;
|
||||
private readonly IPaletteProvider paletteProvider;
|
||||
private readonly IEngineDataManager engineDataManager;
|
||||
private readonly Func<IMapEngine> getMapEngine;
|
||||
|
||||
public MPQDS1 MapData { get; private set; }
|
||||
@ -26,6 +27,7 @@ namespace OpenDiablo2.Core.GameState_
|
||||
ISceneManager sceneManager,
|
||||
IResourceManager resourceManager,
|
||||
IPaletteProvider paletteProvider,
|
||||
IEngineDataManager engineDataManager,
|
||||
Func<IMapEngine> getMapEngine
|
||||
)
|
||||
{
|
||||
@ -33,19 +35,35 @@ namespace OpenDiablo2.Core.GameState_
|
||||
this.resourceManager = resourceManager;
|
||||
this.paletteProvider = paletteProvider;
|
||||
this.getMapEngine = getMapEngine;
|
||||
this.engineDataManager = engineDataManager;
|
||||
}
|
||||
|
||||
public void Initialize(string characterName, eHero hero)
|
||||
{
|
||||
sceneManager.ChangeScene("Game");
|
||||
ChangeMap(ResourcePaths.MapAct1TownE1, 1);
|
||||
ChangeMap(eLevelId.Act5_Baal_Entrance);
|
||||
}
|
||||
|
||||
public void ChangeMap(string mapName, int act)
|
||||
public void ChangeMap(eLevelId levelId)
|
||||
{
|
||||
MapName = mapName;
|
||||
Act = act;
|
||||
MapData = resourceManager.GetMPQDS1(mapName, -1, act);
|
||||
var level = engineDataManager.LevelPresets.First(x => x.LevelId == (int)levelId);
|
||||
var levelDetails = engineDataManager.LevelDetails.First(x => x.Id == level.LevelId);
|
||||
var levelType = engineDataManager.LevelTypes.First(x => x.Id == levelDetails.LevelType);
|
||||
|
||||
|
||||
var mapNames = new List<string>();
|
||||
if (level.File1 != "0") mapNames.Add(level.File1);
|
||||
if (level.File2 != "0") mapNames.Add(level.File2);
|
||||
if (level.File3 != "0") mapNames.Add(level.File3);
|
||||
if (level.File4 != "0") mapNames.Add(level.File4);
|
||||
if (level.File5 != "0") mapNames.Add(level.File5);
|
||||
if (level.File6 != "0") mapNames.Add(level.File6);
|
||||
|
||||
var random = new Random();
|
||||
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
||||
MapName = level.Name;
|
||||
Act = Convert.ToInt32(mapNames.First().ElementAt(3));
|
||||
MapData = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
|
||||
getMapEngine().NotifyMapChanged();
|
||||
}
|
||||
}
|
||||
|
@ -25,16 +25,13 @@ namespace OpenDiablo2.Core.Map_Engine
|
||||
return;
|
||||
|
||||
cameraLocation = value;
|
||||
/*
|
||||
cellOffsetX = CameraLocation.X / cellSizeX;
|
||||
cellOffsetY = CameraLocation.Y / cellSizeY;
|
||||
pixelOffsetX = CameraLocation.X % cellSizeX;
|
||||
pixelOffsetY = CameraLocation.Y % cellSizeY;
|
||||
*/
|
||||
cOffX = (int)((cameraLocation.X - cameraLocation.Y) * (cellSizeX / 2));
|
||||
cOffY = (int)((cameraLocation.X + cameraLocation.Y) * (cellSizeY / 2));
|
||||
}
|
||||
}
|
||||
|
||||
private ISprite loadingSprite;
|
||||
private int cOffX, cOffY;
|
||||
//private ISprite[] tempMapCell;
|
||||
|
||||
private const int
|
||||
@ -60,6 +57,7 @@ namespace OpenDiablo2.Core.Map_Engine
|
||||
{
|
||||
PurgeAllMapData();
|
||||
LoadNewMapData();
|
||||
CameraLocation = new PointF(gameState.MapData.Width / 2, gameState.MapData.Height / 2);
|
||||
}
|
||||
|
||||
private void LoadNewMapData()
|
||||
@ -89,9 +87,6 @@ namespace OpenDiablo2.Core.Map_Engine
|
||||
|
||||
public void Render()
|
||||
{
|
||||
var cOffX = (int)((cameraLocation.X - cameraLocation.Y) * (cellSizeX / 2));
|
||||
var cOffY = (int)((cameraLocation.X + cameraLocation.Y) * (cellSizeY / 2));
|
||||
|
||||
for (int y = 0; y < gameState.MapData.Width; y++)
|
||||
for (int x = 0; x < gameState.MapData.Height; x++)
|
||||
{
|
||||
|
@ -40,10 +40,10 @@ namespace OpenDiablo2.Core
|
||||
return MPQFonts[resourcePath];
|
||||
}
|
||||
|
||||
public MPQDS1 GetMPQDS1(string resourcePath, int definition, int act)
|
||||
public MPQDS1 GetMPQDS1(string resourcePath, LevelPreset level, LevelDetail levelDetail, LevelType levelType)
|
||||
{
|
||||
var mapName = resourcePath.Replace("data\\global\\tiles\\", "").Replace("\\", "/");
|
||||
return new MPQDS1(mpqProvider.GetStream(resourcePath), mapName, definition, act, engineDataManager, this);
|
||||
return new MPQDS1(mpqProvider.GetStream(resourcePath), level, levelDetail, levelType, engineDataManager, this);
|
||||
}
|
||||
|
||||
public Palette GetPalette(string paletteFile)
|
||||
|
@ -41,7 +41,7 @@ namespace OpenDiablo2.Core.UI
|
||||
private ILabel label;
|
||||
private bool pressed = false;
|
||||
private bool active = false; // When true, button is actively being focus pressed
|
||||
private bool activeLock = false; // When true, something else is being pressed so ignore everything
|
||||
private bool activeLock = false; // When true, we have locked the mouse from everything else
|
||||
private bool toggled = false;
|
||||
|
||||
private Point labelOffset = new Point();
|
||||
|
BIN
Screenshot2.png
BIN
Screenshot2.png
Binary file not shown.
Before Width: | Height: | Size: 461 KiB After Width: | Height: | Size: 713 KiB |
Loading…
Reference in New Issue
Block a user