Commit 8db0500e authored by ImmuState's avatar ImmuState Committed by Melledy
Browse files

Add missing forging protos, add data for ongoing forges to player, handler for ForgeStartReq.

parent 3fc63c2c
package emu.grasscutter.game.managers.ForgingManager;
import dev.morphia.annotations.Entity;
@Entity
public class ActiveForgeData {
private int queueId;
private int forgeId;
private int avatarId;
private int startTime;
private int forgeTime;
// private int finishedCount;
// private int unfinishedCount;
// private int nextFinishTimestamp;
// private int totalFinishTimestamp;
public int getQueueId() {
return this.queueId;
}
public void setQueueId(int value) {
this.queueId = value;
}
public int getForgeId() {
return this.forgeId;
}
public void setForgeId(int value) {
this.forgeId = value;
}
public int getAvatarId() {
return this.avatarId;
}
public void setAvatarId(int value) {
this.avatarId = value;
}
public int getStartTime() {
return this.startTime;
}
public void setStartTime(int value) {
this.startTime = value;
}
public int getForgeTime() {
return this.forgeTime;
}
public void setForgeTime(int value) {
this.forgeTime = value;
}
}
package emu.grasscutter.game.managers.ForgingManager;
import java.util.HashMap;
import java.util.Map;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.ForgeStartReqOuterClass;
import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import emu.grasscutter.server.packet.send.PacketForgeDataNotify;
import emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify;
import emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp;
import emu.grasscutter.server.packet.send.PacketForgeStartRsp;
public class ForgingManager {
private final Player player;
......@@ -46,20 +52,49 @@ public class ForgingManager {
: 1;
}
private Map<Integer, ForgeQueueData> determineCurrentForgeQueueData() {
// Dummy for now.
ForgeQueueData data = ForgeQueueData.newBuilder()
.setQueueId(1)
.setForgeId(11001)
.setFinishCount(2)
.setUnfinishCount(3)
.setNextFinishTimestamp(0)
.setNextFinishTimestamp(0)
.setAvatarId(0)
.build();
Map<Integer, ForgeQueueData> res = new HashMap<>();
res.put(1, data);
return res;
}
public void sendForgeDataNotify() {
// Determine the number of queues and unlocked items.
int numQueues = this.determineNumberOfQueues();
var unlockedItems = this.player.getUnlockedForgingBlueprints();
var queueData = this.determineCurrentForgeQueueData();
// Send notification.
this.player.sendPacket(new PacketForgeDataNotify(unlockedItems, numQueues));
this.player.sendPacket(new PacketForgeDataNotify(unlockedItems, numQueues, queueData));
}
public void handleForgeGetQueueDataReq() {
// Determine the number of queues.
int numQueues = this.determineNumberOfQueues();
var queueData = this.determineCurrentForgeQueueData();
// Reply.
this.player.sendPacket(new PacketForgeGetQueueDataRsp(Retcode.RET_SUCC, numQueues));
this.player.sendPacket(new PacketForgeGetQueueDataRsp(Retcode.RET_SUCC, numQueues, queueData));
}
/**********
Initiate forging process.
**********/
public void startForging(ForgeStartReqOuterClass.ForgeStartReq req) {
// Dummy for now.
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_SUCC));
}
}
......@@ -30,6 +30,7 @@ import emu.grasscutter.game.managers.InsectCaptureManager;
import emu.grasscutter.game.managers.StaminaManager.StaminaManager;
import emu.grasscutter.game.managers.SotSManager;
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
import emu.grasscutter.game.managers.ForgingManager.ActiveForgeData;
import emu.grasscutter.game.managers.ForgingManager.ForgingManager;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.EntityType;
......@@ -92,6 +93,7 @@ public class Player {
private Set<Integer> flyCloakList;
private Set<Integer> costumeList;
private Set<Integer> unlockedForgingBlueprints;
private Map<Integer, ActiveForgeData> activeForges;
private Integer widgetId;
......@@ -188,6 +190,7 @@ public class Player {
this.flyCloakList = new HashSet<>();
this.costumeList = new HashSet<>();
this.unlockedForgingBlueprints = new HashSet<>();
this.activeForges = new HashMap<>();
this.setSceneId(3);
this.setRegionId(1);
......@@ -523,7 +526,11 @@ public class Player {
}
public Set<Integer> getUnlockedForgingBlueprints() {
return unlockedForgingBlueprints;
return this.unlockedForgingBlueprints;
}
public Map<Integer, ActiveForgeData> getActiveForges() {
return this.activeForges;
}
public MpSettingType getMpSetting() {
......
package emu.grasscutter.server.packet.recv;
import java.lang.invoke.StringConcatFactory;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ForgeStartReqOuterClass;
import emu.grasscutter.net.proto.DeleteFriendReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketDelMailRsp;
@Opcodes(PacketOpcodes.ForgeStartReq)
public class HandlerForgeStartReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
ForgeStartReqOuterClass.ForgeStartReq req = ForgeStartReqOuterClass.ForgeStartReq.parseFrom(payload);
session.getPlayer().getForgingManager().startForging(req);
}
}
package emu.grasscutter.server.packet.send;
import java.util.Map;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ForgeDataNotifyOuterClass.ForgeDataNotify;
import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData;
public class PacketForgeDataNotify extends BasePacket {
public PacketForgeDataNotify(Iterable<Integer> unlockedItem, int numQueues) {
public PacketForgeDataNotify(Iterable<Integer> unlockedItem, int numQueues, Map<Integer, ForgeQueueData> queueData) {
super(PacketOpcodes.ForgeDataNotify);
/*int adventureRank = player.getLevel();
int numQueues =
(adventureRank >= 15) ? 4
: (adventureRank >= 10) ? 3
: (adventureRank >= 5) ? 2
: 1;*/
ForgeDataNotify proto = ForgeDataNotify.newBuilder()
ForgeDataNotify.Builder builder = ForgeDataNotify.newBuilder()
.addAllForgeIdList(unlockedItem)
.setMaxQueueNum(numQueues)
.build();
.setMaxQueueNum(numQueues);
// ToDo: Add the information for the actual forging queues
// and ongoing forges.
for (int queueId : queueData.keySet()) {
var data = queueData.get(queueId);
builder.putForgeQueueMap(queueId, data);
}
this.setData(proto);
this.setData(builder.build());
}
}
package emu.grasscutter.server.packet.send;
import java.util.Map;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ForgeGetQueueDataRspOuterClass.ForgeGetQueueDataRsp;
import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
public class PacketForgeGetQueueDataRsp extends BasePacket {
public PacketForgeGetQueueDataRsp(Retcode retcode, int numQueues) {
public PacketForgeGetQueueDataRsp(Retcode retcode, int numQueues, Map<Integer, ForgeQueueData> queueData) {
super(PacketOpcodes.ForgeGetQueueDataRsp);
ForgeGetQueueDataRsp proto = ForgeGetQueueDataRsp.newBuilder()
ForgeGetQueueDataRsp.Builder builder = ForgeGetQueueDataRsp.newBuilder()
.setRetcode(retcode.getNumber())
.setMaxQueueNum(numQueues)
.build();
.setMaxQueueNum(numQueues);
// ToDo: Add the information for the actual forging queues
// and ongoing forges.
for (int queueId : queueData.keySet()) {
var data = queueData.get(queueId);
builder.putForgeQueueMap(queueId, data);
}
this.setData(proto);
this.setData(builder.build());
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ForgeStartRspOuterClass.ForgeStartRsp;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import java.util.ArrayList;
import java.util.List;
public class PacketForgeStartRsp extends BasePacket {
public PacketForgeStartRsp(Retcode retcode) {
super(PacketOpcodes.ForgeStartRsp);
ForgeStartRsp proto = ForgeStartRsp.newBuilder()
.setRetcode(retcode.getNumber())
.build();
this.setData(proto);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment