Update game time changing (triggers quests and updates properly)

This commit is contained in:
KingRainbow44 2023-05-04 21:41:41 -04:00
parent 0b87485bdf
commit 48e233eb9b
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
5 changed files with 28 additions and 10 deletions

View File

@ -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);

View File

@ -171,11 +171,9 @@ 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() {

View File

@ -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) {

View File

@ -446,7 +446,7 @@ public class World implements Iterable<Player> {
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<Player> {
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 ->
player
.getQuestManager()
.queueEvent(
QuestContent.QUEST_CONTENT_GAME_TIME_TICK, this.getGameTimeHours(), days));
.queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK));
}
@Override

View File

@ -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;