Commit 5db5c90a authored by ImmuState's avatar ImmuState Committed by Melledy
Browse files

Start a new forge (no checking for now).

parent e5498e37
...@@ -368,4 +368,8 @@ public class GameData { ...@@ -368,4 +368,8 @@ public class GameData {
public static Int2ObjectMap<QuestData> getQuestDataMap() { public static Int2ObjectMap<QuestData> getQuestDataMap() {
return questDataMap; return questDataMap;
} }
public static Int2ObjectMap<ForgeData> getForgeDataMap() {
return forgeDataMap;
}
} }
package emu.grasscutter.game.managers.ForgingManager; package emu.grasscutter.game.managers.ForgingManager;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.grasscutter.utils.Utils;
@Entity @Entity
public class ActiveForgeData { public class ActiveForgeData {
private int forgeId; private int forgeId;
private int avatarId; private int avatarId;
private int count;
private int startTime;
private int forgeTime; private int startTime;
// private int finishedCount; private int forgeTime;
// private int unfinishedCount; // private int finishedCount;
// private int nextFinishTimestamp; // private int unfinishedCount;
// private int totalFinishTimestamp; // private int nextFinishTimestamp;
// private int totalFinishTimestamp;
public int getForgeId() {
return this.forgeId;
} public int getFinishedCount(int currentTime) {
public void setForgeId(int value) { int timeDelta = currentTime - this.startTime;
this.forgeId = value; int finishedCount = (int)Math.floor(timeDelta / this.forgeTime);
}
return Math.min(finishedCount, this.count);
public int getAvatarId() { }
return this.avatarId;
} public int getUnfinishedCount(int currentTime) {
public void setAvatarId(int value) { return this.count - this.getFinishedCount(currentTime);
this.avatarId = value; }
}
public int getNextFinishTimestamp(int currentTime) {
public int getStartTime() { return
return this.startTime; (currentTime >= this.getTotalFinishTimestamp())
} ? this.getTotalFinishTimestamp()
public void setStartTime(int value) { : (this.getFinishedCount(currentTime) * this.forgeTime + this.forgeTime + this.startTime);
this.startTime = value; }
}
public int getTotalFinishTimestamp() {
public int getForgeTime() { return this.startTime + this.forgeTime * this.count;
return this.forgeTime; }
}
public void setForgeTime(int value) { public int getForgeId() {
this.forgeTime = value; 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 getCount() {
return count;
}
public void setCount(int value) {
this.count = 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;
}
} }
...@@ -3,6 +3,9 @@ package emu.grasscutter.game.managers.ForgingManager; ...@@ -3,6 +3,9 @@ package emu.grasscutter.game.managers.ForgingManager;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.ForgeData;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.ForgeStartReqOuterClass; import emu.grasscutter.net.proto.ForgeStartReqOuterClass;
...@@ -12,6 +15,9 @@ import emu.grasscutter.server.packet.send.PacketForgeDataNotify; ...@@ -12,6 +15,9 @@ import emu.grasscutter.server.packet.send.PacketForgeDataNotify;
import emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify; import emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify;
import emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp; import emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp;
import emu.grasscutter.server.packet.send.PacketForgeStartRsp; import emu.grasscutter.server.packet.send.PacketForgeStartRsp;
import emu.grasscutter.utils.Utils;
import emu.grasscutter.utils.ConfigContainer.Game;
import net.bytebuddy.dynamic.TypeResolutionStrategy.Active;
public class ForgingManager { public class ForgingManager {
private final Player player; private final Player player;
...@@ -53,19 +59,25 @@ public class ForgingManager { ...@@ -53,19 +59,25 @@ public class ForgingManager {
} }
private Map<Integer, ForgeQueueData> determineCurrentForgeQueueData() { 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<>(); Map<Integer, ForgeQueueData> res = new HashMap<>();
res.put(1, data); int currentTime = Utils.getCurrentSeconds();
// Create queue information for all active forges.
for (int i = 0; i < this.player.getActiveForges().size(); i++) {
ActiveForgeData activeForge = this.player.getActiveForges().get(i);
ForgeQueueData data = ForgeQueueData.newBuilder()
.setQueueId(i + 1)
.setForgeId(activeForge.getForgeId())
.setFinishCount(activeForge.getFinishedCount(currentTime))
.setUnfinishCount(activeForge.getUnfinishedCount(currentTime))
.setTotalFinishTimestamp(activeForge.getTotalFinishTimestamp())
.setNextFinishTimestamp(activeForge.getNextFinishTimestamp(currentTime))
.setAvatarId(activeForge.getAvatarId())
.build();
res.put(i + 1, data);
}
return res; return res;
} }
...@@ -93,8 +105,39 @@ public class ForgingManager { ...@@ -93,8 +105,39 @@ public class ForgingManager {
Initiate forging process. Initiate forging process.
**********/ **********/
public void startForging(ForgeStartReqOuterClass.ForgeStartReq req) { public void startForging(ForgeStartReqOuterClass.ForgeStartReq req) {
// Dummy for now. // Refuse if all queues are already full.
if (this.player.getActiveForges().size() >= this.determineNumberOfQueues()) {
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_QUEUE_FULL));
return;
}
// Get the required forging information for the target item.
if (!GameData.getForgeDataMap().containsKey(req.getForgeId())) {
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FAIL)); //ToDo: Probably the wrong return code.
Grasscutter.getLogger().error("Missing forgeId");
return;
}
ForgeData forgeData = GameData.getForgeDataMap().get(req.getForgeId());
// Check if we have enough of each material.
// ToDo.
// Consume material.
// ToDo.
// Create and add active forge.
ActiveForgeData activeForge = new ActiveForgeData();
activeForge.setForgeId(req.getForgeId());
activeForge.setAvatarId(req.getAvatarId());
activeForge.setCount(req.getForgeCount());
activeForge.setStartTime(Utils.getCurrentSeconds());
activeForge.setForgeTime(forgeData.getForgeTime());
this.player.getActiveForges().add(activeForge);
// Done.
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_SUCC)); this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_SUCC));
this.sendForgeDataNotify();
} }
} }
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