mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 17:05:20 +01:00
shop improvement
This commit is contained in:
@@ -21,6 +21,7 @@ import emu.grasscutter.game.inventory.Inventory;
|
||||
import emu.grasscutter.game.mail.Mail;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.PlayerProperty;
|
||||
import emu.grasscutter.game.shop.ShopInfo;
|
||||
import emu.grasscutter.game.shop.ShopLimit;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
import emu.grasscutter.game.world.World;
|
||||
@@ -621,27 +622,26 @@ public class Player {
|
||||
return shopLimit;
|
||||
}
|
||||
|
||||
public int getGoodsLimitNum(int goodsId) {
|
||||
for (ShopLimit sl : getShopLimit()) {
|
||||
if (sl.getShopGoodId() == goodsId)
|
||||
return sl.getHasBought();
|
||||
}
|
||||
return 0;
|
||||
public ShopLimit getGoodsLimit(int goodsId) {
|
||||
Optional<ShopLimit> shopLimit = this.shopLimit.stream().filter(x -> x.getShopGoodId() == goodsId).findFirst();
|
||||
if (shopLimit.isEmpty())
|
||||
return null;
|
||||
return shopLimit.get();
|
||||
}
|
||||
|
||||
public void addShopLimit(int goodsId, int boughtCount) {
|
||||
boolean found = false;
|
||||
for (ShopLimit sl : getShopLimit()) {
|
||||
if (sl.getShopGoodId() == goodsId){
|
||||
sl.setHasBought(sl.getHasBought() + boughtCount);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
public void addShopLimit(int goodsId, int boughtCount, int nextRefreshTime) {
|
||||
ShopLimit target = getGoodsLimit(goodsId);
|
||||
if (target != null) {
|
||||
target.setHasBought(target.getHasBought() + boughtCount);
|
||||
target.setHasBoughtInPeriod(target.getHasBoughtInPeriod() + boughtCount);
|
||||
target.setNextRefreshTime(nextRefreshTime);
|
||||
} else {
|
||||
ShopLimit sl = new ShopLimit();
|
||||
sl.setShopGoodId(goodsId);
|
||||
sl.setHasBought(boughtCount);
|
||||
shopLimit.add(sl);
|
||||
sl.setHasBoughtInPeriod(boughtCount);
|
||||
sl.setNextRefreshTime(nextRefreshTime);
|
||||
getShopLimit().add(sl);
|
||||
}
|
||||
this.save();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ public class ShopInfo {
|
||||
private int buyLimit = 0;
|
||||
private int beginTime = 0;
|
||||
private int endTime = 1924992000;
|
||||
private int nextRefreshTime = 1924992000;
|
||||
private int minLevel = 0;
|
||||
private int maxLevel = 61;
|
||||
private List<Integer> preGoodsIdList = new ArrayList<>();
|
||||
@@ -24,6 +23,25 @@ public class ShopInfo {
|
||||
private int disableType = 0;
|
||||
private int secondarySheetId = 0;
|
||||
|
||||
public enum ShopRefreshType {
|
||||
NONE(0),
|
||||
SHOP_REFRESH_DAILY(1),
|
||||
SHOP_REFRESH_WEEKLY(2),
|
||||
SHOP_REFRESH_MONTHLY(3);
|
||||
|
||||
private final int value;
|
||||
ShopRefreshType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int value() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private transient ShopRefreshType shopRefreshType;
|
||||
private int shopRefreshParam;
|
||||
|
||||
public ShopInfo(ShopGoodsData sgd) {
|
||||
this.goodsId = sgd.getGoodsId();
|
||||
this.goodsItem = new ItemParamData(sgd.getItemId(), sgd.getItemCount());
|
||||
@@ -36,6 +54,8 @@ public class ShopInfo {
|
||||
this.maxLevel = sgd.getMaxPlayerLevel();
|
||||
this.costItemList = sgd.getCostItems().stream().filter(x -> x.getId() != 0).map(x -> new ItemParamData(x.getId(), x.getCount())).toList();
|
||||
this.secondarySheetId = sgd.getSubTabId();
|
||||
this.shopRefreshType = sgd.getRefreshType();
|
||||
this.shopRefreshParam = sgd.getRefreshParam();
|
||||
}
|
||||
|
||||
public int getHcoin() {
|
||||
@@ -142,14 +162,6 @@ public class ShopInfo {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public int getNextRefreshTime() {
|
||||
return nextRefreshTime;
|
||||
}
|
||||
|
||||
public void setNextRefreshTime(int nextRefreshTime) {
|
||||
this.nextRefreshTime = nextRefreshTime;
|
||||
}
|
||||
|
||||
public int getMinLevel() {
|
||||
return minLevel;
|
||||
}
|
||||
@@ -165,4 +177,22 @@ public class ShopInfo {
|
||||
public void setMaxLevel(int maxLevel) {
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
public ShopRefreshType getShopRefreshType() {
|
||||
if (shopRefreshType == null)
|
||||
return ShopRefreshType.NONE;
|
||||
return shopRefreshType;
|
||||
}
|
||||
|
||||
public void setShopRefreshType(ShopRefreshType shopRefreshType) {
|
||||
this.shopRefreshType = shopRefreshType;
|
||||
}
|
||||
|
||||
public int getShopRefreshParam() {
|
||||
return shopRefreshParam;
|
||||
}
|
||||
|
||||
public void setShopRefreshParam(int shopRefreshParam) {
|
||||
this.shopRefreshParam = shopRefreshParam;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,24 @@ public class ShopLimit {
|
||||
this.hasBought = hasBought;
|
||||
}
|
||||
|
||||
public int getNextRefreshTime() {
|
||||
return nextRefreshTime;
|
||||
}
|
||||
|
||||
public void setNextRefreshTime(int nextRefreshTime) {
|
||||
this.nextRefreshTime = nextRefreshTime;
|
||||
}
|
||||
|
||||
public int getHasBoughtInPeriod() {
|
||||
return hasBoughtInPeriod;
|
||||
}
|
||||
|
||||
public void setHasBoughtInPeriod(int hasBoughtInPeriod) {
|
||||
this.hasBoughtInPeriod = hasBoughtInPeriod;
|
||||
}
|
||||
|
||||
private int shopGoodId;
|
||||
private int hasBought;
|
||||
private int hasBoughtInPeriod = 0;
|
||||
private int nextRefreshTime = 0;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import emu.grasscutter.data.def.ShopGoodsData;
|
||||
import emu.grasscutter.net.proto.ItemParamOuterClass;
|
||||
import emu.grasscutter.net.proto.ShopGoodsOuterClass;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
@@ -32,6 +33,18 @@ public class ShopManager {
|
||||
this.load();
|
||||
}
|
||||
|
||||
private static final int REFRESH_HOUR = 4; // In GMT+8 server
|
||||
private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone
|
||||
|
||||
public static int getShopNextRefreshTime(ShopInfo shopInfo) {
|
||||
return switch (shopInfo.getShopRefreshType()) {
|
||||
case SHOP_REFRESH_DAILY -> Utils.GetNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||
case SHOP_REFRESH_WEEKLY -> Utils.GetNextTimestampOfThisHourInNextWeek(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||
case SHOP_REFRESH_MONTHLY -> Utils.GetNextTimestampOfThisHourInNextMonth(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
public synchronized void load() {
|
||||
try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "Shop.json")) {
|
||||
getShopData().clear();
|
||||
|
||||
Reference in New Issue
Block a user