mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 09:02:59 +08:00
Start a new forge (no checking for now).
This commit is contained in:
parent
e5498e373e
commit
5db5c90a8b
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,44 +1,76 @@
|
|||||||
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 startTime;
|
||||||
private int forgeTime;
|
private int forgeTime;
|
||||||
// private int finishedCount;
|
// private int finishedCount;
|
||||||
// private int unfinishedCount;
|
// private int unfinishedCount;
|
||||||
// private int nextFinishTimestamp;
|
// private int nextFinishTimestamp;
|
||||||
// private int totalFinishTimestamp;
|
// private int totalFinishTimestamp;
|
||||||
|
|
||||||
public int getForgeId() {
|
|
||||||
return this.forgeId;
|
|
||||||
}
|
|
||||||
public void setForgeId(int value) {
|
|
||||||
this.forgeId = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAvatarId() {
|
public int getFinishedCount(int currentTime) {
|
||||||
return this.avatarId;
|
int timeDelta = currentTime - this.startTime;
|
||||||
}
|
int finishedCount = (int)Math.floor(timeDelta / this.forgeTime);
|
||||||
public void setAvatarId(int value) {
|
|
||||||
this.avatarId = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStartTime() {
|
return Math.min(finishedCount, this.count);
|
||||||
return this.startTime;
|
}
|
||||||
}
|
|
||||||
public void setStartTime(int value) {
|
|
||||||
this.startTime = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getForgeTime() {
|
public int getUnfinishedCount(int currentTime) {
|
||||||
return this.forgeTime;
|
return this.count - this.getFinishedCount(currentTime);
|
||||||
}
|
}
|
||||||
public void setForgeTime(int value) {
|
|
||||||
this.forgeTime = value;
|
public int getNextFinishTimestamp(int currentTime) {
|
||||||
}
|
return
|
||||||
|
(currentTime >= this.getTotalFinishTimestamp())
|
||||||
|
? this.getTotalFinishTimestamp()
|
||||||
|
: (this.getFinishedCount(currentTime) * this.forgeTime + this.forgeTime + this.startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalFinishTimestamp() {
|
||||||
|
return this.startTime + this.forgeTime * this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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;
|
|||||||
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;
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
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.
|
||||||
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_SUCC));
|
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.sendForgeDataNotify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user