Skip to content

Commit

Permalink
Now we have entities this brings more extensions to lower levels
Browse files Browse the repository at this point in the history
This functionality used to exist in the `OpenRpg.Genres` layer but it has now been pulled down into this layer to make things a bit more extensible and composable from lower layers of the library.
  • Loading branch information
grofit committed Sep 10, 2023
1 parent 125772e commit 77c11e1
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OpenRpg.Cards.Types
{
public interface CardVariableTypes : ItemVariableTypes, CombatVariableTypes
public interface ICardCoreVariableTypes : ItemCoreVariableTypes, CombatVariableTypes
{
public static int CardVariables = 50;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenRpg.Cards/Variables/DefaultCardVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Cards.Variables
{
public class DefaultCardVariables : DefaultVariables<object>, ICardVariables
{
public DefaultCardVariables(IDictionary<int, object> internalVariables = null) : base(CardVariableTypes.CardVariables, internalVariables)
public DefaultCardVariables(IDictionary<int, object> internalVariables = null) : base(ICardCoreVariableTypes.CardVariables, internalVariables)
{
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/OpenRpg.Combat/Extensions/IItemEntityVariableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using OpenRpg.Combat.Effects;
using OpenRpg.Combat.Types;
using OpenRpg.Core.Variables.Entity;

namespace OpenRpg.Combat.Extensions
{
/// <summary>
/// This allows you to extend the underlying entity to add active effects onto them
/// </summary>
public static class CombatEntityVariableExtensions
{
public static bool HasActiveEffects(this IEntityVariables vars)
{ return vars.ContainsKey(CombatEntityVariableTypes.ActiveEffects); }

public static IActiveEffects ActiveEffects(this IEntityVariables vars)
{ return vars[CombatEntityVariableTypes.ActiveEffects] as IActiveEffects; }

public static void ActiveEffects(this IEntityVariables vars, IActiveEffects activeEffects)
{ vars[CombatEntityVariableTypes.ActiveEffects] = activeEffects; }
}
}
9 changes: 9 additions & 0 deletions src/OpenRpg.Combat/Types/CombatEntityVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OpenRpg.Core.Types;

namespace OpenRpg.Combat.Types
{
public interface CombatEntityVariableTypes : EntityVariableTypes
{
public static readonly int ActiveEffects = 10;
}
}
8 changes: 8 additions & 0 deletions src/OpenRpg.Core/Types/EntityVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OpenRpg.Core.Types
{
public interface EntityVariableTypes
{
// Unknown
public static readonly int Unknown = 0;
}
}
2 changes: 1 addition & 1 deletion src/OpenRpg.Items/Equipment/DefaultEquipmentSlots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Items.Equipment
{
public class DefaultEquipmentSlots : DefaultVariables<IEquipmentSlot>, IEquipmentSlots
{
public DefaultEquipmentSlots(IDictionary<int, IEquipmentSlot> internalVariables = null) : base(ItemVariableTypes.EquipmentSlotVariables, internalVariables)
public DefaultEquipmentSlots(IDictionary<int, IEquipmentSlot> internalVariables = null) : base(ItemCoreVariableTypes.EquipmentSlotVariables, internalVariables)
{
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/OpenRpg.Items/Extensions/IItemEntityVariableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using OpenRpg.Core.Variables.Entity;
using OpenRpg.Items.Equipment;
using OpenRpg.Items.Inventory;
using OpenRpg.Items.Types;

namespace OpenRpg.Items.Extensions
{
/// <summary>
/// This allows you to extend the underlying entity to add equipment or inventory responsibilities onto them
/// </summary>
public static class ItemEntityVariableExtensions
{
public static bool HasEquipment(this IEntityVariables vars)
{ return vars.ContainsKey(ItemEntityVariableTypes.Equipment); }

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

public static void Equipment(this IEntityVariables vars, IEquipment equipment)
{ vars[ItemEntityVariableTypes.Equipment] = equipment; }

public static bool HasInventory(this IEntityVariables vars)
{ return vars.ContainsKey(ItemEntityVariableTypes.Inventory); }

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

public static void Inventory(this IEntityVariables vars, IInventory inventory)
{ vars[ItemEntityVariableTypes.Inventory] = inventory; }
}
}
20 changes: 12 additions & 8 deletions src/OpenRpg.Items/Extensions/IItemVariablesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ public static class ItemVariablesExtensions
{
public static IItemVariables Clone(this DefaultItemVariables itemVariables)
{
return new DefaultItemVariables { InternalVariables = new Dictionary<int, object>(itemVariables.InternalVariables) };
return new DefaultItemVariables
{
InternalVariables = new Dictionary<int, object>(itemVariables.InternalVariables)
};
}

public static bool HasAmount(this IItemVariables variables)
{ return variables.ContainsKey(DefaultItemVariableTypes.Amount); }
{ return variables.ContainsKey(ItemVariableTypes.Amount); }

public static int Amount(this IItemVariables variables)
{
var amountObject = variables.Get(DefaultItemVariableTypes.Amount);
var amountObject = variables.Get(ItemVariableTypes.Amount);
var amount = Convert.ToInt32(amountObject);
return amount == 0 ? 1 : amount;
}

public static void Amount(this IItemVariables variables, int value) => variables[DefaultItemVariableTypes.Amount] = value;

public static void Amount(this IItemVariables variables, int value)
{ variables[ItemVariableTypes.Amount] = value; }

public static bool HasWeight(this IItemVariables variables)
{ return variables.ContainsKey(DefaultItemVariableTypes.Weight); }
{ return variables.ContainsKey(ItemVariableTypes.Weight); }

public static int Weight(this IItemVariables variables) => Convert.ToInt32(variables.Get(DefaultItemVariableTypes.Weight));
public static void Weight(this IItemVariables variables, int value) => variables[DefaultItemVariableTypes.Weight] = value;
public static int Weight(this IItemVariables variables) => Convert.ToInt32(variables.Get(ItemVariableTypes.Weight));
public static void Weight(this IItemVariables variables, int value) => variables[ItemVariableTypes.Weight] = value;
}
}
2 changes: 1 addition & 1 deletion src/OpenRpg.Items/Inventory/DefaultInventoryVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Items.Inventory
{
public class DefaultInventoryVariables : DefaultVariables<object>, IInventoryVariables
{
public DefaultInventoryVariables(IDictionary<int, object> internalVariables = null) : base(ItemVariableTypes.InventoryVariables, internalVariables)
public DefaultInventoryVariables(IDictionary<int, object> internalVariables = null) : base(ItemCoreVariableTypes.InventoryVariables, internalVariables)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenRpg.Items/Loot/DefaultLootTableEntryVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Items.Loot
{
public class DefaultLootTableEntryVariables : DefaultVariables<object>, ILootTableEntryVariables
{
public DefaultLootTableEntryVariables(IDictionary<int, object> internalVariables = null) : base(ItemVariableTypes.LootTableEntryVariables, internalVariables)
public DefaultLootTableEntryVariables(IDictionary<int, object> internalVariables = null) : base(ItemCoreVariableTypes.LootTableEntryVariables, internalVariables)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Items.Templates
{
public class DefaultItemTemplateVariables : DefaultVariables<object>, IItemTemplateVariables
{
public DefaultItemTemplateVariables(IDictionary<int, object> internalVariables = null) : base(ItemVariableTypes.ItemTemplateVariables, internalVariables)
public DefaultItemTemplateVariables(IDictionary<int, object> internalVariables = null) : base(ItemCoreVariableTypes.ItemTemplateVariables, internalVariables)
{
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/OpenRpg.Items/Types/DefaultItemVariableTypes.cs

This file was deleted.

14 changes: 14 additions & 0 deletions src/OpenRpg.Items/Types/ItemCoreVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using OpenRpg.Core.Types;

namespace OpenRpg.Items.Types
{
public interface ItemCoreVariableTypes : CoreVariableTypes
{
public static int ItemTemplateVariables = 20;
public static int InventoryVariables = 21;
public static int ItemVariables = 23;
public static int EquipmentVariables = 24;
public static int LootTableEntryVariables = 25;
public static int EquipmentSlotVariables = 26;
}
}
10 changes: 10 additions & 0 deletions src/OpenRpg.Items/Types/ItemEntityVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using OpenRpg.Core.Types;

namespace OpenRpg.Items.Types
{
public interface ItemEntityVariableTypes : EntityVariableTypes
{
public static readonly int Equipment = 1;
public static readonly int Inventory = 2;
}
}
14 changes: 5 additions & 9 deletions src/OpenRpg.Items/Types/ItemVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using OpenRpg.Core.Types;

namespace OpenRpg.Items.Types
{
public interface ItemVariableTypes : CoreVariableTypes
public interface ItemVariableTypes
{
public static int ItemTemplateVariables = 20;
public static int InventoryVariables = 21;
public static int ItemVariables = 23;
public static int EquipmentVariables = 24;
public static int LootTableEntryVariables = 25;
public static int EquipmentSlotVariables = 26;
public static int Unknown = 0;

public static int Amount = 1;
public static int Weight = 2;
}
}
2 changes: 1 addition & 1 deletion src/OpenRpg.Items/Variables/DefaultEquipmentVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Items.Variables
{
public class DefaultEquipmentVariables : DefaultVariables<object>, IEquipmentVariables
{
public DefaultEquipmentVariables(IDictionary<int, object> internalVariables = null) : base(ItemVariableTypes.EquipmentVariables, internalVariables)
public DefaultEquipmentVariables(IDictionary<int, object> internalVariables = null) : base(ItemCoreVariableTypes.EquipmentVariables, internalVariables)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenRpg.Items/Variables/DefaultItemVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OpenRpg.Items.Variables
{
public class DefaultItemVariables : DefaultVariables<object>, IItemVariables
{
public DefaultItemVariables(IDictionary<int, object> internalVariables = null) : base(ItemVariableTypes.ItemVariables, internalVariables)
public DefaultItemVariables(IDictionary<int, object> internalVariables = null) : base(ItemCoreVariableTypes.ItemVariables, internalVariables)
{
}
}
Expand Down

0 comments on commit 77c11e1

Please sign in to comment.