Commit 0e1c8dc5 authored by ImmuState's avatar ImmuState Committed by Melledy
Browse files

Cancel forging and refund items.

parent 0cc4bad1
package emu.grasscutter.game.managers.ForgingManager; package emu.grasscutter.game.managers.ForgingManager;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -221,7 +222,40 @@ public class ForgingManager { ...@@ -221,7 +222,40 @@ public class ForgingManager {
} }
private void cancelForge(int queueId) { private void cancelForge(int queueId) {
// Make sure there are no unfinished items.
int currentTime = Utils.getCurrentSeconds();
ActiveForgeData forge = this.player.getActiveForges().get(queueId - 1);
if (forge.getFinishedCount(currentTime) > 0) {
return;
}
// Return material items to the player.
ForgeData data = GameData.getForgeDataMap().get(forge.getForgeId());
var returnItems = new ArrayList<GameItem>();
for (var material : data.getMaterialItems()) {
if (material.getItemId() == 0) {
continue;
}
ItemData resultItemData = GameData.getItemDataMap().get(material.getItemId());
GameItem returnItem = new GameItem(resultItemData, material.getItemCount() * forge.getCount());
this.player.getInventory().addItem(returnItem);
returnItems.add(returnItem);
}
// Return Mora to the player.
this.player.setMora(this.player.getMora() + data.getScoinCost() * forge.getCount());
ItemData moraItem = GameData.getItemDataMap().get(202);
GameItem returnMora = new GameItem(moraItem, data.getScoinCost() * forge.getCount());
returnItems.add(returnMora);
// Send response.
this.player.sendPacket(new PacketForgeQueueManipulateRsp(Retcode.RET_SUCC, ForgeQueueManipulateType.FORGE_QUEUE_MANIPULATE_TYPE_STOP_FORGE, List.of(), returnItems, List.of()));
this.sendForgeDataNotify();
} }
public void handleForgeQueueManipulateReq(ForgeQueueManipulateReq req) { public void handleForgeQueueManipulateReq(ForgeQueueManipulateReq req) {
......
...@@ -16,7 +16,8 @@ public class PacketForgeQueueManipulateRsp extends BasePacket { ...@@ -16,7 +16,8 @@ public class PacketForgeQueueManipulateRsp extends BasePacket {
super(PacketOpcodes.ForgeQueueManipulateRsp); super(PacketOpcodes.ForgeQueueManipulateRsp);
ForgeQueueManipulateRsp.Builder builder = ForgeQueueManipulateRsp.newBuilder() ForgeQueueManipulateRsp.Builder builder = ForgeQueueManipulateRsp.newBuilder()
.setRetcode(retcode.getNumber()); .setRetcode(retcode.getNumber())
.setManipulateType(type);
for (GameItem item : output) { for (GameItem item : output) {
ItemParam toAdd = ItemParam.newBuilder() ItemParam toAdd = ItemParam.newBuilder()
......
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