mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 08:56:04 +01:00
Implement local specialty spawning
This commit is contained in:
@@ -362,6 +362,8 @@ public class SceneScriptManager {
|
||||
entity.setGroupId(groupId);
|
||||
entity.getRotation().set(g.rot);
|
||||
entity.setState(g.state);
|
||||
entity.setPointType(g.point_type);
|
||||
entity.buildContent();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import emu.grasscutter.game.dungeons.DungeonChallenge;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.game.entity.EntityMonster;
|
||||
import emu.grasscutter.game.entity.GameEntity;
|
||||
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
|
||||
import emu.grasscutter.scripts.data.SceneGroup;
|
||||
import emu.grasscutter.scripts.data.SceneRegion;
|
||||
import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify;
|
||||
@@ -83,21 +84,22 @@ public class ScriptLib {
|
||||
public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options) {
|
||||
logger.debug("[LUA] Call SetWorktopOptionsByGroupId with {},{},{}",
|
||||
groupId,configId,options);
|
||||
|
||||
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
||||
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
||||
|
||||
if (entity.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(entity.get() instanceof EntityGadget)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
EntityGadget gadget = (EntityGadget) entity.get();
|
||||
gadget.addWorktopOptions(options);
|
||||
|
||||
if (entity.isEmpty() || !(entity.get() instanceof EntityGadget gadget)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
worktop.addWorktopOptions(options);
|
||||
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,18 +109,17 @@ public class ScriptLib {
|
||||
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
||||
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
||||
|
||||
if (entity.isEmpty()) {
|
||||
if (entity.isEmpty() || !(entity.get() instanceof EntityGadget gadget)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(entity.get() instanceof EntityGadget)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
EntityGadget gadget = (EntityGadget) entity.get();
|
||||
gadget.removeWorktopOption(option);
|
||||
|
||||
worktop.removeWorktopOption(option);
|
||||
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ScriptLoader {
|
||||
return sc.get();
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().info("Loaded Script" + path);
|
||||
Grasscutter.getLogger().info("Loading script " + path);
|
||||
|
||||
File file = new File(path);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ScriptLoader {
|
||||
scriptsCache.put(path, new SoftReference<>(script));
|
||||
return script;
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error("Loaded Script {} failed!", path, e);
|
||||
Grasscutter.getLogger().error("Loading script {} failed!", path, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneBusiness {
|
||||
public int type;
|
||||
}
|
||||
@@ -8,4 +8,5 @@ import lombok.ToString;
|
||||
public class SceneGadget extends SceneObject{
|
||||
public int gadget_id;
|
||||
public int state;
|
||||
public int point_type;
|
||||
}
|
||||
|
||||
12
src/main/java/emu/grasscutter/scripts/data/SceneGarbage.java
Normal file
12
src/main/java/emu/grasscutter/scripts/data/SceneGarbage.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneGarbage {
|
||||
public List<SceneGadget> gadgets;
|
||||
}
|
||||
@@ -26,21 +26,20 @@ public class SceneGroup {
|
||||
public int refresh_id;
|
||||
public Position pos;
|
||||
|
||||
/**
|
||||
* ConfigId - Monster
|
||||
*/
|
||||
public Map<Integer,SceneMonster> monsters;
|
||||
/**
|
||||
* ConfigId - Gadget
|
||||
*/
|
||||
public Map<Integer, SceneGadget> gadgets;
|
||||
public Map<Integer,SceneMonster> monsters; // <ConfigId, Monster>
|
||||
public Map<Integer, SceneGadget> gadgets; // <ConfigId, Gadgets>
|
||||
|
||||
public List<SceneTrigger> triggers;
|
||||
public List<SceneRegion> regions;
|
||||
public List<SceneSuite> suites;
|
||||
public List<SceneVar> variables;
|
||||
|
||||
public SceneBusiness business;
|
||||
public SceneGarbage garbages;
|
||||
public SceneInitConfig init_config;
|
||||
|
||||
public List<SceneVar> variables;
|
||||
private transient boolean loaded; // Not an actual variable in the scripts either
|
||||
private transient CompiledScript script;
|
||||
|
||||
public boolean isLoaded() {
|
||||
return loaded;
|
||||
@@ -49,8 +48,14 @@ public class SceneGroup {
|
||||
public void setLoaded(boolean loaded) {
|
||||
this.loaded = loaded;
|
||||
}
|
||||
|
||||
private transient CompiledScript script; // Not an actual variable in the scripts either
|
||||
|
||||
public int getBusinessType() {
|
||||
return this.business == null ? 0 : this.business.type;
|
||||
}
|
||||
|
||||
public List<SceneGadget> getGarbageGadgets() {
|
||||
return this.garbages == null ? null : this.garbages.gadgets;
|
||||
}
|
||||
|
||||
public CompiledScript getScript() {
|
||||
return script;
|
||||
@@ -75,6 +80,7 @@ public class SceneGroup {
|
||||
}
|
||||
|
||||
this.script = cs;
|
||||
|
||||
// Eval script
|
||||
try {
|
||||
cs.eval(bindings);
|
||||
@@ -90,15 +96,16 @@ public class SceneGroup {
|
||||
|
||||
triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, bindings.get("triggers"));
|
||||
triggers.forEach(t -> t.currentGroup = this);
|
||||
|
||||
|
||||
suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
|
||||
regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions"));
|
||||
garbages = ScriptLoader.getSerializer().toObject(SceneGarbage.class, bindings.get("garbages"));
|
||||
init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
|
||||
|
||||
// Add variables to suite
|
||||
variables = ScriptLoader.getSerializer().toList(SceneVar.class, bindings.get("variables"));
|
||||
|
||||
// Add monsters to suite
|
||||
// Add monsters and gadgets to suite
|
||||
for (SceneSuite suite : suites) {
|
||||
suite.sceneMonsters = new ArrayList<>(
|
||||
suite.monsters.stream()
|
||||
@@ -118,6 +125,7 @@ public class SceneGroup {
|
||||
} catch (ScriptException e) {
|
||||
Grasscutter.getLogger().error("Error loading group " + id + " in scene " + sceneId, e);
|
||||
}
|
||||
|
||||
Grasscutter.getLogger().info("group {} in scene {} is loaded successfully.", id, sceneId);
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user