diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/WorldChallenge.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/WorldChallenge.java index b95a4be5a..2ad3c7923 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/WorldChallenge.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/WorldChallenge.java @@ -29,7 +29,7 @@ public class WorldChallenge { private final AtomicInteger score; private boolean progress; private boolean success; - private long startedAt; + private int startedAt; private int finishedTime; /** diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountInTimeIncChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountInTimeIncChallengeFactoryHandler.java index efa484e6d..1f289c487 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountInTimeIncChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterCountInTimeIncChallengeFactoryHandler.java @@ -36,6 +36,6 @@ public class KillMonsterCountInTimeIncChallengeFactoryHandler implements Challen List.of( new KillMonsterCountTrigger(), new InTimeTrigger(), - new KillMonsterTimeIncTrigger(timeInc))); + new KillMonsterTimeIncTrigger(timeLimit, timeInc))); } } diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java index 29214b91d..daaab28a1 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/factory/KillMonsterTimeChallengeFactoryHandler.java @@ -1,11 +1,12 @@ package emu.grasscutter.game.dungeons.challenge.factory; +import emu.grasscutter.data.GameData; import emu.grasscutter.game.dungeons.challenge.WorldChallenge; import emu.grasscutter.game.dungeons.challenge.enums.ChallengeType; import emu.grasscutter.game.dungeons.challenge.trigger.*; import emu.grasscutter.game.world.Scene; import emu.grasscutter.scripts.data.SceneGroup; -import java.util.List; +import java.util.*; import lombok.val; public class KillMonsterTimeChallengeFactoryHandler implements ChallengeFactoryHandler { @@ -28,6 +29,15 @@ public class KillMonsterTimeChallengeFactoryHandler implements ChallengeFactoryH Scene scene, SceneGroup group) { val realGroup = scene.getScriptManager().getGroupById(groupId); + val challengeTriggers = new ArrayList(); + challengeTriggers.addAll(List.of(new KillMonsterCountTrigger(), new InTimeTrigger())); + + val challengeData = GameData.getDungeonChallengeConfigDataMap().get(challengeId); + val challengeType = challengeData.getChallengeType(); + if (challengeType == ChallengeType.CHALLENGE_KILL_COUNT_FAST) { + challengeTriggers.add(new KillMonsterTimeIncTrigger(timeLimit, 0 /* refresh to original limit on kill */)); + } + return new WorldChallenge( scene, realGroup, @@ -36,6 +46,6 @@ public class KillMonsterTimeChallengeFactoryHandler implements ChallengeFactoryH List.of(targetCount, timeLimit), timeLimit, // Limit targetCount, // Goal - List.of(new KillMonsterCountTrigger(), new InTimeTrigger())); + challengeTriggers); } } diff --git a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterTimeIncTrigger.java b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterTimeIncTrigger.java index 567a98bf4..738a27a66 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterTimeIncTrigger.java +++ b/src/main/java/emu/grasscutter/game/dungeons/challenge/trigger/KillMonsterTimeIncTrigger.java @@ -6,22 +6,31 @@ import emu.grasscutter.server.packet.send.PacketChallengeDataNotify; public class KillMonsterTimeIncTrigger extends ChallengeTrigger { - private int increment; + private final int maxTime; + private final int increment; - public KillMonsterTimeIncTrigger(int increment) { + public KillMonsterTimeIncTrigger(int maxTime, int increment) { + this.maxTime = maxTime; this.increment = increment; } @Override - public void onBegin(WorldChallenge challenge) { - // challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 0, - // challenge.getScore().get())); - } + public void onBegin(WorldChallenge challenge) { } @Override public void onMonsterDeath(WorldChallenge challenge, EntityMonster monster) { - challenge.getScene().broadcastPacket(new PacketChallengeDataNotify(challenge, 0, increment)); - + var scene = challenge.getScene(); + var elapsed = scene.getSceneTimeSeconds() - challenge.getStartedAt(); + var timeLeft = challenge.getTimeLimit() - elapsed; + var increment = this.increment; + if (increment == 0) { + // Refresh time limit back to max + increment = maxTime - timeLeft; + } else if (maxTime < timeLeft + increment) { + // Don't add back more time than original limit + increment -= timeLeft + increment - maxTime; + } challenge.setTimeLimit(challenge.getTimeLimit() + increment); + scene.broadcastPacket(new PacketChallengeDataNotify(challenge, 2, timeLeft + increment + scene.getSceneTimeSeconds())); } } diff --git a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java index 237c27b57..f60f17c13 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java @@ -222,7 +222,9 @@ public class EntityMonster extends GameEntity { } @Override - public void onCreate() { + public void onTick(int sceneTime) { + super.onTick(sceneTime); + // Lua event getScene() .getScriptManager()