mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-17 09:25:06 +01:00
Merge pull request Grasscutter-Quests#53
'Updated with how talks are handle' by `mjolsic`
This commit is contained in:
@@ -5,12 +5,13 @@ import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.binout.MainQuestData;
|
||||
import emu.grasscutter.data.binout.ScenePointEntry;
|
||||
import emu.grasscutter.data.excels.QuestData;
|
||||
import emu.grasscutter.data.excels.quest.QuestData;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.player.BasePlayerManager;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.quest.enums.*;
|
||||
import emu.grasscutter.server.packet.send.PacketFinishedParentQuestUpdateNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketQuestGlobalVarNotify;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import io.netty.util.concurrent.FastThreadLocalThread;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
@@ -226,29 +227,60 @@ public class QuestManager extends BasePlayerManager {
|
||||
this.triggerEvent(QuestCond.QUEST_COND_PLAYER_LEVEL_EQUAL_GREATER, null, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
Looking through mainQuests 72201-72208 and 72174, we can infer that a questGlobalVar's default value is 0
|
||||
*/
|
||||
public Integer getQuestGlobalVarValue(Integer variable) {
|
||||
return getPlayer().getQuestGlobalVariables().getOrDefault(variable,0);
|
||||
/**
|
||||
* Returns the default value of a global variable.
|
||||
*
|
||||
* @param variable The variable ID.
|
||||
* @return The default value.
|
||||
*/
|
||||
public int getGlobalVarDefault(int variable) {
|
||||
var questGlobalVarData = GameData.getQuestGlobalVarDataMap().get(variable);
|
||||
return questGlobalVarData != null ? questGlobalVarData.getDefaultValue() : 0;
|
||||
}
|
||||
|
||||
public void setQuestGlobalVarValue(Integer variable, Integer value) {
|
||||
Integer previousValue = getPlayer().getQuestGlobalVariables().put(variable,value);
|
||||
Grasscutter.getLogger().debug("Changed questGlobalVar {} value from {} to {}", variable, previousValue==null ? 0: previousValue, value);
|
||||
/*
|
||||
* Looking through mainQuests 72201-72208 and 72174, we can infer that a questGlobalVar's default value is 0
|
||||
*/
|
||||
public Integer getQuestGlobalVarValue(Integer variable) {
|
||||
return getPlayer().getQuestGlobalVariables()
|
||||
.computeIfAbsent(variable, k -> this.getGlobalVarDefault(variable));
|
||||
}
|
||||
public void incQuestGlobalVarValue(Integer variable, Integer inc) {
|
||||
//
|
||||
Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable,0);
|
||||
getPlayer().getQuestGlobalVariables().put(variable,previousValue + inc);
|
||||
Grasscutter.getLogger().debug("Incremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue + inc);
|
||||
|
||||
public void setQuestGlobalVarValue(int variable, int setVal) {
|
||||
var prevVal = this.getPlayer().getQuestGlobalVariables().put(variable, setVal);
|
||||
if (prevVal == null){
|
||||
prevVal = this.getGlobalVarDefault(variable);
|
||||
}
|
||||
var newVal = this.getQuestGlobalVarValue(variable);
|
||||
|
||||
Grasscutter.getLogger().debug("Changed questGlobalVar {} value from {} to {}", variable, prevVal, newVal);
|
||||
this.triggerQuestGlobalVarAction(variable, setVal);
|
||||
}
|
||||
//In MainQuest 998, dec is passed as a positive integer
|
||||
public void decQuestGlobalVarValue(Integer variable, Integer dec) {
|
||||
//
|
||||
Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable,0);
|
||||
getPlayer().getQuestGlobalVariables().put(variable,previousValue - dec);
|
||||
Grasscutter.getLogger().debug("Decremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue - dec);
|
||||
|
||||
public void incQuestGlobalVarValue(int variable, int inc) {
|
||||
var prevVal = getQuestGlobalVarValue(variable);
|
||||
var newVal = getPlayer().getQuestGlobalVariables()
|
||||
.compute(variable, (k, v) -> prevVal + inc);
|
||||
|
||||
Grasscutter.getLogger().debug("Incremented questGlobalVar {} value from {} to {}", variable, prevVal, newVal);
|
||||
this.triggerQuestGlobalVarAction(variable, newVal);
|
||||
}
|
||||
|
||||
// In MainQuest 998, dec is passed as a positive integer
|
||||
public void decQuestGlobalVarValue(int variable, int dec) {
|
||||
var prevVal = getQuestGlobalVarValue(variable);
|
||||
this.getPlayer().getQuestGlobalVariables().put(variable, prevVal - dec);
|
||||
var newVal = getQuestGlobalVarValue(variable);
|
||||
|
||||
Grasscutter.getLogger().debug("Decremented questGlobalVar {} value from {} to {}", variable, prevVal, newVal);
|
||||
this.triggerQuestGlobalVarAction(variable, newVal);
|
||||
}
|
||||
|
||||
public void triggerQuestGlobalVarAction(int variable, int value) {
|
||||
this.queueEvent(QuestCond.QUEST_COND_QUEST_GLOBAL_VAR_EQUAL, variable, value);
|
||||
this.queueEvent(QuestCond.QUEST_COND_QUEST_GLOBAL_VAR_GREATER, variable, value);
|
||||
this.queueEvent(QuestCond.QUEST_COND_QUEST_GLOBAL_VAR_LESS, variable, value);
|
||||
this.getPlayer().sendPacket(new PacketQuestGlobalVarNotify(getPlayer()));
|
||||
}
|
||||
|
||||
public GameMainQuest getMainQuestById(int mainQuestId) {
|
||||
@@ -261,13 +293,12 @@ public class QuestManager extends BasePlayerManager {
|
||||
}
|
||||
|
||||
public GameQuest getQuestById(int questId) {
|
||||
QuestData questConfig = GameData.getQuestDataMap().get(questId);
|
||||
var questConfig = GameData.getQuestDataMap().get(questId);
|
||||
if (questConfig == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GameMainQuest mainQuest = getMainQuests().get(questConfig.getMainId());
|
||||
|
||||
var mainQuest = getMainQuests().get(questConfig.getMainId());
|
||||
if (mainQuest == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -276,23 +307,23 @@ public class QuestManager extends BasePlayerManager {
|
||||
}
|
||||
|
||||
public void forEachQuest(Consumer<GameQuest> callback) {
|
||||
for (GameMainQuest mainQuest : getMainQuests().values()) {
|
||||
for (GameQuest quest : mainQuest.getChildQuests().values()) {
|
||||
for (var mainQuest : getMainQuests().values()) {
|
||||
for (var quest : mainQuest.getChildQuests().values()) {
|
||||
callback.accept(quest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void forEachMainQuest(Consumer<GameMainQuest> callback) {
|
||||
for (GameMainQuest mainQuest : getMainQuests().values()) {
|
||||
for (var mainQuest : getMainQuests().values()) {
|
||||
callback.accept(mainQuest);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
public void forEachActiveQuest(Consumer<GameQuest> callback) {
|
||||
for (GameMainQuest mainQuest : getMainQuests().values()) {
|
||||
for (GameQuest quest : mainQuest.getChildQuests().values()) {
|
||||
for (var mainQuest : getMainQuests().values()) {
|
||||
for (var quest : mainQuest.getChildQuests().values()) {
|
||||
if (quest.getState() != QuestState.QUEST_STATE_FINISHED) {
|
||||
callback.accept(quest);
|
||||
}
|
||||
@@ -301,28 +332,25 @@ public class QuestManager extends BasePlayerManager {
|
||||
}
|
||||
|
||||
public GameMainQuest addMainQuest(QuestData questConfig) {
|
||||
GameMainQuest mainQuest = new GameMainQuest(getPlayer(), questConfig.getMainId());
|
||||
getMainQuests().put(mainQuest.getParentQuestId(), mainQuest);
|
||||
|
||||
getPlayer().sendPacket(new PacketFinishedParentQuestUpdateNotify(mainQuest));
|
||||
var mainQuest = new GameMainQuest(getPlayer(), questConfig.getMainId());
|
||||
this.getMainQuests().put(mainQuest.getParentQuestId(), mainQuest);
|
||||
this.getPlayer().sendPacket(new PacketFinishedParentQuestUpdateNotify(mainQuest));
|
||||
|
||||
return mainQuest;
|
||||
}
|
||||
|
||||
public GameQuest addQuest(int questId) {
|
||||
QuestData questConfig = GameData.getQuestDataMap().get(questId);
|
||||
|
||||
var questConfig = GameData.getQuestDataMap().get(questId);
|
||||
if (questConfig == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return addQuest(questConfig);
|
||||
return this.addQuest(questConfig);
|
||||
}
|
||||
|
||||
public GameQuest addQuest(@Nonnull QuestData questConfig) {
|
||||
|
||||
// Main quest
|
||||
GameMainQuest mainQuest = this.getMainQuestById(questConfig.getMainId());
|
||||
var mainQuest = this.getMainQuestById(questConfig.getMainId());
|
||||
|
||||
// Create main quest if it doesnt exist
|
||||
if (mainQuest == null) {
|
||||
@@ -330,11 +358,11 @@ public class QuestManager extends BasePlayerManager {
|
||||
}
|
||||
|
||||
// Sub quest
|
||||
GameQuest quest = mainQuest.getChildQuestById(questConfig.getSubId());
|
||||
|
||||
var quest = mainQuest.getChildQuestById(questConfig.getSubId());
|
||||
// Forcefully start
|
||||
quest.start();
|
||||
checkQuestAlreadyFullfilled(quest);
|
||||
// Check conditions.
|
||||
this.checkQuestAlreadyFullfilled(quest);
|
||||
|
||||
return quest;
|
||||
}
|
||||
@@ -442,7 +470,7 @@ public class QuestManager extends BasePlayerManager {
|
||||
/**
|
||||
* TODO maybe trigger them delayed to allow basic communication finish first
|
||||
* TODO move content checks to use static informations where possible to allow direct already fulfilled checking
|
||||
* @param quest
|
||||
* @param quest The ID of the quest.
|
||||
*/
|
||||
public void checkQuestAlreadyFullfilled(GameQuest quest){
|
||||
Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> {
|
||||
|
||||
Reference in New Issue
Block a user