mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-20 01:29:54 +02:00
Implement story
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package emu.nebula.game.inventory;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import emu.nebula.proto.Public.ItemTpl;
|
||||
import lombok.Getter;
|
||||
@@ -7,7 +9,10 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@Entity(useDiscriminator = false)
|
||||
public class ItemParam {
|
||||
@SerializedName("Tid")
|
||||
public int id;
|
||||
|
||||
@SerializedName("Qty")
|
||||
public int count;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ItemParamMap extends Int2IntOpenHashMap {
|
||||
.map(e -> ItemTpl.newInstance().setTid(e.getIntKey()).setQty(e.getIntValue()));
|
||||
}
|
||||
|
||||
// Proto
|
||||
// Helpers
|
||||
|
||||
public static ItemParamMap fromTemplates(RepeatedMessage<ItemTpl> items) {
|
||||
var map = new ItemParamMap();
|
||||
@@ -97,4 +97,14 @@ public class ItemParamMap extends Int2IntOpenHashMap {
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static ItemParamMap fromItemParams(List<ItemParam> items) {
|
||||
var map = new ItemParamMap();
|
||||
|
||||
for (var template : items) {
|
||||
map.add(template.getId(), template.getCount());
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,13 @@ import emu.nebula.game.character.CharacterStorage;
|
||||
import emu.nebula.game.formation.FormationManager;
|
||||
import emu.nebula.game.inventory.Inventory;
|
||||
import emu.nebula.game.mail.Mailbox;
|
||||
import emu.nebula.game.story.StoryManager;
|
||||
import emu.nebula.game.tower.StarTowerManager;
|
||||
import emu.nebula.net.GameSession;
|
||||
import emu.nebula.proto.PlayerData.PlayerInfo;
|
||||
import emu.nebula.proto.Public.NewbieInfo;
|
||||
import emu.nebula.proto.Public.QuestType;
|
||||
import emu.nebula.proto.Public.Story;
|
||||
import emu.nebula.proto.Public.WorldClass;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
@@ -62,6 +64,7 @@ public class Player implements GameDatabaseObject {
|
||||
private transient FormationManager formations;
|
||||
private transient Mailbox mailbox;
|
||||
private transient StarTowerManager starTowerManager;
|
||||
private transient StoryManager storyManager;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public Player() {
|
||||
@@ -257,6 +260,13 @@ public class Player implements GameDatabaseObject {
|
||||
} else {
|
||||
this.starTowerManager.setPlayer(this);
|
||||
}
|
||||
|
||||
this.storyManager = Nebula.getGameDatabase().getObjectByField(StoryManager.class, "_id", this.getUid());
|
||||
if (this.storyManager == null) {
|
||||
this.storyManager = new StoryManager(this);
|
||||
} else {
|
||||
this.storyManager.setPlayer(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Proto
|
||||
@@ -337,6 +347,16 @@ public class Player implements GameDatabaseObject {
|
||||
}
|
||||
|
||||
acc.addNewbies(NewbieInfo.newInstance().setGroupId(GameConstants.INTRO_GUIDE_ID).setStepId(-1));
|
||||
|
||||
// Story
|
||||
var story = proto.getMutableStory();
|
||||
|
||||
for (int storyId : this.getStoryManager().getCompletedStories()) {
|
||||
var storyProto = Story.newInstance()
|
||||
.setIdx(storyId);
|
||||
|
||||
story.addStories(storyProto);
|
||||
}
|
||||
|
||||
//
|
||||
proto.addBoard(410301);
|
||||
@@ -351,7 +371,6 @@ public class Player implements GameDatabaseObject {
|
||||
proto.getMutableQuests();
|
||||
proto.getMutableAgent();
|
||||
proto.getMutablePhone();
|
||||
proto.getMutableStory();
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,62 @@
|
||||
package emu.nebula.game.story;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
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.IntList;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Entity(value = "story", useDiscriminator = false)
|
||||
public class StoryManager extends PlayerManager implements GameDatabaseObject {
|
||||
@Id
|
||||
private int uid;
|
||||
|
||||
private IntSet completedStories;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public StoryManager() {
|
||||
|
||||
}
|
||||
|
||||
public StoryManager(Player player) {
|
||||
super(player);
|
||||
this.uid = player.getUid();
|
||||
this.completedStories = new IntOpenHashSet();
|
||||
}
|
||||
|
||||
public PlayerChangeInfo settle(IntList list) {
|
||||
var changes = new PlayerChangeInfo();
|
||||
|
||||
for (int id : list) {
|
||||
// Get story data
|
||||
var data = GameData.getStoryDataTable().get(id);
|
||||
if (data == null) continue;
|
||||
|
||||
// Check if we already completed the story
|
||||
if (this.getCompletedStories().contains(id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Complete story and get rewards
|
||||
this.getCompletedStories().add(id);
|
||||
|
||||
// Add rewards
|
||||
this.getPlayer().getInventory().addItems(data.getRewards(), changes);
|
||||
|
||||
// Save to db
|
||||
Nebula.getGameDatabase().addToList(this, this.getPlayerUid(), "completedStories", id);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user