Commit ee3a0c32 authored by Kengxxiao's avatar Kengxxiao Committed by Melledy
Browse files

use better shop config structure

parent 3e0ccbbb
[ [
{ {
"shopId": 1004, "shopId": 1004,
"goodsId": 1004202, "items": [
"goodsItem": { {
"Id": 202, "goodsId": 1004202,
"Count": 1000000 "goodsItem": {
}, "Id": 202,
"scoin": 1, "Count": 1000000
"buyLimit": 500, },
"beginTime": 1575129600, "scoin": 1,
"endTime": 2051193600, "buyLimit": 500,
"minLevel": 1, "beginTime": 1575129600,
"maxLevel": 99 "endTime": 2051193600,
}, "minLevel": 1,
{ "maxLevel": 99,
"shopId": 1004, "costItemList": [
"goodsId": 10048006, {
"goodsItem": { "Id": 223,
"Id": 108006, "Count": 100
"Count": 20 }
}, ]
"scoin": 1, },
"buyLimit": 50000, {
"beginTime": 1575129600, "goodsId": 10048006,
"endTime": 2051193600, "goodsItem": {
"minLevel": 1, "Id": 108006,
"maxLevel": 99 "Count": 20
}, },
{ "scoin": 100,
"shopId": 1004, "hcoin": 100,
"goodsId": 10048033, "mcoin": 100,
"goodsItem": { "buyLimit": 50000,
"Id": 108033, "beginTime": 1575129600,
"Count": 20 "endTime": 2051193600,
}, "minLevel": 1,
"scoin": 1, "maxLevel": 99
"buyLimit": 50000, },
"beginTime": 1575129600, {
"endTime": 2051193600, "goodsId": 10048033,
"minLevel": 1, "goodsItem": {
"maxLevel": 99 "Id": 108033,
}, "Count": 20
{ },
"shopId": 1004, "scoin": 1,
"goodsId": 10040008, "buyLimit": 50000,
"goodsItem": { "beginTime": 1575129600,
"Id": 220008, "endTime": 2051193600,
"Count": 1 "minLevel": 1,
}, "maxLevel": 99
"scoin": 1, }
"buyLimit": 1, ]
"beginTime": 1575129600,
"endTime": 2051193600,
"minLevel": 1,
"maxLevel": 99
},
{
"shopId": 1004,
"goodsId": 10044003,
"goodsItem": {
"Id": 104003,
"Count": 200
},
"scoin": 1,
"buyLimit": 50000,
"beginTime": 1575129600,
"endTime": 2051193600,
"minLevel": 1,
"maxLevel": 99
},
{
"shopId": 1004,
"goodsId": 10044013,
"goodsItem": {
"Id": 104013,
"Count": 200
},
"scoin": 1,
"buyLimit": 50000,
"beginTime": 1575129600,
"endTime": 2051193600,
"minLevel": 1,
"maxLevel": 99
} }
] ]
\ No newline at end of file
...@@ -6,23 +6,22 @@ import java.util.ArrayList; ...@@ -6,23 +6,22 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ShopInfo { public class ShopInfo {
public int shopId = 1004; private int goodsId = 0;
public int goodsId = 0; private ItemParamData goodsItem;
public ItemParamData goodsItem; private int scoin = 0;
public int scoin = 0; private List<ItemParamData> costItemList;
public List<ItemParamData> costItemList; private int boughtNum = 0;
public int boughtNum = 0; private int buyLimit = 0;
public int buyLimit = 0; private int beginTime = 0;
public int beginTime = 0; private int endTime = 1924992000;
public int endTime = 1924992000; private int nextRefreshTime = 1924992000;
public int nextRefreshTime = 1924992000; private int minLevel = 0;
public int minLevel = 0; private int maxLevel = 61;
public int maxLevel = 61; private List<Integer> preGoodsIdList = new ArrayList<>();
public List<Integer> preGoodsIdList = new ArrayList<>(); private int mcoin = 0;
public int mcoin = 0; private int hcoin = 0;
public int hcoin = 0; private int disableType = 0;
public int disableType = 0; private int secondarySheetId = 0;
public int secondarySheetId = 0;
public int getHcoin() { public int getHcoin() {
return hcoin; return hcoin;
...@@ -64,14 +63,6 @@ public class ShopInfo { ...@@ -64,14 +63,6 @@ public class ShopInfo {
this.secondarySheetId = secondarySheetId; this.secondarySheetId = secondarySheetId;
} }
public int getShopId() {
return shopId;
}
public void setShopId(int shopId) {
this.shopId = shopId;
}
public int getGoodsId() { public int getGoodsId() {
return goodsId; return goodsId;
} }
......
...@@ -7,7 +7,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; ...@@ -7,7 +7,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.io.FileReader; import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -19,7 +18,7 @@ public class ShopManager { ...@@ -19,7 +18,7 @@ public class ShopManager {
} }
private final Int2ObjectMap<List<ShopInfo>> shopData; private final Int2ObjectMap<List<ShopInfo>> shopData;
public ShopManager(GameServer server) { public ShopManager(GameServer server) {
this.server = server; this.server = server;
this.shopData = new Int2ObjectOpenHashMap<>(); this.shopData = new Int2ObjectOpenHashMap<>();
...@@ -29,13 +28,10 @@ public class ShopManager { ...@@ -29,13 +28,10 @@ public class ShopManager {
public synchronized void load() { public synchronized void load() {
try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "Shop.json")) { try (FileReader fileReader = new FileReader(Grasscutter.getConfig().DATA_FOLDER + "Shop.json")) {
getShopData().clear(); getShopData().clear();
List<ShopInfo> banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ShopInfo.class).getType()); List<ShopTable> banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ShopTable.class).getType());
if(banners.size() > 0) { if(banners.size() > 0) {
for (ShopInfo shopInfo : banners) { for (ShopTable shopTable : banners) {
if (!getShopData().containsKey(shopInfo.getShopId())) getShopData().put(shopTable.getShopId(), shopTable.getItems());
getShopData().put(shopInfo.getShopId(), new ArrayList<>());
getShopData().get(shopInfo.getShopId()).add(shopInfo);
Grasscutter.getLogger().info(String.format("Shop add: id [%d], data [%d*%d]", shopInfo.getShopId(), shopInfo.getGoodsItem().getId(), shopInfo.getGoodsItem().getCount()));
} }
Grasscutter.getLogger().info("Shop data successfully loaded."); Grasscutter.getLogger().info("Shop data successfully loaded.");
} else { } else {
......
package emu.grasscutter.game.shop;
import java.util.ArrayList;
import java.util.List;
public class ShopTable {
private int shopId;
private List<ShopInfo> items = new ArrayList<>();
public int getShopId() {
return shopId;
}
public void setShopId(int shopId) {
this.shopId = shopId;
}
public List<ShopInfo> getItems() {
return items;
}
public void setItems(List<ShopInfo> items) {
this.items = items;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment