mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 13:37:42 +00:00
Move forging stuff to ForgingManager, make client respond to ForgeGetQueueDataReq and actually display forging queues.
This commit is contained in:
parent
662c9d4ec2
commit
0c0719bd2a
14
proto/ForgeGetQueueDataRsp.proto
Normal file
14
proto/ForgeGetQueueDataRsp.proto
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "emu.grasscutter.net.proto";
|
||||||
|
|
||||||
|
import "ForgeQueueData.proto";
|
||||||
|
|
||||||
|
// CmdId: 628
|
||||||
|
// EnetChannelId: 0
|
||||||
|
// EnetIsReliable: true
|
||||||
|
message ForgeGetQueueDataRsp {
|
||||||
|
int32 retcode = 15;
|
||||||
|
uint32 max_queue_num = 13;
|
||||||
|
map<uint32, ForgeQueueData> forge_queue_map = 11;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package emu.grasscutter.game.managers.ForgingManager;
|
||||||
|
|
||||||
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
|
import emu.grasscutter.game.player.Player;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class ForgingManager {
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
|
public ForgingManager(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********
|
||||||
|
Blueprint unlocking.
|
||||||
|
**********/
|
||||||
|
public boolean unlockForgingBlueprint(GameItem blueprintItem) {
|
||||||
|
// Make sure this is actually a forging blueprint.
|
||||||
|
if (!blueprintItem.getItemData().getItemUse().get(0).getUseOp().equals("ITEM_USE_UNLOCK_FORGE")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the forging item we should unlock.
|
||||||
|
int forgeId = Integer.parseInt(blueprintItem.getItemData().getItemUse().get(0).getUseParam().get(0));
|
||||||
|
|
||||||
|
// Tell the client that this blueprint is now unlocked and add the unlocked item to the player.
|
||||||
|
this.player.sendPacket(new PacketForgeFormulaDataNotify(forgeId));
|
||||||
|
this.player.getUnlockedForgingBlueprints().add(forgeId);
|
||||||
|
|
||||||
|
// Done.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********
|
||||||
|
Communicate forging information to the client.
|
||||||
|
**********/
|
||||||
|
private int determineNumberOfQueues() {
|
||||||
|
int adventureRank = player.getLevel();
|
||||||
|
return
|
||||||
|
(adventureRank >= 15) ? 4
|
||||||
|
: (adventureRank >= 10) ? 3
|
||||||
|
: (adventureRank >= 5) ? 2
|
||||||
|
: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendForgeDataNotify() {
|
||||||
|
// Determine the number of queues and unlocked items.
|
||||||
|
int numQueues = this.determineNumberOfQueues();
|
||||||
|
var unlockedItems = this.player.getUnlockedForgingBlueprints();
|
||||||
|
|
||||||
|
// Send notification.
|
||||||
|
this.player.sendPacket(new PacketForgeDataNotify(unlockedItems, numQueues));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleForgeGetQueueDataReq() {
|
||||||
|
// Determine the number of queues.
|
||||||
|
int numQueues = this.determineNumberOfQueues();
|
||||||
|
|
||||||
|
// Reply.
|
||||||
|
this.player.sendPacket(new PacketForgeGetQueueDataRsp(Retcode.RET_SUCC, numQueues));
|
||||||
|
}
|
||||||
|
}
|
@ -852,16 +852,14 @@ public class InventoryManager {
|
|||||||
|
|
||||||
// Handle forging blueprints.
|
// Handle forging blueprints.
|
||||||
if (useItem.getItemData().getItemUse().get(0).getUseOp().equals("ITEM_USE_UNLOCK_FORGE")) {
|
if (useItem.getItemData().getItemUse().get(0).getUseOp().equals("ITEM_USE_UNLOCK_FORGE")) {
|
||||||
// Determine the forging item we should unlock.
|
// Unlock.
|
||||||
int forgeId = Integer.parseInt(useItem.getItemData().getItemUse().get(0).getUseParam().get(0));
|
boolean success = player.getForgingManager().unlockForgingBlueprint(useItem);
|
||||||
|
|
||||||
// Tell the client that this blueprint is now unlocked and add the unlocked item to the player.
|
// Use up the blueprint item if successful.
|
||||||
player.sendPacket(new PacketForgeFormulaDataNotify(forgeId));
|
if (success) {
|
||||||
player.getUnlockedForgingBlueprints().add(forgeId);
|
|
||||||
|
|
||||||
// Use up the blueprint item.
|
|
||||||
used = 1;
|
used = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MATERIAL_CHEST:
|
case MATERIAL_CHEST:
|
||||||
List<ShopChestTable> shopChestTableList = player.getServer().getShopManager().getShopChestData();
|
List<ShopChestTable> shopChestTableList = player.getServer().getShopManager().getShopChestData();
|
||||||
|
@ -30,6 +30,7 @@ import emu.grasscutter.game.managers.InsectCaptureManager;
|
|||||||
import emu.grasscutter.game.managers.StaminaManager.StaminaManager;
|
import emu.grasscutter.game.managers.StaminaManager.StaminaManager;
|
||||||
import emu.grasscutter.game.managers.SotSManager;
|
import emu.grasscutter.game.managers.SotSManager;
|
||||||
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
|
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
|
||||||
|
import emu.grasscutter.game.managers.ForgingManager.ForgingManager;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
import emu.grasscutter.game.props.EntityType;
|
import emu.grasscutter.game.props.EntityType;
|
||||||
import emu.grasscutter.game.props.PlayerProperty;
|
import emu.grasscutter.game.props.PlayerProperty;
|
||||||
@ -153,6 +154,7 @@ public class Player {
|
|||||||
@Transient private MapMarksManager mapMarksManager;
|
@Transient private MapMarksManager mapMarksManager;
|
||||||
@Transient private StaminaManager staminaManager;
|
@Transient private StaminaManager staminaManager;
|
||||||
@Transient private EnergyManager energyManager;
|
@Transient private EnergyManager energyManager;
|
||||||
|
@Transient private ForgingManager forgingManager;
|
||||||
@Transient private DeforestationManager deforestationManager;
|
@Transient private DeforestationManager deforestationManager;
|
||||||
|
|
||||||
private long springLastUsed;
|
private long springLastUsed;
|
||||||
@ -209,6 +211,7 @@ public class Player {
|
|||||||
this.staminaManager = new StaminaManager(this);
|
this.staminaManager = new StaminaManager(this);
|
||||||
this.sotsManager = new SotSManager(this);
|
this.sotsManager = new SotSManager(this);
|
||||||
this.energyManager = new EnergyManager(this);
|
this.energyManager = new EnergyManager(this);
|
||||||
|
this.forgingManager = new ForgingManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// On player creation
|
// On player creation
|
||||||
@ -240,6 +243,7 @@ public class Player {
|
|||||||
this.sotsManager = new SotSManager(this);
|
this.sotsManager = new SotSManager(this);
|
||||||
this.energyManager = new EnergyManager(this);
|
this.energyManager = new EnergyManager(this);
|
||||||
this.deforestationManager = new DeforestationManager(this);
|
this.deforestationManager = new DeforestationManager(this);
|
||||||
|
this.forgingManager = new ForgingManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUid() {
|
public int getUid() {
|
||||||
@ -1120,6 +1124,10 @@ public class Player {
|
|||||||
return this.energyManager;
|
return this.energyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ForgingManager getForgingManager() {
|
||||||
|
return this.forgingManager;
|
||||||
|
}
|
||||||
|
|
||||||
public AbilityManager getAbilityManager() {
|
public AbilityManager getAbilityManager() {
|
||||||
return abilityManager;
|
return abilityManager;
|
||||||
}
|
}
|
||||||
@ -1265,7 +1273,7 @@ public class Player {
|
|||||||
session.send(new PacketWidgetGadgetAllDataNotify());
|
session.send(new PacketWidgetGadgetAllDataNotify());
|
||||||
session.send(new PacketPlayerHomeCompInfoNotify(this));
|
session.send(new PacketPlayerHomeCompInfoNotify(this));
|
||||||
session.send(new PacketHomeComfortInfoNotify(this));
|
session.send(new PacketHomeComfortInfoNotify(this));
|
||||||
session.send(new PacketForgeDataNotify(this));
|
this.forgingManager.sendForgeDataNotify();
|
||||||
|
|
||||||
getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward.
|
getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward.
|
||||||
|
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package emu.grasscutter.server.packet.recv;
|
||||||
|
|
||||||
|
import emu.grasscutter.net.packet.Opcodes;
|
||||||
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
|
import emu.grasscutter.net.packet.PacketHandler;
|
||||||
|
import emu.grasscutter.server.game.GameSession;
|
||||||
|
|
||||||
|
@Opcodes(PacketOpcodes.ForgeGetQueueDataReq)
|
||||||
|
public class HandlerForgeGetQueueDataReq extends PacketHandler {
|
||||||
|
@Override
|
||||||
|
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||||
|
session.getPlayer().getForgingManager().handleForgeGetQueueDataReq();
|
||||||
|
}
|
||||||
|
}
|
@ -7,18 +7,18 @@ import emu.grasscutter.net.proto.ForgeDataNotifyOuterClass.ForgeDataNotify;
|
|||||||
|
|
||||||
public class PacketForgeDataNotify extends BasePacket {
|
public class PacketForgeDataNotify extends BasePacket {
|
||||||
|
|
||||||
public PacketForgeDataNotify(Player player) {
|
public PacketForgeDataNotify(Iterable<Integer> unlockedItem, int numQueues) {
|
||||||
super(PacketOpcodes.ForgeDataNotify);
|
super(PacketOpcodes.ForgeDataNotify);
|
||||||
|
|
||||||
int adventureRank = player.getLevel();
|
/*int adventureRank = player.getLevel();
|
||||||
int numQueues =
|
int numQueues =
|
||||||
(adventureRank >= 15) ? 4
|
(adventureRank >= 15) ? 4
|
||||||
: (adventureRank >= 10) ? 3
|
: (adventureRank >= 10) ? 3
|
||||||
: (adventureRank >= 5) ? 2
|
: (adventureRank >= 5) ? 2
|
||||||
: 1;
|
: 1;*/
|
||||||
|
|
||||||
ForgeDataNotify proto = ForgeDataNotify.newBuilder()
|
ForgeDataNotify proto = ForgeDataNotify.newBuilder()
|
||||||
.addAllForgeIdList(player.getUnlockedForgingBlueprints())
|
.addAllForgeIdList(unlockedItem)
|
||||||
.setMaxQueueNum(numQueues)
|
.setMaxQueueNum(numQueues)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package emu.grasscutter.server.packet.send;
|
||||||
|
|
||||||
|
import emu.grasscutter.net.packet.BasePacket;
|
||||||
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
|
import emu.grasscutter.net.proto.ForgeGetQueueDataRspOuterClass.ForgeGetQueueDataRsp;
|
||||||
|
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
||||||
|
|
||||||
|
public class PacketForgeGetQueueDataRsp extends BasePacket {
|
||||||
|
|
||||||
|
public PacketForgeGetQueueDataRsp(Retcode retcode, int numQueues) {
|
||||||
|
super(PacketOpcodes.ForgeGetQueueDataRsp);
|
||||||
|
|
||||||
|
ForgeGetQueueDataRsp proto = ForgeGetQueueDataRsp.newBuilder()
|
||||||
|
.setRetcode(retcode.getNumber())
|
||||||
|
.setMaxQueueNum(numQueues)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// ToDo: Add the information for the actual forging queues
|
||||||
|
// and ongoing forges.
|
||||||
|
|
||||||
|
this.setData(proto);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user