Skip to content

Commit e128622

Browse files
committed
fix: address PR review feedback for Epic 4.8
- Consolidate class progress updates into single variable - Extract MasterRankLevel constant to ClassProgressCollection - Add missing using statement for ClassProgressCollection Refs #39
1 parent 0f9ecda commit e128622

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/FantasyRpgWorld.Core/Domain/Components/ClassProgressCollection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace FantasyRpgWorld.Core.Domain.Components;
88
/// </summary>
99
public readonly record struct ClassProgressCollection
1010
{
11+
/// <summary>
12+
/// Master rank level threshold. Achieved when creating a Masterwork item.
13+
/// </summary>
14+
public const int MasterRankLevel = 10;
15+
1116
private readonly IReadOnlyDictionary<ClassId, ClassProgress> _progressByClass;
1217

1318
public ClassProgressCollection()

src/FantasyRpgWorld.Simulation/Systems/CraftingSystem.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FantasyRpgWorld.Core.Definitions;
2+
using FantasyRpgWorld.Core.Domain.Components;
23
using FantasyRpgWorld.Core.Domain.ValueObjects;
34
using FantasyRpgWorld.Core.Domain.World;
45
using FantasyRpgWorld.Core.Events;
@@ -62,10 +63,11 @@ public SystemUpdateResult Update(WorldState worldState, GameTime currentTime)
6263
activeCraft.WorkspaceModifier,
6364
_random);
6465

65-
// Award XP if item was produced
66+
// Consolidate all class progress updates
6667
int xpAwarded = 0;
67-
var updatedCharacter = character;
68+
var classProgress = character.ClassProgress;
6869

70+
// Award XP if item was produced
6971
if (outcomeResult.ItemProduced)
7072
{
7173
// Calculate base XP (simple formula: quality / 2)
@@ -76,35 +78,29 @@ public SystemUpdateResult Update(WorldState worldState, GameTime currentTime)
7678
xpAwarded = XpCalculator.CalculateXp(baseXp, totalLevels);
7779

7880
// Award XP to all applicable classes (classes listed in skill requirements)
79-
var classProgress = character.ClassProgress;
8081
foreach (var skillReq in recipe.SkillRequirements)
8182
{
8283
if (classProgress.HasClass(skillReq.ClassId))
8384
{
8485
classProgress = classProgress.AddXp(skillReq.ClassId, xpAwarded, out _);
8586
}
8687
}
87-
88-
updatedCharacter = updatedCharacter.WithClassProgress(classProgress);
8988
}
9089

9190
// Handle Masterwork → Master rank trigger
9291
if (outcomeResult.Outcome == CraftingOutcome.Masterwork)
9392
{
94-
const int MasterRankLevel = 10;
95-
var classProgress = updatedCharacter.ClassProgress;
96-
9793
foreach (var skillReq in recipe.SkillRequirements)
9894
{
9995
if (classProgress.HasClass(skillReq.ClassId))
10096
{
10197
int currentLevel = classProgress.GetLevel(skillReq.ClassId);
102-
if (currentLevel < MasterRankLevel)
98+
if (currentLevel < ClassProgressCollection.MasterRankLevel)
10399
{
104100
// Set character to Master rank (level 10)
105-
// Calculate XP needed to reach level 10
101+
// Calculate XP needed to reach Master rank
106102
int xpToAdd = 0;
107-
for (int level = currentLevel; level < MasterRankLevel; level++)
103+
for (int level = currentLevel; level < ClassProgressCollection.MasterRankLevel; level++)
108104
{
109105
xpToAdd += 100 * level; // XP formula from ClassProgressCollection
110106
}
@@ -120,12 +116,12 @@ public SystemUpdateResult Update(WorldState worldState, GameTime currentTime)
120116
}
121117
}
122118
}
123-
124-
updatedCharacter = updatedCharacter.WithClassProgress(classProgress);
125119
}
126120

127-
// Clear the active craft
128-
updatedCharacter = updatedCharacter.WithActiveCraft(null);
121+
// Apply all class progress changes at once
122+
var updatedCharacter = character
123+
.WithClassProgress(classProgress)
124+
.WithActiveCraft(null);
129125

130126
// Update world state
131127
updatedWorld = updatedWorld.UpdateCharacter(updatedCharacter);

tests/FantasyRpgWorld.Simulation.Tests/Systems/CraftingSystemMasterworkTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace FantasyRpgWorld.Simulation.Tests.Systems;
1414
/// </summary>
1515
public class CraftingSystemMasterworkTests
1616
{
17-
private const int MasterRankLevel = 10;
1817

1918
private static Character CreateTestCharacter(string name, ClassProgressCollection? classProgress = null)
2019
{
@@ -92,7 +91,7 @@ public void MasterworkCraft_GrantsMasterRankToNovice()
9291
var updatedCharacter = result.UpdatedWorld.GetCharacter(character.Id);
9392
Assert.NotNull(updatedCharacter);
9493
var blacksmithLevel = updatedCharacter.ClassProgress.GetLevel(new ClassId("blacksmith"));
95-
Assert.Equal(MasterRankLevel, blacksmithLevel);
94+
Assert.Equal(ClassProgressCollection.MasterRankLevel, blacksmithLevel);
9695
}
9796

9897
[Fact]
@@ -146,7 +145,7 @@ public void MasterworkCraft_WhenAlreadyMaster_DoesNotEmitDuplicateEvent()
146145
// Character with blacksmith at level 10
147146
var classProgress = new ClassProgressCollection().AddClass(new ClassId("blacksmith"));
148147
// Level up to 10
149-
for (int i = 1; i < MasterRankLevel; i++)
148+
for (int i = 1; i < ClassProgressCollection.MasterRankLevel; i++)
150149
{
151150
int xpNeeded = 100 * i; // Based on ClassProgressCollection formula
152151
classProgress = classProgress.AddXp(new ClassId("blacksmith"), xpNeeded, out _);

0 commit comments

Comments
 (0)