-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic trade skills and a few other updates/fixes
- Loading branch information
Showing
51 changed files
with
547 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/OpenRpg.Items.TradeSkills/Calculator/ITradeSkillCalculator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/OpenRpg.Items.TradeSkills/Calculator/TradeSkillCalculator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
src/OpenRpg.Items.TradeSkills/Crafting/ItemCraftingTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
src/OpenRpg.Items.TradeSkills/Extensions/InventoryExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/OpenRpg.Items.TradeSkills/Extensions/TradeSkillItemEntryExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/OpenRpg.Items.TradeSkills/Gathering/ItemGatheringTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
src/OpenRpg.Items.TradeSkills/OpenRpg.Items.TradeSkills.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/OpenRpg.Items.TradeSkills/Types/ItemCoreVariableTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/OpenRpg.Items.TradeSkills/Types/TradeSkillItemEntryVariableTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/OpenRpg.Items.TradeSkills/Variables/DefaultItemTradeEntryVariables.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/OpenRpg.Items.TradeSkills/Variables/DefaultTradeSkillItemEntryVariables.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/OpenRpg.Items.TradeSkills/Variables/DefaultTradeSkillTemplateVariables.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.