mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 20:03:21 +00:00
Implement spawning monsters by suite
This commit is contained in:
parent
ae3d9a4dc1
commit
ffc1f801e6
@ -6,6 +6,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
@ -43,7 +44,7 @@ public class SceneScriptManager {
|
||||
private final Scene scene;
|
||||
private final ScriptLib scriptLib;
|
||||
private final LuaValue scriptLibLua;
|
||||
private final Map<String, LuaValue> variables;
|
||||
private final Map<String, Integer> variables;
|
||||
|
||||
private Bindings bindings;
|
||||
private SceneConfig config;
|
||||
@ -91,7 +92,7 @@ public class SceneScriptManager {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public Map<String, LuaValue> getVariables() {
|
||||
public Map<String, Integer> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
@ -212,8 +213,22 @@ public class SceneScriptManager {
|
||||
group.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
|
||||
group.init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
|
||||
|
||||
// Add variables to suite
|
||||
List<SceneVar> variables = ScriptLoader.getSerializer().toList(SceneVar.class, bindings.get("variables"));
|
||||
variables.forEach(var -> this.getVariables().put(var.name, LuaValue.valueOf(var.value)));
|
||||
variables.forEach(var -> this.getVariables().put(var.name, var.value));
|
||||
|
||||
// Add monsters to suite TODO optimize
|
||||
HashMap<Integer, SceneMonster> map = (HashMap<Integer, SceneMonster>) group.monsters.stream().collect(Collectors.toMap(m -> m.config_id, m -> m));
|
||||
|
||||
for (SceneSuite suite : group.suites) {
|
||||
suite.sceneMonsters = new ArrayList<>(suite.monsters.size());
|
||||
for (int id : suite.monsters) {
|
||||
SceneMonster monster = map.get(id);
|
||||
if (monster != null) {
|
||||
suite.sceneMonsters.add(monster);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ScriptException e) {
|
||||
Grasscutter.getLogger().error("Error loading group " + group.id + " in scene " + getScene().getId(), e);
|
||||
}
|
||||
@ -244,10 +259,24 @@ public class SceneScriptManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnMonstersInGroup(SceneGroup group, int suiteIndex) {
|
||||
spawnMonstersInGroup(group, group.getSuiteByIndex(suiteIndex));
|
||||
}
|
||||
|
||||
public void spawnMonstersInGroup(SceneGroup group) {
|
||||
spawnMonstersInGroup(group, null);
|
||||
}
|
||||
|
||||
public void spawnMonstersInGroup(SceneGroup group, SceneSuite suite) {
|
||||
List<SceneMonster> monsters = group.monsters;
|
||||
|
||||
if (suite != null) {
|
||||
monsters = suite.sceneMonsters;
|
||||
}
|
||||
|
||||
List<GameEntity> toAdd = new ArrayList<>();
|
||||
|
||||
for (SceneMonster monster : group.monsters) {
|
||||
for (SceneMonster monster : monsters) {
|
||||
MonsterData data = GameData.getMonsterDataMap().get(monster.monster_id);
|
||||
|
||||
if (data == null) {
|
||||
|
@ -129,7 +129,7 @@ public class ScriptLib {
|
||||
}
|
||||
|
||||
// TODO just spawn all from group for now
|
||||
this.getSceneScriptManager().spawnMonstersInGroup(group);
|
||||
this.getSceneScriptManager().spawnMonstersInGroup(group, suite);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -158,11 +158,11 @@ public class ScriptLib {
|
||||
.count();
|
||||
}
|
||||
|
||||
public LuaValue GetGroupVariableValue(String var) {
|
||||
return getSceneScriptManager().getVariables().getOrDefault(var, LuaValue.NIL);
|
||||
public int GetGroupVariableValue(String var) {
|
||||
return getSceneScriptManager().getVariables().getOrDefault(var, 0);
|
||||
}
|
||||
|
||||
public LuaValue ChangeGroupVariableValue(String var, LuaValue value) {
|
||||
public LuaValue ChangeGroupVariableValue(String var, int value) {
|
||||
getSceneScriptManager().getVariables().put(var, value);
|
||||
return LuaValue.ZERO;
|
||||
}
|
||||
@ -179,7 +179,7 @@ public class ScriptLib {
|
||||
}
|
||||
|
||||
// TODO just spawn all from group for now
|
||||
this.getSceneScriptManager().spawnMonstersInGroup(group);
|
||||
this.getSceneScriptManager().spawnMonstersInGroup(group, suite);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,4 +26,8 @@ public class SceneGroup {
|
||||
public boolean setLoaded(boolean loaded) {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public SceneSuite getSuiteByIndex(int index) {
|
||||
return suites.get(index - 1);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ import java.util.List;
|
||||
import emu.grasscutter.utils.Position;
|
||||
|
||||
public class SceneSuite {
|
||||
public List<Integer> monsters;
|
||||
public List<String> triggers;
|
||||
public int rand_weight;
|
||||
|
||||
public transient List<SceneMonster> sceneMonsters;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user