Skip to content

Commit

Permalink
Adding gender var to base entity
Browse files Browse the repository at this point in the history
  • Loading branch information
grofit committed Sep 18, 2023
1 parent 9046125 commit d18485d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/OpenRpg.Core/Extensions/EntityVariableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ namespace OpenRpg.Core.Extensions
{
public static class EntityVariableExtensions
{
public static bool HasGender(this IEntityVariables vars)
{ return vars.ContainsKey(EntityVariableTypes.Gender); }

public static byte Gender(this IEntityVariables vars)
{ return (byte)vars[EntityVariableTypes.Gender]; }

public static void Gender(this IEntityVariables vars, byte gender)
{ vars[EntityVariableTypes.Gender] = gender; }

public static bool HasRace(this IEntityVariables vars)
{ return vars.ContainsKey(EntityVariableTypes.Race); }

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 @@ -13,6 +13,8 @@





</PropertyGroup>


Expand Down
1 change: 1 addition & 0 deletions src/OpenRpg.Core/Types/EntityVariableTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface EntityVariableTypes
public static readonly int Race = 1;
public static readonly int Class = 2;
public static readonly int MultiClasses = 3;
public static readonly int Gender = 4;
}
}
12 changes: 6 additions & 6 deletions src/OpenRpg.Quests/DefaultQuestState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public class DefaultQuestState : IQuestState

public IReadOnlyDictionary<int, int> QuestStates => InternalQuestStates;

public DefaultQuestState()
{}

public DefaultQuestState(Dictionary<int, int> questStates)
{ InternalQuestStates = questStates; }

public int GetQuestState(int questId)
{
return InternalQuestStates.TryGetValue(questId, out var state)
Expand All @@ -18,11 +24,5 @@ public int GetQuestState(int questId)

public void SetQuestState(int questId, int questState)
{ InternalQuestStates[questId] = questState; }

public DefaultQuestState()
{}

public DefaultQuestState(Dictionary<int, int> questStates)
{ InternalQuestStates = questStates; }
}
}
12 changes: 12 additions & 0 deletions src/OpenRpg.UnitTests/Core/EntityVariableExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ namespace OpenRpg.UnitTests.Core;

public class EntityVariableExtensionTests
{
[Fact]
public void should_correctly_handle_gender_on_entity()
{
var entityVars = new DefaultEntityVariables();
Assert.False(entityVars.HasGender());

var dummyGender = (byte)1;
entityVars.Gender(dummyGender);
Assert.True(entityVars.HasGender());
Assert.Equal(entityVars.Gender(), dummyGender);
}

[Fact]
public void should_correctly_handle_race_on_entity()
{
Expand Down

0 comments on commit d18485d

Please sign in to comment.