diff --git a/PckStudio.Core/GameRule/AbstractGameRule.cs b/PckStudio.Core/GameRule/AbstractGameRule.cs new file mode 100644 index 00000000..d36ff6fa --- /dev/null +++ b/PckStudio.Core/GameRule/AbstractGameRule.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal abstract class AbstractGameRule + { + private List _gameRules = new List(); + protected void AddRule(AbstractGameRule gameRule) => _gameRules.Add(gameRule); + + protected abstract GameRuleFile.GameRule GetGameRule(); + public static implicit operator GameRuleFile.GameRule(AbstractGameRule abstractGameRule) + { + GameRuleFile.GameRule gameRule = abstractGameRule.GetGameRule(); + gameRule.AddRules(abstractGameRule._gameRules.Select(agr => agr.GetGameRule())); + return gameRule; + } + } +} diff --git a/PckStudio.Core/GameRule/DistributeItems.cs b/PckStudio.Core/GameRule/DistributeItems.cs new file mode 100644 index 00000000..189e837c --- /dev/null +++ b/PckStudio.Core/GameRule/DistributeItems.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class DistributeItems : AbstractGameRule + { + private static string[] _strings = + { + "StartItems", + "OuterItems", + "HVItems" + }; + + internal enum DistributeItemsId + { + StartItems, + OuterItems, + HighValueItems + } + private DistributeItemsId _id; + + internal void AddPosition(int x, int y, int z) => AddRule(new WorldPosition(x, y, z)); + + public DistributeItems(DistributeItemsId id) + { + _id = id; + } + + protected override GameRuleFile.GameRule GetGameRule() + { + var gameRule = new GameRuleFile.GameRule("DistributeItems"); + gameRule.AddParameter(new GameRuleFile.GameRuleParameter("id", _strings[(int)_id])); + return gameRule; + } + } +} diff --git a/PckStudio.Core/GameRule/NamedArea.cs b/PckStudio.Core/GameRule/NamedArea.cs new file mode 100644 index 00000000..cfdb6d3e --- /dev/null +++ b/PckStudio.Core/GameRule/NamedArea.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class NamedArea : AbstractGameRule + { + public string Name { get; } + + public Vector3 Start { get; } + public Vector3 End { get; } + + public NamedArea(string name, Vector3 start, Vector3 end) + { + Name = name; + Start = start; + End = end; + } + + protected override GameRuleFile.GameRule GetGameRule() + { + GameRuleFile.GameRule gameRule = new GameRuleFile.GameRule("NamedArea", null); + gameRule.AddParameters( + new GameRuleFile.GameRuleParameter("name", Name), + new GameRuleFile.IntParameter("x0", (int)Start.X), + new GameRuleFile.IntParameter("y0", (int)Start.Y), + new GameRuleFile.IntParameter("z0", (int)Start.Z), + new GameRuleFile.IntParameter("x1", (int)End.X), + new GameRuleFile.IntParameter("y1", (int)End.Y), + new GameRuleFile.IntParameter("z1", (int)End.Z) + ); + return gameRule; + } + } +} diff --git a/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs b/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs new file mode 100644 index 00000000..cf66e3a0 --- /dev/null +++ b/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class OnGameStartSpawnPositions : AbstractGameRule + { + public SpawnPositionSet OnStart { get; } = new SpawnPositionSet(SpawnPositionSet.SpanPositionMethod.OnStart); + public SpawnPositionSet OnRespawn { get; } = new SpawnPositionSet(SpawnPositionSet.SpanPositionMethod.OnRespawn); + + protected override GameRuleFile.GameRule GetGameRule() + { + AddRule(OnStart); + AddRule(OnRespawn); + return new GameRuleFile.GameRule("OnGameStartSpawnPositions"); + } + } +} diff --git a/PckStudio.Core/GameRule/OnInitialiseWorld.cs b/PckStudio.Core/GameRule/OnInitialiseWorld.cs new file mode 100644 index 00000000..ef36e45d --- /dev/null +++ b/PckStudio.Core/GameRule/OnInitialiseWorld.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class OnInitialiseWorld : AbstractGameRule + { + public DistributeItems StartItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.StartItems); + public DistributeItems OuterItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.OuterItems); + public DistributeItems HighValueItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.HighValueItems); + + protected override GameRuleFile.GameRule GetGameRule() + { + AddRule(StartItems); + AddRule(OuterItems); + AddRule(HighValueItems); + return new GameRuleFile.GameRule("OnInitialiseWorld"); + } + } +} diff --git a/PckStudio.Core/GameRule/SpawnPositionSet.cs b/PckStudio.Core/GameRule/SpawnPositionSet.cs new file mode 100644 index 00000000..31c4c86c --- /dev/null +++ b/PckStudio.Core/GameRule/SpawnPositionSet.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class SpawnPositionSet : AbstractGameRule + { + internal enum SpanPositionMethod + { + OnStart, + OnRespawn + } + private SpanPositionMethod _method; + + internal SpawnPositionSet(SpanPositionMethod method) => _method = method; + + public void AddSpawnPosition(int x, int y, int z, int xRot, int yRot) => AddRule(new UpdatePlayer(new Vector3(x, y, z), new Vector2(xRot, yRot))); + + protected override GameRuleFile.GameRule GetGameRule() + { + var gameRule = new GameRuleFile.GameRule("SpawnPositionSet"); + gameRule.AddParameter(new GameRuleFile.IntParameter("method", (int)_method)); + return gameRule; + } + } +} diff --git a/PckStudio.Core/GameRule/UpdatePlayer.cs b/PckStudio.Core/GameRule/UpdatePlayer.cs new file mode 100644 index 00000000..c6dd59dc --- /dev/null +++ b/PckStudio.Core/GameRule/UpdatePlayer.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class UpdatePlayer : AbstractGameRule + { + private Vector3 _spawn; + private Vector2 _rot; + + public UpdatePlayer(Vector3 spawn, Vector2 rot) + { + _spawn = spawn; + _rot = rot; + } + + protected override GameRuleFile.GameRule GetGameRule() + { + var gameRule = new GameRuleFile.GameRule("UpdatePlayer"); + gameRule.AddParameters( + new GameRuleFile.IntParameter("x", (int)_spawn.X), + new GameRuleFile.IntParameter("y", (int)_spawn.Y), + new GameRuleFile.IntParameter("z", (int)_spawn.Z), + new GameRuleFile.IntParameter("xRot", (int)_rot.X), + new GameRuleFile.IntParameter("yRot", (int)_rot.Y) + ); + return gameRule; + } + } +} diff --git a/PckStudio.Core/GameRule/WorldPosition.cs b/PckStudio.Core/GameRule/WorldPosition.cs new file mode 100644 index 00000000..10014e21 --- /dev/null +++ b/PckStudio.Core/GameRule/WorldPosition.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using OMI.Formats.GameRule; + +namespace PckStudio.Core.GameRule +{ + internal sealed class WorldPosition(int x, int y, int z) : AbstractGameRule + { + private Vector3 _pos = new Vector3(x, y, z); + + protected override GameRuleFile.GameRule GetGameRule() + { + var gameRule = new GameRuleFile.GameRule("WorldPosition"); + gameRule.AddParameters( + new GameRuleFile.IntParameter("x", (int)_pos.X), + new GameRuleFile.IntParameter("y", (int)_pos.Y), + new GameRuleFile.IntParameter("z", (int)_pos.Z) + ); + return gameRule; + } + } +} diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj index 75089f38..00d514ea 100644 --- a/PckStudio.Core/PckStudio.Core.csproj +++ b/PckStudio.Core/PckStudio.Core.csproj @@ -99,6 +99,14 @@ + + + + + + + +