mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 12:24:35 +01:00
Implement character stories
This commit is contained in:
@@ -43,6 +43,7 @@ public class GameData {
|
||||
@Getter private static DataTable<WorldClassDef> WorldClassDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<GuideGroupDef> GuideGroupDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<StoryDef> StoryDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<StorySetSectionDef> StorySetSectionDataTable = new DataTable<>();
|
||||
|
||||
@Getter private static DataTable<StarTowerDef> StarTowerDataTable = new DataTable<>();
|
||||
@Getter private static DataTable<StarTowerStageDef> StarTowerStageDataTable = new DataTable<>();
|
||||
|
||||
@@ -2,6 +2,7 @@ package emu.nebula.data.resources;
|
||||
|
||||
import emu.nebula.data.BaseDef;
|
||||
import emu.nebula.data.ResourceType;
|
||||
import emu.nebula.game.inventory.ItemParamMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import lombok.Getter;
|
||||
@@ -12,6 +13,11 @@ public class StorySetSectionDef extends BaseDef {
|
||||
private int Id;
|
||||
private int ChapterId;
|
||||
|
||||
private int RewardItem1Tid;
|
||||
private int RewardItem1Qty;
|
||||
|
||||
private transient ItemParamMap rewards;
|
||||
|
||||
@Getter
|
||||
private static IntSet chapterIds = new IntOpenHashSet();
|
||||
|
||||
@@ -22,6 +28,14 @@ public class StorySetSectionDef extends BaseDef {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// Add to chapter ids
|
||||
chapterIds.add(this.getChapterId());
|
||||
|
||||
// Parse rewards
|
||||
this.rewards = new ItemParamMap();
|
||||
|
||||
if (this.RewardItem1Tid > 0) {
|
||||
this.rewards.add(this.RewardItem1Tid, this.RewardItem1Qty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,26 @@ public class HandlerStorySetInfoReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Create response
|
||||
var rsp = StorySetInfoResp.newInstance();
|
||||
|
||||
// Get completed sets
|
||||
var completedSets = session.getPlayer().getStoryManager().getCompletedSets();
|
||||
|
||||
// Story set (trekker story)
|
||||
for (int chapterId : StorySetSectionDef.getChapterIds()) {
|
||||
// Get completed index
|
||||
int index = completedSets.get(chapterId);
|
||||
|
||||
var chapter = StorySetChapter.newInstance()
|
||||
.setChapterId(chapterId);
|
||||
.setChapterId(chapterId)
|
||||
.setSectionIndex(index);
|
||||
|
||||
// Add rewarded ids
|
||||
if (index > 0) {
|
||||
for (int i = 1; i <= index; i++)
|
||||
chapter.addRewardedIds((chapterId * 100) + i);
|
||||
}
|
||||
|
||||
rsp.addChapters(chapter);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.StorySetRewardReceive.StorySetRewardReceiveReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.story_set_reward_receive_req)
|
||||
public class HandlerStorySetRewardReceiveReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = StorySetRewardReceiveReq.parseFrom(message);
|
||||
|
||||
// Settle
|
||||
var changes = session.getPlayer().getStoryManager().settleSet(req.getChapterId(), req.getSectionId());
|
||||
|
||||
// Finish
|
||||
return this.encodeMsg(NetMsgId.story_set_reward_receive_succeed_ack, changes.toProto());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user