Add events to support scene group substitution (#2413)

* Add events to support scene group substitution

* make event members private with getter/setter

* delete stray unused var
This commit is contained in:
longfruit
2023-10-31 18:52:01 -07:00
committed by GitHub
parent 269f7b4fbf
commit cf6fb275be
9 changed files with 130 additions and 29 deletions

View File

@@ -252,12 +252,16 @@ public class EntityMonster extends GameEntity {
if (scriptManager.isInit() && this.getGroupId() > 0) {
Optional.ofNullable(scriptManager.getScriptMonsterSpawnService()).ifPresent(s -> s.onMonsterDead(this));
// prevent spawn monster after success
/*if (challenge.map(c -> c.inProgress()).orElse(true)) {
scriptManager.callEvent(new ScriptArgs(EventType.EVENT_ANY_MONSTER_DIE, this.getConfigId()).setGroupId(this.getGroupId()));
} else if (getScene().getChallenge() == null) {
}*/
scriptManager.callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_ANY_MONSTER_DIE, this.getConfigId()));
// Ensure each EVENT_ANY_MONSTER_DIE runs to completion.
// Multiple such events firing at the same time may cause
// the same lua trigger to fire multiple times, when it
// should happen only once.
var future = scriptManager.callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_ANY_MONSTER_DIE, this.getConfigId()));
try {
future.get();
} catch (Exception e) {
e.printStackTrace();
}
}
// Battle Pass trigger
scene.getPlayers().forEach(p -> p.getBattlePassManager().triggerMission(WatcherTriggerType.TRIGGER_MONSTER_DIE, this.getMonsterId(), 1));

View File

@@ -5,6 +5,13 @@ import lombok.Data;
@Data
public class GroupReplacementData {
int id;
List<Integer> replace_groups;
public int id;
public List<Integer> replace_groups;
public GroupReplacementData() {}
public GroupReplacementData(int id, List<Integer> replace_groups) {
this.id = id;
this.replace_groups = replace_groups;
}
}

View File

@@ -1110,6 +1110,9 @@ public class Scene {
if (group.regions != null) {
group.regions.values().forEach(getScriptManager()::deregisterRegion);
}
if (challenge != null && group.id == challenge.getGroup().id) {
challenge.fail();
}
scriptManager.getLoadedGroupSetPerBlock().get(block.id).remove(group);
this.loadedGroups.remove(group);