Implement character stories

This commit is contained in:
Melledy
2025-10-28 01:09:03 -07:00
parent 38d44f7a71
commit 276d9f9002
5 changed files with 89 additions and 2 deletions

View File

@@ -8,7 +8,8 @@ import emu.nebula.database.GameDatabaseObject;
import emu.nebula.game.player.Player;
import emu.nebula.game.player.PlayerChangeInfo;
import emu.nebula.game.player.PlayerManager;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
@@ -22,6 +23,7 @@ public class StoryManager extends PlayerManager implements GameDatabaseObject {
private int uid;
private IntSet completedStories;
private Int2IntMap completedSets;
@Deprecated // Morphia only
public StoryManager() {
@@ -32,9 +34,13 @@ public class StoryManager extends PlayerManager implements GameDatabaseObject {
super(player);
this.uid = player.getUid();
this.completedStories = new IntOpenHashSet();
this.completedSets = new Int2IntOpenHashMap();
this.save();
}
public PlayerChangeInfo settle(IntList list) {
// Player change info
var changes = new PlayerChangeInfo();
for (int id : list) {
@@ -59,4 +65,31 @@ public class StoryManager extends PlayerManager implements GameDatabaseObject {
return changes;
}
public PlayerChangeInfo settleSet(int chapterId, int sectionId) {
// Player change info
var changes = new PlayerChangeInfo();
// Get story data
var data = GameData.getStorySetSectionDataTable().get(sectionId);
if (data == null) return changes;
int sectionIndex = sectionId % 10;
// Check if we already completed the story
if (this.getCompletedSets().get(chapterId) >= sectionIndex) {
return changes;
}
// Complete story and get rewards
this.getCompletedSets().put(chapterId, sectionIndex);
// Add rewards
this.getPlayer().getInventory().addItems(data.getRewards(), changes);
// Save to db
Nebula.getGameDatabase().update(this, this.getPlayerUid(), "completedSets." + chapterId, sectionIndex);
return changes;
}
}