Skip to content

Commit

Permalink
Added operating check for ride control menu, added station accelerati…
Browse files Browse the repository at this point in the history
…on config
  • Loading branch information
JVerbruggen committed Jun 23, 2024
1 parent ff38424 commit d341e50
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jverbruggen.jrides.models.ride.coaster.track.Track;
import com.jverbruggen.jrides.models.ride.coaster.train.Train;
import com.jverbruggen.jrides.models.ride.section.Section;
import org.bukkit.Bukkit;

import javax.annotation.Nullable;

Expand All @@ -52,7 +53,7 @@ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section s
if(newSpeed.isPositive()){
newSpeed.approach(acceleration, deceleration, driveSpeed);
}else{
newSpeed.approach(acceleration, deceleration, -driveSpeed);
newSpeed.approach(deceleration, acceleration, -driveSpeed);
}
}else{
newSpeed.approach(acceleration, deceleration, driveSpeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ public TrackBehaviour getStationBehaviour(Frame blockBrakeEngageFrame, CoasterHa

CoasterStationConfig coasterStationConfig = rangedSectionConfig.getStationSectionSpec();
double driveSpeed = coasterStationConfig.getDriveSpeed();
double acceleration = coasterStationConfig.getAcceleration();
double deceleration = coasterStationConfig.getDeceleration();

CoasterStationHandle stationHandle = coasterStationConfig.createStationHandle(
stationName, shortStationName, triggerContext, coasterHandle,
gates, minimumWaitTimeDispatchLock);

return new StationTrackBehaviour(coasterHandle, cartMovementFactory, blockBrakeEngageFrame, coasterStationConfig.canSpawn(), triggerContext,
stationHandle, trainInStationDispatchLock, blockSectionOccupiedDispatchLock, restraintLock, driveSpeed,
stationHandle, trainInStationDispatchLock, blockSectionOccupiedDispatchLock, restraintLock, driveSpeed, acceleration, deceleration,
coasterStationConfig.isForwardsDispatch(), coasterStationConfig.getPassThroughCount());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.jverbruggen.jrides.models.ride.coaster.train.Train;
import com.jverbruggen.jrides.models.ride.section.Section;
import com.jverbruggen.jrides.models.ride.section.result.BlockSectionSafetyResult;
import org.bukkit.Bukkit;

import javax.annotation.Nullable;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -69,13 +70,13 @@ public class StationTrackBehaviour extends BaseTrackBehaviour {

public StationTrackBehaviour(CoasterHandle coasterHandle, CartMovementFactory cartMovementFactory, Frame stopFrame, boolean canSpawn, TriggerContext triggerContext,
CoasterStationHandle stationHandle, DispatchLock trainInStationDispatchLock, DispatchLock blockSectionOccupiedDispatchLock,
DispatchLock restraintsLock, double driveSpeed, boolean forwardsDispatch, int passThroughCount) {
DispatchLock restraintsLock, double driveSpeed, double acceleration, double deceleration, boolean forwardsDispatch, int passThroughCount) {
super(cartMovementFactory);
this.coasterHandle = coasterHandle;
this.logger = JRidesPlugin.getLogger();
this.deceleration = 0.2;
this.acceleration = 0.1;
this.driveSpeed = driveSpeed;
this.acceleration = acceleration;
this.deceleration = deceleration;
this.handlingTrain = null;
this.phase = StationPhase.IDLE;
this.stopFrame = stopFrame;
Expand Down Expand Up @@ -133,7 +134,7 @@ public TrainMovement move(Speed currentSpeed, TrainHandle trainHandle, Section s
phase = StationPhase.ARRIVING;
goIntoSwitch = true;
} else {
newSpeed.approach(acceleration, deceleration, driveSpeed);
newSpeed.approach(deceleration, acceleration, driveSpeed);
}
}
case ARRIVING -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
import com.jverbruggen.jrides.animator.flatride.FlatRideHandle;
import com.jverbruggen.jrides.control.trigger.TriggerContext;
import com.jverbruggen.jrides.effect.handle.train.TrainEffectTriggerHandle;
import com.jverbruggen.jrides.models.entity.Player;
import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
import com.jverbruggen.jrides.models.properties.MinMaxWaitingTimer;
import com.jverbruggen.jrides.models.properties.PlayerLocation;
import com.jverbruggen.jrides.models.ride.StationHandle;
import com.jverbruggen.jrides.models.ride.coaster.train.Train;
import com.jverbruggen.jrides.models.ride.coaster.train.Vehicle;
import com.jverbruggen.jrides.models.ride.gate.Gate;
import com.jverbruggen.jrides.serviceprovider.ServiceProvider;
import com.jverbruggen.jrides.state.player.PlayerManager;

import java.util.List;

Expand All @@ -51,4 +55,13 @@ public FlatRideUniVehicle getVehicle() {
public void setFlatRideHandle(FlatRideHandle flatRideHandle) {
this.vehicle.setFlatRideHandle(flatRideHandle);
}

@Override
public boolean canOperate(MessageAgent messageAgent) {
if(messageAgent == null) return true;
if(!messageAgent.isPlayer()) return true;

Player player = messageAgent.getPlayer(ServiceProvider.getSingleton(PlayerManager.class));
return player.getOperating() == vehicle.getFlatRideHandle().getRideController();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ public Vector3 getCurrentLocation() {
public void setFlatRideHandle(FlatRideHandle flatRideHandle) {
this.flatRideHandle = flatRideHandle;
}

public FlatRideHandle getFlatRideHandle() {
return flatRideHandle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ public class CoasterStationConfig extends StationConfig {
private final boolean canSpawn;
private final double engage;
private final double driveSpeed;
private final double acceleration;
private final double deceleration;
private final int passThroughCount;
private final boolean forwardsDispatch;

public CoasterStationConfig(double engage, double driveSpeed, int passThroughCount, boolean forwardsDispatch, int minimumWaitIntervalSeconds, int maximumWaitIntervalSeconds, StationEffectsConfig stationEffectsConfig, PlayerLocation ejectLocation, boolean canSpawn) {
public CoasterStationConfig(double engage, double driveSpeed, int passThroughCount, boolean forwardsDispatch, int minimumWaitIntervalSeconds, int maximumWaitIntervalSeconds, StationEffectsConfig stationEffectsConfig, PlayerLocation ejectLocation, boolean canSpawn, double acceleration, double deceleration) {
super(minimumWaitIntervalSeconds, maximumWaitIntervalSeconds, stationEffectsConfig, ejectLocation);
this.engage = engage;
this.driveSpeed = driveSpeed;
this.passThroughCount = passThroughCount;
this.forwardsDispatch = forwardsDispatch;
this.canSpawn = canSpawn;
this.acceleration = acceleration;
this.deceleration = deceleration;
}

public boolean canSpawn() {
Expand All @@ -63,6 +67,14 @@ public double getDriveSpeed() {
return driveSpeed;
}

public double getAcceleration() {
return acceleration;
}

public double getDeceleration() {
return deceleration;
}

public int getPassThroughCount() {
return passThroughCount;
}
Expand All @@ -75,14 +87,16 @@ public static CoasterStationConfig fromConfigurationSection(ConfigurationSection
boolean canSpawn = getBoolean(configurationSection, "canSpawn", true);
double engage = getDouble(configurationSection, "engage", 0.5);
double driveSpeed = getDouble(configurationSection, "driveSpeed", 1.0);
double acceleration = getDouble(configurationSection, "acceleration", 0.1);
double deceleration = getDouble(configurationSection, "deceleration", 0.2);
int passThroughCount = getInt(configurationSection, "passThroughCount", 0);
boolean forwardsDispatch = getBoolean(configurationSection, "forwardsDispatch", true);
int minimumWaitIntervalSeconds = getInt(configurationSection, "minimumWaitIntervalSeconds", 0);
int maximumWaitIntervalSeconds = getInt(configurationSection, "maximumWaitIntervalSeconds", 60);
StationEffectsConfig effects = StationEffectsConfig.fromConfigurationSection(configurationSection.getConfigurationSection("effects"));
PlayerLocation ejectLocation = PlayerLocation.fromDoubleList(configurationSection.getDoubleList("ejectLocation"));

return new CoasterStationConfig(engage, driveSpeed, passThroughCount, forwardsDispatch, minimumWaitIntervalSeconds, maximumWaitIntervalSeconds, effects, ejectLocation, canSpawn);
return new CoasterStationConfig(engage, driveSpeed, passThroughCount, forwardsDispatch, minimumWaitIntervalSeconds, maximumWaitIntervalSeconds, effects, ejectLocation, canSpawn, acceleration, deceleration);
}

public @Nonnull CoasterStationHandle createStationHandle(String stationName, String shortStationName, TriggerContext triggerContext, CoasterHandle coasterHandle, List<Gate> gates, DispatchLock minimumWaitTimeDispatchLock){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.jverbruggen.jrides.control.controlmode.factory.ControlModeFactory;
import com.jverbruggen.jrides.control.trigger.TriggerContext;
import com.jverbruggen.jrides.models.entity.Player;
import com.jverbruggen.jrides.models.properties.MinMaxWaitingTimer;
import com.jverbruggen.jrides.models.ride.Ride;
import com.jverbruggen.jrides.models.ride.StationHandle;
import com.jverbruggen.jrides.models.ride.coaster.train.Vehicle;
Expand Down Expand Up @@ -87,6 +88,12 @@ public boolean setOperator(Player player){
this.changeMode(this.controlModeFactory.getForWithOperator(this.rideHandle));
result = this.getControlMode().setOperator(player);
}

MinMaxWaitingTimer waitingTimer = this.getControlMode().getWaitingTimer();
if(result && waitingTimer.reachedMinimum()) {
waitingTimer.reset();
}

return result;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public Result canExecute(MessageAgent messageAgent) {
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}

if(!stationHandle.canOperate(messageAgent)){
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}

if(stationHandle == null){
JRidesPlugin.getLogger().severe("No station handle set for gate trigger");
return Result.isNotOk();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public Result canExecute(MessageAgent messageAgent) {
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}

if(!stationHandle.canOperate(messageAgent)){
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}

if(stationHandle == null){
JRidesPlugin.getLogger().severe("No station handle set for restraint trigger");
return Result.isNotOk();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@

import com.jverbruggen.jrides.common.Result;
import com.jverbruggen.jrides.common.permissions.Permissions;
import com.jverbruggen.jrides.control.DispatchLock;
import com.jverbruggen.jrides.control.DispatchLockCollection;
import com.jverbruggen.jrides.language.LanguageFile;
import com.jverbruggen.jrides.language.LanguageFileField;
import com.jverbruggen.jrides.models.entity.agent.MessageAgent;
import com.jverbruggen.jrides.models.ride.StationHandle;
import com.jverbruggen.jrides.serviceprovider.ServiceProvider;

public class SimpleDispatchTrigger implements DispatchTrigger {
import java.util.List;

public class SimpleDispatchTrigger implements DispatchTrigger, StationTrigger {
private StationHandle stationHandle;
private boolean active;
private final DispatchLockCollection dispatchLockCollection;
private final LanguageFile languageFile;

public SimpleDispatchTrigger(DispatchLockCollection dispatchLockCollection) {
this.stationHandle = null;
this.active = false;
this.dispatchLockCollection = dispatchLockCollection;
this.languageFile = ServiceProvider.getSingleton(LanguageFile.class);
Expand All @@ -40,7 +46,6 @@ public SimpleDispatchTrigger(DispatchLockCollection dispatchLockCollection) {
public boolean execute(MessageAgent messageAgent){
Result canExecuteResult = canExecute(messageAgent);
if(!canExecuteResult.ok()){
languageFile.sendMessage(messageAgent, languageFile.get(LanguageFileField.NOTIFICATION_RIDE_DISPATCH_PROBLEMS));
canExecuteResult.sendMessageTo(messageAgent);
return false;
}
Expand All @@ -51,16 +56,21 @@ public boolean execute(MessageAgent messageAgent){

@Override
public Result canExecute(MessageAgent messageAgent) {
if(messageAgent != null && !messageAgent.hasPermission(Permissions.CABIN_OPERATE)){
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}
if(!stationHandle.canOperate(messageAgent)){
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}
if(!dispatchLockCollection.allUnlocked()){
if(messageAgent != null){
return Result.isNotOk(dispatchLockCollection.getProblems(Integer.MAX_VALUE, messageAgent.hasPermission(Permissions.ELEVATED_DISPATCH_PROBLEMS_DEBUG)));
List<String> problemList = dispatchLockCollection.getProblems(Integer.MAX_VALUE, messageAgent.hasPermission(Permissions.ELEVATED_DISPATCH_PROBLEMS_DEBUG));
problemList.add(0, languageFile.get(LanguageFileField.NOTIFICATION_RIDE_DISPATCH_PROBLEMS));
return Result.isNotOk(problemList);
}else{
return Result.isNotOk();
}
}
if(messageAgent != null && !messageAgent.hasPermission(Permissions.CABIN_OPERATE)){
return Result.isNotOk(languageFile.get(LanguageFileField.ERROR_OPERATING_NO_PERMISSION));
}

return Result.isOk();
}
Expand All @@ -79,4 +89,14 @@ public boolean isActive(){
public DispatchLockCollection getDispatchLockCollection() {
return dispatchLockCollection;
}

@Override
public void setStationHandle(StationHandle stationHandle) {
this.stationHandle = stationHandle;
}

@Override
public DispatchLock getLock() {
return dispatchLockCollection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.jverbruggen.jrides.control.DispatchLockCollection;
import com.jverbruggen.jrides.control.controller.RideController;
import com.jverbruggen.jrides.control.trigger.DispatchTrigger;
import com.jverbruggen.jrides.control.trigger.SimpleDispatchTrigger;
import com.jverbruggen.jrides.control.trigger.StationTrigger;
import com.jverbruggen.jrides.control.uiinterface.menu.button.LockResembledControlButton;
import com.jverbruggen.jrides.control.uiinterface.menu.button.action.RunnableButtonAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ public boolean equals(Player other) {
}

public boolean setOperating(RideController rideController) {
// Check if player is already operating ride
if(rideController != null && rideController.getOperator() == this && operating == rideController) return true;

// If already operating something..
if(operating != null){
// stop operating it
languageFile.sendMessage(this, LanguageFileField.NOTIFICATION_RIDE_CONTROL_INACTIVE,
(b) -> b.add(LanguageFileTag.rideDisplayName, operating.getRide().getDisplayName()));
operating.setOperator(null);
Expand All @@ -179,13 +182,15 @@ public boolean setOperating(RideController rideController) {
return false;
}

// Try to operate the selected ride
boolean set = rideController.setOperator(this);
if(!set){
languageFile.sendMessage(this, LanguageFileField.ERROR_OPERATING_CABIN_OCCUPIED);
bukkitPlayer.closeInventory();
return false;
}

// All is ok, setting operating field for player
operating = rideController;

languageFile.sendMessage(this, LanguageFileField.NOTIFICATION_RIDE_CONTROL_ACTIVE,
Expand Down
Loading

0 comments on commit d341e50

Please sign in to comment.