From 48e233eb9b0669f2e948f377f5f832b3aa0e03c7 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 4 May 2023 21:41:41 -0400 Subject: [PATCH] Update game time changing (triggers quests and updates properly) --- .../emu/grasscutter/game/player/Player.java | 5 +++++ .../grasscutter/game/quest/QuestManager.java | 8 +++---- .../quest/content/ContentGameTimeTick.java | 1 - .../emu/grasscutter/game/world/World.java | 21 ++++++++++++++++--- .../recv/HandlerSkipPlayerGameTimeReq.java | 3 ++- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 2a38069ab..5dcff8dca 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -331,6 +331,11 @@ public class Player { if (this.playerGameTime == gameTime) return; this.playerGameTime = gameTime; + // If the player is the host of the world, update the game time as well. + if (this.getWorld().getHost() == this) { + this.getWorld().changeTime(gameTime); + } + // Trigger the script event for game time update. var questManager = this.getQuestManager(); questManager.queueEvent(QuestCond.QUEST_COND_IS_DAYTIME); diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index 1de65b7c5..9a3b4b1e9 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -171,17 +171,15 @@ public class QuestManager extends BasePlayerManager { var world = this.getPlayer().getWorld(); if (world == null) return; - checkTimeVars(); + this.checkTimeVars(); // trigger game time tick for quests - queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK, - world.getGameTimeHours() , // hours - 0); + this.queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK); } private void checkTimeVars() { val currentDays = player.getWorld().getTotalGameTimeDays(); val currentHours = player.getWorld().getTotalGameTimeHours(); - boolean checkDays = currentDays != lastDayCheck; + boolean checkDays = currentDays != lastDayCheck; boolean checkHours = currentHours != lastHourCheck; if(!checkDays && !checkHours){ diff --git a/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java b/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java index 1686813f9..e07e4fd0e 100644 --- a/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java +++ b/src/main/java/emu/grasscutter/game/quest/content/ContentGameTimeTick.java @@ -9,7 +9,6 @@ import lombok.val; @QuestValueContent(QUEST_CONTENT_GAME_TIME_TICK) public class ContentGameTimeTick extends BaseContent { - @Override public boolean execute( GameQuest quest, QuestData.QuestContentCondition condition, String paramStr, int... params) { diff --git a/src/main/java/emu/grasscutter/game/world/World.java b/src/main/java/emu/grasscutter/game/world/World.java index b00b16495..81a57edda 100644 --- a/src/main/java/emu/grasscutter/game/world/World.java +++ b/src/main/java/emu/grasscutter/game/world/World.java @@ -446,7 +446,7 @@ public class World implements Iterable { return currentWorldTime; } - /** Returns the current in game days world time in ingame minutes (0-1439) */ + /** Returns the current in game days world time in in-game minutes (0-1439) */ public int getGameTime() { return (int) (getTotalGameTimeMinutes() % 1440); } @@ -491,6 +491,22 @@ public class World implements Iterable { this.getScenes().forEach((key, scene) -> scene.setPaused(paused)); } + /** + * Changes the game time of the world. + * + * @param gameTime The time in game minutes. + */ + public void changeTime(long gameTime) { + this.currentWorldTime = gameTime; + + // Trigger script events. + this.players.forEach( + player -> + player + .getQuestManager() + .queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK)); + } + /** * Changes the time of the world. * @@ -512,8 +528,7 @@ public class World implements Iterable { player -> player .getQuestManager() - .queueEvent( - QuestContent.QUEST_CONTENT_GAME_TIME_TICK, this.getGameTimeHours(), days)); + .queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK)); } @Override diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSkipPlayerGameTimeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSkipPlayerGameTimeReq.java index acd209289..c0634a6c7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSkipPlayerGameTimeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSkipPlayerGameTimeReq.java @@ -4,6 +4,7 @@ import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.SkipPlayerGameTimeReqOuterClass; +import emu.grasscutter.net.proto.SkipPlayerGameTimeReqOuterClass.SkipPlayerGameTimeReq; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify; import emu.grasscutter.server.packet.send.PacketSkipPlayerGameTimeRsp; @@ -12,7 +13,7 @@ import emu.grasscutter.server.packet.send.PacketSkipPlayerGameTimeRsp; public class HandlerSkipPlayerGameTimeReq extends PacketHandler { @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = SkipPlayerGameTimeReqOuterClass.SkipPlayerGameTimeReq.parseFrom(payload); + var req = SkipPlayerGameTimeReq.parseFrom(payload); var player = session.getPlayer(); var newTime = req.getGameTime() * 1000L;