Spawnables now contain configuration for CollectAction outcomes

This commit is contained in:
hz
2025-06-08 21:46:01 -05:00
parent 22eb487aaa
commit 2ed8aaffc6
6 changed files with 42 additions and 4 deletions
+2 -1
View File
@@ -25,7 +25,8 @@ public class SpawnableController : ControllerBase
{ {
Name = req.Name.ToLower(), Name = req.Name.ToLower(),
SpawnRate = req.SpawnRate, SpawnRate = req.SpawnRate,
CollectAction = req.CollectAction CollectAction = req.CollectAction,
CollectResults = req.CollectResults
}; };
await _spawnableService.CreateAsync(spawnable); await _spawnableService.CreateAsync(spawnable);
+11 -2
View File
@@ -17,7 +17,11 @@ public class SpawnableControllerTests
public async Task Create_ReturnsOk() public async Task Create_ReturnsOk()
{ {
var svc = new Mock<SpawnableService>(config); var svc = new Mock<SpawnableService>(config);
svc.Setup(s => s.CreateAsync(It.Is<Spawnable>(sp => sp.CollectAction == "gather"))) svc.Setup(s => s.CreateAsync(It.Is<Spawnable>(sp =>
sp.CollectAction == "gather" &&
sp.CollectResults.Count == 2 &&
sp.CollectResults[0].Result == "resource" &&
sp.CollectResults[0].SuccessRate == 75)))
.Returns(Task.CompletedTask).Verifiable(); .Returns(Task.CompletedTask).Verifiable();
var controller = new SpawnableController(svc.Object); var controller = new SpawnableController(svc.Object);
@@ -25,7 +29,12 @@ public class SpawnableControllerTests
{ {
Name = "item", Name = "item",
SpawnRate = 50, SpawnRate = 50,
CollectAction = "gather" CollectAction = "gather",
CollectResults = new List<CollectOutcome>
{
new() { Result = "resource", SuccessRate = 75 },
new() { Result = "nothing", SuccessRate = 25 }
}
}); });
Assert.IsType<OkObjectResult>(result); Assert.IsType<OkObjectResult>(result);
+7
View File
@@ -0,0 +1,7 @@
namespace GameAuthApi.Models;
public class CollectOutcome
{
public string Result { get; set; }
public int SuccessRate { get; set; }
}
+5
View File
@@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace GameAuthApi.Models; namespace GameAuthApi.Models;
public class CreateSpawnableRequest public class CreateSpawnableRequest
@@ -7,4 +9,7 @@ public class CreateSpawnableRequest
// Action players must perform to collect the item // Action players must perform to collect the item
public string CollectAction { get; set; } public string CollectAction { get; set; }
// Possible outcomes of collecting the item
public List<CollectOutcome> CollectResults { get; set; } = [];
} }
+4
View File
@@ -1,5 +1,6 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using System.Collections.Generic;
namespace GameAuthApi.Models; namespace GameAuthApi.Models;
@@ -14,4 +15,7 @@ public class Spawnable
// Action required by the player to collect this spawnable item // Action required by the player to collect this spawnable item
public string CollectAction { get; set; } public string CollectAction { get; set; }
// Possible outcomes of collecting this item
public List<CollectOutcome> CollectResults { get; set; } = [];
} }
+13 -1
View File
@@ -7,4 +7,16 @@ dotnet publish -c Release
sudo systemctl restart gameapi.service sudo systemctl restart gameapi.service
# Check logs # Check logs
journalctl -u gameapi.service -b --no-pager --lines=100 journalctl -u gameapi.service -b --no-pager --lines=100
## Spawnables
Spawnables describe items that can appear in the world. Along with the
name and spawn rate, they now specify how the item behaves when a player
performs the required collect action.
- **CollectAction** – the action a player must perform.
- **CollectResults** – a list of possible outcomes when the collect action
succeeds. Each entry defines:
- **Result** – textual description of the outcome.
- **SuccessRate** – percentage chance (0-100) for that outcome.