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

@@ -31,7 +31,8 @@ public class GameData {
@Getter private static DataTable<DiscPromoteLimitDef> DiscPromoteLimitDataTable = new DataTable<>();
@Getter private static DataTable<ItemDef> ItemDataTable = new DataTable<>();
@Getter private static DataTable<ProductionDef> ProductionDataTable = new DataTable<>();
@Getter private static DataTable<MallMonthlyCardDef> MallMonthlyCardDataTable = new DataTable<>();
@Getter private static DataTable<MallPackageDef> MallPackageDataTable = new DataTable<>();
@Getter private static DataTable<MallShopDef> MallShopDataTable = new DataTable<>();

View File

@@ -3,13 +3,12 @@ package emu.nebula.data.resources;
import emu.nebula.GameConstants;
import emu.nebula.data.BaseDef;
import emu.nebula.data.ResourceType;
import emu.nebula.data.ResourceType.LoadPriority;
import emu.nebula.game.inventory.ItemParamMap;
import lombok.Getter;
@Getter
@ResourceType(name = "CharacterSkillUpgrade.json", loadPriority = LoadPriority.LOW)
@ResourceType(name = "CharacterSkillUpgrade.json")
public class CharacterSkillUpgradeDef extends BaseDef {
private int Group;
private int AdvanceNum;

View File

@@ -0,0 +1,34 @@
package emu.nebula.data.resources;
import emu.nebula.data.BaseDef;
import emu.nebula.data.ResourceType;
import emu.nebula.game.inventory.ItemParamMap;
import lombok.Getter;
@Getter
@ResourceType(name = "Production.json")
public class ProductionDef extends BaseDef {
private int Id;
private int UnlockWorldLevel;
private int ProductionId;
private int ProductionPerBatch;
private int RawMaterialId1;
private int RawMaterialCount1;
private transient ItemParamMap materials;
@Override
public int getId() {
return Id;
}
@Override
public void onLoad() {
this.materials = new ItemParamMap();
if (this.RawMaterialId1 > 0) {
this.materials.add(this.RawMaterialId1, this.RawMaterialCount1);
}
}
}

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() {

View File

@@ -0,0 +1,28 @@
package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.ItemProduct.ItemProductReq;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.item_product_req)
public class HandlerItemProductReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse request
var req = ItemProductReq.parseFrom(message);
// Produce item
var changes = session.getPlayer().getInventory().produce(req.getId(), req.getNum());
if (changes == null) {
return this.encodeMsg(NetMsgId.item_product_failed_ack);
}
// Send response
return this.encodeMsg(NetMsgId.item_product_succeed_ack, changes.toProto());
}
}