Allowing player to gather resources
This commit is contained in:
@@ -46,7 +46,14 @@ Outbound JSON documents
|
||||
"coord": {
|
||||
"x": "number",
|
||||
"y": "number"
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"itemKey": "wood",
|
||||
"remainingQuantity": 100,
|
||||
"gatherQuantity": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
@@ -15,4 +15,7 @@ public class VisibleLocation
|
||||
|
||||
[BsonElement("coord")]
|
||||
public LocationCoord Coord { get; set; } = new();
|
||||
|
||||
[BsonElement("resources")]
|
||||
public List<VisibleLocationResource> Resources { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -140,10 +140,34 @@ public class CharacterStore
|
||||
{
|
||||
X = coord.GetValue("x", 0).ToInt32(),
|
||||
Y = coord.GetValue("y", 0).ToInt32()
|
||||
}
|
||||
},
|
||||
Resources = MapVisibleLocationResources(document)
|
||||
};
|
||||
}
|
||||
|
||||
private static List<VisibleLocationResource> MapVisibleLocationResources(BsonDocument document)
|
||||
{
|
||||
if (!document.TryGetValue("resources", out var resourcesValue) || resourcesValue.BsonType != BsonType.Array)
|
||||
return [];
|
||||
|
||||
var results = new List<VisibleLocationResource>();
|
||||
foreach (var value in resourcesValue.AsBsonArray)
|
||||
{
|
||||
if (value.BsonType != BsonType.Document)
|
||||
continue;
|
||||
|
||||
var resource = value.AsBsonDocument;
|
||||
results.Add(new VisibleLocationResource
|
||||
{
|
||||
ItemKey = resource.GetValue("itemKey", "").AsString,
|
||||
RemainingQuantity = resource.GetValue("remainingQuantity", 0).ToInt32(),
|
||||
GatherQuantity = resource.GetValue("gatherQuantity", 1).ToInt32()
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private void EnsureLocationCoordIndexes()
|
||||
{
|
||||
var indexes = _locations.Indexes.List().ToList();
|
||||
|
||||
Reference in New Issue
Block a user