Spawnables now contain configuration for CollectAction outcomes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -17,7 +17,11 @@ public class SpawnableControllerTests
|
||||
public async Task Create_ReturnsOk()
|
||||
{
|
||||
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();
|
||||
var controller = new SpawnableController(svc.Object);
|
||||
|
||||
@@ -25,7 +29,12 @@ public class SpawnableControllerTests
|
||||
{
|
||||
Name = "item",
|
||||
SpawnRate = 50,
|
||||
CollectAction = "gather"
|
||||
CollectAction = "gather",
|
||||
CollectResults = new List<CollectOutcome>
|
||||
{
|
||||
new() { Result = "resource", SuccessRate = 75 },
|
||||
new() { Result = "nothing", SuccessRate = 25 }
|
||||
}
|
||||
});
|
||||
|
||||
Assert.IsType<OkObjectResult>(result);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace GameAuthApi.Models;
|
||||
|
||||
public class CollectOutcome
|
||||
{
|
||||
public string Result { get; set; }
|
||||
public int SuccessRate { get; set; }
|
||||
}
|
||||
@@ -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<CollectOutcome> CollectResults { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -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<CollectOutcome> CollectResults { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -7,4 +7,16 @@ dotnet publish -c Release
|
||||
sudo systemctl restart gameapi.service
|
||||
|
||||
# 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.
|
||||
Reference in New Issue
Block a user