Skip to content

Commit

Permalink
Merge pull request #81 from XenotropicDev/2.1
Browse files Browse the repository at this point in the history
2.1 features merge
  • Loading branch information
XenotropicDev authored Feb 5, 2023
2 parents fa028ee + d26f6f1 commit a3e596e
Show file tree
Hide file tree
Showing 55 changed files with 2,695 additions and 108 deletions.
2 changes: 1 addition & 1 deletion JsonClassGenerator/JsonClassGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.7.2" />
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
46 changes: 46 additions & 0 deletions Server/Data/IEntityRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Server.GameInterfaces;
using TheOracle2.Data;

namespace Server.Data;

public interface IEntityRepository
{
IEnumerable<OracleGameEntity> GetEntities();
OracleGameEntity? GetEntity(string id);
}

public class JsonEntityRepository : IEntityRepository
{
private List<OracleGameEntity>? Entities;

public OracleGameEntity? GetEntity(string id)
{
return GetEntities().FirstOrDefault(o => o.Id == id);
}

public IEnumerable<OracleGameEntity> GetEntities()
{
if (Entities == null)
{
Entities = new List<OracleGameEntity>();
var files = new DirectoryInfo(Path.Combine("Data", "game entities")).GetFiles("*.json").ToList();

foreach (var file in files)
{
using var fileStream = file.OpenText();
string text = fileStream.ReadToEnd();

var root = JsonConvert.DeserializeObject<List<OracleGameEntity>>(text, new JsonSerializerSettings() { MetadataPropertyHandling = MetadataPropertyHandling.Ignore });

if (root != null) Entities.AddRange(root);
}
}

return Entities;
}
}
27 changes: 26 additions & 1 deletion Server/Data/IronGame.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
namespace TheOracle2;
using System.Text.RegularExpressions;

namespace TheOracle2;

public enum IronGame
{
Ironsworn,
Starforged
}

public static class IronGameExtenstions
{
public static IronGame? GetIronGameInString(string value)
{
foreach(var game in Enum.GetValues<IronGame>())
{
if (value.Contains(game.ToString(), StringComparison.OrdinalIgnoreCase)) return game;
}

return null;
}

public static string RemoveIronGameInString(string value)
{
foreach (var game in Enum.GetValues<IronGame>())
{
value = Regex.Replace(value, game.ToString() + " ?", "", RegexOptions.IgnoreCase);
}

return value.Trim();
}
}
35 changes: 24 additions & 11 deletions Server/Data/PlayerDataFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Server.DiscordServer;
using Server.GameInterfaces;
using TheOracle2;
using TheOracle2.Data;

namespace Server.Data;
Expand All @@ -11,35 +13,46 @@ public class PlayerDataFactory
private IAssetRepository Assets { get; }
private IMoveRepository Moves { get; }
private IOracleRepository Oracles { get; }
public IEntityRepository Entities { get; }

public PlayerDataFactory(IAssetRepository assets, IMoveRepository moves, IOracleRepository oracles, IDbContextFactory<ApplicationContext> dbFactory)
public PlayerDataFactory(IAssetRepository assets, IMoveRepository moves, IOracleRepository oracles, IEntityRepository entities, IDbContextFactory<ApplicationContext> dbFactory)
{
Assets = assets;
Moves = moves;
Oracles = oracles;
Entities = entities;
this.dbFactory = dbFactory;
}

public IEnumerable<Asset> GetPlayerAssets(ulong PlayerId)
public async Task<IEnumerable<Asset>> GetPlayerAssets(ulong PlayerId, IronGame? gameOverride = null)
{
using var db = dbFactory.CreateDbContext();
var playerGame = db.Players.Find(PlayerId)?.Game ?? default;
var playerGame = gameOverride ?? (await db.Players.FindAsync(PlayerId))?.Game ?? default;
var assets = Assets.GetAssetRoots().SelectMany(ar => ar.Assets);
var playerAssets = assets.Where(a => a.Id.Contains(playerGame.ToString()));
return playerAssets;

return assets.Where(a => a.Id.Contains(playerGame.ToString(), StringComparison.OrdinalIgnoreCase));
}

public async Task<IEnumerable<OracleGameEntity>> GetPlayerEntites(ulong PlayerId, IronGame? gameOverride = null)
{
using var db = dbFactory.CreateDbContext();
var playerGame = gameOverride ?? (await db.Players.FindAsync(PlayerId))?.Game ?? default;

return Entities.GetEntities().Where(a => a.Game == playerGame);
}

public IEnumerable<Move> GetPlayerMoves(ulong PlayerId)
public async Task<IEnumerable<Move>> GetPlayerMoves(ulong PlayerId, IronGame? gameOverride = null)
{
using var db = dbFactory.CreateDbContext();
var playerGame = db.Players.Find(PlayerId)?.Game ?? default;
var playerGame = gameOverride ?? (await db.Players.FindAsync(PlayerId))?.Game ?? default;

return Moves.GetMoveRoots().SelectMany(mr => mr.Moves).Where(a => a.Id.Contains(playerGame.ToString()));
}

public IEnumerable<Oracle> GetPlayerOracles(ulong PlayerId)
public async Task<IEnumerable<Oracle>> GetPlayerOracles(ulong PlayerId, IronGame? gameOverride = null)
{
using var db = dbFactory.CreateDbContext();
var playerGame = db.Players.Find(PlayerId)?.Game ?? default;
var playerGame = gameOverride ?? (await db.Players.FindAsync(PlayerId))?.Game ?? default;
var playerOracles = Oracles.GetOracleRoots()
.SelectMany(or => or.Oracles)
.Where(a => a.Id.Contains(playerGame.ToString())).ToList();
Expand All @@ -55,10 +68,10 @@ public IEnumerable<Oracle> GetPlayerOracles(ulong PlayerId)
return playerOracles;
}

public IEnumerable<OracleRoot> GetPlayerOraclesRoots(ulong PlayerId)
public async Task<IEnumerable<OracleRoot>> GetPlayerOraclesRoots(ulong PlayerId, IronGame? gameOverride = null)
{
using var db = dbFactory.CreateDbContext();
var playerGame = db.Players.Find(PlayerId)?.Game ?? default;
var playerGame = gameOverride ?? (await db.Players.FindAsync(PlayerId))?.Game ?? default;
return Oracles.GetOracleRoots().Where(or => or.Id.Contains(playerGame.ToString()));
}
}
47 changes: 47 additions & 0 deletions Server/Data/game entities/Creature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"Id": "Starforged_Creature",
"SearchName": "Starforged Creature",
"title": "Creature",
"game": "Starforged",
"shortName": "Creature",
"InitialOracles": [
{
"FieldName": "Environment",
"FieldValue": "[[Starforged/Oracles/Creatures/Environment]]",
"HasModalOverride": false
},
{
"FieldName": "Scale",
"FieldValue": "[[Starforged/Oracles/Creatures/Scale]]",
"HasModalOverride": false
},
{
"FieldName": "Basic Form",
"FieldValue": "[[Starforged/Oracles/Creatures/Basic_Form]]",
"HasModalOverride": false
},
{
"FieldName": "First Look",
"FieldValue": "[[Starforged/Oracles/Creatures/First_Look]]",
"HasModalOverride": false
}
],
"FollowUpOracles": [
{
"FieldName": "Encountered Behavior",
"FieldValue": "[[Starforged/Oracles/Creatures/Encountered_Behavior]]",
"Emoji": "👋",
"AllowReroll": true,
"AllowFudge": true
},
{
"FieldName": "Revealed Aspect",
"FieldValue": "Starforged/Oracles/Creatures/Revealed_Aspect",
"Emoji": "👁️",
"AllowReroll": true,
"AllowFudge": true
}
]
}
]
117 changes: 117 additions & 0 deletions Server/Data/game entities/NPC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
[
{
"Id": "Ironsworn_NPC",
"SearchName": "Ironsworn NPC",
"title": "[[Ironsworn/Oracles/Name/Ironlander]]",
"author": "NPC",
"game": "Ironsworn",
"shortName": "NPC",
"InitialOracles": [
{
"FieldName": "Description",
"FieldValue": "[[Ironsworn/Oracles/Character/Descriptor]]",
"HasModalOverride": false
}
],
"FollowUpOracles": [
{
"FieldName": "Role",
"FieldValue": "[[Ironsworn/Oracles/Character/Role]]",
"Emoji": "🎭",
"AllowReroll": true,
"AllowFudge": true
},
{
"FieldName": "Goal",
"FieldValue": "Ironsworn/Oracles/Character/Goal",
"Emoji": "",
"AllowReroll": true,
"AllowFudge": true
},
{
"FieldName": "Disposition",
"FieldValue": "[[Ironsworn/Oracles/Character/Disposition]]",
"Emoji": "👋",
"AllowReroll": true,
"AllowFudge": true
},
{
"FieldName": "Activity",
"FieldValue": "[[Ironsworn/Oracles/Character/Activity]]",
"Emoji": "💃",
"AllowReroll": true,
"AllowFudge": true
}
]
},
{
"Id": "Starforged_NPC_Callsign",
"SearchName": "Starforged NPC with Callsign",
"title": "NPC",
"game": "Starforged",
"InitialOracles": [
{
"FieldName": "Callsign",
"FieldValue": "[[Starforged/Oracles/Characters/Name/Callsign]]",
"HasModalOverride": false
},
{
"FieldName": "First Look",
"FieldValue": "[[Starforged/Oracles/Characters/First_Look]]"
}
],
"FollowUpOracles": [
{
"FieldName": "Disposition",
"FieldValue": "Starforged/Oracles/Characters/Disposition",
"Emoji": "👋",
"AllowReroll": true,
"AllowFudge": true
},
{
"FieldName": "Revealed Aspect",
"FieldValue": "Starforged/Oracles/Characters/Revealed_Aspect",
"AllowReroll": true,
"AllowFudge": true
}
]
},
{
"Id": "Starforged_NPC_Name",
"SearchName": "Starforged NPC with Name",
"title": "NPC",
"game": "Starforged",
"InitialOracles": [
{
"FieldName": "Name",
"FieldValue": "[[Starforged/Oracles/Characters/Name/Given_Name]] [[Starforged/Oracles/Characters/Name/Family_Name]]",
"HasModalOverride": false
},
{
"FieldName": "First Look",
"FieldValue": "[[Starforged/Oracles/Characters/First_Look]]",
"AllowFudge": true
}
],
"FollowUpOracles": [
{
"FieldName": "Callsign",
"FieldValue": "[[Starforged/Oracles/Characters/Name/Callsign]]",
"HasModalOverride": true
},
{
"FieldName": "Disposition",
"FieldValue": "[[Starforged/Oracles/Characters/Disposition]]",
"Emoji": "👋",
"AllowReroll": true,
"AllowFudge": true
},
{
"FieldName": "Revealed Aspect",
"FieldValue": "[[Starforged/Oracles/Characters/Revealed_Aspect]]",
"AllowReroll": true,
"AllowFudge": true
}
]
}
]
Loading

0 comments on commit a3e596e

Please sign in to comment.