Fix mirror tower stages; fix tower time challenge and star scoring (#2406)

This commit is contained in:
longfruit
2023-10-19 06:18:12 -07:00
committed by GitHub
Unverified
parent bc8e7c21ce
commit f5703e5964
13 changed files with 264 additions and 53 deletions
@@ -807,11 +807,11 @@ public class SceneScriptManager {
}
}
// Events
public void callEvent(int groupId, int eventType) {
callEvent(new ScriptArgs(groupId, eventType));
public Future<?> callEvent(int groupId, int eventType) {
return callEvent(new ScriptArgs(groupId, eventType));
}
public void callEvent(@Nonnull ScriptArgs params) {
public Future<?> callEvent(@Nonnull ScriptArgs params) {
/**
* We use ThreadLocal to trans SceneScriptManager context to ScriptLib, to avoid eval script for
* every groups' trigger in every scene instances. But when callEvent is called in a ScriptLib
@@ -819,7 +819,7 @@ public class SceneScriptManager {
* not get it. e.g. CallEvent -> set -> ScriptLib.xxx -> CallEvent -> set -> remove -> NPE ->
* (remove) So we use thread pool to clean the stack to avoid this new issue.
*/
eventExecutor.submit(() -> this.realCallEvent(params));
return eventExecutor.submit(() -> this.realCallEvent(params));
}
private void realCallEvent(@Nonnull ScriptArgs params) {
@@ -190,8 +190,27 @@ public class ScriptLib {
// TODO: ActivateGroupLinkBundle
// TODO: ActivateGroupLinkBundleByBundleId
public int ActiveChallenge(int challengeId, int challengeIndex, int timeLimitOrGroupId, int groupId, int objectiveKills, int param5) {
public synchronized int ActiveChallenge(int challengeId, int challengeIndex, int timeLimitOrGroupId, int groupId, int objectiveKills, int param5) {
logger.debug("[LUA] Call ActiveChallenge with {},{},{},{},{},{}", challengeId, challengeIndex, timeLimitOrGroupId, groupId, objectiveKills, param5);
var scene = getSceneScriptManager().getScene();
var existingChallenge = scene.getChallenge();
if (existingChallenge != null && existingChallenge.inProgress()) {
logger.warn("ActiveChallenge: tried to create challenge while one is already in progress");
return 0;
}
var towerManager = scene.getPlayers().get(0).getTowerManager();
if (towerManager.isInProgress()) {
// Tower scripts call ActiveChallenge twice in mirror stages.
// The second call provides the time _taken_ in the first stage,
// not the actual time limit for the challenge.
timeLimitOrGroupId = towerManager.getCurrentTimeLimit() - timeLimitOrGroupId;
if (timeLimitOrGroupId < 0) {
timeLimitOrGroupId = 0;
}
}
var challenge = ChallengeFactory.getChallenge(
challengeId,
challengeIndex,
@@ -199,7 +218,7 @@ public class ScriptLib {
groupId,
objectiveKills,
param5,
getSceneScriptManager().getScene(),
scene,
getCurrentGroup().get()
);
@@ -212,7 +231,7 @@ public class ScriptLib {
dungeonChallenge.setStage(getSceneScriptManager().getVariables(groupId).getOrDefault("stage", -1) == 0);
}
getSceneScriptManager().getScene().setChallenge(challenge);
scene.setChallenge(challenge);
challenge.start();
return 0;
}