mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-18 07:14:49 +01:00
Implement basic quest stuff
This commit is contained in:
47
src/main/java/emu/nebula/game/quest/GameQuest.java
Normal file
47
src/main/java/emu/nebula/game/quest/GameQuest.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package emu.nebula.game.quest;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
|
||||
import emu.nebula.data.resources.DailyQuestDef;
|
||||
import emu.nebula.proto.Public.Quest;
|
||||
import emu.nebula.proto.Public.QuestProgress;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Entity(useDiscriminator = false)
|
||||
public class GameQuest {
|
||||
private int id;
|
||||
private int type;
|
||||
private int curProgress;
|
||||
private int maxProgress;
|
||||
|
||||
@Deprecated
|
||||
public GameQuest() {
|
||||
|
||||
}
|
||||
|
||||
public GameQuest(DailyQuestDef data) {
|
||||
this.id = data.getId();
|
||||
this.type = QuestType.Daily;
|
||||
this.maxProgress = data.getCompleteCondParams()[0];
|
||||
}
|
||||
|
||||
public void resetProgress() {
|
||||
this.curProgress = 0;
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public Quest toProto() {
|
||||
var progress = QuestProgress.newInstance()
|
||||
.setCur(this.getCurProgress())
|
||||
.setMax(this.getMaxProgress());
|
||||
|
||||
var proto = Quest.newInstance()
|
||||
.setId(this.getId())
|
||||
.setTypeValue(this.getType())
|
||||
.addProgress(progress);
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
61
src/main/java/emu/nebula/game/quest/QuestManager.java
Normal file
61
src/main/java/emu/nebula/game/quest/QuestManager.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package emu.nebula.game.quest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.database.GameDatabaseObject;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Entity(value = "quests", useDiscriminator = false)
|
||||
public class QuestManager extends PlayerManager implements GameDatabaseObject {
|
||||
@Id
|
||||
private int uid;
|
||||
|
||||
private Map<Integer, GameQuest> quests;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public QuestManager() {
|
||||
|
||||
}
|
||||
|
||||
public QuestManager(Player player) {
|
||||
super(player);
|
||||
this.uid = player.getUid();
|
||||
this.quests = new HashMap<>();
|
||||
|
||||
this.resetDailyQuests();
|
||||
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void resetDailyQuests() {
|
||||
// Reset daily quests
|
||||
for (var data : GameData.getDailyQuestDataTable()) {
|
||||
// Get quest
|
||||
var quest = getQuests().computeIfAbsent(data.getId(), i -> new GameQuest(data));
|
||||
|
||||
// Reset progress
|
||||
quest.resetProgress();
|
||||
|
||||
// Update to player
|
||||
if (getPlayer().hasSession()) {
|
||||
getPlayer().addNextPackage(
|
||||
NetMsgId.quest_change_notify,
|
||||
quest.toProto()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Persist to database
|
||||
this.save();
|
||||
}
|
||||
|
||||
}
|
||||
17
src/main/java/emu/nebula/game/quest/QuestType.java
Normal file
17
src/main/java/emu/nebula/game/quest/QuestType.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package emu.nebula.game.quest;
|
||||
|
||||
public class QuestType {
|
||||
public static final int UnknownQuest = 0;
|
||||
public static final int TourGuide = 1;
|
||||
public static final int Daily = 2;
|
||||
public static final int TravelerDuel = 3;
|
||||
public static final int TravelerDuelChallenge = 4;
|
||||
public static final int Affinity = 5;
|
||||
public static final int BattlePassDaily = 6;
|
||||
public static final int BattlePassWeekly = 7;
|
||||
public static final int VampireSurvivorNormal = 8;
|
||||
public static final int VampireSurvivorSeason = 9;
|
||||
public static final int Tower = 10;
|
||||
public static final int Demon = 11;
|
||||
public static final int TowerEvent = 12;
|
||||
}
|
||||
Reference in New Issue
Block a user