Commit 286d6289 authored by KingRainbow44's avatar KingRainbow44
Browse files

Move banner loading to `debug`

parent 5895439a
...@@ -50,7 +50,7 @@ public class GachaManager { ...@@ -50,7 +50,7 @@ public class GachaManager {
private final GameServer server; private final GameServer server;
private final Int2ObjectMap<GachaBanner> gachaBanners; private final Int2ObjectMap<GachaBanner> gachaBanners;
private WatchService watchService; private WatchService watchService;
private static final int starglitterId = 221; private static final int starglitterId = 221;
private static final int stardustId = 222; private static final int stardustId = 222;
private int[] fallbackItems4Pool2Default = {11401, 11402, 11403, 11405, 12401, 12402, 12403, 12405, 13401, 13407, 14401, 14402, 14403, 14409, 15401, 15402, 15403, 15405}; private int[] fallbackItems4Pool2Default = {11401, 11402, 11403, 11405, 12401, 12402, 12403, 12405, 13401, 13407, 14401, 14402, 14403, 14409, 15401, 15402, 15403, 15405};
...@@ -70,15 +70,15 @@ public class GachaManager { ...@@ -70,15 +70,15 @@ public class GachaManager {
public Int2ObjectMap<GachaBanner> getGachaBanners() { public Int2ObjectMap<GachaBanner> getGachaBanners() {
return gachaBanners; return gachaBanners;
} }
public int randomRange(int min, int max) { // Both are inclusive public int randomRange(int min, int max) { // Both are inclusive
return ThreadLocalRandom.current().nextInt(max - min + 1) + min; return ThreadLocalRandom.current().nextInt(max - min + 1) + min;
} }
public int getRandom(int[] array) { public int getRandom(int[] array) {
return array[randomRange(0, array.length - 1)]; return array[randomRange(0, array.length - 1)];
} }
public synchronized void load() { public synchronized void load() {
try (Reader fileReader = new InputStreamReader(DataLoader.load("Banners.json"))) { try (Reader fileReader = new InputStreamReader(DataLoader.load("Banners.json"))) {
getGachaBanners().clear(); getGachaBanners().clear();
...@@ -87,7 +87,7 @@ public class GachaManager { ...@@ -87,7 +87,7 @@ public class GachaManager {
for (GachaBanner banner : banners) { for (GachaBanner banner : banners) {
getGachaBanners().put(banner.getScheduleId(), banner); getGachaBanners().put(banner.getScheduleId(), banner);
} }
Grasscutter.getLogger().info("Banners successfully loaded."); Grasscutter.getLogger().debug("Banners successfully loaded.");
} else { } else {
Grasscutter.getLogger().error("Unable to load banners. Banners size is 0."); Grasscutter.getLogger().error("Unable to load banners. Banners size is 0.");
} }
...@@ -256,18 +256,18 @@ public class GachaManager { ...@@ -256,18 +256,18 @@ public class GachaManager {
yield getRandom(banner.getFallbackItems3()); yield getRandom(banner.getFallbackItems3());
}; };
} }
public synchronized void doPulls(Player player, int scheduleId, int times) { public synchronized void doPulls(Player player, int scheduleId, int times) {
// Sanity check // Sanity check
if (times != 10 && times != 1) { if (times != 10 && times != 1) {
return; return;
} }
Inventory inventory = player.getInventory(); Inventory inventory = player.getInventory();
if (inventory.getInventoryTab(ItemType.ITEM_WEAPON).getSize() + times > inventory.getInventoryTab(ItemType.ITEM_WEAPON).getMaxCapacity()) { if (inventory.getInventoryTab(ItemType.ITEM_WEAPON).getSize() + times > inventory.getInventoryTab(ItemType.ITEM_WEAPON).getMaxCapacity()) {
player.sendPacket(new PacketDoGachaRsp(Retcode.RET_ITEM_EXCEED_LIMIT)); player.sendPacket(new PacketDoGachaRsp(Retcode.RET_ITEM_EXCEED_LIMIT));
return; return;
} }
// Get banner // Get banner
GachaBanner banner = this.getGachaBanners().get(scheduleId); GachaBanner banner = this.getGachaBanners().get(scheduleId);
if (banner == null) { if (banner == null) {
...@@ -281,7 +281,7 @@ public class GachaManager { ...@@ -281,7 +281,7 @@ public class GachaManager {
player.sendPacket(new PacketDoGachaRsp()); player.sendPacket(new PacketDoGachaRsp());
return; return;
} }
// Add to character // Add to character
PlayerGachaBannerInfo gachaInfo = player.getGachaInfo().getBannerInfo(banner); PlayerGachaBannerInfo gachaInfo = player.getGachaInfo().getBannerInfo(banner);
BannerPools pools = new BannerPools(banner); BannerPools pools = new BannerPools(banner);
...@@ -296,7 +296,7 @@ public class GachaManager { ...@@ -296,7 +296,7 @@ public class GachaManager {
pools.fallbackItems5Pool1 = removeC6FromPool(pools.fallbackItems5Pool1, player); pools.fallbackItems5Pool1 = removeC6FromPool(pools.fallbackItems5Pool1, player);
pools.fallbackItems5Pool2 = removeC6FromPool(pools.fallbackItems5Pool2, player); pools.fallbackItems5Pool2 = removeC6FromPool(pools.fallbackItems5Pool2, player);
} }
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
// Roll // Roll
int itemId = doPull(banner, gachaInfo, pools); int itemId = doPull(banner, gachaInfo, pools);
...@@ -308,12 +308,12 @@ public class GachaManager { ...@@ -308,12 +308,12 @@ public class GachaManager {
// Write gacha record // Write gacha record
GachaRecord gachaRecord = new GachaRecord(itemId, player.getUid(), banner.getGachaType()); GachaRecord gachaRecord = new GachaRecord(itemId, player.getUid(), banner.getGachaType());
DatabaseHelper.saveGachaRecord(gachaRecord); DatabaseHelper.saveGachaRecord(gachaRecord);
// Create gacha item // Create gacha item
GachaItem.Builder gachaItem = GachaItem.newBuilder(); GachaItem.Builder gachaItem = GachaItem.newBuilder();
int addStardust = 0, addStarglitter = 0; int addStardust = 0, addStarglitter = 0;
boolean isTransferItem = false; boolean isTransferItem = false;
// Const check // Const check
int constellation = checkPlayerAvatarConstellationLevel(player, itemId); int constellation = checkPlayerAvatarConstellationLevel(player, itemId);
switch (constellation) { switch (constellation) {
...@@ -348,10 +348,10 @@ public class GachaManager { ...@@ -348,10 +348,10 @@ public class GachaManager {
GameItem item = new GameItem(itemData); GameItem item = new GameItem(itemData);
gachaItem.setGachaItem(item.toItemParam()); gachaItem.setGachaItem(item.toItemParam());
inventory.addItem(item); inventory.addItem(item);
stardust += addStardust; stardust += addStardust;
starglitter += addStarglitter; starglitter += addStarglitter;
if (addStardust > 0) { if (addStardust > 0) {
gachaItem.addTokenItemList(ItemParam.newBuilder().setItemId(stardustId).setCount(addStardust)); gachaItem.addTokenItemList(ItemParam.newBuilder().setItemId(stardustId).setCount(addStardust));
} }
...@@ -362,10 +362,10 @@ public class GachaManager { ...@@ -362,10 +362,10 @@ public class GachaManager {
} }
gachaItem.addTokenItemList(starglitterParam); gachaItem.addTokenItemList(starglitterParam);
} }
list.add(gachaItem.build()); list.add(gachaItem.build());
} }
// Add stardust/starglitter // Add stardust/starglitter
if (stardust > 0) { if (stardust > 0) {
inventory.addItem(stardustId, stardust); inventory.addItem(stardustId, stardust);
...@@ -376,7 +376,7 @@ public class GachaManager { ...@@ -376,7 +376,7 @@ public class GachaManager {
// Packets // Packets
player.sendPacket(new PacketDoGachaRsp(banner, list, gachaInfo)); player.sendPacket(new PacketDoGachaRsp(banner, list, gachaInfo));
// Battle Pass trigger // Battle Pass trigger
player.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_GACHA_NUM, 0, times); player.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_GACHA_NUM, 0, times);
} }
...@@ -420,10 +420,10 @@ public class GachaManager { ...@@ -420,10 +420,10 @@ public class GachaManager {
} }
} }
} }
private synchronized GetGachaInfoRsp createProto(Player player) { private synchronized GetGachaInfoRsp createProto(Player player) {
GetGachaInfoRsp.Builder proto = GetGachaInfoRsp.newBuilder().setGachaRandom(12345); GetGachaInfoRsp.Builder proto = GetGachaInfoRsp.newBuilder().setGachaRandom(12345);
long currentTime = System.currentTimeMillis() / 1000L; long currentTime = System.currentTimeMillis() / 1000L;
for (GachaBanner banner : getGachaBanners().values()) { for (GachaBanner banner : getGachaBanners().values()) {
...@@ -432,7 +432,7 @@ public class GachaManager { ...@@ -432,7 +432,7 @@ public class GachaManager {
proto.addGachaInfoList(banner.toProto(player)); proto.addGachaInfoList(banner.toProto(player));
} }
} }
return proto.build(); return proto.build();
} }
......
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