mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-29 14:26:10 +00:00
De-hardcode ChestBatchUse
This commit is contained in:
parent
1767833ebe
commit
6098b51e4f
@ -1,25 +0,0 @@
|
|||||||
package emu.grasscutter.game.shop;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ShopChestBatchUseTable {
|
|
||||||
private int itemId;
|
|
||||||
private List<Integer> optionItem = new ArrayList<>();
|
|
||||||
|
|
||||||
public int getItemId() {
|
|
||||||
return itemId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItemId(int itemId) {
|
|
||||||
this.itemId = itemId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getOptionItem() {
|
|
||||||
return optionItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOptionItem(List<Integer> optionItem) {
|
|
||||||
this.optionItem = optionItem;
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,7 +18,6 @@ import java.util.List;
|
|||||||
public class ShopSystem extends BaseGameSystem {
|
public class ShopSystem extends BaseGameSystem {
|
||||||
private final Int2ObjectMap<List<ShopInfo>> shopData;
|
private final Int2ObjectMap<List<ShopInfo>> shopData;
|
||||||
private final List<ShopChestTable> shopChestData;
|
private final List<ShopChestTable> shopChestData;
|
||||||
private final List<ShopChestBatchUseTable> shopChestBatchUseData;
|
|
||||||
|
|
||||||
private static final int REFRESH_HOUR = 4; // In GMT+8 server
|
private static final int REFRESH_HOUR = 4; // In GMT+8 server
|
||||||
private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone
|
private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone
|
||||||
@ -27,7 +26,6 @@ public class ShopSystem extends BaseGameSystem {
|
|||||||
super(server);
|
super(server);
|
||||||
this.shopData = new Int2ObjectOpenHashMap<>();
|
this.shopData = new Int2ObjectOpenHashMap<>();
|
||||||
this.shopChestData = new ArrayList<>();
|
this.shopChestData = new ArrayList<>();
|
||||||
this.shopChestBatchUseData = new ArrayList<>();
|
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +37,6 @@ public class ShopSystem extends BaseGameSystem {
|
|||||||
return shopChestData;
|
return shopChestData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ShopChestBatchUseTable> getShopChestBatchUseData() {
|
|
||||||
return shopChestBatchUseData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getShopNextRefreshTime(ShopInfo shopInfo) {
|
public static int getShopNextRefreshTime(ShopInfo shopInfo) {
|
||||||
return switch (shopInfo.getShopRefreshType()) {
|
return switch (shopInfo.getShopRefreshType()) {
|
||||||
case SHOP_REFRESH_DAILY -> Utils.getNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
case SHOP_REFRESH_DAILY -> Utils.getNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
|
||||||
@ -96,25 +90,9 @@ public class ShopSystem extends BaseGameSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadShopChestBatchUse() {
|
|
||||||
getShopChestBatchUseData().clear();
|
|
||||||
try {
|
|
||||||
List<ShopChestBatchUseTable> shopChestBatchUseTableList = DataLoader.loadList("ShopChestBatchUse.json", ShopChestBatchUseTable.class);
|
|
||||||
if (shopChestBatchUseTableList.size() > 0) {
|
|
||||||
getShopChestBatchUseData().addAll(shopChestBatchUseTableList);
|
|
||||||
Grasscutter.getLogger().debug("ShopChestBatchUse data successfully loaded.");
|
|
||||||
} else {
|
|
||||||
Grasscutter.getLogger().error("Unable to load ShopChestBatchUse data. ShopChestBatchUse data size is 0.");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Grasscutter.getLogger().error("Unable to load ShopChestBatchUse data.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void load() {
|
public synchronized void load() {
|
||||||
loadShop();
|
loadShop();
|
||||||
loadShopChest();
|
loadShopChest();
|
||||||
loadShopChestBatchUse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameServer getServer() {
|
public GameServer getServer() {
|
||||||
|
@ -10,10 +10,8 @@ import emu.grasscutter.data.GameData;
|
|||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import emu.grasscutter.data.common.ItemUseData;
|
import emu.grasscutter.data.common.ItemUseData;
|
||||||
import emu.grasscutter.data.excels.AvatarPromoteData;
|
import emu.grasscutter.data.excels.AvatarPromoteData;
|
||||||
import emu.grasscutter.data.excels.AvatarSkillData;
|
|
||||||
import emu.grasscutter.data.excels.AvatarSkillDepotData;
|
import emu.grasscutter.data.excels.AvatarSkillDepotData;
|
||||||
import emu.grasscutter.data.excels.ItemData;
|
import emu.grasscutter.data.excels.ItemData;
|
||||||
import emu.grasscutter.data.excels.ProudSkillData;
|
|
||||||
import emu.grasscutter.data.excels.WeaponPromoteData;
|
import emu.grasscutter.data.excels.WeaponPromoteData;
|
||||||
import emu.grasscutter.data.excels.AvatarSkillDepotData.InherentProudSkillOpens;
|
import emu.grasscutter.data.excels.AvatarSkillDepotData.InherentProudSkillOpens;
|
||||||
import emu.grasscutter.game.avatar.Avatar;
|
import emu.grasscutter.game.avatar.Avatar;
|
||||||
@ -23,7 +21,6 @@ import emu.grasscutter.game.player.Player;
|
|||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
import emu.grasscutter.game.props.ItemUseOp;
|
import emu.grasscutter.game.props.ItemUseOp;
|
||||||
import emu.grasscutter.game.props.ItemUseTarget;
|
import emu.grasscutter.game.props.ItemUseTarget;
|
||||||
import emu.grasscutter.game.shop.ShopChestBatchUseTable;
|
|
||||||
import emu.grasscutter.game.shop.ShopChestTable;
|
import emu.grasscutter.game.shop.ShopChestTable;
|
||||||
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
|
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
|
||||||
import emu.grasscutter.net.proto.MaterialInfoOuterClass.MaterialInfo;
|
import emu.grasscutter.net.proto.MaterialInfoOuterClass.MaterialInfo;
|
||||||
@ -713,6 +710,7 @@ public class InventorySystem extends BaseGameSystem {
|
|||||||
int used = 0;
|
int used = 0;
|
||||||
boolean useSuccess = false;
|
boolean useSuccess = false;
|
||||||
ItemData itemData = useItem.getItemData();
|
ItemData itemData = useItem.getItemData();
|
||||||
|
if (itemData == null) return null;
|
||||||
|
|
||||||
// Use
|
// Use
|
||||||
switch (itemData.getMaterialType()) {
|
switch (itemData.getMaterialType()) {
|
||||||
@ -816,26 +814,20 @@ public class InventorySystem extends BaseGameSystem {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MATERIAL_CHEST_BATCH_USE:
|
case MATERIAL_CHEST_BATCH_USE:
|
||||||
if (optionId < 1) {
|
if (optionId < 1) return null; // 1-indexed selection
|
||||||
break;
|
for (var use : itemData.getItemUse()) {
|
||||||
}
|
if (use.getUseOp() != ItemUseOp.ITEM_USE_CHEST_SELECT_ITEM) continue;
|
||||||
List<ShopChestBatchUseTable> shopChestBatchUseTableList = player.getServer().getShopSystem().getShopChestBatchUseData();
|
String[] choices = use.getUseParam()[0].split(",");
|
||||||
for (ShopChestBatchUseTable shopChestBatchUseTable : shopChestBatchUseTableList) {
|
if (optionId > choices.length) return null;
|
||||||
if (shopChestBatchUseTable.getItemId() != useItem.getItemId()) {
|
String[] choiceParts = choices[optionId-1].split(":");
|
||||||
continue;
|
int optionItemId = Integer.parseInt(choiceParts[0]);
|
||||||
}
|
int optionItemCount = Integer.parseInt(choiceParts[1]);
|
||||||
|
|
||||||
if (shopChestBatchUseTable.getOptionItem() == null || optionId > shopChestBatchUseTable.getOptionItem().size()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int optionItemId = shopChestBatchUseTable.getOptionItem().get(optionId - 1);
|
|
||||||
ItemData optionItem = GameData.getItemDataMap().get(optionItemId);
|
ItemData optionItem = GameData.getItemDataMap().get(optionItemId);
|
||||||
if (optionItem == null) {
|
if (optionItem == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().addItem(new GameItem(optionItem, count), ActionReason.Shop);
|
player.getInventory().addItem(new GameItem(optionItem, optionItemCount * count), ActionReason.Shop);
|
||||||
|
|
||||||
used = count;
|
used = count;
|
||||||
break;
|
break;
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"itemId": 115017,
|
|
||||||
"optionItem": [
|
|
||||||
104302,
|
|
||||||
104305,
|
|
||||||
104308,
|
|
||||||
104311,
|
|
||||||
104314,
|
|
||||||
104317,
|
|
||||||
104321,
|
|
||||||
104324,
|
|
||||||
104327
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"itemId": 115024,
|
|
||||||
"optionItem": [
|
|
||||||
114001,
|
|
||||||
114005,
|
|
||||||
114009,
|
|
||||||
114013,
|
|
||||||
114017,
|
|
||||||
114021,
|
|
||||||
114025,
|
|
||||||
114029,
|
|
||||||
114033
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"itemId": 115013,
|
|
||||||
"optionItem": [
|
|
||||||
104112,
|
|
||||||
104122,
|
|
||||||
104142,
|
|
||||||
104152,
|
|
||||||
104162,
|
|
||||||
104172
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"itemId": 115025,
|
|
||||||
"optionItem": [
|
|
||||||
114002,
|
|
||||||
114006,
|
|
||||||
114010,
|
|
||||||
114014,
|
|
||||||
114018,
|
|
||||||
114022,
|
|
||||||
114026,
|
|
||||||
114030,
|
|
||||||
114034
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
Loading…
Reference in New Issue
Block a user