mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-20 01:29:54 +02:00
Implement vampire survivor records
This commit is contained in:
@@ -15,6 +15,7 @@ import lombok.Getter;
|
||||
public class VampireSurvivorGame {
|
||||
private final VampireSurvivorManager manager;
|
||||
private final VampireSurvivorDef data;
|
||||
private long[] builds;
|
||||
|
||||
private IntSet cards;
|
||||
|
||||
@@ -22,9 +23,10 @@ public class VampireSurvivorGame {
|
||||
private int rewardLevel;
|
||||
private IntList rewards;
|
||||
|
||||
public VampireSurvivorGame(VampireSurvivorManager manager, VampireSurvivorDef data) {
|
||||
public VampireSurvivorGame(VampireSurvivorManager manager, VampireSurvivorDef data, long[] builds) {
|
||||
this.manager = manager;
|
||||
this.data = data;
|
||||
this.builds = builds;
|
||||
|
||||
this.cards = new IntOpenHashSet();
|
||||
this.rewards = new IntArrayList();
|
||||
@@ -32,6 +34,10 @@ public class VampireSurvivorGame {
|
||||
this.calcRewards();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.getData().getId();
|
||||
}
|
||||
|
||||
private WeightedList<Integer> getRandom() {
|
||||
var random = new WeightedList<Integer>();
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package emu.nebula.game.vampire;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import emu.nebula.proto.Public.VampireSurvivorLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Entity(useDiscriminator = false)
|
||||
public class VampireSurvivorLog {
|
||||
private int id;
|
||||
|
||||
@Setter private int score;
|
||||
@Setter private boolean passed;
|
||||
@Setter private long[] builds;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public VampireSurvivorLog() {
|
||||
|
||||
}
|
||||
|
||||
public VampireSurvivorLog(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public VampireSurvivorLevel toProto() {
|
||||
var proto = VampireSurvivorLevel.newInstance()
|
||||
.setId(this.getId())
|
||||
.setScore(this.getScore())
|
||||
.setPassed(this.isPassed());
|
||||
|
||||
if (this.builds != null) {
|
||||
for (long buildId : this.builds) {
|
||||
proto.addBuildIds(buildId);
|
||||
}
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,100 @@
|
||||
package emu.nebula.game.vampire;
|
||||
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
|
||||
import emu.nebula.game.player.PlayerProgress;
|
||||
import emu.nebula.util.Bitset;
|
||||
import lombok.Getter;
|
||||
import us.hebi.quickbuf.RepeatedLong;
|
||||
|
||||
@Getter
|
||||
public class VampireSurvivorManager extends PlayerManager {
|
||||
// Game
|
||||
private transient VampireSurvivorGame game;
|
||||
private VampireSurvivorGame game;
|
||||
|
||||
public VampireSurvivorManager(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
public VampireSurvivorGame apply(int levelId) {
|
||||
public PlayerProgress getProgress() {
|
||||
return this.getPlayer().getProgress();
|
||||
}
|
||||
|
||||
public Bitset getTalents() {
|
||||
return this.getProgress().getVampireTalents();
|
||||
}
|
||||
|
||||
public int getTalentPoints() {
|
||||
return this.getProgress().getVampireCards().size() * 5;
|
||||
}
|
||||
|
||||
public VampireSurvivorGame apply(int levelId, RepeatedLong builds) {
|
||||
// Get data
|
||||
var data = GameData.getVampireSurvivorDataTable().get(levelId);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check player level (world class)
|
||||
if (this.getPlayer().getLevel() < data.getNeedWorldClass()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check builds
|
||||
if (builds.length() != data.getMode()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Make sure our builds exist
|
||||
for (long buildId : builds) {
|
||||
boolean hasBuild = this.getPlayer().getStarTowerManager().hasBuild(buildId);
|
||||
if (hasBuild == false) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Create game
|
||||
this.game = new VampireSurvivorGame(this, data);
|
||||
this.game = new VampireSurvivorGame(this, data, builds.toArray());
|
||||
|
||||
// Success
|
||||
return this.game;
|
||||
}
|
||||
|
||||
public void settle(boolean isWin, int score) {
|
||||
// Sanity check
|
||||
if (this.game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if we didn't win
|
||||
if (!isWin) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get log from database
|
||||
var log = this.getProgress().getVampireLog().computeIfAbsent(
|
||||
game.getId(),
|
||||
id -> new VampireSurvivorLog(id)
|
||||
);
|
||||
|
||||
// Check if we should update score
|
||||
if (score >= log.getScore() || !log.isPassed()) {
|
||||
// Set record info
|
||||
log.setPassed(isWin);
|
||||
log.setScore(score);
|
||||
log.setBuilds(game.getBuilds());
|
||||
|
||||
// Save record to database if we set any data
|
||||
Nebula.getGameDatabase().update(
|
||||
this.getProgress(),
|
||||
this.getPlayerUid(),
|
||||
"vampireLog." + game.getId(),
|
||||
log
|
||||
);
|
||||
}
|
||||
|
||||
// Clear game
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user