Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some more dungeons #2449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public WorldChallenge build(
List.of(
new KillMonsterCountTrigger(),
new InTimeTrigger(),
new KillMonsterTimeIncTrigger(timeInc)));
new KillMonsterTimeIncTrigger(timeLimit, timeInc)));
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -28,6 +29,15 @@ public WorldChallenge build(
Scene scene,
SceneGroup group) {
val realGroup = scene.getScriptManager().getGroupById(groupId);
val challengeTriggers = new ArrayList<ChallengeTrigger>();
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,
Expand All @@ -36,6 +46,6 @@ public WorldChallenge build(
List.of(targetCount, timeLimit),
timeLimit, // Limit
targetCount, // Goal
List.of(new KillMonsterCountTrigger(), new InTimeTrigger()));
challengeTriggers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@

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()));
}
}
4 changes: 3 additions & 1 deletion src/main/java/emu/grasscutter/game/entity/EntityMonster.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ public void onInteract(Player player, GadgetInteractReq interactReq) {
}

@Override
public void onCreate() {
public void onTick(int sceneTime) {
super.onTick(sceneTime);

// Lua event
getScene()
.getScriptManager()
Expand Down
Loading