Skip to content

Commit

Permalink
Moved race and class to entity vars
Browse files Browse the repository at this point in the history
This is a big change but hopefully makes things far more extensible in the long run.
  • Loading branch information
grofit committed Sep 16, 2023
1 parent f4fae77 commit 9046125
Show file tree
Hide file tree
Showing 47 changed files with 405 additions and 67 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 0.30.{build}
version: 0.31.{build}
branches:
only:
- master
Expand Down
2 changes: 1 addition & 1 deletion src/OpenRpg.Combat/Types/CombatEntityVariableTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace OpenRpg.Combat.Types
{
public interface CombatEntityVariableTypes : EntityVariableTypes
{
public static readonly int ActiveEffects = 10;
public static readonly int ActiveEffects = 20;
}
}
10 changes: 3 additions & 7 deletions src/OpenRpg.Core/Classes/DefaultClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ namespace OpenRpg.Core.Classes
{
public class DefaultClass : IClass
{
public int Level { get; set; }
public IClassTemplate ClassTemplate { get; set; }
public IClassTemplate Template { get; set; } = new DefaultClassTemplate();
public IClassVariables Variables { get; set; } = new DefaultClassVariables();

public DefaultClass(){}

public DefaultClass(int level, IClassTemplate classTemplate)
{
Level = level;
ClassTemplate = classTemplate;
}
public DefaultClass(IClassTemplate template)
{ Template = template; }
}
}
36 changes: 36 additions & 0 deletions src/OpenRpg.Core/Classes/DefaultMultiClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Linq;

namespace OpenRpg.Core.Classes
{
public class DefaultMultiClass : IMultiClass
{
public Dictionary<int, IClass> InternalClasses { get; set; } = new Dictionary<int, IClass>();

public IEnumerable<IClass> Classes => InternalClasses.Values;

public void AddClass(IClass classToAdd)
{
if (!HasClass(classToAdd.Template.Id))
{ InternalClasses.Add(classToAdd.Template.Id, classToAdd); }
}

public void RemoveClass(int classTemplateId)
{
if (HasClass(classTemplateId))
{ InternalClasses.Remove(classTemplateId); }
}

public IClass GetClass(int classTemplateId)
{ return HasClass(classTemplateId) ? InternalClasses[classTemplateId] : null; }

public bool HasClass(int classTemplateId)
{ return InternalClasses.ContainsKey(classTemplateId); }

public DefaultMultiClass()
{}

public DefaultMultiClass(IEnumerable<IClass> classes)
{ InternalClasses = classes.ToDictionary(x => x.Template.Id, x => x); }
}
}
5 changes: 2 additions & 3 deletions src/OpenRpg.Core/Classes/IClass.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using OpenRpg.Core.Classes.Variables;
using OpenRpg.Core.Common;
using OpenRpg.Core.Variables.General;

namespace OpenRpg.Core.Classes
{
public interface IClass : IHasVariables<IClassVariables>
public interface IClass : IHasVariables<IClassVariables>, IHasTemplate<IClassTemplate>
{
int Level { get; set; }
IClassTemplate ClassTemplate { get; }
}
}
2 changes: 1 addition & 1 deletion src/OpenRpg.Core/Classes/IClassTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OpenRpg.Core.Classes
{
public interface IClassTemplate : IHasDataId, IHasEffects, IHasRequirements, IHasLocaleDescription, IHasVariables<IClassTemplateVariables>
public interface IClassTemplate : IDataTemplate, IHasEffects, IHasRequirements, IHasVariables<IClassTemplateVariables>
{
}
}
7 changes: 0 additions & 7 deletions src/OpenRpg.Core/Classes/IHasClass.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/OpenRpg.Core/Classes/IHasMultiClass.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/OpenRpg.Core/Classes/IMultiClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;

namespace OpenRpg.Core.Classes
{
public interface IMultiClass
{
IEnumerable<IClass> Classes { get; }

void AddClass(IClass classToAdd);
void RemoveClass(int classIdToRemove);
IClass GetClass(int classIdGet);
bool HasClass(int classTemplateId);
}
}
7 changes: 7 additions & 0 deletions src/OpenRpg.Core/Common/IDataTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenRpg.Core.Common
{
public interface IDataTemplate : IHasDataId, IHasLocaleDescription
{

}
}
7 changes: 7 additions & 0 deletions src/OpenRpg.Core/Common/IHasTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenRpg.Core.Common
{
public interface IHasTemplate<out T> where T : IDataTemplate
{
T Template { get; }
}
}
2 changes: 0 additions & 2 deletions src/OpenRpg.Core/Entity/DefaultEntity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using OpenRpg.Core.State.Entity;
using OpenRpg.Core.Stats.Entity;
using OpenRpg.Core.Variables.Entity;
Expand All @@ -10,7 +9,6 @@ namespace OpenRpg.Core.Entity
/// </summary>
public class DefaultEntity : IEntity
{
public Guid UniqueId { get; set; } = Guid.NewGuid();
public string NameLocaleId { get; set; } = string.Empty;
public string DescriptionLocaleId { get; set; } = string.Empty;
public IEntityStatsVariables Stats { get; set; } = new DefaultEntityStatsVariables();
Expand Down
7 changes: 7 additions & 0 deletions src/OpenRpg.Core/Entity/DefaultEntityTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenRpg.Core.Entity
{
public class DefaultEntityTemplate : DefaultEntity, IEntityTemplate
{
public int Id { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/OpenRpg.Core/Entity/DefaultUniqueEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace OpenRpg.Core.Entity
{
public class DefaultUniqueEntity : DefaultEntity, IUniqueEntity
{
public Guid UniqueId { get; set; } = Guid.NewGuid();
}
}
2 changes: 1 addition & 1 deletion src/OpenRpg.Core/Entity/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace OpenRpg.Core.Entity
/// to add additional requirements on but this gives a building block to allow more functionality in
/// the base layers.
/// </remarks>
public interface IEntity : IIsUnique, IHasLocaleDescription,
public interface IEntity : IHasLocaleDescription,
IHasState<IEntityStateVariables>, IHasStats<IEntityStatsVariables>, IHasVariables<IEntityVariables>
{}
}
9 changes: 9 additions & 0 deletions src/OpenRpg.Core/Entity/IEntityTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OpenRpg.Core.Common;

namespace OpenRpg.Core.Entity
{
public interface IEntityTemplate : IDataTemplate, IEntity
{

}
}
9 changes: 9 additions & 0 deletions src/OpenRpg.Core/Entity/IUniqueEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OpenRpg.Core.Common;

namespace OpenRpg.Core.Entity
{
public interface IUniqueEntity : IIsUnique, IEntity
{

}
}
37 changes: 37 additions & 0 deletions src/OpenRpg.Core/Extensions/EntityVariableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using OpenRpg.Core.Classes;
using OpenRpg.Core.Races;
using OpenRpg.Core.Types;
using OpenRpg.Core.Variables.Entity;

namespace OpenRpg.Core.Extensions
{
public static class EntityVariableExtensions
{
public static bool HasRace(this IEntityVariables vars)
{ return vars.ContainsKey(EntityVariableTypes.Race); }

public static IRaceTemplate Race(this IEntityVariables vars)
{ return vars[EntityVariableTypes.Race] as IRaceTemplate; }

public static void Race(this IEntityVariables vars, IRaceTemplate race)
{ vars[EntityVariableTypes.Race] = race; }

public static bool HasClass(this IEntityVariables vars)
{ return vars.ContainsKey(EntityVariableTypes.Class); }

public static IClass Class(this IEntityVariables vars)
{ return vars[EntityVariableTypes.Class] as IClass; }

public static void Class(this IEntityVariables vars, IClass classToUse)
{ vars[EntityVariableTypes.Class] = classToUse; }

public static bool HasMultiClass(this IEntityVariables vars)
{ return vars.ContainsKey(EntityVariableTypes.MultiClasses); }

public static IMultiClass MultiClass(this IEntityVariables vars)
{ return vars[EntityVariableTypes.MultiClasses] as IMultiClass; }

public static void MultiClass(this IEntityVariables vars, IMultiClass multiClass)
{ vars[EntityVariableTypes.MultiClasses] = multiClass; }
}
}
18 changes: 18 additions & 0 deletions src/OpenRpg.Core/Extensions/IClassVariableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using OpenRpg.Core.Classes.Variables;
using OpenRpg.Core.Effects;
using OpenRpg.Core.Types;

namespace OpenRpg.Core.Extensions
{
public static class IClassVariableExtensions
{
public static int Level(this IClassVariables vars) => (int)vars.Get(ClassVariableTypes.Level);
public static void Level(this IClassVariables vars, int level) => vars[ClassVariableTypes.Level] = level;

public static int Experience(this IClassVariables vars) => (int)vars.Get(ClassVariableTypes.Experience);
public static void Experience(this IClassVariables vars, int experience) => vars[ClassVariableTypes.Experience] = experience;
public static void AddExperience(this IClassVariables state, int change) => state.Experience(state.Experience() + change);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OpenRpg.Core.Modifications
{
public class DefaultModification : IModification
public class DefaultModificationTemplate : IModificationTemplate
{
public int Id { get; set; }
public IEnumerable<Effect> Effects { get; set; } = Array.Empty<Effect>();
Expand Down
2 changes: 1 addition & 1 deletion src/OpenRpg.Core/Modifications/IHasModifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace OpenRpg.Core.Modifications
{
public interface IHasModifications
{
IEnumerable<IModification> Modifications { get; }
IEnumerable<IModificationTemplate> Modifications { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OpenRpg.Core.Modifications
{
public interface IModification : IHasDataId, IHasEffects, IHasLocaleDescription
public interface IModificationTemplate : IDataTemplate, IHasEffects
{
int ModificationType { get; }
}
Expand Down
2 changes: 2 additions & 0 deletions src/OpenRpg.Core/OpenRpg.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PackageTags>rpg game-development xna monogame unity godot</PackageTags>
<LangVersion>8</LangVersion>



</PropertyGroup>


Expand Down
2 changes: 1 addition & 1 deletion src/OpenRpg.Core/Races/IRaceTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OpenRpg.Core.Races
{
public interface IRaceTemplate : IHasDataId, IHasEffects, IHasRequirements, IHasLocaleDescription, IHasVariables<IRaceTemplateVariables>
public interface IRaceTemplate : IDataTemplate, IHasEffects, IHasRequirements, IHasVariables<IRaceTemplateVariables>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Core.Stats.Entity
{
public class DefaultEntityStatsVariables : DefaultVariables<float>, IEntityStatsVariables
{
public DefaultEntityStatsVariables(IDictionary<int, float> internalVariables = null) : base(CoreVariableTypes.EntityStateVariables, internalVariables)
public DefaultEntityStatsVariables(IDictionary<int, float> internalVariables = null) : base(CoreVariableTypes.EntityStatsVariables, internalVariables)
{
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/OpenRpg.Core/Types/ClassVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OpenRpg.Core.Types
{
public interface ClassVariableTypes
{
public static readonly int Unknown = 0;

public static readonly int Level = 1;
public static readonly int Experience = 2;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace OpenRpg.Core.Types
{
public interface StatsVariableTypes
public interface EntityStatsVariableTypes
{
public static readonly int Unknown = 0;
}
Expand Down
5 changes: 4 additions & 1 deletion src/OpenRpg.Core/Types/EntityVariableTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ namespace OpenRpg.Core.Types
{
public interface EntityVariableTypes
{
// Unknown
public static readonly int Unknown = 0;

public static readonly int Race = 1;
public static readonly int Class = 2;
public static readonly int MultiClasses = 3;
}
}
2 changes: 1 addition & 1 deletion src/OpenRpg.Items/DefaultItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DefaultItem : IUniqueItem
public Guid UniqueId { get; set; } = Guid.NewGuid();

public IItemTemplate ItemTemplate { get; set; } = new DefaultItemTemplate();
public IEnumerable<IModification> Modifications { get; set;} = new List<IModification>();
public IEnumerable<IModificationTemplate> Modifications { get; set;} = new List<IModificationTemplate>();
public IItemVariables Variables { get; set; } = new DefaultItemVariables();
}
}
10 changes: 10 additions & 0 deletions src/OpenRpg.Items/Extensions/IItemEntityVariableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using OpenRpg.Core.Variables.Entity;
using OpenRpg.Items.Equipment;
using OpenRpg.Items.Inventory;
using OpenRpg.Items.Loot;
using OpenRpg.Items.Types;

namespace OpenRpg.Items.Extensions
Expand All @@ -27,5 +28,14 @@ public static IInventory Inventory(this IEntityVariables vars)

public static void Inventory(this IEntityVariables vars, IInventory inventory)
{ vars[ItemEntityVariableTypes.Inventory] = inventory; }

public static bool HasLootTable(this IEntityVariables vars)
{ return vars.ContainsKey(ItemEntityVariableTypes.LootTable); }

public static ILootTable LootTable(this IEntityVariables vars)
{ return vars[ItemEntityVariableTypes.LootTable] as ILootTable; }

public static void LootTable(this IEntityVariables vars, ILootTable lootTable)
{ vars[ItemEntityVariableTypes.LootTable] = lootTable; }
}
}
Loading

0 comments on commit 9046125

Please sign in to comment.