1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-20 14:15:23 +00:00

Fixed more rule validations. Added ImmultableDictionary reference.

This commit is contained in:
Tim Sarbin 2018-12-08 12:52:09 -05:00
parent 86547875fd
commit 382b38abe0
19 changed files with 114 additions and 76 deletions

View File

@ -1,8 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace OpenDiablo2.Common.Enums.Mobs
{

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -15,12 +16,12 @@ namespace OpenDiablo2.Common.Enums
public static class eArmorTypeHelper
{
private static readonly Dictionary<eArmorType, string> tokens = new Dictionary<eArmorType, string>()
private static readonly ImmutableDictionary<eArmorType, string> tokens = new Dictionary<eArmorType, string>()
{
{ eArmorType.Lite , "lit" },
{ eArmorType.Medium , "med" },
{ eArmorType.Heavy , "hvy" }
};
}.ToImmutableDictionary();
public static string ToToken(this eArmorType armorType) => tokens[armorType];
public static eArmorType ToArmorType(this string source) => tokens.First(x => x.Value.ToUpper() == source.ToUpper()).Key;
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -19,7 +20,7 @@ namespace OpenDiablo2.Common.Enums
public static class eHeroExtensions
{
public readonly static Dictionary<eHero, string> tokens = new Dictionary<eHero, string>
public readonly static ImmutableDictionary<eHero, string> tokens = new Dictionary<eHero, string>
{
{ eHero.Amazon , "AM" },
{ eHero.Sorceress , "SO" },
@ -28,7 +29,7 @@ namespace OpenDiablo2.Common.Enums
{ eHero.Barbarian , "BA" },
{ eHero.Druid , "DZ" },
{ eHero.Assassin , "AI" }
};
}.ToImmutableDictionary();
public static string ToToken(this eHero source) => tokens[source];
public static eHero ToHero(this string source) => tokens.First(x => x.Value.ToUpper() == source.ToUpper()).Key;

View File

@ -50,7 +50,7 @@ namespace OpenDiablo2.Common.Enums
{
public static string GenerateEnum(List<LevelPreset> levelPresets)
{
string output = string.Empty;
var output = new StringBuilder();
foreach (LevelPreset lp in levelPresets)
{
// need to convert e.g. 'Act 1 - Town 1' to 'Act1_Town'
@ -59,9 +59,9 @@ namespace OpenDiablo2.Common.Enums
continue;
}
string name = lp.Name.Replace(" - ", "_").Replace(" ", "").Replace("'", "");
output += name + " = " + lp.LevelId + ",\r\n";
output.AppendLine($"{name}={lp.LevelId}");
}
return output;
return output.ToString();
}
}
}

View File

@ -20,8 +20,8 @@ namespace OpenDiablo2.Common.Models
public int ReadBits(int bitCount)
{
if (bitCount > 16)
throw new ArgumentOutOfRangeException("BitCount", "Maximum BitCount is 16");
if (EnsureBits(bitCount) == false) return -1;
throw new ArgumentOutOfRangeException("bitCount", "Maximum BitCount is 16");
if (!EnsureBits(bitCount)) return -1;
int result = _current & (0xffff >> (16 - bitCount));
WasteBits(bitCount);
return result;
@ -29,7 +29,7 @@ namespace OpenDiablo2.Common.Models
public int PeekByte()
{
if (EnsureBits(8) == false) return -1;
if (!EnsureBits(8)) return -1;
return _current & 0xff;
}
@ -44,11 +44,10 @@ namespace OpenDiablo2.Common.Models
return true;
}
private bool WasteBits(int bitCount)
private void WasteBits(int bitCount)
{
_current >>= bitCount;
_bitCount -= bitCount;
return true;
}
}
}

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Immutable;
using OpenDiablo2.Common.Enums;
namespace OpenDiablo2.Common.Models
@ -15,7 +12,7 @@ namespace OpenDiablo2.Common.Models
public bool Toggleable { get; internal set; } = false;
public int BaseFrame { get; internal set; } = 0;
public static Dictionary<eButtonType, ButtonLayout> Values = new Dictionary<eButtonType, ButtonLayout>
public static ImmutableDictionary<eButtonType, ButtonLayout> Values { get; } = new Dictionary<eButtonType, ButtonLayout>
{
{eButtonType.Wide, new ButtonLayout { XSegments = 2, ResourceName = ResourcePaths.WideButtonBlank, PaletteName = Palettes.Units } },
{eButtonType.Medium, new ButtonLayout{ XSegments = 1, ResourceName=ResourcePaths.MediumButtonBlank, PaletteName = Palettes.Units } },
@ -33,7 +30,7 @@ namespace OpenDiablo2.Common.Models
{eButtonType.Run, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.RunButton,PaletteName = Palettes.Units, Toggleable = true } },
{eButtonType.Menu, new ButtonLayout {XSegments = 1, ResourceName = ResourcePaths.MenuButton,PaletteName = Palettes.Units, Toggleable = true } },
};
}.ToImmutableDictionary();
}
}

View File

@ -1,25 +1,21 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenDiablo2.Common.Models
{
public class ImageFrame : IDisposable
{
public UInt32 Flip;
public UInt32 Width;
public UInt32 Height;
public Int32 OffsetX;
public Int32 OffsetY; // from bottom border, not up
public UInt32 Unknown;
public UInt32 NextBlock;
public UInt32 Length;
public Int16[] ImageData;
public UInt32 Flip { get; internal set; }
public UInt32 Width { get; internal set; }
public UInt32 Height { get; internal set; }
public Int32 OffsetX { get; internal set; }
public Int32 OffsetY { get; internal set; } // from bottom border, not up
public UInt32 Unknown { get; internal set; }
public UInt32 NextBlock { get; internal set; }
public UInt32 Length { get; internal set; }
public Int16[] ImageData { get; internal set; }
public void Dispose()
{
@ -42,8 +38,6 @@ namespace OpenDiablo2.Common.Models
public sealed class ImageSet : IDisposable
{
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private UInt32[] framePointers;
public ImageFrame[] Frames { get; private set; }
@ -53,10 +47,10 @@ namespace OpenDiablo2.Common.Models
public static ImageSet LoadFromStream(Stream stream)
{
var br = new BinaryReader(stream);
var version = br.ReadUInt32();
var unknown1 = br.ReadUInt32();
var unknown2 = br.ReadUInt32();
var termination = br.ReadUInt32();
br.ReadUInt32(); // Version
br.ReadUInt32(); // Unknown 1
br.ReadUInt32(); // Unknown 2
br.ReadUInt32(); // Termination
var result = new ImageSet
{

View File

@ -1,8 +1,21 @@
using System;
/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Immutable;
using OpenDiablo2.Common.Enums;
namespace OpenDiablo2.Common.Models
@ -13,17 +26,17 @@ namespace OpenDiablo2.Common.Models
public string PaletteName { get; internal set; } = Palettes.Units;
public int BaseFrame { get; internal set; } = 0;
public static Dictionary<eItemContainerType, ItemContainerLayout> Values = new Dictionary<eItemContainerType, ItemContainerLayout>
public static ImmutableDictionary<eItemContainerType, ItemContainerLayout> Values { get; } = new Dictionary<eItemContainerType, ItemContainerLayout>
{
{eItemContainerType.Helm, new ItemContainerLayout { ResourceName = ResourcePaths.HelmGlovePlaceholder, BaseFrame = 1 } },
{eItemContainerType.Amulet, new ItemContainerLayout{ ResourceName = ResourcePaths.RingAmuletPlaceholder } },
{eItemContainerType.Armor, new ItemContainerLayout { ResourceName = ResourcePaths.ArmorPlaceholder } },
{eItemContainerType.Weapon, new ItemContainerLayout { ResourceName = ResourcePaths.WeaponsPlaceholder } },
{eItemContainerType.Belt, new ItemContainerLayout { ResourceName = ResourcePaths.BeltPlaceholder } },
{eItemContainerType.Ring, new ItemContainerLayout { ResourceName = ResourcePaths.RingAmuletPlaceholder, BaseFrame = 1 } },
{eItemContainerType.Glove, new ItemContainerLayout { ResourceName = ResourcePaths.HelmGlovePlaceholder } },
{eItemContainerType.Belt, new ItemContainerLayout { ResourceName = ResourcePaths.BeltPlaceholder } },
{eItemContainerType.Ring, new ItemContainerLayout { ResourceName = ResourcePaths.RingAmuletPlaceholder, BaseFrame = 1 } },
{eItemContainerType.Glove, new ItemContainerLayout { ResourceName = ResourcePaths.HelmGlovePlaceholder } },
{eItemContainerType.Boots, new ItemContainerLayout { ResourceName = ResourcePaths.BootsPlaceholder } },
};
}.ToImmutableDictionary();
}
}

View File

@ -167,5 +167,12 @@ namespace OpenDiablo2.Common.Models.Mobs
public int CompareTo(object obj) => Id - ((MobState)obj).Id;
public override bool Equals(object obj) => Id == (obj as MobState)?.Id;
public static bool operator ==(MobState obj1, MobState obj2) => obj1?.Id == obj2?.Id;
public static bool operator !=(MobState obj1, MobState obj2) => obj1?.Id != obj2?.Id;
public static bool operator <(MobState obj1, MobState obj2) => obj1?.Id < obj2?.Id;
public static bool operator >(MobState obj1, MobState obj2) => obj1?.Id > obj2?.Id;
public static bool operator <=(MobState obj1, MobState obj2) => obj1?.Id <= obj2?.Id;
public static bool operator >=(MobState obj1, MobState obj2) => obj1?.Id >= obj2?.Id;
}
}

View File

@ -43,6 +43,9 @@
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Caching" />

View File

@ -4,4 +4,5 @@
<package id="log4net" version="2.0.8" targetFramework="net461" />
<package id="NetSword.Common.ICSharpCode.SharpZipLib" version="0.84.0" targetFramework="net461" developmentDependency="true" />
<package id="SharpZipLib" version="1.0.0" targetFramework="net461" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net461" />
</packages>

View File

@ -25,7 +25,20 @@
*
*/
#endregion
#pragma warning disable S4200
#pragma warning disable S4214
#pragma warning disable S2346
#pragma warning disable S3459
#pragma warning disable S1854
#pragma warning disable S101
#pragma warning disable S2344
#pragma warning disable S1134
#pragma warning disable S1144
#pragma warning disable S125
#pragma warning disable S1135
#pragma warning disable S1168
#pragma warning disable S1104
#pragma warning disable S1168
#region Using Statements
using System;
using System.Runtime.InteropServices;
@ -158,13 +171,13 @@ namespace SDL2
/* mem refers to a void*, IntPtr to an SDL_RWops* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr SDL_RWFromMem(IntPtr mem, int size);
public static extern IntPtr SDL_RWFromMem(IntPtr mem, int size);
#endregion
#endregion
#region SDL_main.h
#region SDL_main.h
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_SetMainReady();
/* This is used as a function pointer to a C main() function for SDL_WinRTRunApp() */

View File

@ -25,7 +25,10 @@
*
*/
#endregion
#pragma warning disable S4200
#pragma warning disable S4214
#pragma warning disable S2344
#pragma warning disable S101
#region Using Statements
using System;
using System.Runtime.InteropServices;

View File

@ -25,7 +25,10 @@
*
*/
#endregion
#pragma warning disable S4200
#pragma warning disable S4214
#pragma warning disable S2344
#pragma warning disable S101
#region Using Statements
using System;
using System.Runtime.InteropServices;

View File

@ -25,7 +25,9 @@
*
*/
#endregion
#pragma warning disable S4200
#pragma warning disable S4214
#pragma warning disable S101
#region Using Statements
using System;
using System.Runtime.InteropServices;
@ -486,3 +488,5 @@ namespace SDL2
#endregion
}
}
#pragma warning restore S4214
#pragma warning restore S4200 // Native methods should be wrapped

View File

@ -10,23 +10,13 @@ namespace OpenDiablo2.Scenes
[Scene(eSceneType.Game)]
public sealed class Game : IScene
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private readonly IRenderWindow renderWindow;
private readonly IMapEngine mapEngine;
private readonly IMouseInfoProvider mouseInfoProvider;
private readonly IGameState gameState;
private readonly ISessionManager sessionManager;
private readonly IKeyboardInfoProvider keyboardInfoProvider;
private readonly IGameHUD gameHUD;
//private ISprite[] testSprite;
private readonly ISprite panelSprite, healthManaSprite, gameGlobeOverlapSprite;
private readonly IMiniPanel minipanel;
private readonly IButton runButton, menuButton;
private eMovementType lastMovementType = eMovementType.Stopped;
private byte lastDirection = 255;
@ -37,7 +27,6 @@ namespace OpenDiablo2.Scenes
IMapEngine mapEngine,
IGameState gameState,
IMouseInfoProvider mouseInfoProvider,
IKeyboardInfoProvider keyboardInfoProvider,
IItemManager itemManager,
ISessionManager sessionManager,
IGameHUD gameHUD
@ -47,7 +36,6 @@ namespace OpenDiablo2.Scenes
this.mapEngine = mapEngine;
this.gameState = gameState;
this.mouseInfoProvider = mouseInfoProvider;
this.keyboardInfoProvider = keyboardInfoProvider;
this.sessionManager = sessionManager;
this.gameHUD = gameHUD;

View File

@ -16,13 +16,10 @@ namespace OpenDiablo2.ServiceBus.Message_Frames.Client
public byte[] Data
{
get
{
return new byte[] { (byte)HeroType }
get => new byte[] { (byte)HeroType }
.Concat(BitConverter.GetBytes((UInt16)PlayerName.Length))
.Concat(Encoding.UTF8.GetBytes(PlayerName))
.ToArray();
}
set
{

View File

@ -63,6 +63,9 @@
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Console, Version=4.0.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Console.4.3.1\lib\net46\System.Console.dll</HintPath>

View File

@ -4,6 +4,7 @@
<package id="CommandLineParser" version="2.3.0" targetFramework="net461" />
<package id="log4net" version="2.0.8" targetFramework="net461" />
<package id="System.Collections" version="4.3.0" targetFramework="net461" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net461" />
<package id="System.Console" version="4.3.1" targetFramework="net461" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" />
<package id="System.Globalization" version="4.3.0" targetFramework="net461" />