mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 09:54:59 +01:00
Format code [skip actions]
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
package emu.grasscutter.scripts;
|
||||
|
||||
import com.github.davidmoten.rtreemulti.Entry;
|
||||
import com.github.davidmoten.rtreemulti.RTree;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Geometry;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SceneIndexManager {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
var newPos = position.clone();
|
||||
for (int i = 0; i < newPos.length; i++) {
|
||||
newPos[i] += range;
|
||||
}
|
||||
return newPos;
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.scripts;
|
||||
|
||||
import com.github.davidmoten.rtreemulti.Entry;
|
||||
import com.github.davidmoten.rtreemulti.RTree;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Geometry;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SceneIndexManager {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
var newPos = position.clone();
|
||||
for (int i = 0; i < newPos.length; i++) {
|
||||
newPos[i] += range;
|
||||
}
|
||||
return newPos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,126 +1,126 @@
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneBusiness {
|
||||
public int type;
|
||||
}
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneBusiness {
|
||||
public int type;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneGarbage {
|
||||
public List<SceneGadget> gadgets;
|
||||
}
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneGarbage {
|
||||
public List<SceneGadget> gadgets;
|
||||
}
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import com.github.davidmoten.rtreemulti.RTree;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Geometry;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.scripts.SceneIndexManager;
|
||||
import emu.grasscutter.scripts.ScriptLoader;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptException;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneMeta {
|
||||
|
||||
public SceneConfig config;
|
||||
public Map<Integer, SceneBlock> blocks;
|
||||
|
||||
public Bindings context;
|
||||
|
||||
public RTree<SceneBlock, Geometry> sceneBlockIndex;
|
||||
|
||||
public static SceneMeta of(int sceneId) {
|
||||
return new SceneMeta().load(sceneId);
|
||||
}
|
||||
|
||||
public SceneMeta load(int sceneId) {
|
||||
// Get compiled script if cached
|
||||
CompiledScript cs = ScriptLoader.getScript("Scene/" + sceneId + "/scene" + sceneId + ".lua");
|
||||
|
||||
if (cs == null) {
|
||||
Grasscutter.getLogger().warn("No script found for scene " + sceneId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create bindings
|
||||
this.context = ScriptLoader.getEngine().createBindings();
|
||||
|
||||
// Eval script
|
||||
try {
|
||||
cs.eval(this.context);
|
||||
|
||||
this.config =
|
||||
ScriptLoader.getSerializer()
|
||||
.toObject(SceneConfig.class, this.context.get("scene_config"));
|
||||
|
||||
// TODO optimize later
|
||||
// Create blocks
|
||||
List<Integer> blockIds =
|
||||
ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks"));
|
||||
List<SceneBlock> blocks =
|
||||
ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects"));
|
||||
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
SceneBlock block = blocks.get(i);
|
||||
block.id = blockIds.get(i);
|
||||
}
|
||||
|
||||
this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b, (a, b) -> a));
|
||||
this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle);
|
||||
|
||||
} catch (ScriptException exception) {
|
||||
Grasscutter.getLogger().error("An error occurred while running a script.", exception);
|
||||
return null;
|
||||
}
|
||||
Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import com.github.davidmoten.rtreemulti.RTree;
|
||||
import com.github.davidmoten.rtreemulti.geometry.Geometry;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.scripts.SceneIndexManager;
|
||||
import emu.grasscutter.scripts.ScriptLoader;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptException;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneMeta {
|
||||
|
||||
public SceneConfig config;
|
||||
public Map<Integer, SceneBlock> blocks;
|
||||
|
||||
public Bindings context;
|
||||
|
||||
public RTree<SceneBlock, Geometry> sceneBlockIndex;
|
||||
|
||||
public static SceneMeta of(int sceneId) {
|
||||
return new SceneMeta().load(sceneId);
|
||||
}
|
||||
|
||||
public SceneMeta load(int sceneId) {
|
||||
// Get compiled script if cached
|
||||
CompiledScript cs = ScriptLoader.getScript("Scene/" + sceneId + "/scene" + sceneId + ".lua");
|
||||
|
||||
if (cs == null) {
|
||||
Grasscutter.getLogger().warn("No script found for scene " + sceneId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create bindings
|
||||
this.context = ScriptLoader.getEngine().createBindings();
|
||||
|
||||
// Eval script
|
||||
try {
|
||||
cs.eval(this.context);
|
||||
|
||||
this.config =
|
||||
ScriptLoader.getSerializer()
|
||||
.toObject(SceneConfig.class, this.context.get("scene_config"));
|
||||
|
||||
// TODO optimize later
|
||||
// Create blocks
|
||||
List<Integer> blockIds =
|
||||
ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks"));
|
||||
List<SceneBlock> blocks =
|
||||
ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects"));
|
||||
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
SceneBlock block = blocks.get(i);
|
||||
block.id = blockIds.get(i);
|
||||
}
|
||||
|
||||
this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b, (a, b) -> a));
|
||||
this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle);
|
||||
|
||||
} catch (ScriptException exception) {
|
||||
Grasscutter.getLogger().error("An error occurred while running a script.", exception);
|
||||
return null;
|
||||
}
|
||||
Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneNPC extends SceneObject {
|
||||
public int npc_id;
|
||||
}
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneNPC extends SceneObject {
|
||||
public int npc_id;
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import emu.grasscutter.scripts.constants.ScriptRegionShape;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import java.util.List;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
public class SceneRegion {
|
||||
public int config_id;
|
||||
public int shape;
|
||||
public Position pos;
|
||||
// for CUBIC
|
||||
public Position size;
|
||||
// for SPHERE
|
||||
public int radius;
|
||||
public int area_id;
|
||||
public float height;
|
||||
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());
|
||||
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 false;
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import emu.grasscutter.scripts.constants.ScriptRegionShape;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import java.util.List;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
public class SceneRegion {
|
||||
public int config_id;
|
||||
public int shape;
|
||||
public Position pos;
|
||||
// for CUBIC
|
||||
public Position size;
|
||||
// for SPHERE
|
||||
public int radius;
|
||||
public int area_id;
|
||||
public float height;
|
||||
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());
|
||||
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 false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneVar {
|
||||
public String name;
|
||||
public int value;
|
||||
public boolean no_refresh;
|
||||
public int configId;
|
||||
}
|
||||
package emu.grasscutter.scripts.data;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
@Setter
|
||||
public class SceneVar {
|
||||
public String name;
|
||||
public int value;
|
||||
public boolean no_refresh;
|
||||
public int configId;
|
||||
}
|
||||
|
||||
@@ -1,195 +1,195 @@
|
||||
package emu.grasscutter.scripts.serializer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import com.fasterxml.jackson.annotation.Nulls;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.fasterxml.jackson.databind.type.MapType;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implements Serializer {
|
||||
|
||||
private static ObjectMapper objectMapper;
|
||||
|
||||
public LuaTableJacksonSerializer() {
|
||||
if (objectMapper == null) {
|
||||
objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
|
||||
// Some properties in Lua table but not in java field
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper
|
||||
.configOverride(List.class)
|
||||
.setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY));
|
||||
SimpleModule luaSerializeModule = new SimpleModule();
|
||||
luaSerializeModule.addSerializer(LuaTable.class, this);
|
||||
objectMapper.registerModule(luaSerializeModule);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(LuaTable value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
if (value == null || value.isnil()) {
|
||||
gen.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect table type
|
||||
boolean isArray = false;
|
||||
LuaValue[] keys = value.keys();
|
||||
if (keys.length == 0) {
|
||||
gen.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (!keys[i].isint() || (i + 1) != keys[i].toint()) {
|
||||
break;
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == keys.length) {
|
||||
isArray = true;
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
gen.writeStartArray();
|
||||
for (LuaValue key : keys) {
|
||||
LuaValue luaValue = value.get(key);
|
||||
if (luaValue.isnil()) {
|
||||
gen.writeNull();
|
||||
} else if (luaValue.isboolean()) {
|
||||
gen.writeBoolean(luaValue.toboolean());
|
||||
} else if (luaValue.isint()) {
|
||||
gen.writeNumber(luaValue.toint());
|
||||
} else if (luaValue.islong()) {
|
||||
gen.writeNumber(luaValue.tolong());
|
||||
} else if (luaValue.isnumber()) {
|
||||
gen.writeNumber(luaValue.tofloat());
|
||||
} else if (luaValue.isstring()) {
|
||||
gen.writeString(luaValue.tojstring());
|
||||
} else if (luaValue.istable()) {
|
||||
serialize(luaValue.checktable(), gen, serializers);
|
||||
}
|
||||
}
|
||||
gen.writeEndArray();
|
||||
} else {
|
||||
gen.writeStartObject();
|
||||
for (LuaValue key : keys) {
|
||||
String keyStr = key.toString();
|
||||
LuaValue luaValue = value.get(key);
|
||||
if (luaValue.isnil()) {
|
||||
gen.writeNullField(keyStr);
|
||||
} else if (luaValue.isboolean()) {
|
||||
gen.writeBooleanField(keyStr, luaValue.toboolean());
|
||||
} else if (luaValue.isint()) {
|
||||
gen.writeNumberField(keyStr, luaValue.toint());
|
||||
} else if (luaValue.islong()) {
|
||||
gen.writeNumberField(keyStr, luaValue.tolong());
|
||||
} else if (luaValue.isnumber()) {
|
||||
gen.writeNumberField(keyStr, luaValue.tofloat());
|
||||
} else if (luaValue.isstring()) {
|
||||
gen.writeStringField(keyStr, luaValue.tojstring());
|
||||
} else if (luaValue.istable()) {
|
||||
gen.writeFieldName(keyStr);
|
||||
serialize(luaValue.checktable(), gen, serializers);
|
||||
}
|
||||
}
|
||||
gen.writeEndObject();
|
||||
}
|
||||
|
||||
gen.flush();
|
||||
gen.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> toList(Class<T> type, Object obj) {
|
||||
List<T> list = new ArrayList<>();
|
||||
if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) {
|
||||
return list;
|
||||
}
|
||||
|
||||
CollectionType collectionType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, type);
|
||||
JsonNode jsonNode = objectMapper.valueToTree(luaTable);
|
||||
Grasscutter.getLogger()
|
||||
.trace(
|
||||
"[LuaTableToList] className={},data={}", type.getCanonicalName(), jsonNode.toString());
|
||||
if (jsonNode.isEmpty()) {
|
||||
return list;
|
||||
}
|
||||
if (jsonNode.isArray()) {
|
||||
try {
|
||||
Object o = objectMapper.treeToValue(jsonNode, collectionType);
|
||||
if (o != null) {
|
||||
list = (ArrayList<T>) o;
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (jsonNode.isObject()) {
|
||||
Iterator<Map.Entry<String, JsonNode>> fields = jsonNode.fields();
|
||||
List<JsonNode> nodes = new ArrayList<>();
|
||||
while (fields.hasNext()) {
|
||||
Map.Entry<String, JsonNode> next = fields.next();
|
||||
nodes.add(next.getValue());
|
||||
}
|
||||
list = objectMapper.convertValue(nodes, collectionType);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObject(Class<T> type, Object obj) {
|
||||
if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonNode jsonNode = objectMapper.valueToTree(luaTable);
|
||||
Grasscutter.getLogger()
|
||||
.trace(
|
||||
"[LuaTableToObject] className={},data={}",
|
||||
type.getCanonicalName(),
|
||||
jsonNode.toString());
|
||||
try {
|
||||
return objectMapper.treeToValue(jsonNode, type);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<String, T> toMap(Class<T> type, Object obj) {
|
||||
HashMap<String, T> map = new HashMap<>();
|
||||
if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) {
|
||||
return map;
|
||||
}
|
||||
|
||||
MapType mapStringType =
|
||||
objectMapper.getTypeFactory().constructMapType(HashMap.class, String.class, type);
|
||||
JsonNode jsonNode = objectMapper.valueToTree(luaTable);
|
||||
Grasscutter.getLogger()
|
||||
.trace(
|
||||
"[LuaTableToMap] className={},data={}", type.getCanonicalName(), jsonNode.toString());
|
||||
try {
|
||||
Object o = objectMapper.treeToValue(jsonNode, mapStringType);
|
||||
if (o != null) {
|
||||
return (HashMap<String, T>) o;
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.scripts.serializer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import com.fasterxml.jackson.annotation.Nulls;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.fasterxml.jackson.databind.type.MapType;
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
public class LuaTableJacksonSerializer extends JsonSerializer<LuaTable> implements Serializer {
|
||||
|
||||
private static ObjectMapper objectMapper;
|
||||
|
||||
public LuaTableJacksonSerializer() {
|
||||
if (objectMapper == null) {
|
||||
objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
|
||||
// Some properties in Lua table but not in java field
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper
|
||||
.configOverride(List.class)
|
||||
.setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY));
|
||||
SimpleModule luaSerializeModule = new SimpleModule();
|
||||
luaSerializeModule.addSerializer(LuaTable.class, this);
|
||||
objectMapper.registerModule(luaSerializeModule);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(LuaTable value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
if (value == null || value.isnil()) {
|
||||
gen.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect table type
|
||||
boolean isArray = false;
|
||||
LuaValue[] keys = value.keys();
|
||||
if (keys.length == 0) {
|
||||
gen.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (!keys[i].isint() || (i + 1) != keys[i].toint()) {
|
||||
break;
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == keys.length) {
|
||||
isArray = true;
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
gen.writeStartArray();
|
||||
for (LuaValue key : keys) {
|
||||
LuaValue luaValue = value.get(key);
|
||||
if (luaValue.isnil()) {
|
||||
gen.writeNull();
|
||||
} else if (luaValue.isboolean()) {
|
||||
gen.writeBoolean(luaValue.toboolean());
|
||||
} else if (luaValue.isint()) {
|
||||
gen.writeNumber(luaValue.toint());
|
||||
} else if (luaValue.islong()) {
|
||||
gen.writeNumber(luaValue.tolong());
|
||||
} else if (luaValue.isnumber()) {
|
||||
gen.writeNumber(luaValue.tofloat());
|
||||
} else if (luaValue.isstring()) {
|
||||
gen.writeString(luaValue.tojstring());
|
||||
} else if (luaValue.istable()) {
|
||||
serialize(luaValue.checktable(), gen, serializers);
|
||||
}
|
||||
}
|
||||
gen.writeEndArray();
|
||||
} else {
|
||||
gen.writeStartObject();
|
||||
for (LuaValue key : keys) {
|
||||
String keyStr = key.toString();
|
||||
LuaValue luaValue = value.get(key);
|
||||
if (luaValue.isnil()) {
|
||||
gen.writeNullField(keyStr);
|
||||
} else if (luaValue.isboolean()) {
|
||||
gen.writeBooleanField(keyStr, luaValue.toboolean());
|
||||
} else if (luaValue.isint()) {
|
||||
gen.writeNumberField(keyStr, luaValue.toint());
|
||||
} else if (luaValue.islong()) {
|
||||
gen.writeNumberField(keyStr, luaValue.tolong());
|
||||
} else if (luaValue.isnumber()) {
|
||||
gen.writeNumberField(keyStr, luaValue.tofloat());
|
||||
} else if (luaValue.isstring()) {
|
||||
gen.writeStringField(keyStr, luaValue.tojstring());
|
||||
} else if (luaValue.istable()) {
|
||||
gen.writeFieldName(keyStr);
|
||||
serialize(luaValue.checktable(), gen, serializers);
|
||||
}
|
||||
}
|
||||
gen.writeEndObject();
|
||||
}
|
||||
|
||||
gen.flush();
|
||||
gen.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> toList(Class<T> type, Object obj) {
|
||||
List<T> list = new ArrayList<>();
|
||||
if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) {
|
||||
return list;
|
||||
}
|
||||
|
||||
CollectionType collectionType =
|
||||
objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, type);
|
||||
JsonNode jsonNode = objectMapper.valueToTree(luaTable);
|
||||
Grasscutter.getLogger()
|
||||
.trace(
|
||||
"[LuaTableToList] className={},data={}", type.getCanonicalName(), jsonNode.toString());
|
||||
if (jsonNode.isEmpty()) {
|
||||
return list;
|
||||
}
|
||||
if (jsonNode.isArray()) {
|
||||
try {
|
||||
Object o = objectMapper.treeToValue(jsonNode, collectionType);
|
||||
if (o != null) {
|
||||
list = (ArrayList<T>) o;
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (jsonNode.isObject()) {
|
||||
Iterator<Map.Entry<String, JsonNode>> fields = jsonNode.fields();
|
||||
List<JsonNode> nodes = new ArrayList<>();
|
||||
while (fields.hasNext()) {
|
||||
Map.Entry<String, JsonNode> next = fields.next();
|
||||
nodes.add(next.getValue());
|
||||
}
|
||||
list = objectMapper.convertValue(nodes, collectionType);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toObject(Class<T> type, Object obj) {
|
||||
if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonNode jsonNode = objectMapper.valueToTree(luaTable);
|
||||
Grasscutter.getLogger()
|
||||
.trace(
|
||||
"[LuaTableToObject] className={},data={}",
|
||||
type.getCanonicalName(),
|
||||
jsonNode.toString());
|
||||
try {
|
||||
return objectMapper.treeToValue(jsonNode, type);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<String, T> toMap(Class<T> type, Object obj) {
|
||||
HashMap<String, T> map = new HashMap<>();
|
||||
if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) {
|
||||
return map;
|
||||
}
|
||||
|
||||
MapType mapStringType =
|
||||
objectMapper.getTypeFactory().constructMapType(HashMap.class, String.class, type);
|
||||
JsonNode jsonNode = objectMapper.valueToTree(luaTable);
|
||||
Grasscutter.getLogger()
|
||||
.trace(
|
||||
"[LuaTableToMap] className={},data={}", type.getCanonicalName(), jsonNode.toString());
|
||||
try {
|
||||
Object o = objectMapper.treeToValue(jsonNode, mapStringType);
|
||||
if (o != null) {
|
||||
return (HashMap<String, T>) o;
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package emu.grasscutter.scripts.serializer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Serializer {
|
||||
|
||||
<T> List<T> toList(Class<T> type, Object obj);
|
||||
|
||||
<T> T toObject(Class<T> type, Object obj);
|
||||
|
||||
<T> Map<String, T> toMap(Class<T> type, Object obj);
|
||||
}
|
||||
package emu.grasscutter.scripts.serializer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Serializer {
|
||||
|
||||
<T> List<T> toList(Class<T> type, Object obj);
|
||||
|
||||
<T> T toObject(Class<T> type, Object obj);
|
||||
|
||||
<T> Map<String, T> toMap(Class<T> type, Object obj);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package emu.grasscutter.scripts.service;
|
||||
|
||||
import emu.grasscutter.game.entity.EntityMonster;
|
||||
import emu.grasscutter.scripts.SceneScriptManager;
|
||||
import emu.grasscutter.scripts.listener.ScriptMonsterListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptMonsterSpawnService {
|
||||
|
||||
public final List<ScriptMonsterListener> onMonsterCreatedListener = new ArrayList<>();
|
||||
public final List<ScriptMonsterListener> onMonsterDeadListener = new ArrayList<>();
|
||||
private final SceneScriptManager sceneScriptManager;
|
||||
|
||||
public ScriptMonsterSpawnService(SceneScriptManager sceneScriptManager) {
|
||||
this.sceneScriptManager = sceneScriptManager;
|
||||
}
|
||||
|
||||
public void addMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterCreatedListener.add(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void addMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterDeadListener.add(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void removeMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterCreatedListener.remove(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void removeMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterDeadListener.remove(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void onMonsterDead(EntityMonster entityMonster) {
|
||||
onMonsterDeadListener.forEach(l -> l.onNotify(entityMonster));
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.scripts.service;
|
||||
|
||||
import emu.grasscutter.game.entity.EntityMonster;
|
||||
import emu.grasscutter.scripts.SceneScriptManager;
|
||||
import emu.grasscutter.scripts.listener.ScriptMonsterListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptMonsterSpawnService {
|
||||
|
||||
public final List<ScriptMonsterListener> onMonsterCreatedListener = new ArrayList<>();
|
||||
public final List<ScriptMonsterListener> onMonsterDeadListener = new ArrayList<>();
|
||||
private final SceneScriptManager sceneScriptManager;
|
||||
|
||||
public ScriptMonsterSpawnService(SceneScriptManager sceneScriptManager) {
|
||||
this.sceneScriptManager = sceneScriptManager;
|
||||
}
|
||||
|
||||
public void addMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterCreatedListener.add(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void addMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterDeadListener.add(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void removeMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterCreatedListener.remove(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void removeMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) {
|
||||
onMonsterDeadListener.remove(scriptMonsterListener);
|
||||
}
|
||||
|
||||
public void onMonsterDead(EntityMonster entityMonster) {
|
||||
onMonsterDeadListener.forEach(l -> l.onNotify(entityMonster));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user