From 2ed8aaffc6ccb2456b4c1d9c579ece05e0ab8322 Mon Sep 17 00:00:00 2001 From: hz Date: Sun, 8 Jun 2025 21:46:01 -0500 Subject: [PATCH] Spawnables now contain configuration for CollectAction outcomes --- Controllers/SpawnableController.cs | 3 ++- GameAuthApi.Tests/SpawnableControllerTests.cs | 13 +++++++++++-- Models/CollectOutcome.cs | 7 +++++++ Models/DTOs/CreateSpawnableRequest.cs | 5 +++++ Models/Spawnable.cs | 4 ++++ README.md | 14 +++++++++++++- 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 Models/CollectOutcome.cs diff --git a/Controllers/SpawnableController.cs b/Controllers/SpawnableController.cs index 314bd24..ca5229b 100644 --- a/Controllers/SpawnableController.cs +++ b/Controllers/SpawnableController.cs @@ -25,7 +25,8 @@ public class SpawnableController : ControllerBase { Name = req.Name.ToLower(), SpawnRate = req.SpawnRate, - CollectAction = req.CollectAction + CollectAction = req.CollectAction, + CollectResults = req.CollectResults }; await _spawnableService.CreateAsync(spawnable); diff --git a/GameAuthApi.Tests/SpawnableControllerTests.cs b/GameAuthApi.Tests/SpawnableControllerTests.cs index c18e7ba..9d383c5 100644 --- a/GameAuthApi.Tests/SpawnableControllerTests.cs +++ b/GameAuthApi.Tests/SpawnableControllerTests.cs @@ -17,7 +17,11 @@ public class SpawnableControllerTests public async Task Create_ReturnsOk() { var svc = new Mock(config); - svc.Setup(s => s.CreateAsync(It.Is(sp => sp.CollectAction == "gather"))) + svc.Setup(s => s.CreateAsync(It.Is(sp => + sp.CollectAction == "gather" && + sp.CollectResults.Count == 2 && + sp.CollectResults[0].Result == "resource" && + sp.CollectResults[0].SuccessRate == 75))) .Returns(Task.CompletedTask).Verifiable(); var controller = new SpawnableController(svc.Object); @@ -25,7 +29,12 @@ public class SpawnableControllerTests { Name = "item", SpawnRate = 50, - CollectAction = "gather" + CollectAction = "gather", + CollectResults = new List + { + new() { Result = "resource", SuccessRate = 75 }, + new() { Result = "nothing", SuccessRate = 25 } + } }); Assert.IsType(result); diff --git a/Models/CollectOutcome.cs b/Models/CollectOutcome.cs new file mode 100644 index 0000000..166ecb4 --- /dev/null +++ b/Models/CollectOutcome.cs @@ -0,0 +1,7 @@ +namespace GameAuthApi.Models; + +public class CollectOutcome +{ + public string Result { get; set; } + public int SuccessRate { get; set; } +} diff --git a/Models/DTOs/CreateSpawnableRequest.cs b/Models/DTOs/CreateSpawnableRequest.cs index c5fcd2c..6d4ddcb 100644 --- a/Models/DTOs/CreateSpawnableRequest.cs +++ b/Models/DTOs/CreateSpawnableRequest.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace GameAuthApi.Models; public class CreateSpawnableRequest @@ -7,4 +9,7 @@ public class CreateSpawnableRequest // Action players must perform to collect the item public string CollectAction { get; set; } + + // Possible outcomes of collecting the item + public List CollectResults { get; set; } = []; } diff --git a/Models/Spawnable.cs b/Models/Spawnable.cs index 6b2c96e..2e34d46 100644 --- a/Models/Spawnable.cs +++ b/Models/Spawnable.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using System.Collections.Generic; namespace GameAuthApi.Models; @@ -14,4 +15,7 @@ public class Spawnable // Action required by the player to collect this spawnable item public string CollectAction { get; set; } + + // Possible outcomes of collecting this item + public List CollectResults { get; set; } = []; } diff --git a/README.md b/README.md index ab47ad8..91ac8e0 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,16 @@ dotnet publish -c Release sudo systemctl restart gameapi.service # Check logs -journalctl -u gameapi.service -b --no-pager --lines=100 \ No newline at end of file +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. \ No newline at end of file