small quest fixes (#1677)

* small quest fixes

* uncomment hack
This commit is contained in:
akatatsu27 2022-08-21 10:08:37 +03:00 committed by GitHub
parent abd1e7569e
commit 77f2bcf5bf
8 changed files with 42 additions and 45 deletions

View File

@ -225,6 +225,7 @@ public class Player {
this.unlockedFurnitureSuite = new HashSet<>(); this.unlockedFurnitureSuite = new HashSet<>();
this.activeForges = new ArrayList<>(); this.activeForges = new ArrayList<>();
this.unlockedRecipies = new HashMap<>(); this.unlockedRecipies = new HashMap<>();
this.questGlobalVariables = new HashMap<>();
this.openStates = new HashMap<>(); this.openStates = new HashMap<>();
this.unlockedSceneAreas = new HashMap<>(); this.unlockedSceneAreas = new HashMap<>();
this.unlockedScenePoints = new HashMap<>(); this.unlockedScenePoints = new HashMap<>();
@ -1197,7 +1198,7 @@ public class Player {
session.send(new PacketPlayerLevelRewardUpdateNotify(rewardedLevels)); session.send(new PacketPlayerLevelRewardUpdateNotify(rewardedLevels));
// First notify packets sent // First notify packets sent
this.hasSentLoginPackets = true; this.hasSentLoginPackets = true;
// Set session state // Set session state
session.setState(SessionState.ACTIVE); session.setState(SessionState.ACTIVE);

View File

@ -46,6 +46,7 @@ public class PlayerProgressManager extends BasePlayerDataManager {
// that particular statue interactable. // that particular statue interactable.
this.player.getUnlockedScenePoints(3).add(7); this.player.getUnlockedScenePoints(3).add(7);
this.player.getUnlockedSceneAreas(3).add(1); this.player.getUnlockedSceneAreas(3).add(1);
} }
/****************************************************************************************************************** /******************************************************************************************************************
@ -61,12 +62,12 @@ public class PlayerProgressManager extends BasePlayerDataManager {
// Set of open states that are set per default for all accounts. Can be overwritten by an entry in `map`. // Set of open states that are set per default for all accounts. Can be overwritten by an entry in `map`.
public static final Set<Integer> DEFAULT_OPEN_STATES = GameData.getOpenStateList().stream() public static final Set<Integer> DEFAULT_OPEN_STATES = GameData.getOpenStateList().stream()
.filter(s -> .filter(s ->
s.isDefaultState() // Actual default-opened states. s.isDefaultState() // Actual default-opened states.
// All states whose unlock we don't handle correctly yet. // All states whose unlock we don't handle correctly yet.
|| (s.getCond().stream().filter(c -> c.getCondType() == OpenStateCondType.OPEN_STATE_COND_PLAYER_LEVEL).count() == 0) || (s.getCond().stream().filter(c -> c.getCondType() == OpenStateCondType.OPEN_STATE_COND_PLAYER_LEVEL).count() == 0)
// Always unlock OPEN_STATE_PAIMON, otherwise the player will not have a working chat. // Always unlock OPEN_STATE_PAIMON, otherwise the player will not have a working chat.
|| s.getId() == 1 || s.getId() == 1
) )
.filter(s -> !BLACKLIST_OPEN_STATES.contains(s.getId())) // Filter out states in the blacklist. .filter(s -> !BLACKLIST_OPEN_STATES.contains(s.getId())) // Filter out states in the blacklist.
.map(s -> s.getId()) .map(s -> s.getId())
@ -119,7 +120,7 @@ public class PlayerProgressManager extends BasePlayerDataManager {
// ToDo: Implement. // ToDo: Implement.
} }
} }
// Done. If we didn't find any violations, all conditions are met. // Done. If we didn't find any violations, all conditions are met.
return true; return true;
} }
@ -195,14 +196,13 @@ public class PlayerProgressManager extends BasePlayerDataManager {
} }
} }
public void unlockTransPoint(int sceneId, int pointId, boolean isStatue) { public boolean unlockTransPoint(int sceneId, int pointId, boolean isStatue) {
// Check whether the unlocked point exists and whether it is still locked. // Check whether the unlocked point exists and whether it is still locked.
String key = sceneId + "_" + pointId; String key = sceneId + "_" + pointId;
ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(key); ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(key);
if (scenePointEntry == null || this.player.getUnlockedScenePoints(sceneId).contains(pointId)) { if (scenePointEntry == null || this.player.getUnlockedScenePoints(sceneId).contains(pointId)) {
this.player.sendPacket(new PacketUnlockTransPointRsp(Retcode.RET_FAIL)); return false;
return;
} }
// Add the point to the list of unlocked points for its scene. // Add the point to the list of unlocked points for its scene.
@ -222,7 +222,7 @@ public class PlayerProgressManager extends BasePlayerDataManager {
// Send packet. // Send packet.
this.player.sendPacket(new PacketScenePointUnlockNotify(sceneId, pointId)); this.player.sendPacket(new PacketScenePointUnlockNotify(sceneId, pointId));
this.player.sendPacket(new PacketUnlockTransPointRsp(Retcode.RET_SUCC)); return true;
} }
public void unlockSceneArea(int sceneId, int areaId) { public void unlockSceneArea(int sceneId, int areaId) {

View File

@ -194,8 +194,9 @@ public class GameMainQuest {
CompiledScript cs = ScriptLoader.getScriptByPath( CompiledScript cs = ScriptLoader.getScriptByPath(
SCRIPT("Quest/Share/Q" + getParentQuestId() + "ShareConfig." + ScriptLoader.getScriptType())); SCRIPT("Quest/Share/Q" + getParentQuestId() + "ShareConfig." + ScriptLoader.getScriptType()));
//mainQuest 303 doesn't have a ShareConfig
if (cs == null) { if (cs == null) {
Grasscutter.getLogger().error("Couldn't find Q" + getParentQuestId() + "ShareConfig." + ScriptLoader.getScriptType()); Grasscutter.getLogger().debug("Couldn't find Q" + getParentQuestId() + "ShareConfig." + ScriptLoader.getScriptType());
return; return;
} }
@ -283,15 +284,19 @@ public class GameMainQuest {
for (GameQuest subQuestWithCond : subQuestsWithCond) { for (GameQuest subQuestWithCond : subQuestsWithCond) {
List<QuestData.QuestCondition> failCond = subQuestWithCond.getQuestData().getFailCond(); List<QuestData.QuestCondition> failCond = subQuestWithCond.getQuestData().getFailCond();
int[] fail = new int[failCond.size()];
for (int i = 0; i < subQuestWithCond.getQuestData().getFailCond().size(); i++) { for (int i = 0; i < subQuestWithCond.getQuestData().getFailCond().size(); i++) {
QuestData.QuestCondition condition = failCond.get(i); QuestData.QuestCondition condition = failCond.get(i);
boolean result = this.getOwner().getServer().getQuestSystem().triggerContent(subQuestWithCond, condition, paramStr, params); if(condition.getType() == condType) {
fail[i] = result ? 1 : 0; boolean result = this.getOwner().getServer().getQuestSystem().triggerContent(subQuestWithCond, condition, paramStr, params);
subQuestWithCond.getFailProgressList()[i] = result ? 1 : 0;
if(result) {
getOwner().getSession().send(new PacketQuestProgressUpdateNotify(subQuestWithCond));
}
}
} }
boolean shouldFail = LogicType.calculate(subQuestWithCond.getQuestData().getFailCondComb(), fail); boolean shouldFail = LogicType.calculate(subQuestWithCond.getQuestData().getFailCondComb(), subQuestWithCond.getFailProgressList());
if (shouldFail) { if (shouldFail) {
subQuestWithCond.fail(); subQuestWithCond.fail();
@ -314,15 +319,19 @@ public class GameMainQuest {
for (GameQuest subQuestWithCond : subQuestsWithCond) { for (GameQuest subQuestWithCond : subQuestsWithCond) {
List<QuestData.QuestCondition> finishCond = subQuestWithCond.getQuestData().getFinishCond(); List<QuestData.QuestCondition> finishCond = subQuestWithCond.getQuestData().getFinishCond();
int[] finish = new int[finishCond.size()];
for (int i = 0; i < finishCond.size(); i++) { for (int i = 0; i < finishCond.size(); i++) {
QuestData.QuestCondition condition = finishCond.get(i); QuestData.QuestCondition condition = finishCond.get(i);
boolean result = this.getOwner().getServer().getQuestSystem().triggerContent(subQuestWithCond, condition, paramStr, params); if(condition.getType() == condType) {
finish[i] = result ? 1 : 0; boolean result = this.getOwner().getServer().getQuestSystem().triggerContent(subQuestWithCond, condition, paramStr, params);
subQuestWithCond.getFinishProgressList()[i] = result ? 1 : 0;
if(result) {
getOwner().getSession().send(new PacketQuestProgressUpdateNotify(subQuestWithCond));
}
}
} }
boolean shouldFinish = LogicType.calculate(subQuestWithCond.getQuestData().getFinishCondComb(), finish); boolean shouldFinish = LogicType.calculate(subQuestWithCond.getQuestData().getFinishCondComb(), subQuestWithCond.getFinishProgressList());
if (shouldFinish) { if (shouldFinish) {
subQuestWithCond.finish(); subQuestWithCond.finish();

View File

@ -137,13 +137,6 @@ public class GameQuest {
this.state = QuestState.QUEST_STATE_FINISHED; this.state = QuestState.QUEST_STATE_FINISHED;
this.finishTime = Utils.getCurrentSeconds(); this.finishTime = Utils.getCurrentSeconds();
if (getFinishProgressList() != null) {
Arrays.fill(getFinishProgressList(), 1);
}
getOwner().getSession().send(new PacketQuestProgressUpdateNotify(this));
if (getQuestData().finishParent()) { if (getQuestData().finishParent()) {
// This quest finishes the questline - the main quest will also save the quest to db, so we don't have to call save() here // This quest finishes the questline - the main quest will also save the quest to db, so we don't have to call save() here
getMainQuest().finish(); getMainQuest().finish();
@ -169,12 +162,6 @@ public class GameQuest {
this.state = QuestState.QUEST_STATE_FAILED; this.state = QuestState.QUEST_STATE_FAILED;
this.finishTime = Utils.getCurrentSeconds(); this.finishTime = Utils.getCurrentSeconds();
if (getFailProgressList() != null) {
Arrays.fill(getFailProgressList(), 1);
}
getOwner().getSession().send(new PacketQuestProgressUpdateNotify(this));
getQuestData().getFailExec().forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam())); getQuestData().getFailExec().forEach(e -> getOwner().getServer().getQuestSystem().triggerExec(this, e, e.getParam()));
//Some subQuests have conditions that subQuests fail (even from different MainQuests) //Some subQuests have conditions that subQuests fail (even from different MainQuests)
getOwner().getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_QUEST_STATE_EQUAL, this.subQuestId, this.state.getValue(),0,0,0); getOwner().getQuestManager().triggerEvent(QuestTrigger.QUEST_CONTENT_QUEST_STATE_EQUAL, this.subQuestId, this.state.getValue(),0,0,0);

View File

@ -25,8 +25,6 @@ import lombok.Getter;
public class QuestManager extends BasePlayerManager { public class QuestManager extends BasePlayerManager {
@Getter private final Player player; @Getter private final Player player;
@Getter private Map<Integer,Integer> questGlobalVariables;
@Getter private final Int2ObjectMap<GameMainQuest> mainQuests; @Getter private final Int2ObjectMap<GameMainQuest> mainQuests;
@Getter private List<GameQuest> addToQuestListUpdateNotify; @Getter private List<GameQuest> addToQuestListUpdateNotify;
/* /*
@ -63,7 +61,7 @@ public class QuestManager extends BasePlayerManager {
); );
*/ */
public static long getQuestKey(int mainQuestId){ public static long getQuestKey(int mainQuestId){
QuestEncryptionKey questEncryptionKey = GameData.getMainQuestEncryptionMap().get(mainQuestId); QuestEncryptionKey questEncryptionKey = GameData.getMainQuestEncryptionMap().get(mainQuestId);
return questEncryptionKey != null ? questEncryptionKey.getEncryptionKey() : 0L; return questEncryptionKey != null ? questEncryptionKey.getEncryptionKey() : 0L;
@ -72,7 +70,6 @@ public class QuestManager extends BasePlayerManager {
super(player); super(player);
this.player = player; this.player = player;
this.questGlobalVariables = player.getQuestGlobalVariables();
this.mainQuests = new Int2ObjectOpenHashMap<>(); this.mainQuests = new Int2ObjectOpenHashMap<>();
this.addToQuestListUpdateNotify = new ArrayList<>(); this.addToQuestListUpdateNotify = new ArrayList<>();
} }
@ -81,7 +78,7 @@ public class QuestManager extends BasePlayerManager {
List<GameMainQuest> newQuests = this.addMultMainQuests(newPlayerMainQuests); List<GameMainQuest> newQuests = this.addMultMainQuests(newPlayerMainQuests);
//getPlayer().sendPacket(new PacketServerCondMeetQuestListUpdateNotify(newPlayerServerCondMeetQuestListUpdateNotify)); //getPlayer().sendPacket(new PacketServerCondMeetQuestListUpdateNotify(newPlayerServerCondMeetQuestListUpdateNotify));
getPlayer().sendPacket(new PacketFinishedParentQuestUpdateNotify(newQuests)); //getPlayer().sendPacket(new PacketFinishedParentQuestUpdateNotify(newQuests));
} }
@ -112,24 +109,24 @@ public class QuestManager extends BasePlayerManager {
Looking through mainQuests 72201-72208 and 72174, we can infer that a questGlobalVar's default value is 0 Looking through mainQuests 72201-72208 and 72174, we can infer that a questGlobalVar's default value is 0
*/ */
public Integer getQuestGlobalVarValue(Integer variable) { public Integer getQuestGlobalVarValue(Integer variable) {
return this.questGlobalVariables.getOrDefault(variable,0); return getPlayer().getQuestGlobalVariables().getOrDefault(variable,0);
} }
public void setQuestGlobalVarValue(Integer variable, Integer value) { public void setQuestGlobalVarValue(Integer variable, Integer value) {
Integer previousValue = this.questGlobalVariables.put(variable,value); Integer previousValue = getPlayer().getQuestGlobalVariables().put(variable,value);
Grasscutter.getLogger().debug("Changed questGlobalVar {} value from {} to {}", variable, previousValue==null ? 0: previousValue, value); Grasscutter.getLogger().debug("Changed questGlobalVar {} value from {} to {}", variable, previousValue==null ? 0: previousValue, value);
} }
public void incQuestGlobalVarValue(Integer variable, Integer inc) { public void incQuestGlobalVarValue(Integer variable, Integer inc) {
// //
Integer previousValue = this.questGlobalVariables.getOrDefault(variable,0); Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable,0);
this.questGlobalVariables.put(variable,previousValue + inc); getPlayer().getQuestGlobalVariables().put(variable,previousValue + inc);
Grasscutter.getLogger().debug("Incremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue + inc); Grasscutter.getLogger().debug("Incremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue + inc);
} }
//In MainQuest 998, dec is passed as a positive integer //In MainQuest 998, dec is passed as a positive integer
public void decQuestGlobalVarValue(Integer variable, Integer dec) { public void decQuestGlobalVarValue(Integer variable, Integer dec) {
// //
Integer previousValue = this.questGlobalVariables.getOrDefault(variable,0); Integer previousValue = getPlayer().getQuestGlobalVariables().getOrDefault(variable,0);
this.questGlobalVariables.put(variable,previousValue - dec); getPlayer().getQuestGlobalVariables().put(variable,previousValue - dec);
Grasscutter.getLogger().debug("Decremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue - dec); Grasscutter.getLogger().debug("Decremented questGlobalVar {} value from {} to {}", variable, previousValue, previousValue - dec);
} }

View File

@ -10,6 +10,6 @@ import emu.grasscutter.game.quest.handlers.QuestBaseHandler;
public class ContentUnlockTransPoint extends QuestBaseHandler { public class ContentUnlockTransPoint extends QuestBaseHandler {
@Override @Override
public boolean execute(GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) { public boolean execute(GameQuest quest, QuestData.QuestCondition condition, String paramStr, int... params) {
return true; return condition.getParam()[0] == params[0] && condition.getParam()[1] == params[1];
} }
} }

View File

@ -13,7 +13,7 @@ public class ExecUnlockPoint extends QuestExecHandler {
// Unlock the trans point for the player. // Unlock the trans point for the player.
int sceneId = Integer.parseInt(paramStr[0]); int sceneId = Integer.parseInt(paramStr[0]);
int pointId = Integer.parseInt(paramStr[1]); int pointId = Integer.parseInt(paramStr[1]);
boolean isStatue = quest.getMainQuestId() == 303; boolean isStatue = quest.getMainQuestId() == 303 || quest.getMainQuestId() == 352;
quest.getOwner().getProgressManager().unlockTransPoint(sceneId, pointId, isStatue); quest.getOwner().getProgressManager().unlockTransPoint(sceneId, pointId, isStatue);

View File

@ -2,15 +2,18 @@ package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.RetcodeOuterClass;
import emu.grasscutter.net.proto.UnlockTransPointReqOuterClass.UnlockTransPointReq; import emu.grasscutter.net.proto.UnlockTransPointReqOuterClass.UnlockTransPointReq;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketUnlockTransPointRsp;
@Opcodes(PacketOpcodes.UnlockTransPointReq) @Opcodes(PacketOpcodes.UnlockTransPointReq)
public class HandlerUnlockTransPointReq extends PacketHandler { public class HandlerUnlockTransPointReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
UnlockTransPointReq req = UnlockTransPointReq.parseFrom(payload); UnlockTransPointReq req = UnlockTransPointReq.parseFrom(payload);
session.getPlayer().getProgressManager().unlockTransPoint(req.getSceneId(), req.getPointId(), false); boolean unlocked = session.getPlayer().getProgressManager().unlockTransPoint(req.getSceneId(), req.getPointId(), false);
session.getPlayer().sendPacket(new PacketUnlockTransPointRsp(unlocked ? RetcodeOuterClass.Retcode.RET_SUCC : RetcodeOuterClass.Retcode.RET_FAIL));
} }
} }