Implement material crafting

This commit is contained in:
Melledy
2025-10-30 19:33:07 -07:00
parent 489b88ea4a
commit 00b77e80e1
5 changed files with 95 additions and 3 deletions

View File

@@ -296,6 +296,36 @@ public class Inventory extends PlayerManager {
return hasItems;
}
// Utility functions
public PlayerChangeInfo produce(int id, int num) {
// Get production data
var data = GameData.getProductionDataTable().get(id);
if (data == null) {
return null;
}
// Get materials
var materials = data.getMaterials().mulitply(num);
// Verify that we have the materials
if (!this.verifyItems(materials)) {
return null;
}
// Create change info
var changes = new PlayerChangeInfo();
// Remove items
this.removeItems(materials, changes);
// Add produced items
this.addItem(data.getProductionId(), data.getProductionPerBatch() * num, changes);
// Success
return changes.setSuccess(true);
}
// Database
public void loadFromDatabase() {