mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-24 00:23:06 +08:00
parent
f3277dee9f
commit
98fbc4e512
@ -9,6 +9,7 @@ import emu.grasscutter.Grasscutter;
|
|||||||
import emu.grasscutter.data.binout.*;
|
import emu.grasscutter.data.binout.*;
|
||||||
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
|
import emu.grasscutter.data.binout.AbilityModifier.AbilityModifierAction;
|
||||||
import emu.grasscutter.data.binout.config.*;
|
import emu.grasscutter.data.binout.config.*;
|
||||||
|
import emu.grasscutter.data.binout.routes.*;
|
||||||
import emu.grasscutter.data.common.PointData;
|
import emu.grasscutter.data.common.PointData;
|
||||||
import emu.grasscutter.data.custom.*;
|
import emu.grasscutter.data.custom.*;
|
||||||
import emu.grasscutter.data.excels.trial.TrialAvatarActivityDataData;
|
import emu.grasscutter.data.excels.trial.TrialAvatarActivityDataData;
|
||||||
@ -107,6 +108,7 @@ public final class ResourceLoader {
|
|||||||
// Load default home layout
|
// Load default home layout
|
||||||
loadHomeworldDefaultSaveData();
|
loadHomeworldDefaultSaveData();
|
||||||
loadNpcBornData();
|
loadNpcBornData();
|
||||||
|
loadRoutes();
|
||||||
loadBlossomResources();
|
loadBlossomResources();
|
||||||
cacheTalentLevelSets();
|
cacheTalentLevelSets();
|
||||||
// Load activities.
|
// Load activities.
|
||||||
@ -264,6 +266,30 @@ public final class ResourceLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void loadRoutes() {
|
||||||
|
try {
|
||||||
|
Files.newDirectoryStream(getResourcePath("BinOutput/LevelDesign/Routes/"),"*.json")
|
||||||
|
.forEach(
|
||||||
|
path -> {
|
||||||
|
try {
|
||||||
|
val data = JsonUtils.loadToClass(path, SceneRoutes.class);
|
||||||
|
val routesArray = data.getRoutes();
|
||||||
|
if (routesArray == null) return;
|
||||||
|
val routesMap = GameData.getSceneRouteData().getOrDefault(data.getSceneId(), new Int2ObjectOpenHashMap<>());
|
||||||
|
for (Route route : routesArray) {
|
||||||
|
routesMap.put(route.getLocalId(), route);
|
||||||
|
}
|
||||||
|
GameData.getSceneRouteData().put(data.getSceneId(), routesMap);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Grasscutter.getLogger()
|
||||||
|
.debug("Loaded " + GameData.getSceneNpcBornData().size() + " SceneRouteDatas.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Grasscutter.getLogger().error("Failed to load SceneRouteData folder.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void cacheTalentLevelSets() {
|
private static void cacheTalentLevelSets() {
|
||||||
// All known levels, keyed by proudSkillGroupId
|
// All known levels, keyed by proudSkillGroupId
|
||||||
GameData.getProudSkillDataMap()
|
GameData.getProudSkillDataMap()
|
||||||
|
@ -7,6 +7,7 @@ import emu.grasscutter.data.binout.config.fields.ConfigAbilityData;
|
|||||||
import emu.grasscutter.data.excels.GadgetData;
|
import emu.grasscutter.data.excels.GadgetData;
|
||||||
import emu.grasscutter.game.entity.gadget.*;
|
import emu.grasscutter.game.entity.gadget.*;
|
||||||
import emu.grasscutter.game.entity.gadget.platform.BaseRoute;
|
import emu.grasscutter.game.entity.gadget.platform.BaseRoute;
|
||||||
|
import emu.grasscutter.game.entity.gadget.platform.ConfigRoute;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.*;
|
import emu.grasscutter.game.props.*;
|
||||||
import emu.grasscutter.game.world.*;
|
import emu.grasscutter.game.world.*;
|
||||||
@ -246,6 +247,37 @@ public class EntityGadget extends EntityBaseGadget {
|
|||||||
if (routeConfig.isStarted()) {
|
if (routeConfig.isStarted()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(routeConfig instanceof ConfigRoute configRoute) {
|
||||||
|
var route = this.getScene().getSceneRouteById(configRoute.getRouteId());
|
||||||
|
if(route != null) {
|
||||||
|
var points = route.getPoints();
|
||||||
|
val currIndex = configRoute.getStartIndex();
|
||||||
|
|
||||||
|
Position prevpos;
|
||||||
|
if(currIndex == 0) {
|
||||||
|
prevpos = getPosition();
|
||||||
|
this.getScene().getScriptManager().callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_PLATFORM_REACH_POINT, this.getConfigId(), configRoute.getRouteId()).setParam3(0).setEventSource(this.getConfigId()));
|
||||||
|
}else {
|
||||||
|
prevpos = points[currIndex].getPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
double time = 0;
|
||||||
|
for(var i = currIndex; i < points.length;++i) {
|
||||||
|
time += points[i].getPos().computeDistance(prevpos) / points[i].getTargetVelocity();
|
||||||
|
prevpos = points[i].getPos();
|
||||||
|
val I = i;
|
||||||
|
configRoute.getScheduledIndexes().add(this.getScene().getScheduler().scheduleDelayedTask(() -> {
|
||||||
|
if(points[I].isHasReachEvent() && I > currIndex) {
|
||||||
|
this.getScene().getScriptManager().callEvent(new ScriptArgs(this.getGroupId(), EventType.EVENT_PLATFORM_REACH_POINT, this.getConfigId(), configRoute.getRouteId()).setParam3(I).setEventSource(this.getConfigId()));
|
||||||
|
}
|
||||||
|
configRoute.setStartIndex(I);
|
||||||
|
this.position.set(points[I].getPos());
|
||||||
|
},(int)time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getScene().broadcastPacket(new PacketSceneTimeNotify(getScene()));
|
getScene().broadcastPacket(new PacketSceneTimeNotify(getScene()));
|
||||||
routeConfig.startRoute(getScene());
|
routeConfig.startRoute(getScene());
|
||||||
getScene().broadcastPacket(new PacketPlatformStartRouteNotify(this));
|
getScene().broadcastPacket(new PacketPlatformStartRouteNotify(this));
|
||||||
@ -261,6 +293,14 @@ public class EntityGadget extends EntityBaseGadget {
|
|||||||
if (!routeConfig.isStarted()) {
|
if (!routeConfig.isStarted()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(routeConfig instanceof ConfigRoute configRoute) {
|
||||||
|
for(var task : configRoute.getScheduledIndexes()) {
|
||||||
|
this.getScene().getScheduler().cancelTask(task);
|
||||||
|
}
|
||||||
|
configRoute.getScheduledIndexes().clear();
|
||||||
|
}
|
||||||
|
|
||||||
routeConfig.stopRoute(getScene());
|
routeConfig.stopRoute(getScene());
|
||||||
getScene().broadcastPacket(new PacketPlatformStopRouteNotify(this));
|
getScene().broadcastPacket(new PacketPlatformStopRouteNotify(this));
|
||||||
|
|
||||||
|
@ -6,25 +6,34 @@ import emu.grasscutter.net.proto.PlatformInfoOuterClass;
|
|||||||
import emu.grasscutter.scripts.data.SceneGadget;
|
import emu.grasscutter.scripts.data.SceneGadget;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ConfigRoute extends BaseRoute {
|
public class ConfigRoute extends BaseRoute {
|
||||||
|
|
||||||
@Getter @Setter private int routeId;
|
@Getter @Setter private int routeId;
|
||||||
|
@Getter @Setter private int startIndex;
|
||||||
|
@Getter @Setter private List<Integer> scheduledIndexes;
|
||||||
|
|
||||||
public ConfigRoute(SceneGadget gadget) {
|
public ConfigRoute(SceneGadget gadget) {
|
||||||
super(gadget);
|
super(gadget);
|
||||||
this.routeId = gadget.route_id;
|
this.routeId = gadget.route_id;
|
||||||
|
this.startIndex = 0;
|
||||||
|
this.scheduledIndexes = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigRoute(Position startRot, boolean startRoute, boolean isActive, int routeId) {
|
public ConfigRoute(Position startRot, boolean startRoute, boolean isActive, int routeId) {
|
||||||
super(startRot, startRoute, isActive);
|
super(startRot, startRoute, isActive);
|
||||||
this.routeId = routeId;
|
this.routeId = routeId;
|
||||||
|
this.startIndex = 0;
|
||||||
|
this.scheduledIndexes = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlatformInfoOuterClass.PlatformInfo.Builder toProto() {
|
public PlatformInfoOuterClass.PlatformInfo.Builder toProto() {
|
||||||
return super.toProto()
|
return super.toProto()
|
||||||
.setRouteId(routeId)
|
.setRouteId(this.routeId)
|
||||||
|
.setStartIndex(this.startIndex)
|
||||||
.setMovingPlatformType(
|
.setMovingPlatformType(
|
||||||
MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_USE_CONFIG);
|
MovingPlatformTypeOuterClass.MovingPlatformType.MOVING_PLATFORM_TYPE_USE_CONFIG);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import emu.grasscutter.scripts.data.*;
|
|||||||
import emu.grasscutter.server.event.entity.EntityCreationEvent;
|
import emu.grasscutter.server.event.entity.EntityCreationEvent;
|
||||||
import emu.grasscutter.server.event.player.PlayerTeleportEvent;
|
import emu.grasscutter.server.event.player.PlayerTeleportEvent;
|
||||||
import emu.grasscutter.server.packet.send.*;
|
import emu.grasscutter.server.packet.send.*;
|
||||||
|
import emu.grasscutter.server.scheduler.ServerTaskScheduler;
|
||||||
import emu.grasscutter.utils.objects.KahnsSort;
|
import emu.grasscutter.utils.objects.KahnsSort;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -71,6 +72,7 @@ public final class Scene {
|
|||||||
private final List<Runnable> afterHostInitCallbacks = new ArrayList<>();
|
private final List<Runnable> afterHostInitCallbacks = new ArrayList<>();
|
||||||
|
|
||||||
@Getter private GameEntity sceneEntity;
|
@Getter private GameEntity sceneEntity;
|
||||||
|
@Getter private final ServerTaskScheduler scheduler;
|
||||||
|
|
||||||
public Scene(World world, SceneData sceneData) {
|
public Scene(World world, SceneData sceneData) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@ -94,6 +96,7 @@ public final class Scene {
|
|||||||
this.blossomManager = new BlossomManager(this);
|
this.blossomManager = new BlossomManager(this);
|
||||||
this.unlockedForces = new HashSet<>();
|
this.unlockedForces = new HashSet<>();
|
||||||
this.sceneEntity = new EntityScene(this);
|
this.sceneEntity = new EntityScene(this);
|
||||||
|
this.scheduler = new ServerTaskScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -533,6 +536,10 @@ public final class Scene {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isPaused) {
|
||||||
|
this.getScheduler().runTasks();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.getScriptManager().isInit()) {
|
if (this.getScriptManager().isInit()) {
|
||||||
// this.checkBlocks();
|
// this.checkBlocks();
|
||||||
this.checkGroups();
|
this.checkGroups();
|
||||||
|
@ -1319,6 +1319,13 @@ public class ScriptLib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configRoute.setRouteId(routeId);
|
configRoute.setRouteId(routeId);
|
||||||
|
configRoute.setStartIndex(0);
|
||||||
|
configRoute.setStarted(false);
|
||||||
|
for(var task : configRoute.getScheduledIndexes()) {
|
||||||
|
sceneScriptManager.get().getScene().getScheduler().cancelTask(task);
|
||||||
|
}
|
||||||
|
configRoute.getScheduledIndexes().clear();
|
||||||
|
|
||||||
sceneScriptManager.get().getScene().broadcastPacket(new PacketPlatformChangeRouteNotify(entityGadget));
|
sceneScriptManager.get().getScene().broadcastPacket(new PacketPlatformChangeRouteNotify(entityGadget));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public final class ServerTask implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public boolean shouldRun() {
|
public boolean shouldRun() {
|
||||||
// Increase tick count.
|
// Increase tick count.
|
||||||
var ticks = this.ticks++;
|
++this.ticks;
|
||||||
if (this.delay != -1 && this.considerDelay) {
|
if (this.delay != -1 && this.considerDelay) {
|
||||||
// Check if the task should run.
|
// Check if the task should run.
|
||||||
var shouldRun = ticks >= this.delay;
|
var shouldRun = ticks >= this.delay;
|
||||||
|
Loading…
Reference in New Issue
Block a user