Implement gacha banners (not newbie)

This commit is contained in:
Melledy
2025-11-01 04:17:44 -07:00
parent e9f991355a
commit 37b74c9b35
20 changed files with 697 additions and 40 deletions

View File

@@ -0,0 +1,46 @@
package emu.nebula.game.gacha;
import java.util.Collection;
import emu.nebula.Nebula;
import emu.nebula.data.resources.GachaDef;
import emu.nebula.game.player.Player;
import emu.nebula.game.player.PlayerManager;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class GachaManager extends PlayerManager {
private final Int2ObjectMap<GachaBannerInfo> bannerInfos;
private boolean loaded;
public GachaManager(Player player) {
super(player);
this.bannerInfos = new Int2ObjectOpenHashMap<>();
}
public synchronized Collection<GachaBannerInfo> getBannerInfos() {
return this.bannerInfos.values();
}
public synchronized GachaBannerInfo getBannerInfo(GachaDef gachaData) {
if (!this.loaded) {
this.loadFromDatabase();
}
return this.bannerInfos.computeIfAbsent(
gachaData.getId(),
i -> new GachaBannerInfo(this.getPlayer(), gachaData)
);
}
private void loadFromDatabase() {
var db = Nebula.getGameDatabase();
db.getObjects(GachaBannerInfo.class, "playerUid", getPlayerUid()).forEach(bannerInfo -> {
this.bannerInfos.put(bannerInfo.getBannerId(), bannerInfo);
});
this.loaded = true;
}
}