Skip to content

Commit

Permalink
De-hardcode ChestBatchUse
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdulon committed Aug 24, 2022
1 parent 1767833 commit 6098b51
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 120 deletions.

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/emu/grasscutter/game/shop/ShopSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
public class ShopSystem extends BaseGameSystem {
private final Int2ObjectMap<List<ShopInfo>> shopData;
private final List<ShopChestTable> shopChestData;
private final List<ShopChestBatchUseTable> shopChestBatchUseData;

private static final int REFRESH_HOUR = 4; // In GMT+8 server
private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone
Expand All @@ -27,7 +26,6 @@ public ShopSystem(GameServer server) {
super(server);
this.shopData = new Int2ObjectOpenHashMap<>();
this.shopChestData = new ArrayList<>();
this.shopChestBatchUseData = new ArrayList<>();
this.load();
}

Expand All @@ -39,10 +37,6 @@ public List<ShopChestTable> getShopChestData() {
return shopChestData;
}

public List<ShopChestBatchUseTable> getShopChestBatchUseData() {
return shopChestBatchUseData;
}

public static int getShopNextRefreshTime(ShopInfo shopInfo) {
return switch (shopInfo.getShopRefreshType()) {
case SHOP_REFRESH_DAILY -> Utils.getNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
Expand Down Expand Up @@ -96,25 +90,9 @@ private void loadShopChest() {
}
}

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() {
loadShop();
loadShopChest();
loadShopChestBatchUse();
}

public GameServer getServer() {
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/emu/grasscutter/game/systems/InventorySystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.common.ItemUseData;
import emu.grasscutter.data.excels.AvatarPromoteData;
import emu.grasscutter.data.excels.AvatarSkillData;
import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.data.excels.ProudSkillData;
import emu.grasscutter.data.excels.WeaponPromoteData;
import emu.grasscutter.data.excels.AvatarSkillDepotData.InherentProudSkillOpens;
import emu.grasscutter.game.avatar.Avatar;
Expand All @@ -23,7 +21,6 @@
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.ItemUseOp;
import emu.grasscutter.game.props.ItemUseTarget;
import emu.grasscutter.game.shop.ShopChestBatchUseTable;
import emu.grasscutter.game.shop.ShopChestTable;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.net.proto.MaterialInfoOuterClass.MaterialInfo;
Expand Down Expand Up @@ -713,6 +710,7 @@ public GameItem useItem(Player player, long targetGuid, long itemGuid, int count
int used = 0;
boolean useSuccess = false;
ItemData itemData = useItem.getItemData();
if (itemData == null) return null;

// Use
switch (itemData.getMaterialType()) {
Expand Down Expand Up @@ -816,26 +814,20 @@ public GameItem useItem(Player player, long targetGuid, long itemGuid, int count
}
break;
case MATERIAL_CHEST_BATCH_USE:
if (optionId < 1) {
break;
}
List<ShopChestBatchUseTable> shopChestBatchUseTableList = player.getServer().getShopSystem().getShopChestBatchUseData();
for (ShopChestBatchUseTable shopChestBatchUseTable : shopChestBatchUseTableList) {
if (shopChestBatchUseTable.getItemId() != useItem.getItemId()) {
continue;
}

if (shopChestBatchUseTable.getOptionItem() == null || optionId > shopChestBatchUseTable.getOptionItem().size()) {
break;
}

int optionItemId = shopChestBatchUseTable.getOptionItem().get(optionId - 1);
if (optionId < 1) return null; // 1-indexed selection
for (var use : itemData.getItemUse()) {
if (use.getUseOp() != ItemUseOp.ITEM_USE_CHEST_SELECT_ITEM) continue;
String[] choices = use.getUseParam()[0].split(",");
if (optionId > choices.length) return null;
String[] choiceParts = choices[optionId-1].split(":");
int optionItemId = Integer.parseInt(choiceParts[0]);
int optionItemCount = Integer.parseInt(choiceParts[1]);
ItemData optionItem = GameData.getItemDataMap().get(optionItemId);
if (optionItem == null) {
break;
}

player.getInventory().addItem(new GameItem(optionItem, count), ActionReason.Shop);
player.getInventory().addItem(new GameItem(optionItem, optionItemCount * count), ActionReason.Shop);

used = count;
break;
Expand Down
55 changes: 0 additions & 55 deletions src/main/resources/defaults/data/ShopChestBatchUse.json

This file was deleted.

0 comments on commit 6098b51

Please sign in to comment.