mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-02-07 02:26:43 +01:00
Run IntelliJ IDEA code formatter
This commit is contained in:
@@ -12,20 +12,22 @@ import java.util.function.Function;
|
||||
|
||||
public class SceneIndexManager {
|
||||
|
||||
public static <T> RTree<T, Geometry> buildIndex(int dimensions, Collection<T> elements, Function<T, Geometry> extractor){
|
||||
public static <T> RTree<T, Geometry> buildIndex(int dimensions, Collection<T> elements, Function<T, Geometry> extractor) {
|
||||
RTree<T, Geometry> rtree = RTree.dimensions(dimensions).create();
|
||||
return rtree.add(elements.stream().map(e -> Entry.entry(e, extractor.apply(e))).toList());
|
||||
}
|
||||
public static <T> List<T> queryNeighbors(RTree<T, Geometry> tree, double[] position, int range){
|
||||
|
||||
public static <T> List<T> queryNeighbors(RTree<T, Geometry> tree, double[] position, int range) {
|
||||
var result = new ArrayList<T>();
|
||||
Rectangle rectangle = Rectangle.create(calRange(position, -range), calRange(position, range));
|
||||
var queryResult = tree.search(rectangle);
|
||||
queryResult.forEach(q -> result.add(q.value()));
|
||||
return result;
|
||||
}
|
||||
private static double[] calRange(double[] position, int range){
|
||||
|
||||
private static double[] calRange(double[] position, int range) {
|
||||
var newPos = position.clone();
|
||||
for(int i=0;i<newPos.length;i++){
|
||||
for (int i = 0; i < newPos.length; i++) {
|
||||
newPos[i] += range;
|
||||
}
|
||||
return newPos;
|
||||
|
||||
@@ -24,28 +24,31 @@ import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SceneScriptManager {
|
||||
public static final ExecutorService eventExecutor;
|
||||
|
||||
static {
|
||||
eventExecutor = new ThreadPoolExecutor(4, 4,
|
||||
60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000),
|
||||
FastThreadLocalThread::new, new ThreadPoolExecutor.AbortPolicy());
|
||||
}
|
||||
|
||||
private final Scene scene;
|
||||
private final Map<String, Integer> variables;
|
||||
private SceneMeta meta;
|
||||
private boolean isInit;
|
||||
/**
|
||||
* current triggers controlled by RefreshGroup
|
||||
*/
|
||||
private final Map<Integer, Set<SceneTrigger>> currentTriggers;
|
||||
private final Map<Integer, EntityRegion> regions; // <EntityId-Region>
|
||||
private final Map<Integer,SceneGroup> sceneGroups;
|
||||
private ScriptMonsterTideService scriptMonsterTideService;
|
||||
private ScriptMonsterSpawnService scriptMonsterSpawnService;
|
||||
private final Map<Integer, SceneGroup> sceneGroups;
|
||||
/**
|
||||
* blockid - loaded groupSet
|
||||
*/
|
||||
private final Map<Integer, Set<SceneGroup>> loadedGroupSetPerBlock;
|
||||
public static final ExecutorService eventExecutor;
|
||||
static {
|
||||
eventExecutor = new ThreadPoolExecutor(4, 4,
|
||||
60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000),
|
||||
FastThreadLocalThread::new, new ThreadPoolExecutor.AbortPolicy());
|
||||
}
|
||||
private SceneMeta meta;
|
||||
private boolean isInit;
|
||||
private ScriptMonsterTideService scriptMonsterTideService;
|
||||
private final ScriptMonsterSpawnService scriptMonsterSpawnService;
|
||||
|
||||
public SceneScriptManager(Scene scene) {
|
||||
this.scene = scene;
|
||||
this.currentTriggers = new ConcurrentHashMap<>();
|
||||
@@ -87,22 +90,28 @@ public class SceneScriptManager {
|
||||
public Set<SceneTrigger> getTriggersByEvent(int eventId) {
|
||||
return currentTriggers.computeIfAbsent(eventId, e -> new HashSet<>());
|
||||
}
|
||||
|
||||
public void registerTrigger(List<SceneTrigger> triggers) {
|
||||
triggers.forEach(this::registerTrigger);
|
||||
}
|
||||
|
||||
public void registerTrigger(SceneTrigger trigger) {
|
||||
getTriggersByEvent(trigger.event).add(trigger);
|
||||
Grasscutter.getLogger().debug("Registered trigger {}", trigger.name);
|
||||
}
|
||||
|
||||
public void deregisterTrigger(List<SceneTrigger> triggers) {
|
||||
triggers.forEach(this::deregisterTrigger);
|
||||
}
|
||||
|
||||
public void deregisterTrigger(SceneTrigger trigger) {
|
||||
getTriggersByEvent(trigger.event).remove(trigger);
|
||||
}
|
||||
|
||||
public void resetTriggers(int eventId) {
|
||||
currentTriggers.put(eventId, new HashSet<>());
|
||||
}
|
||||
|
||||
public void refreshGroup(SceneGroup group, int suiteIndex) {
|
||||
if (group == null) {
|
||||
return;
|
||||
@@ -123,6 +132,7 @@ public class SceneScriptManager {
|
||||
spawnMonstersInGroup(group, suite);
|
||||
spawnGadgetsInGroup(group, suite);
|
||||
}
|
||||
|
||||
public EntityRegion getRegionById(int id) {
|
||||
return regions.get(id);
|
||||
}
|
||||
@@ -131,10 +141,12 @@ public class SceneScriptManager {
|
||||
regions.put(region.getId(), region);
|
||||
Grasscutter.getLogger().debug("Registered region {} from group {}", region.getMetaRegion().config_id, region.getGroupId());
|
||||
}
|
||||
|
||||
public void registerRegionInGroupSuite(SceneGroup group, SceneSuite suite) {
|
||||
suite.sceneRegions.stream().map(region -> new EntityRegion(this.getScene(), region))
|
||||
.forEach(this::registerRegion);
|
||||
}
|
||||
|
||||
public synchronized void deregisterRegion(SceneRegion region) {
|
||||
var instance = regions.values().stream()
|
||||
.filter(r -> r.getConfigId() == region.config_id)
|
||||
@@ -209,7 +221,7 @@ public class SceneScriptManager {
|
||||
targetID = players.get(0).getUid();
|
||||
|
||||
if (region.hasNewEntities()) {
|
||||
Grasscutter.getLogger().trace("Call EVENT_ENTER_REGION_{}",region.getMetaRegion().config_id);
|
||||
Grasscutter.getLogger().trace("Call EVENT_ENTER_REGION_{}", region.getMetaRegion().config_id);
|
||||
callEvent(EventType.EVENT_ENTER_REGION, new ScriptArgs(region.getConfigId())
|
||||
.setSourceEntityId(region.getId())
|
||||
.setTargetEntityId(targetID)
|
||||
@@ -241,12 +253,14 @@ public class SceneScriptManager {
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<EntityMonster> getMonstersInGroupSuite(SceneGroup group, SceneSuite suite) {
|
||||
return suite.sceneMonsters.stream()
|
||||
.map(mob -> createMonster(group.id, group.block_id, mob))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void addGroupSuite(SceneGroup group, SceneSuite suite) {
|
||||
// we added trigger first
|
||||
registerTrigger(suite.sceneTriggers);
|
||||
@@ -258,6 +272,7 @@ public class SceneScriptManager {
|
||||
|
||||
registerRegionInGroupSuite(group, suite);
|
||||
}
|
||||
|
||||
public void removeGroupSuite(SceneGroup group, SceneSuite suite) {
|
||||
deregisterTrigger(suite.sceneTriggers);
|
||||
removeMonstersInGroup(group, suite);
|
||||
@@ -274,9 +289,9 @@ public class SceneScriptManager {
|
||||
}
|
||||
|
||||
var toCreate = gadgets.stream()
|
||||
.map(g -> createGadget(g.group.id, group.block_id, g))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
.map(g -> createGadget(g.group.id, group.block_id, g))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
this.addEntities(toCreate);
|
||||
}
|
||||
|
||||
@@ -285,24 +300,27 @@ public class SceneScriptManager {
|
||||
return;
|
||||
}
|
||||
this.addEntities(suite.sceneMonsters.stream()
|
||||
.map(mob -> createMonster(group.id, group.block_id, mob)).toList());
|
||||
.map(mob -> createMonster(group.id, group.block_id, mob)).toList());
|
||||
}
|
||||
|
||||
public void startMonsterTideInGroup(SceneGroup group, Integer[] ordersConfigId, int tideCount, int sceneLimit) {
|
||||
this.scriptMonsterTideService =
|
||||
new ScriptMonsterTideService(this, group, tideCount, sceneLimit, ordersConfigId);
|
||||
new ScriptMonsterTideService(this, group, tideCount, sceneLimit, ordersConfigId);
|
||||
|
||||
}
|
||||
|
||||
public void unloadCurrentMonsterTide() {
|
||||
if (this.getScriptMonsterTideService() == null) {
|
||||
return;
|
||||
}
|
||||
this.getScriptMonsterTideService().unload();
|
||||
}
|
||||
|
||||
public void spawnMonstersByConfigId(SceneGroup group, int configId, int delayTime) {
|
||||
// TODO delay
|
||||
getScene().addEntity(createMonster(group.id, group.block_id, group.monsters.get(configId)));
|
||||
}
|
||||
|
||||
// Events
|
||||
public void callEvent(int eventType, ScriptArgs params) {
|
||||
/**
|
||||
@@ -322,7 +340,9 @@ public class SceneScriptManager {
|
||||
List<SceneTrigger> relevantTriggersList = this.getTriggersByEvent(eventType).stream()
|
||||
.filter(p -> p.condition.contains(String.valueOf(params.param1))).toList();
|
||||
relevantTriggers = new HashSet<>(relevantTriggersList);
|
||||
} else {relevantTriggers = this.getTriggersByEvent(eventType);}
|
||||
} else {
|
||||
relevantTriggers = this.getTriggersByEvent(eventType);
|
||||
}
|
||||
for (SceneTrigger trigger : relevantTriggers) {
|
||||
try {
|
||||
ScriptLoader.getScriptLib().setCurrentGroup(trigger.currentGroup);
|
||||
@@ -346,11 +366,11 @@ public class SceneScriptManager {
|
||||
Grasscutter.getLogger().debug("Condition Trigger {} returned {}", trigger.condition, ret);
|
||||
}
|
||||
//TODO some ret do not bool
|
||||
}finally {
|
||||
} finally {
|
||||
ScriptLoader.getScriptLib().removeCurrentGroup();
|
||||
}
|
||||
}
|
||||
}finally {
|
||||
} finally {
|
||||
// make sure it is removed
|
||||
ScriptLoader.getScriptLib().removeSceneScriptManager();
|
||||
}
|
||||
@@ -379,8 +399,8 @@ public class SceneScriptManager {
|
||||
public LuaValue safetyCall(String name, LuaValue func, LuaValue args) {
|
||||
try {
|
||||
return func.call(ScriptLoader.getScriptLibLua(), args);
|
||||
}catch (LuaError error) {
|
||||
ScriptLib.logger.error("[LUA] call trigger failed {},{}",name,args,error);
|
||||
} catch (LuaError error) {
|
||||
ScriptLib.logger.error("[LUA] call trigger failed {},{}", name, args, error);
|
||||
return LuaValue.valueOf(-1);
|
||||
}
|
||||
}
|
||||
@@ -421,9 +441,11 @@ public class SceneScriptManager {
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public EntityNPC createNPC(SceneNPC npc, int blockId, int suiteId) {
|
||||
return new EntityNPC(getScene(), npc, blockId, suiteId);
|
||||
}
|
||||
|
||||
public EntityMonster createMonster(int groupId, int blockId, SceneMonster monster) {
|
||||
if (monster == null) {
|
||||
return null;
|
||||
@@ -457,7 +479,7 @@ public class SceneScriptManager {
|
||||
entity.setPoseId(monster.pose_id);
|
||||
|
||||
this.getScriptMonsterSpawnService()
|
||||
.onMonsterCreatedListener.forEach(action -> action.onNotify(entity));
|
||||
.onMonsterCreatedListener.forEach(action -> action.onNotify(entity));
|
||||
|
||||
return entity;
|
||||
}
|
||||
@@ -477,27 +499,29 @@ public class SceneScriptManager {
|
||||
public RTree<SceneBlock, Geometry> getBlocksIndex() {
|
||||
return meta.sceneBlockIndex;
|
||||
}
|
||||
|
||||
public void removeMonstersInGroup(SceneGroup group, SceneSuite suite) {
|
||||
var configSet = suite.sceneMonsters.stream()
|
||||
.map(m -> m.config_id)
|
||||
.collect(Collectors.toSet());
|
||||
.map(m -> m.config_id)
|
||||
.collect(Collectors.toSet());
|
||||
var toRemove = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityMonster)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
.filter(e -> e instanceof EntityMonster)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
|
||||
getScene().removeEntities(toRemove, VisionTypeOuterClass.VisionType.VISION_TYPE_MISS);
|
||||
}
|
||||
|
||||
public void removeGadgetsInGroup(SceneGroup group, SceneSuite suite) {
|
||||
var configSet = suite.sceneGadgets.stream()
|
||||
.map(m -> m.config_id)
|
||||
.collect(Collectors.toSet());
|
||||
.map(m -> m.config_id)
|
||||
.collect(Collectors.toSet());
|
||||
var toRemove = getScene().getEntities().values().stream()
|
||||
.filter(e -> e instanceof EntityGadget)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
.filter(e -> e instanceof EntityGadget)
|
||||
.filter(e -> e.getGroupId() == group.id)
|
||||
.filter(e -> configSet.contains(e.getConfigId()))
|
||||
.toList();
|
||||
|
||||
getScene().removeEntities(toRemove, VisionTypeOuterClass.VisionType.VISION_TYPE_MISS);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,6 @@ import emu.grasscutter.scripts.serializer.LuaSerializer;
|
||||
import emu.grasscutter.scripts.serializer.Serializer;
|
||||
import emu.grasscutter.utils.FileUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.OneArgFunction;
|
||||
@@ -31,19 +30,23 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ScriptLoader {
|
||||
private static ScriptEngineManager sm;
|
||||
@Getter private static ScriptEngine engine;
|
||||
@Getter
|
||||
private static ScriptEngine engine;
|
||||
private static ScriptEngineFactory factory;
|
||||
@Getter private static Serializer serializer;
|
||||
@Getter private static ScriptLib scriptLib;
|
||||
@Getter private static LuaValue scriptLibLua;
|
||||
@Getter
|
||||
private static Serializer serializer;
|
||||
@Getter
|
||||
private static ScriptLib scriptLib;
|
||||
@Getter
|
||||
private static LuaValue scriptLibLua;
|
||||
/**
|
||||
* suggest GC to remove it if the memory is less
|
||||
*/
|
||||
private static Map<String, SoftReference<CompiledScript>> scriptsCache = new ConcurrentHashMap<>();
|
||||
private static final Map<String, SoftReference<CompiledScript>> scriptsCache = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* sceneId - SceneMeta
|
||||
*/
|
||||
private static Map<Integer, SoftReference<SceneMeta>> sceneMetaCache = new ConcurrentHashMap<>();
|
||||
private static final Map<Integer, SoftReference<SceneMeta>> sceneMetaCache = new ConcurrentHashMap<>();
|
||||
|
||||
public synchronized static void init() throws Exception {
|
||||
if (sm != null) {
|
||||
@@ -87,7 +90,7 @@ public class ScriptLoader {
|
||||
public static <T> Optional<T> tryGet(SoftReference<T> softReference) {
|
||||
try {
|
||||
return Optional.ofNullable(softReference.get());
|
||||
}catch (NullPointerException npe) {
|
||||
} catch (NullPointerException npe) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
package emu.grasscutter.scripts;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ScriptUtils {
|
||||
|
||||
public static HashMap<Object, Object> toMap(LuaTable table) {
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
LuaValue[] rootKeys = table.keys();
|
||||
for (LuaValue k : rootKeys) {
|
||||
if (table.get(k).istable()) {
|
||||
map.put(k, toMap(table.get(k).checktable()));
|
||||
} else {
|
||||
map.put(k, table.get(k));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void print(LuaTable table) {
|
||||
Grasscutter.getLogger().info(toMap(table).toString());
|
||||
}
|
||||
|
||||
public static HashMap<Object, Object> toMap(LuaTable table) {
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
LuaValue[] rootKeys = table.keys();
|
||||
for (LuaValue k : rootKeys) {
|
||||
if (table.get(k).istable()) {
|
||||
map.put(k, toMap(table.get(k).checktable()));
|
||||
} else {
|
||||
map.put(k, table.get(k));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void print(LuaTable table) {
|
||||
Grasscutter.getLogger().info(toMap(table).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,127 +1,127 @@
|
||||
package emu.grasscutter.scripts.constants;
|
||||
|
||||
public class EventType {
|
||||
public static final int EVENT_NONE = 0;
|
||||
/**
|
||||
* param1: monster.configId
|
||||
*/
|
||||
public static final int EVENT_ANY_MONSTER_DIE = 1;
|
||||
public static final int EVENT_ANY_GADGET_DIE = 2;
|
||||
public static final int EVENT_VARIABLE_CHANGE = 3;
|
||||
public static final int EVENT_ENTER_REGION = 4;
|
||||
public static final int EVENT_LEAVE_REGION = 5;
|
||||
public static final int EVENT_GADGET_CREATE = 6;
|
||||
public static final int EVENT_GADGET_STATE_CHANGE = 7;
|
||||
public static final int EVENT_DUNGEON_SETTLE = 8;
|
||||
public static final int EVENT_SELECT_OPTION = 9;
|
||||
public static final int EVENT_CLIENT_EXECUTE = 10;
|
||||
public static final int EVENT_ANY_MONSTER_LIVE = 11;
|
||||
public static final int EVENT_SPECIFIC_MONSTER_HP_CHANGE = 12;
|
||||
public static final int EVENT_CITY_LEVELUP_UNLOCK_DUNGEON_ENTRY = 13;
|
||||
public static final int EVENT_DUNGEON_BROADCAST_ONTIMER = 14;
|
||||
public static final int EVENT_TIMER_EVENT = 15;
|
||||
public static final int EVENT_CHALLENGE_SUCCESS = 16;
|
||||
public static final int EVENT_CHALLENGE_FAIL = 17;
|
||||
public static final int EVENT_SEAL_BATTLE_BEGIN = 18;
|
||||
public static final int EVENT_SEAL_BATTLE_END = 19;
|
||||
public static final int EVENT_GATHER = 20;
|
||||
public static final int EVENT_QUEST_FINISH = 21;
|
||||
public static final int EVENT_MONSTER_BATTLE = 22;
|
||||
public static final int EVENT_CITY_LEVELUP = 23;
|
||||
public static final int EVENT_CUTSCENE_END = 24;
|
||||
public static final int EVENT_AVATAR_NEAR_PLATFORM = 25;
|
||||
public static final int EVENT_PLATFORM_REACH_POINT = 26;
|
||||
public static final int EVENT_UNLOCK_TRANS_POINT = 27;
|
||||
public static final int EVENT_QUEST_START = 28;
|
||||
public static final int EVENT_GROUP_LOAD = 29;
|
||||
public static final int EVENT_GROUP_WILL_UNLOAD = 30;
|
||||
public static final int EVENT_GROUP_WILL_REFRESH = 31;
|
||||
public static final int EVENT_GROUP_REFRESH = 32;
|
||||
public static final int EVENT_DUNGEON_REWARD_GET = 33;
|
||||
public static final int EVENT_SPECIFIC_GADGET_HP_CHANGE = 34;
|
||||
public static final int EVENT_MONSTER_TIDE_OVER = 35;
|
||||
public static final int EVENT_MONSTER_TIDE_CREATE = 36;
|
||||
public static final int EVENT_MONSTER_TIDE_DIE = 37;
|
||||
public static final int EVENT_SEALAMP_PHASE_CHANGE = 38;
|
||||
public static final int EVENT_BLOSSOM_PROGRESS_FINISH = 39;
|
||||
public static final int EVENT_BLOSSOM_CHEST_DIE = 40;
|
||||
public static final int EVENT_GADGET_PLAY_START = 41;
|
||||
public static final int EVENT_GADGET_PLAY_START_CD = 42;
|
||||
public static final int EVENT_GADGET_PLAY_STOP = 43;
|
||||
public static final int EVENT_GADGET_LUA_NOTIFY = 44;
|
||||
public static final int EVENT_MP_PLAY_PREPARE = 45;
|
||||
public static final int EVENT_MP_PLAY_BATTLE = 46;
|
||||
public static final int EVENT_MP_PLAY_PREPARE_INTERRUPT = 47;
|
||||
public static final int EVENT_SELECT_DIFFICULTY = 48;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_STATE = 49;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_STAGE_CHANGE = 50;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_RESULT = 51;
|
||||
public static final int EVENT_SEAL_BATTLE_PROGRESS_DECREASE = 52;
|
||||
public static final int EVENT_GENERAL_REWARD_DIE = 53;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_INTERRUPT = 54;
|
||||
public static final int EVENT_MONSTER_DIE_BEFORE_LEAVE_SCENE = 55;
|
||||
public static final int EVENT_SCENE_MP_PLAY_OPEN = 56;
|
||||
public static final int EVENT_OFFERING_LEVELUP = 57;
|
||||
public static final int EVENT_DUNGEON_REVIVE = 58;
|
||||
public static final int EVENT_SCENE_MP_PLAY_ALL_AVATAR_DIE = 59;
|
||||
public static final int EVENT_DUNGEON_ALL_AVATAR_DIE = 60;
|
||||
public static final int EVENT_GENERAL_REWARD_TAKEN = 61;
|
||||
public static final int EVENT_PLATFORM_REACH_ARRAYPOINT = 62;
|
||||
public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_END = 63;
|
||||
public static final int EVENT_SCENE_MULTISTAGE_PLAY_END_STAGE_REQ = 64;
|
||||
public static final int EVENT_MECHANICUS_PICKED_CARD = 65;
|
||||
public static final int EVENT_POOL_MONSTER_TIDE_OVER = 66;
|
||||
public static final int EVENT_POOL_MONSTER_TIDE_CREATE = 67;
|
||||
public static final int EVENT_POOL_MONSTER_TIDE_DIE = 68;
|
||||
public static final int EVENT_DUNGEON_AVATAR_SLIP_DIE = 69;
|
||||
public static final int EVENT_GALLERY_START = 70;
|
||||
public static final int EVENT_GALLERY_STOP = 71;
|
||||
public static final int EVENT_TIME_AXIS_PASS = 72;
|
||||
public static final int EVENT_FLEUR_FAIR_DUNGEON_ALL_PLAYER_ENTER = 73;
|
||||
public static final int EVENT_GADGETTALK_DONE = 74;
|
||||
public static final int EVENT_SET_GAME_TIME = 75;
|
||||
public static final int EVENT_HIDE_AND_SEEK_PLAYER_QUIT = 76;
|
||||
public static final int EVENT_AVATAR_DIE = 77;
|
||||
public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_START = 78;
|
||||
public static final int EVENT_GALLERY_PROGRESS_PASS = 79;
|
||||
public static final int EVENT_GALLERY_PROGRESS_EMPTY = 80;
|
||||
public static final int EVENT_GALLERY_PROGRESS_FULL = 81;
|
||||
public static final int EVENT_HUNTING_FINISH_FINAL = 82;
|
||||
public static final int EVENT_USE_WIDGET_TOY_FOX_CAMERA = 83;
|
||||
public static final int EVENT_LUNA_RITE_SACRIFICE = 84;
|
||||
public static final int EVENT_SUMO_SWITCH_TEAM_EVENT = 85;
|
||||
public static final int EVENT_FISHING_START = 86;
|
||||
public static final int EVENT_FISHING_STOP = 87;
|
||||
public static final int EVENT_FISHING_QTE_FINISH = 88;
|
||||
public static final int EVENT_FISHING_TIMEOUT_FLEE = 89;
|
||||
public static final int EVENT_ROGUE_CELL_STATE_CHANGE = 90;
|
||||
public static final int EVENT_ROGUE_CELL_CONSTRUCT = 91;
|
||||
public static final int EVENT_ROGUE_CELL_FINISH_SELECT_CARD = 92;
|
||||
public static final int EVENT_ANY_MONSTER_CAPTURE = 93;
|
||||
public static final int EVENT_ACTIVITY_INTERACT_GADGET = 94;
|
||||
public static final int EVENT_CHALLENGE_PAUSE = 95;
|
||||
public static final int EVENT_LEVEL_TAG_CHANGE = 96;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_START = 97;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_RESTART = 98;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_REACTIVE = 99;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_OUT_STUCK = 100;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_EXIT_TRY = 101;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_OFFICIAL_RESTART = 102;
|
||||
public static final int EVENT_ANY_MONSTER_CAPTURE_AND_DISAPPEAR = 103;
|
||||
public static final int EVENT_MICHIAE_INTERACT = 104;
|
||||
public static final int EVENT_SELECT_UIINTERACT = 105;
|
||||
public static final int EVENT_LUA_NOTIFY = 106;
|
||||
public static final int EVENT_PHOTO_FINISH = 107;
|
||||
public static final int EVENT_IRODORI_MASTER_READY = 108;
|
||||
public static final int EVENT_ROGUE_START_FIGHT = 109;
|
||||
public static final int EVENT_ROGUE_CREAGE_FIGHT_GADGET = 110;
|
||||
public static final int EVENT_ROGUE_CREAGE_REPAIR_GADGET = 111;
|
||||
public static final int EVENT_ROGUE_OPEN_ACCESS = 112;
|
||||
public static final int EVENT_GADGET_GIVING_FINISHED = 113;
|
||||
public static final int EVENT_OBSERVATION_POINT_NOTIFY = 114;
|
||||
public static final int EVENT_GADGET_GIVING_TAKEBACK = 115;
|
||||
public static final int EVENT_ECHO_SHELL_INTERACT = 116;
|
||||
public static final int EVENT_PLATFORM_ARRIVAL = 2701;
|
||||
public static final int EVENT_PLAYER_BACK_GALLERY_REVIVE_POINT = 2800;
|
||||
public static final int EVENT_GALLERY_CANNOT_START_AFTER_COUNTDOWN = 2801;
|
||||
public static final int EVENT_NONE = 0;
|
||||
/**
|
||||
* param1: monster.configId
|
||||
*/
|
||||
public static final int EVENT_ANY_MONSTER_DIE = 1;
|
||||
public static final int EVENT_ANY_GADGET_DIE = 2;
|
||||
public static final int EVENT_VARIABLE_CHANGE = 3;
|
||||
public static final int EVENT_ENTER_REGION = 4;
|
||||
public static final int EVENT_LEAVE_REGION = 5;
|
||||
public static final int EVENT_GADGET_CREATE = 6;
|
||||
public static final int EVENT_GADGET_STATE_CHANGE = 7;
|
||||
public static final int EVENT_DUNGEON_SETTLE = 8;
|
||||
public static final int EVENT_SELECT_OPTION = 9;
|
||||
public static final int EVENT_CLIENT_EXECUTE = 10;
|
||||
public static final int EVENT_ANY_MONSTER_LIVE = 11;
|
||||
public static final int EVENT_SPECIFIC_MONSTER_HP_CHANGE = 12;
|
||||
public static final int EVENT_CITY_LEVELUP_UNLOCK_DUNGEON_ENTRY = 13;
|
||||
public static final int EVENT_DUNGEON_BROADCAST_ONTIMER = 14;
|
||||
public static final int EVENT_TIMER_EVENT = 15;
|
||||
public static final int EVENT_CHALLENGE_SUCCESS = 16;
|
||||
public static final int EVENT_CHALLENGE_FAIL = 17;
|
||||
public static final int EVENT_SEAL_BATTLE_BEGIN = 18;
|
||||
public static final int EVENT_SEAL_BATTLE_END = 19;
|
||||
public static final int EVENT_GATHER = 20;
|
||||
public static final int EVENT_QUEST_FINISH = 21;
|
||||
public static final int EVENT_MONSTER_BATTLE = 22;
|
||||
public static final int EVENT_CITY_LEVELUP = 23;
|
||||
public static final int EVENT_CUTSCENE_END = 24;
|
||||
public static final int EVENT_AVATAR_NEAR_PLATFORM = 25;
|
||||
public static final int EVENT_PLATFORM_REACH_POINT = 26;
|
||||
public static final int EVENT_UNLOCK_TRANS_POINT = 27;
|
||||
public static final int EVENT_QUEST_START = 28;
|
||||
public static final int EVENT_GROUP_LOAD = 29;
|
||||
public static final int EVENT_GROUP_WILL_UNLOAD = 30;
|
||||
public static final int EVENT_GROUP_WILL_REFRESH = 31;
|
||||
public static final int EVENT_GROUP_REFRESH = 32;
|
||||
public static final int EVENT_DUNGEON_REWARD_GET = 33;
|
||||
public static final int EVENT_SPECIFIC_GADGET_HP_CHANGE = 34;
|
||||
public static final int EVENT_MONSTER_TIDE_OVER = 35;
|
||||
public static final int EVENT_MONSTER_TIDE_CREATE = 36;
|
||||
public static final int EVENT_MONSTER_TIDE_DIE = 37;
|
||||
public static final int EVENT_SEALAMP_PHASE_CHANGE = 38;
|
||||
public static final int EVENT_BLOSSOM_PROGRESS_FINISH = 39;
|
||||
public static final int EVENT_BLOSSOM_CHEST_DIE = 40;
|
||||
public static final int EVENT_GADGET_PLAY_START = 41;
|
||||
public static final int EVENT_GADGET_PLAY_START_CD = 42;
|
||||
public static final int EVENT_GADGET_PLAY_STOP = 43;
|
||||
public static final int EVENT_GADGET_LUA_NOTIFY = 44;
|
||||
public static final int EVENT_MP_PLAY_PREPARE = 45;
|
||||
public static final int EVENT_MP_PLAY_BATTLE = 46;
|
||||
public static final int EVENT_MP_PLAY_PREPARE_INTERRUPT = 47;
|
||||
public static final int EVENT_SELECT_DIFFICULTY = 48;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_STATE = 49;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_STAGE_CHANGE = 50;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_RESULT = 51;
|
||||
public static final int EVENT_SEAL_BATTLE_PROGRESS_DECREASE = 52;
|
||||
public static final int EVENT_GENERAL_REWARD_DIE = 53;
|
||||
public static final int EVENT_SCENE_MP_PLAY_BATTLE_INTERRUPT = 54;
|
||||
public static final int EVENT_MONSTER_DIE_BEFORE_LEAVE_SCENE = 55;
|
||||
public static final int EVENT_SCENE_MP_PLAY_OPEN = 56;
|
||||
public static final int EVENT_OFFERING_LEVELUP = 57;
|
||||
public static final int EVENT_DUNGEON_REVIVE = 58;
|
||||
public static final int EVENT_SCENE_MP_PLAY_ALL_AVATAR_DIE = 59;
|
||||
public static final int EVENT_DUNGEON_ALL_AVATAR_DIE = 60;
|
||||
public static final int EVENT_GENERAL_REWARD_TAKEN = 61;
|
||||
public static final int EVENT_PLATFORM_REACH_ARRAYPOINT = 62;
|
||||
public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_END = 63;
|
||||
public static final int EVENT_SCENE_MULTISTAGE_PLAY_END_STAGE_REQ = 64;
|
||||
public static final int EVENT_MECHANICUS_PICKED_CARD = 65;
|
||||
public static final int EVENT_POOL_MONSTER_TIDE_OVER = 66;
|
||||
public static final int EVENT_POOL_MONSTER_TIDE_CREATE = 67;
|
||||
public static final int EVENT_POOL_MONSTER_TIDE_DIE = 68;
|
||||
public static final int EVENT_DUNGEON_AVATAR_SLIP_DIE = 69;
|
||||
public static final int EVENT_GALLERY_START = 70;
|
||||
public static final int EVENT_GALLERY_STOP = 71;
|
||||
public static final int EVENT_TIME_AXIS_PASS = 72;
|
||||
public static final int EVENT_FLEUR_FAIR_DUNGEON_ALL_PLAYER_ENTER = 73;
|
||||
public static final int EVENT_GADGETTALK_DONE = 74;
|
||||
public static final int EVENT_SET_GAME_TIME = 75;
|
||||
public static final int EVENT_HIDE_AND_SEEK_PLAYER_QUIT = 76;
|
||||
public static final int EVENT_AVATAR_DIE = 77;
|
||||
public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_START = 78;
|
||||
public static final int EVENT_GALLERY_PROGRESS_PASS = 79;
|
||||
public static final int EVENT_GALLERY_PROGRESS_EMPTY = 80;
|
||||
public static final int EVENT_GALLERY_PROGRESS_FULL = 81;
|
||||
public static final int EVENT_HUNTING_FINISH_FINAL = 82;
|
||||
public static final int EVENT_USE_WIDGET_TOY_FOX_CAMERA = 83;
|
||||
public static final int EVENT_LUNA_RITE_SACRIFICE = 84;
|
||||
public static final int EVENT_SUMO_SWITCH_TEAM_EVENT = 85;
|
||||
public static final int EVENT_FISHING_START = 86;
|
||||
public static final int EVENT_FISHING_STOP = 87;
|
||||
public static final int EVENT_FISHING_QTE_FINISH = 88;
|
||||
public static final int EVENT_FISHING_TIMEOUT_FLEE = 89;
|
||||
public static final int EVENT_ROGUE_CELL_STATE_CHANGE = 90;
|
||||
public static final int EVENT_ROGUE_CELL_CONSTRUCT = 91;
|
||||
public static final int EVENT_ROGUE_CELL_FINISH_SELECT_CARD = 92;
|
||||
public static final int EVENT_ANY_MONSTER_CAPTURE = 93;
|
||||
public static final int EVENT_ACTIVITY_INTERACT_GADGET = 94;
|
||||
public static final int EVENT_CHALLENGE_PAUSE = 95;
|
||||
public static final int EVENT_LEVEL_TAG_CHANGE = 96;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_START = 97;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_RESTART = 98;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_REACTIVE = 99;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_OUT_STUCK = 100;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_EXIT_TRY = 101;
|
||||
public static final int EVENT_CUSTOM_DUNGEON_OFFICIAL_RESTART = 102;
|
||||
public static final int EVENT_ANY_MONSTER_CAPTURE_AND_DISAPPEAR = 103;
|
||||
public static final int EVENT_MICHIAE_INTERACT = 104;
|
||||
public static final int EVENT_SELECT_UIINTERACT = 105;
|
||||
public static final int EVENT_LUA_NOTIFY = 106;
|
||||
public static final int EVENT_PHOTO_FINISH = 107;
|
||||
public static final int EVENT_IRODORI_MASTER_READY = 108;
|
||||
public static final int EVENT_ROGUE_START_FIGHT = 109;
|
||||
public static final int EVENT_ROGUE_CREAGE_FIGHT_GADGET = 110;
|
||||
public static final int EVENT_ROGUE_CREAGE_REPAIR_GADGET = 111;
|
||||
public static final int EVENT_ROGUE_OPEN_ACCESS = 112;
|
||||
public static final int EVENT_GADGET_GIVING_FINISHED = 113;
|
||||
public static final int EVENT_OBSERVATION_POINT_NOTIFY = 114;
|
||||
public static final int EVENT_GADGET_GIVING_TAKEBACK = 115;
|
||||
public static final int EVENT_ECHO_SHELL_INTERACT = 116;
|
||||
public static final int EVENT_PLATFORM_ARRIVAL = 2701;
|
||||
public static final int EVENT_PLAYER_BACK_GALLERY_REVIVE_POINT = 2800;
|
||||
public static final int EVENT_GALLERY_CANNOT_START_AFTER_COUNTDOWN = 2801;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package emu.grasscutter.scripts.constants;
|
||||
|
||||
public class ScriptGadgetState {
|
||||
public static final int Default = 0;
|
||||
public static final int GatherDrop = 1;
|
||||
public static final int ChestLocked = 101;
|
||||
public static final int ChestOpened = 102;
|
||||
public static final int ChestTrap = 103;
|
||||
public static final int ChestBramble = 104;
|
||||
public static final int ChestFrozen = 105;
|
||||
public static final int ChestRock = 106;
|
||||
public static final int GearStart = 201;
|
||||
public static final int GearStop = 202;
|
||||
public static final int GearAction1 = 203;
|
||||
public static final int GearAction2 = 204;
|
||||
public static final int CrystalResonate1 = 301;
|
||||
public static final int CrystalResonate2 = 302;
|
||||
public static final int CrystalExplode = 303;
|
||||
public static final int CrystalDrain = 304;
|
||||
public static final int StatueActive = 401;
|
||||
public static final int Action01 = 901;
|
||||
public static final int Action02 = 902;
|
||||
public static final int Action03 = 903;
|
||||
public static final int Default = 0;
|
||||
public static final int GatherDrop = 1;
|
||||
public static final int ChestLocked = 101;
|
||||
public static final int ChestOpened = 102;
|
||||
public static final int ChestTrap = 103;
|
||||
public static final int ChestBramble = 104;
|
||||
public static final int ChestFrozen = 105;
|
||||
public static final int ChestRock = 106;
|
||||
public static final int GearStart = 201;
|
||||
public static final int GearStop = 202;
|
||||
public static final int GearAction1 = 203;
|
||||
public static final int GearAction2 = 204;
|
||||
public static final int CrystalResonate1 = 301;
|
||||
public static final int CrystalResonate2 = 302;
|
||||
public static final int CrystalExplode = 303;
|
||||
public static final int CrystalDrain = 304;
|
||||
public static final int StatueActive = 401;
|
||||
public static final int Action01 = 901;
|
||||
public static final int Action02 = 902;
|
||||
public static final int Action03 = 903;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package emu.grasscutter.scripts.constants;
|
||||
|
||||
public class ScriptRegionShape {
|
||||
public static final int NONE = 0;
|
||||
public static final int SPHERE = 1;
|
||||
public static final int CUBIC = 2;
|
||||
public static final int CYLINDER = 3;
|
||||
public static final int POLYGON = 4;
|
||||
public static final int NONE = 0;
|
||||
public static final int SPHERE = 1;
|
||||
public static final int CUBIC = 2;
|
||||
public static final int CYLINDER = 3;
|
||||
public static final int POLYGON = 4;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import lombok.ToString;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -25,7 +24,7 @@ public class SceneBlock {
|
||||
public Position min;
|
||||
|
||||
public int sceneId;
|
||||
public Map<Integer,SceneGroup> groups;
|
||||
public Map<Integer, SceneGroup> groups;
|
||||
public RTree<SceneGroup, Geometry> sceneGroupIndex;
|
||||
|
||||
private transient boolean loaded; // Not an actual variable in the scripts either
|
||||
@@ -39,8 +38,8 @@ public class SceneBlock {
|
||||
}
|
||||
|
||||
public boolean contains(Position pos) {
|
||||
return pos.getX() <= this.max.getX() && pos.getX() >= this.min.getX() &&
|
||||
pos.getZ() <= this.max.getZ() && pos.getZ() >= this.min.getZ();
|
||||
return pos.getX() <= this.max.getX() && pos.getX() >= this.min.getX() &&
|
||||
pos.getZ() <= this.max.getZ() && pos.getZ() >= this.min.getZ();
|
||||
}
|
||||
|
||||
public SceneBlock load(int sceneId, Bindings bindings) {
|
||||
@@ -62,7 +61,7 @@ public class SceneBlock {
|
||||
|
||||
// Set groups
|
||||
this.groups = ScriptLoader.getSerializer().toList(SceneGroup.class, bindings.get("groups")).stream()
|
||||
.collect(Collectors.toMap(x -> x.id, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.id, y -> y, (a, b) -> a));
|
||||
|
||||
this.groups.values().forEach(g -> g.block_id = this.id);
|
||||
this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.pos.toPoint());
|
||||
|
||||
@@ -6,5 +6,5 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneBusiness {
|
||||
public int type;
|
||||
public int type;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneConfig {
|
||||
public Position vision_anchor;
|
||||
public Position born_pos;
|
||||
public Position born_rot;
|
||||
public Position begin_pos;
|
||||
public Position size;
|
||||
public Position vision_anchor;
|
||||
public Position born_pos;
|
||||
public Position born_rot;
|
||||
public Position begin_pos;
|
||||
public Position size;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneGadget extends SceneObject{
|
||||
public class SceneGadget extends SceneObject {
|
||||
public int gadget_id;
|
||||
public int state;
|
||||
public int point_type;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneGarbage {
|
||||
public List<SceneGadget> gadgets;
|
||||
public List<SceneGadget> gadgets;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.luaj.vm2.LuaValue;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -25,7 +24,7 @@ public class SceneGroup {
|
||||
public int refresh_id;
|
||||
public Position pos;
|
||||
|
||||
public Map<Integer,SceneMonster> monsters; // <ConfigId, Monster>
|
||||
public Map<Integer, SceneMonster> monsters; // <ConfigId, Monster>
|
||||
public Map<Integer, SceneGadget> gadgets; // <ConfigId, Gadgets>
|
||||
public Map<String, SceneTrigger> triggers;
|
||||
public Map<Integer, SceneRegion> regions;
|
||||
@@ -39,6 +38,7 @@ public class SceneGroup {
|
||||
private transient boolean loaded; // Not an actual variable in the scripts either
|
||||
private transient CompiledScript script;
|
||||
private transient Bindings bindings;
|
||||
|
||||
public static SceneGroup of(int groupId) {
|
||||
var group = new SceneGroup();
|
||||
group.id = groupId;
|
||||
@@ -96,15 +96,15 @@ public class SceneGroup {
|
||||
|
||||
// Set
|
||||
this.monsters = ScriptLoader.getSerializer().toList(SceneMonster.class, this.bindings.get("monsters")).stream()
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
this.monsters.values().forEach(m -> m.group = this);
|
||||
|
||||
this.gadgets = ScriptLoader.getSerializer().toList(SceneGadget.class, this.bindings.get("gadgets")).stream()
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a));
|
||||
this.gadgets.values().forEach(m -> m.group = this);
|
||||
|
||||
this.triggers = ScriptLoader.getSerializer().toList(SceneTrigger.class, this.bindings.get("triggers")).stream()
|
||||
.collect(Collectors.toMap(x -> x.name, y -> y, (a, b) -> a));
|
||||
.collect(Collectors.toMap(x -> x.name, y -> y, (a, b) -> a));
|
||||
this.triggers.values().forEach(t -> t.currentGroup = this);
|
||||
|
||||
this.suites = ScriptLoader.getSerializer().toList(SceneSuite.class, this.bindings.get("suites"));
|
||||
@@ -140,9 +140,9 @@ public class SceneGroup {
|
||||
|
||||
public Optional<SceneBossChest> searchBossChestInGroup() {
|
||||
return this.gadgets.values().stream()
|
||||
.filter(g -> g.boss_chest != null && g.boss_chest.monster_config_id > 0)
|
||||
.map(g -> g.boss_chest)
|
||||
.findFirst();
|
||||
.filter(g -> g.boss_chest != null && g.boss_chest.monster_config_id > 0)
|
||||
.map(g -> g.boss_chest)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneInitConfig {
|
||||
public int suite;
|
||||
public int end_suite;
|
||||
public boolean rand_suite;
|
||||
public int suite;
|
||||
public int end_suite;
|
||||
public boolean rand_suite;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import lombok.ToString;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -5,10 +5,10 @@ import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneMonster extends SceneObject{
|
||||
public int monster_id;
|
||||
public int pose_id;
|
||||
public int drop_id;
|
||||
public class SceneMonster extends SceneObject {
|
||||
public int monster_id;
|
||||
public int pose_id;
|
||||
public int drop_id;
|
||||
public int special_name_id;
|
||||
public String drop_tag;
|
||||
public int climate_area_id;
|
||||
|
||||
@@ -5,6 +5,6 @@ import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneNPC extends SceneObject{
|
||||
public int npc_id;
|
||||
}
|
||||
public class SceneNPC extends SceneObject {
|
||||
public int npc_id;
|
||||
}
|
||||
|
||||
@@ -21,18 +21,19 @@ public class SceneRegion {
|
||||
public List<Position> point_array;
|
||||
|
||||
public transient SceneGroup group;
|
||||
|
||||
public boolean contains(Position position) {
|
||||
switch (shape) {
|
||||
case ScriptRegionShape.CUBIC:
|
||||
return (Math.abs(pos.getX() - position.getX()) <= size.getX()) &&
|
||||
(Math.abs(pos.getY() - position.getY()) <= size.getY()) &&
|
||||
(Math.abs(pos.getZ() - position.getZ()) <= size.getZ());
|
||||
(Math.abs(pos.getY() - position.getY()) <= size.getY()) &&
|
||||
(Math.abs(pos.getZ() - position.getZ()) <= size.getZ());
|
||||
case ScriptRegionShape.SPHERE:
|
||||
var x = Math.pow(pos.getX() - position.getX(), 2);
|
||||
var y = Math.pow(pos.getY() - position.getY(), 2);
|
||||
var z = Math.pow(pos.getZ() - position.getZ(), 2);
|
||||
// ^ means XOR in java!
|
||||
return x + y + z <= (radius*radius);
|
||||
return x + y + z <= (radius * radius);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneSuite {
|
||||
// make it refer the default empty list to avoid NPE caused by some group
|
||||
public List<Integer> monsters = List.of();
|
||||
public List<Integer> gadgets = List.of();
|
||||
public List<String> triggers = List.of();
|
||||
public List<Integer> monsters = List.of();
|
||||
public List<Integer> gadgets = List.of();
|
||||
public List<String> triggers = List.of();
|
||||
public List<Integer> regions = List.of();
|
||||
public int rand_weight;
|
||||
public int[] npcs;
|
||||
|
||||
public transient List<SceneMonster> sceneMonsters = List.of();
|
||||
public transient List<SceneGadget> sceneGadgets = List.of();
|
||||
public transient List<SceneTrigger> sceneTriggers = List.of();
|
||||
public transient List<SceneMonster> sceneMonsters = List.of();
|
||||
public transient List<SceneGadget> sceneGadgets = List.of();
|
||||
public transient List<SceneTrigger> sceneTriggers = List.of();
|
||||
public transient List<SceneRegion> sceneRegions = List.of();
|
||||
|
||||
public void init(SceneGroup sceneGroup) {
|
||||
if(sceneGroup.monsters != null && this.monsters != null){
|
||||
if (sceneGroup.monsters != null && this.monsters != null) {
|
||||
this.sceneMonsters = new ArrayList<>(
|
||||
this.monsters.stream()
|
||||
.filter(sceneGroup.monsters::containsKey)
|
||||
@@ -32,7 +32,7 @@ public class SceneSuite {
|
||||
);
|
||||
}
|
||||
|
||||
if(sceneGroup.gadgets != null && this.gadgets != null){
|
||||
if (sceneGroup.gadgets != null && this.gadgets != null) {
|
||||
this.sceneGadgets = new ArrayList<>(
|
||||
this.gadgets.stream()
|
||||
.filter(sceneGroup.gadgets::containsKey)
|
||||
@@ -41,7 +41,7 @@ public class SceneSuite {
|
||||
);
|
||||
}
|
||||
|
||||
if(sceneGroup.triggers != null && this.triggers != null) {
|
||||
if (sceneGroup.triggers != null && this.triggers != null) {
|
||||
this.sceneTriggers = new ArrayList<>(
|
||||
this.triggers.stream()
|
||||
.filter(sceneGroup.triggers::containsKey)
|
||||
@@ -49,7 +49,7 @@ public class SceneSuite {
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
if(sceneGroup.regions != null && this.regions != null) {
|
||||
if (sceneGroup.regions != null && this.regions != null) {
|
||||
this.sceneRegions = new ArrayList<>(
|
||||
this.regions.stream()
|
||||
.filter(sceneGroup.regions::containsKey)
|
||||
|
||||
@@ -4,41 +4,42 @@ import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
public class SceneTrigger {
|
||||
public String name;
|
||||
public int config_id;
|
||||
public int event;
|
||||
public String source;
|
||||
public String condition;
|
||||
public String action;
|
||||
public String name;
|
||||
public int config_id;
|
||||
public int event;
|
||||
public String source;
|
||||
public String condition;
|
||||
public String action;
|
||||
public boolean forbid_guest;
|
||||
public int trigger_count;
|
||||
public String tlog_tag;
|
||||
|
||||
public transient SceneGroup currentGroup;
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof SceneTrigger sceneTrigger){
|
||||
return this.name.equals(sceneTrigger.name);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
public transient SceneGroup currentGroup;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof SceneTrigger sceneTrigger) {
|
||||
return this.name.equals(sceneTrigger.name);
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SceneTrigger{" +
|
||||
"name='" + name + '\'' +
|
||||
", config_id=" + config_id +
|
||||
", event=" + event +
|
||||
", source='" + source + '\'' +
|
||||
", condition='" + condition + '\'' +
|
||||
", action='" + action + '\'' +
|
||||
", forbid_guest='" + forbid_guest + '\'' +
|
||||
", trigger_count='" + trigger_count + '\'' +
|
||||
'}';
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SceneTrigger{" +
|
||||
"name='" + name + '\'' +
|
||||
", config_id=" + config_id +
|
||||
", event=" + event +
|
||||
", source='" + source + '\'' +
|
||||
", condition='" + condition + '\'' +
|
||||
", action='" + action + '\'' +
|
||||
", forbid_guest='" + forbid_guest + '\'' +
|
||||
", trigger_count='" + trigger_count + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneVar {
|
||||
public String name;
|
||||
public int value;
|
||||
public boolean no_refresh;
|
||||
public String name;
|
||||
public int value;
|
||||
public boolean no_refresh;
|
||||
public int configId;
|
||||
}
|
||||
|
||||
@@ -1,59 +1,60 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
public class ScriptArgs {
|
||||
public int param1;
|
||||
public int param2;
|
||||
public int param3;
|
||||
public int source_eid; // Source entity
|
||||
public int param1;
|
||||
public int param2;
|
||||
public int param3;
|
||||
public int source_eid; // Source entity
|
||||
public int target_eid;
|
||||
public ScriptArgs() {
|
||||
|
||||
}
|
||||
public ScriptArgs() {
|
||||
|
||||
public ScriptArgs(int param1) {
|
||||
this.param1 = param1;
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptArgs(int param1, int param2) {
|
||||
this.param1 = param1;
|
||||
this.param2 = param2;
|
||||
}
|
||||
public ScriptArgs(int param1) {
|
||||
this.param1 = param1;
|
||||
}
|
||||
|
||||
public int getParam1() {
|
||||
return param1;
|
||||
}
|
||||
public ScriptArgs(int param1, int param2) {
|
||||
this.param1 = param1;
|
||||
this.param2 = param2;
|
||||
}
|
||||
|
||||
public ScriptArgs setParam1(int param1) {
|
||||
this.param1 = param1;
|
||||
return this;
|
||||
}
|
||||
public int getParam1() {
|
||||
return param1;
|
||||
}
|
||||
|
||||
public int getParam2() {
|
||||
return param2;
|
||||
}
|
||||
public ScriptArgs setParam1(int param1) {
|
||||
this.param1 = param1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScriptArgs setParam2(int param2) {
|
||||
this.param2 = param2;
|
||||
return this;
|
||||
}
|
||||
public int getParam2() {
|
||||
return param2;
|
||||
}
|
||||
|
||||
public int getParam3() {
|
||||
return param3;
|
||||
}
|
||||
public ScriptArgs setParam2(int param2) {
|
||||
this.param2 = param2;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScriptArgs setParam3(int param3) {
|
||||
this.param3 = param3;
|
||||
return this;
|
||||
}
|
||||
public int getParam3() {
|
||||
return param3;
|
||||
}
|
||||
|
||||
public int getSourceEntityId() {
|
||||
return source_eid;
|
||||
}
|
||||
public ScriptArgs setParam3(int param3) {
|
||||
this.param3 = param3;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScriptArgs setSourceEntityId(int source_eid) {
|
||||
this.source_eid = source_eid;
|
||||
return this;
|
||||
}
|
||||
public int getSourceEntityId() {
|
||||
return source_eid;
|
||||
}
|
||||
|
||||
public ScriptArgs setSourceEntityId(int source_eid) {
|
||||
this.source_eid = source_eid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getTargetEntityId() {
|
||||
return target_eid;
|
||||
|
||||
@@ -35,8 +35,8 @@ public class LuaSerializer implements Serializer {
|
||||
return serializeMap(type, (LuaTable) obj);
|
||||
}
|
||||
|
||||
private <T> Map<String,T> serializeMap(Class<T> type, LuaTable table) {
|
||||
Map<String,T> map = new HashMap<>();
|
||||
private <T> Map<String, T> serializeMap(Class<T> type, LuaTable table) {
|
||||
Map<String, T> map = new HashMap<>();
|
||||
|
||||
if (table == null) {
|
||||
return map;
|
||||
@@ -65,7 +65,7 @@ public class LuaSerializer implements Serializer {
|
||||
}
|
||||
|
||||
if (object != null) {
|
||||
map.put(String.valueOf(k),object);
|
||||
map.put(String.valueOf(k), object);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -197,21 +197,21 @@ public class LuaSerializer implements Serializer {
|
||||
var methodNameSet = new HashSet<>(Arrays.stream(methodAccess.getMethodNames()).toList());
|
||||
|
||||
Arrays.stream(type.getDeclaredFields())
|
||||
.filter(field -> methodNameSet.contains(getSetterName(field.getName())))
|
||||
.forEach(field -> {
|
||||
var setter = getSetterName(field.getName());
|
||||
var index = methodAccess.getIndex(setter);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), setter, index, field.getType()));
|
||||
});
|
||||
.filter(field -> methodNameSet.contains(getSetterName(field.getName())))
|
||||
.forEach(field -> {
|
||||
var setter = getSetterName(field.getName());
|
||||
var index = methodAccess.getIndex(setter);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), setter, index, field.getType()));
|
||||
});
|
||||
|
||||
Arrays.stream(type.getFields())
|
||||
.filter(field -> !fieldMetaMap.containsKey(field.getName()))
|
||||
.filter(field -> methodNameSet.contains(getSetterName(field.getName())))
|
||||
.forEach(field -> {
|
||||
var setter = getSetterName(field.getName());
|
||||
var index = methodAccess.getIndex(setter);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), setter, index, field.getType()));
|
||||
});
|
||||
.filter(field -> !fieldMetaMap.containsKey(field.getName()))
|
||||
.filter(field -> methodNameSet.contains(getSetterName(field.getName())))
|
||||
.forEach(field -> {
|
||||
var setter = getSetterName(field.getName());
|
||||
var index = methodAccess.getIndex(setter);
|
||||
fieldMetaMap.put(field.getName(), new FieldMeta(field.getName(), setter, index, field.getType()));
|
||||
});
|
||||
|
||||
fieldMetaCache.put(type, fieldMetaMap);
|
||||
return fieldMetaMap;
|
||||
@@ -230,7 +230,7 @@ public class LuaSerializer implements Serializer {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE)
|
||||
static class FieldMeta{
|
||||
static class FieldMeta {
|
||||
String name;
|
||||
String setter;
|
||||
int index;
|
||||
|
||||
@@ -6,9 +6,9 @@ import java.util.Map;
|
||||
|
||||
public interface Serializer {
|
||||
|
||||
public <T> List<T> toList(Class<T> type, Object obj);
|
||||
<T> List<T> toList(Class<T> type, Object obj);
|
||||
|
||||
public <T> T toObject(Class<T> type, Object obj);
|
||||
<T> T toObject(Class<T> type, Object obj);
|
||||
|
||||
public <T> Map<String,T> toMap(Class<T> type, Object obj);
|
||||
<T> Map<String, T> toMap(Class<T> type, Object obj);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
package emu.grasscutter.scripts.service;
|
||||
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.excels.MonsterData;
|
||||
import emu.grasscutter.data.excels.WorldLevelData;
|
||||
import emu.grasscutter.game.entity.EntityMonster;
|
||||
import emu.grasscutter.scripts.SceneScriptManager;
|
||||
import emu.grasscutter.scripts.constants.EventType;
|
||||
import emu.grasscutter.scripts.data.SceneMonster;
|
||||
import emu.grasscutter.scripts.data.ScriptArgs;
|
||||
import emu.grasscutter.scripts.listener.ScriptMonsterListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -15,28 +9,31 @@ import java.util.List;
|
||||
|
||||
public class ScriptMonsterSpawnService {
|
||||
|
||||
private final SceneScriptManager sceneScriptManager;
|
||||
public final List<ScriptMonsterListener> onMonsterCreatedListener = new ArrayList<>();
|
||||
|
||||
public final List<ScriptMonsterListener> onMonsterDeadListener = new ArrayList<>();
|
||||
private final SceneScriptManager sceneScriptManager;
|
||||
|
||||
public ScriptMonsterSpawnService(SceneScriptManager sceneScriptManager){
|
||||
public ScriptMonsterSpawnService(SceneScriptManager sceneScriptManager) {
|
||||
this.sceneScriptManager = sceneScriptManager;
|
||||
}
|
||||
|
||||
public void addMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener){
|
||||
public void addMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterCreatedListener.add(scriptMonsterListener);
|
||||
}
|
||||
public void addMonsterDeadListener(ScriptMonsterListener scriptMonsterListener){
|
||||
|
||||
public void addMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterDeadListener.add(scriptMonsterListener);
|
||||
}
|
||||
public void removeMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener){
|
||||
|
||||
public void removeMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterCreatedListener.remove(scriptMonsterListener);
|
||||
}
|
||||
public void removeMonsterDeadListener(ScriptMonsterListener scriptMonsterListener){
|
||||
|
||||
public void removeMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterDeadListener.remove(scriptMonsterListener);
|
||||
}
|
||||
public void onMonsterDead(EntityMonster entityMonster){
|
||||
|
||||
public void onMonsterDead(EntityMonster entityMonster) {
|
||||
onMonsterDeadListener.forEach(l -> l.onNotify(entityMonster));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ public class ScriptMonsterTideService {
|
||||
private final AtomicInteger monsterKillCount;
|
||||
private final int monsterSceneLimit;
|
||||
private final ConcurrentLinkedQueue<Integer> monsterConfigOrders;
|
||||
private final OnMonsterCreated onMonsterCreated= new OnMonsterCreated();
|
||||
private final OnMonsterDead onMonsterDead= new OnMonsterDead();
|
||||
private final OnMonsterCreated onMonsterCreated = new OnMonsterCreated();
|
||||
private final OnMonsterDead onMonsterDead = new OnMonsterDead();
|
||||
|
||||
public ScriptMonsterTideService(SceneScriptManager sceneScriptManager,
|
||||
SceneGroup group, int tideCount, int monsterSceneLimit, Integer[] ordersConfigId){
|
||||
SceneGroup group, int tideCount, int monsterSceneLimit, Integer[] ordersConfigId) {
|
||||
this.sceneScriptManager = sceneScriptManager;
|
||||
this.currentGroup = group;
|
||||
this.monsterSceneLimit = monsterSceneLimit;
|
||||
@@ -41,25 +41,30 @@ public class ScriptMonsterTideService {
|
||||
}
|
||||
}
|
||||
|
||||
public class OnMonsterCreated implements ScriptMonsterListener{
|
||||
@Override
|
||||
public void onNotify(EntityMonster sceneMonster) {
|
||||
if(monsterSceneLimit > 0){
|
||||
monsterAlive.incrementAndGet();
|
||||
monsterTideCount.decrementAndGet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SceneMonster getNextMonster(){
|
||||
public SceneMonster getNextMonster() {
|
||||
var nextId = this.monsterConfigOrders.poll();
|
||||
if(currentGroup.monsters.containsKey(nextId)){
|
||||
if (currentGroup.monsters.containsKey(nextId)) {
|
||||
return currentGroup.monsters.get(nextId);
|
||||
}
|
||||
// TODO some monster config_id do not exist in groups, so temporarily set it to the first
|
||||
return currentGroup.monsters.values().stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
this.sceneScriptManager.getScriptMonsterSpawnService().removeMonsterCreatedListener(onMonsterCreated);
|
||||
this.sceneScriptManager.getScriptMonsterSpawnService().removeMonsterDeadListener(onMonsterDead);
|
||||
}
|
||||
|
||||
public class OnMonsterCreated implements ScriptMonsterListener {
|
||||
@Override
|
||||
public void onNotify(EntityMonster sceneMonster) {
|
||||
if (monsterSceneLimit > 0) {
|
||||
monsterAlive.incrementAndGet();
|
||||
monsterTideCount.decrementAndGet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OnMonsterDead implements ScriptMonsterListener {
|
||||
@Override
|
||||
public void onNotify(EntityMonster sceneMonster) {
|
||||
@@ -81,9 +86,4 @@ public class ScriptMonsterTideService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void unload(){
|
||||
this.sceneScriptManager.getScriptMonsterSpawnService().removeMonsterCreatedListener(onMonsterCreated);
|
||||
this.sceneScriptManager.getScriptMonsterSpawnService().removeMonsterDeadListener(onMonsterDead);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user