mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 02:43:15 +00:00
Reset forge points every day to enable crafting of enhancement ores.
This commit is contained in:
parent
e117bfac91
commit
c8fcff2ede
@ -6,7 +6,6 @@ import emu.grasscutter.data.GameResource;
|
|||||||
import emu.grasscutter.data.ResourceType;
|
import emu.grasscutter.data.ResourceType;
|
||||||
import emu.grasscutter.data.ResourceType.LoadPriority;
|
import emu.grasscutter.data.ResourceType.LoadPriority;
|
||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import emu.grasscutter.data.common.OpenCondData;
|
|
||||||
|
|
||||||
@ResourceType(name = {"ForgeExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST)
|
@ResourceType(name = {"ForgeExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST)
|
||||||
public class ForgeData extends GameResource {
|
public class ForgeData extends GameResource {
|
||||||
@ -19,6 +18,7 @@ public class ForgeData extends GameResource {
|
|||||||
private int queueNum;
|
private int queueNum;
|
||||||
private int scoinCost;
|
private int scoinCost;
|
||||||
private int priority;
|
private int priority;
|
||||||
|
private int forgePoint;
|
||||||
private List<ItemParamData> materialItems;
|
private List<ItemParamData> materialItems;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,6 +58,10 @@ public class ForgeData extends GameResource {
|
|||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getForgePoint() {
|
||||||
|
return forgePoint;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ItemParamData> getMaterialItems() {
|
public List<ItemParamData> getMaterialItems() {
|
||||||
return materialItems;
|
return materialItems;
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,15 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.mongodb.QueryBuilder;
|
|
||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import emu.grasscutter.data.excels.ForgeData;
|
import emu.grasscutter.data.excels.ForgeData;
|
||||||
import emu.grasscutter.data.excels.ItemData;
|
import emu.grasscutter.data.excels.ItemData;
|
||||||
import emu.grasscutter.game.inventory.GameItem;
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
import emu.grasscutter.game.inventory.ItemType;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
import emu.grasscutter.game.props.WatcherTriggerType;
|
import emu.grasscutter.game.props.WatcherTriggerType;
|
||||||
import emu.grasscutter.net.proto.ForgeStartReqOuterClass;
|
|
||||||
import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData;
|
import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData;
|
||||||
import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq;
|
import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq;
|
||||||
import emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType;
|
import emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType;
|
||||||
@ -149,6 +145,13 @@ public class ForgingManager {
|
|||||||
|
|
||||||
ForgeData forgeData = GameData.getForgeDataMap().get(req.getForgeId());
|
ForgeData forgeData = GameData.getForgeDataMap().get(req.getForgeId());
|
||||||
|
|
||||||
|
//Check if the player has sufficient forge points.
|
||||||
|
int requiredPoints = forgeData.getForgePoint() * req.getForgeCount();
|
||||||
|
if (requiredPoints > this.player.getForgePoints()) {
|
||||||
|
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we have enough of each material and consume.
|
// Check if we have enough of each material and consume.
|
||||||
List<ItemParamData> material = new ArrayList<>(forgeData.getMaterialItems());
|
List<ItemParamData> material = new ArrayList<>(forgeData.getMaterialItems());
|
||||||
material.add(new ItemParamData(202, forgeData.getScoinCost()));
|
material.add(new ItemParamData(202, forgeData.getScoinCost()));
|
||||||
@ -159,6 +162,9 @@ public class ForgingManager {
|
|||||||
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH)); //ToDo: Probably the wrong return code.
|
this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH)); //ToDo: Probably the wrong return code.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consume forge points.
|
||||||
|
this.player.setForgePoints(this.player.getForgePoints() - requiredPoints);
|
||||||
|
|
||||||
// Create and add active forge.
|
// Create and add active forge.
|
||||||
ActiveForgeData activeForge = new ActiveForgeData();
|
ActiveForgeData activeForge = new ActiveForgeData();
|
||||||
activeForge.setForgeId(req.getForgeId());
|
activeForge.setForgeId(req.getForgeId());
|
||||||
@ -256,6 +262,12 @@ public class ForgingManager {
|
|||||||
GameItem returnMora = new GameItem(moraItem, data.getScoinCost() * forge.getCount());
|
GameItem returnMora = new GameItem(moraItem, data.getScoinCost() * forge.getCount());
|
||||||
returnItems.add(returnMora);
|
returnItems.add(returnMora);
|
||||||
|
|
||||||
|
// Return forge points to the player.
|
||||||
|
int requiredPoints = data.getForgePoint() * forge.getCount();
|
||||||
|
int newPoints = Math.min(this.player.getForgePoints() + requiredPoints, 300_000);
|
||||||
|
|
||||||
|
this.player.setForgePoints(newPoints);
|
||||||
|
|
||||||
// Remove the forge queue.
|
// Remove the forge queue.
|
||||||
this.player.getActiveForges().remove(queueId - 1);
|
this.player.getActiveForges().remove(queueId - 1);
|
||||||
this.sendForgeQueueDataNotify(true);
|
this.sendForgeQueueDataNotify(true);
|
||||||
|
@ -76,6 +76,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
@ -181,6 +184,7 @@ public class Player {
|
|||||||
private long springLastUsed;
|
private long springLastUsed;
|
||||||
private HashMap<String, MapMark> mapMarks;
|
private HashMap<String, MapMark> mapMarks;
|
||||||
private int nextResinRefresh;
|
private int nextResinRefresh;
|
||||||
|
private int lastDailyReset;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only!
|
@SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only!
|
||||||
@ -447,7 +451,7 @@ public class Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setWorldLevel(int level) {
|
public void setWorldLevel(int level) {
|
||||||
this.getWorld().setWorldLevel(newWorldLevel);
|
this.getWorld().setWorldLevel(level);
|
||||||
|
|
||||||
this.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);
|
this.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);
|
||||||
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_WORLD_LEVEL));
|
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_WORLD_LEVEL));
|
||||||
@ -455,6 +459,19 @@ public class Player {
|
|||||||
this.updateProfile();
|
this.updateProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getForgePoints() {
|
||||||
|
return this.getProperty(PlayerProperty.PROP_PLAYER_FORGE_POINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForgePoints(int value) {
|
||||||
|
if (value == this.getForgePoints()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setProperty(PlayerProperty.PROP_PLAYER_FORGE_POINT, value);
|
||||||
|
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_FORGE_POINT));
|
||||||
|
}
|
||||||
|
|
||||||
public int getPrimogems() {
|
public int getPrimogems() {
|
||||||
return this.getProperty(PlayerProperty.PROP_PLAYER_HCOIN);
|
return this.getProperty(PlayerProperty.PROP_PLAYER_HCOIN);
|
||||||
}
|
}
|
||||||
@ -796,6 +813,14 @@ public class Player {
|
|||||||
return showAvatarList;
|
return showAvatarList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLastDailyReset() {
|
||||||
|
return this.lastDailyReset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastDailyReset(int value) {
|
||||||
|
this.lastDailyReset = value;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean inMoonCard() {
|
public boolean inMoonCard() {
|
||||||
return moonCard;
|
return moonCard;
|
||||||
}
|
}
|
||||||
@ -1316,6 +1341,10 @@ public class Player {
|
|||||||
this.resetSendPlayerLocTime();
|
this.resetSendPlayerLocTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle daily reset.
|
||||||
|
this.doDailyReset();
|
||||||
|
|
||||||
// Expedition
|
// Expedition
|
||||||
var timeNow = Utils.getCurrentSeconds();
|
var timeNow = Utils.getCurrentSeconds();
|
||||||
var needNotify = false;
|
var needNotify = false;
|
||||||
@ -1340,8 +1369,26 @@ public class Player {
|
|||||||
this.getResinManager().rechargeResin();
|
this.getResinManager().rechargeResin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doDailyReset() {
|
||||||
|
// Check if we should execute a daily reset on this tick.
|
||||||
|
int currentTime = Utils.getCurrentSeconds();
|
||||||
|
|
||||||
|
var currentDate = LocalDate.ofInstant(Instant.ofEpochSecond(currentTime), ZoneId.systemDefault());
|
||||||
|
var lastResetDate = LocalDate.ofInstant(Instant.ofEpochSecond(this.getLastDailyReset()), ZoneId.systemDefault());
|
||||||
|
|
||||||
|
if (!currentDate.isAfter(lastResetDate)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Grasscutter.getLogger().info("Executing daily reset logic ...");
|
||||||
|
|
||||||
|
// We should - now execute all the resetting logic we need.
|
||||||
|
// Reset forge points.
|
||||||
|
this.setForgePoints(300_000);
|
||||||
|
|
||||||
|
// Done. Update last reset time.
|
||||||
|
this.setLastDailyReset(currentTime);
|
||||||
|
}
|
||||||
|
|
||||||
public void resetSendPlayerLocTime() {
|
public void resetSendPlayerLocTime() {
|
||||||
this.nextSendPlayerLocTime = System.currentTimeMillis() + 5000;
|
this.nextSendPlayerLocTime = System.currentTimeMillis() + 5000;
|
||||||
|
Loading…
Reference in New Issue
Block a user