Skip to content

Commit

Permalink
Added basic trade skills and a few other updates/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
grofit committed Sep 15, 2023
1 parent 6c60066 commit 39c1ba3
Show file tree
Hide file tree
Showing 51 changed files with 547 additions and 14 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.29.{build}
version: 0.30.{build}
branches:
only:
- master
Expand Down
5 changes: 3 additions & 2 deletions build/pack.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set version=0.19.00
set version=0.29.00
dotnet pack ../src/OpenRpg.Core -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Items -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Combat -c Release -o ../../_dist /p:version=%version%
Expand All @@ -10,4 +10,5 @@ dotnet pack ../src/OpenRpg.Quests -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Genres.Fantasy -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Cards -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.CurveFunctions -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Tags -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Tags -c Release -o ../../_dist /p:version=%version%
dotnet pack ../src/OpenRpg.Items.TradeSkills -c Release -o ../../_dist /p:version=%version%
12 changes: 12 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Calculator/ITradeSkillCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace OpenRpg.Items.TradeSkills.Calculator
{
public interface ITradeSkillCalculator
{
float MinimumPointThreshold { get; set; }
float PointMultiplier { get; set; }
float MaximumSkillDifference { get; set; }

bool CanUseSkill(int skillScore, int skillDifficulty);
int CalculateSkillUpPointsFor(int skillScore, int skillDifficulty);
}
}
36 changes: 36 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Calculator/TradeSkillCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using OpenRpg.CurveFunctions;
using OpenRpg.CurveFunctions.Scaling;
using OpenRpg.Items.TradeSkills.Calculator;

public class TradeSkillCalculator : ITradeSkillCalculator
{
public float MinimumPointThreshold { get; set; } = 0.5f;
public float PointMultiplier { get; set; } = 1.0f;
public float MaximumSkillDifference { get; set; } = 10.0f;

public IScalingFunction SkillPointCurve { get; }

public TradeSkillCalculator()
{
SkillPointCurve = new ScalingFunction(PresetCurves.InverseLinear, 0, 1, 0, MaximumSkillDifference);
}

public bool CanUseSkill(int skillScore, int skillDifficulty)
{
var skillDifference = skillDifficulty - skillScore;
var absoluteScore = Math.Abs(skillDifference);
return absoluteScore <= MaximumSkillDifference;
}

public int CalculateSkillUpPointsFor(int skillScore, int skillDifficulty)
{
var skillDifference = skillDifficulty - skillScore;
var absoluteScore = Math.Abs(skillDifference);
if (absoluteScore > MaximumSkillDifference) { return 0; }

var result = SkillPointCurve.Plot(absoluteScore);
if (result < MinimumPointThreshold) { return 0; }
return (int)Math.Round(result * PointMultiplier);
}
}
17 changes: 17 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Crafting/ItemCraftingTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace OpenRpg.Items.TradeSkills.Crafting
{
public class ItemCraftingTemplate : TradeSkillTemplate
{
/// <summary>
/// The items required to craft this template
/// </summary>
public List<TradeSkillItemEntry> InputItems { get; set; } = new List<TradeSkillItemEntry>();

/// <summary>
/// The items output from this template
/// </summary>
public List<TradeSkillItemEntry> OutputItems { get; set; } = new List<TradeSkillItemEntry>();
}
}
35 changes: 35 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Extensions/InventoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using OpenRpg.Items.Extensions;
using OpenRpg.Items.Inventory;
using OpenRpg.Items.TradeSkills.Crafting;

namespace OpenRpg.Items.TradeSkills.Extensions
{
public static class InventoryExtensions
{
public static bool HasItemsRequiredFor(this IInventory inventory, ItemCraftingTemplate craftingTemplate)
{
foreach (var itemEntry in craftingTemplate.InputItems)
{
if (itemEntry.Variables.HasAmount())
{
var amount = itemEntry.Variables.Amount();
if (!inventory.HasItem(itemEntry.ItemTemplateId, amount))
{ return false; }
}
else if (itemEntry.Variables.HasWeight())
{
var weight = itemEntry.Variables.Weight();
if (!inventory.HasItem(itemEntry.ItemTemplateId, weight))
{ return false; }
}
else
{
if (!inventory.HasItem(itemEntry.ItemTemplateId))
{ return false; }
}
}

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using OpenRpg.Items.TradeSkills.Types;
using OpenRpg.Items.TradeSkills.Variables;

namespace OpenRpg.Items.TradeSkills.Extensions
{
public static class TradeSkillItemEntryExtensions
{
public static bool HasAmount(this TradeSkillItemEntryVariables variables)
{ return variables.ContainsKey(TradeSkillItemEntryVariableTypes.Amount); }

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

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

public static bool HasWeight(this TradeSkillItemEntryVariables variables)
{ return variables.ContainsKey(TradeSkillItemEntryVariableTypes.Weight); }

public static float Weight(this TradeSkillItemEntryVariables variables) => Convert.ToSingle(variables.Get(TradeSkillItemEntryVariableTypes.Weight));
public static void Weight(this TradeSkillItemEntryVariables variables, float value) => variables[TradeSkillItemEntryVariableTypes.Weight] = value;
}
}
12 changes: 12 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Gathering/ItemGatheringTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace OpenRpg.Items.TradeSkills.Gathering
{
public class ItemGatheringTemplate : TradeSkillTemplate
{
/// <summary>
/// The items output from this template
/// </summary>
public List<TradeSkillItemEntry> OutputItems { get; set; } = new List<TradeSkillItemEntry>();
}
}
29 changes: 29 additions & 0 deletions src/OpenRpg.Items.TradeSkills/ITradeSkillTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using OpenRpg.Core.Common;
using OpenRpg.Core.Requirements;
using OpenRpg.Items.TradeSkills.Variables;

namespace OpenRpg.Items.TradeSkills
{
public interface ITradeSkillTemplate : IHasDataId, IHasRequirements
{
/// <summary>
/// Time in seconds for the action to complete i.e gathered/created
/// </summary>
public float TimeToComplete { get; }

/// <summary>
/// The category of trade skill type
/// </summary>
public int SkillType { get; }

/// <summary>
/// Indicates how difficult this is to get, effects gather/creation rates and level up rates
/// </summary>
public int SkillDifficulty { get; }

/// <summary>
/// Variables for this template
/// </summary>
public ITradeSkillTemplateVariables Variables { get; }
}
}
21 changes: 21 additions & 0 deletions src/OpenRpg.Items.TradeSkills/OpenRpg.Items.TradeSkills.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.0.0</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<Title>OpenRpg.Items.TradeSkills</Title>
<Authors>Grofit (LP)</Authors>
<PackageLicenseUrl>https://github.com/openrpg/OpenRpg/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/openrpg/OpenRpg</PackageProjectUrl>
<Description>Adds the notion of trade skills such as gathering or crafting to OpenRpg</Description>
<PackageTags>rpg game-development xna monogame unity godot</PackageTags>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\OpenRpg.CurveFunctions\OpenRpg.CurveFunctions.csproj" />
<ProjectReference Include="..\OpenRpg.Items\OpenRpg.Items.csproj" />
</ItemGroup>


</Project>
11 changes: 11 additions & 0 deletions src/OpenRpg.Items.TradeSkills/TradeSkillItemEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using OpenRpg.Items.TradeSkills.Variables;

namespace OpenRpg.Items.TradeSkills
{
public class TradeSkillItemEntry
{
public int ItemTemplateId { get; set; }

public TradeSkillItemEntryVariables Variables { get; set; } = new DefaultTradeSkillItemEntryVariables();
}
}
40 changes: 40 additions & 0 deletions src/OpenRpg.Items.TradeSkills/TradeSkillTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using OpenRpg.Core.Requirements;
using OpenRpg.Items.TradeSkills.Variables;

namespace OpenRpg.Items.TradeSkills
{
public class TradeSkillTemplate : ITradeSkillTemplate
{
/// <summary>
/// The Id for this template
/// </summary>
public int Id { get; set; }

/// <summary>
/// Gathering time in seconds, per unit gathered
/// </summary>
public float TimeToComplete { get; set; } = 1.0f;

/// <summary>
/// The category of skill type used for Gathering
/// </summary>
public int SkillType { get; set; }

/// <summary>
/// Indicates how difficult this is to get, effects if you can use the trade skill and skill up rates
/// </summary>
public int SkillDifficulty { get; set; }

/// <summary>
/// Requirements needed before this tradeskill is allowed
/// </summary>
public IEnumerable<Requirement> Requirements { get; set; } = Array.Empty<Requirement>();

/// <summary>
/// Variables for this template
/// </summary>
public ITradeSkillTemplateVariables Variables { get; set; } = new DefaultTradeSkillTemplateVariables();
}
}
9 changes: 9 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Trading/ITrader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace OpenRpg.Items.TradeSkills.Trading
{
public interface ITrader
{
IReadOnlyList<ItemTradeEntry> Items { get; }
}
}
14 changes: 14 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Trading/ItemTradeEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using OpenRpg.Items.TradeSkills.Variables;

namespace OpenRpg.Items.TradeSkills.Trading
{
public class ItemTradeEntry
{
public int ItemTemplateId { get; set; }

public float BuyRate { get; set; }
public float SellRate { get; set; }

private IItemTradeTradeEntryVariables Variables { get; set; } = new DefaultItemTradeEntryVariables();
}
}
12 changes: 12 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Types/ItemCoreVariableTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using OpenRpg.Items.Types;

namespace OpenRpg.Items.TradeSkills.Types
{
public interface TradeSkillCoreVariableTypes : ItemCoreVariableTypes
{
public static int TradeSkillTemplateVariables = 50;
public static int TraderVariables = 51;
public static int ItemTradeEntryVariables = 52;
public static int TradeSkillItemEntryVariables = 53;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OpenRpg.Items.TradeSkills.Types
{
public interface TradeSkillItemEntryVariableTypes
{
public static readonly int Unknown = 0;

public static readonly int Amount = 1;
public static readonly int Weight = 2;
}
}
7 changes: 7 additions & 0 deletions src/OpenRpg.Items.TradeSkills/Types/TradeSkillTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenRpg.Items.TradeSkills.Types
{
public interface TradeSkillTypes
{
public static readonly int Unknown = 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using OpenRpg.Core.Variables;
using OpenRpg.Items.TradeSkills.Types;

namespace OpenRpg.Items.TradeSkills.Variables
{
public class DefaultItemTradeEntryVariables : DefaultVariables<object>, IItemTradeTradeEntryVariables
{
public DefaultItemTradeEntryVariables(IDictionary<int, object> internalVariables = null) : base(TradeSkillCoreVariableTypes.ItemTradeEntryVariables, internalVariables)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using OpenRpg.Core.Variables;
using OpenRpg.Items.TradeSkills.Types;

namespace OpenRpg.Items.TradeSkills.Variables
{
public class DefaultTradeSkillItemEntryVariables : DefaultVariables<object>, TradeSkillItemEntryVariables
{
public DefaultTradeSkillItemEntryVariables(IDictionary<int, object> internalVariables = null) : base(TradeSkillCoreVariableTypes.TradeSkillItemEntryVariables, internalVariables)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using OpenRpg.Core.Variables;
using OpenRpg.Items.TradeSkills.Types;
using OpenRpg.Items.Types;

namespace OpenRpg.Items.TradeSkills.Variables
{
public class DefaultTradeSkillTemplateVariables : DefaultVariables<object>, ITradeSkillTemplateVariables
{
public DefaultTradeSkillTemplateVariables(IDictionary<int, object> internalVariables = null) : base(TradeSkillCoreVariableTypes.TradeSkillTemplateVariables, internalVariables)
{
}
}
}
Loading

0 comments on commit 39c1ba3

Please sign in to comment.