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

This commit is contained in:
ImmuState 2022-06-04 11:40:58 -07:00 committed by Melledy
parent 0c0719bd2a
commit 47bcfe96f6
12 changed files with 227 additions and 24 deletions

View File

@ -0,0 +1,14 @@
syntax = "proto3";
option java_package = "emu.grasscutter.net.proto";
import "ForgeQueueManipulateType.proto";
// CmdId: 659
// EnetChannelId: 0
// EnetIsReliable: true
// IsAllowClient: true
message ForgeQueueManipulateReq {
uint32 forge_queue_id = 11;
ForgeQueueManipulateType manipulate_type = 7;
}

View File

@ -0,0 +1,17 @@
syntax = "proto3";
option java_package = "emu.grasscutter.net.proto";
import "ForgeQueueManipulateType.proto";
import "ItemParam.proto";
// CmdId: 684
// EnetChannelId: 0
// EnetIsReliable: true
message ForgeQueueManipulateRsp {
int32 retcode = 13;
ForgeQueueManipulateType manipulate_type = 8;
repeated ItemParam output_item_list = 6;
repeated ItemParam return_item_list = 10;
repeated ItemParam extra_output_item_list = 3;
}

View File

@ -0,0 +1,8 @@
syntax = "proto3";
option java_package = "emu.grasscutter.net.proto";
enum ForgeQueueManipulateType {
FORGE_QUEUE_MANIPULATE_TYPE_RECEIVE_OUTPUT = 0;
FORGE_QUEUE_MANIPULATE_TYPE_STOP_FORGE = 1;
}

13
proto/ForgeStartReq.proto Normal file
View File

@ -0,0 +1,13 @@
syntax = "proto3";
option java_package = "emu.grasscutter.net.proto";
// CmdId: 676
// EnetChannelId: 0
// EnetIsReliable: true
// IsAllowClient: true
message ForgeStartReq {
uint32 forge_id = 9;
uint32 forge_count = 11;
uint32 avatar_id = 13;
}

10
proto/ForgeStartRsp.proto Normal file
View File

@ -0,0 +1,10 @@
syntax = "proto3";
option java_package = "emu.grasscutter.net.proto";
// CmdId: 672
// EnetChannelId: 0
// EnetIsReliable: true
message ForgeStartRsp {
int32 retcode = 11;
}

View File

@ -0,0 +1,52 @@
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;
}
}

View File

@ -1,11 +1,17 @@
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));
}
}

View File

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

View File

@ -0,0 +1,23 @@
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);
}
}

View File

@ -1,30 +1,27 @@
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());
}
}

View File

@ -1,23 +1,27 @@
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());
}
}

View File

@ -0,0 +1,23 @@
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);
}
}