Add AbstractGameRule.cs & derived classes

This commit is contained in:
miku-666
2025-11-09 22:45:29 +01:00
parent 56e381af24
commit dc69ddc433
9 changed files with 251 additions and 0 deletions

View File

@@ -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<AbstractGameRule> _gameRules = new List<AbstractGameRule>();
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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -99,6 +99,14 @@
<Compile Include="FileDialogFilter.cs" />
<Compile Include="FileFormats\PckAudioFile.cs" />
<Compile Include="GameConstants.cs" />
<Compile Include="GameRule\AbstractGameRule.cs" />
<Compile Include="GameRule\DistributeItems.cs" />
<Compile Include="GameRule\NamedArea.cs" />
<Compile Include="GameRule\OnGameStartSpawnPositions.cs" />
<Compile Include="GameRule\OnInitialiseWorld.cs" />
<Compile Include="GameRule\SpawnPositionSet.cs" />
<Compile Include="GameRule\UpdatePlayer.cs" />
<Compile Include="GameRule\WorldPosition.cs" />
<Compile Include="Interfaces\IDLCPackage.cs" />
<Compile Include="Interfaces\IDLCPackageLocationInfo.cs" />
<Compile Include="Interfaces\IEditor.cs" />