package com.hypixel.hytale.server.npc.corecomponents.movement.builders;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.Feature;
import com.hypixel.hytale.server.npc.asset.builder.holder.DoubleHolder;
import com.hypixel.hytale.server.npc.asset.builder.holder.NumberArrayHolder;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleRangeValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSequenceValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderBodyMotionBase;
import com.hypixel.hytale.server.npc.corecomponents.movement.BodyMotionMaintainDistance;
import com.hypixel.hytale.server.npc.movement.controllers.MotionControllerWalk;
import com.hypixel.hytale.server.npc.util.expression.ExecutionContext;
import com.hypixel.hytale.server.npc.util.expression.Scope;
import com.hypixel.hytale.server.npc.validators.NPCLoadTimeValidationHelper;
import java.util.List;
import javax.annotation.Nonnull;
publicclassBuilderBodyMotionMaintainDistanceextendsBuilderBodyMotionBase {
publicstaticfinalStringMIN_RANGE_PARAMETER="MinRange";
publicstaticfinalStringMAX_RANGE_PARAMETER="MaxRange";
publicstaticfinalStringPOSITIONING_ANGLE_PARAMETER="PositioningAngle";
publicstaticfinaldoubleNO_POSITIONING=1.7976931348623157E308;
publicstaticfinaldouble[] DEFAULT_STRAFING_DURATION_RANGE = newdouble[]{0.0, 0.0};
publicstaticfinaldouble[] DEFAULT_STRAFING_FREQUENCY_RANGE = newdouble[]{2.0, 2.0};
protectedfinalNumberArrayHolderdesiredDistanceRange=newNumberArrayHolder();
protectedfinalDoubleHoldertargetDistanceFactor=newDoubleHolder();
protectedfinalDoubleHoldermoveThreshold=newDoubleHolder();
protectedfinalDoubleHolderrelativeForwardsSpeed=newDoubleHolder();
protectedfinalDoubleHolderrelativeBackwardsSpeed=newDoubleHolder();
protectedfinalDoubleHoldermoveTowardsSlowdownThreshold=newDoubleHolder();
protectedfinalNumberArrayHolderstrafingDurationRange=newNumberArrayHolder();
protectedfinalNumberArrayHolderstrafingFrequencyRange=newNumberArrayHolder();
publicBuilderBodyMotionMaintainDistance() {
}
@Nonnullpublic BodyMotionMaintainDistance build(@Nonnull BuilderSupport builderSupport) {
returnnewBodyMotionMaintainDistance(this, builderSupport);
}
@Nonnullpublic String getShortDescription() {
return"Maintain distance from a given position";
}
@Nonnullpublic String getLongDescription() {
returnthis.getShortDescription();
}
@Nonnullpublic BuilderDescriptorState getBuilderDescriptorState() {
return BuilderDescriptorState.Stable;
}
@Nonnullpublic BuilderBodyMotionMaintainDistance readConfig(@Nonnull JsonElement data) {
this.requireDoubleRange(data, "DesiredDistanceRange", this.desiredDistanceRange, DoubleSequenceValidator.betweenWeaklyMonotonic(-1.7976931348623157E308, 1.7976931348623157E308), BuilderDescriptorState.Stable, "The desired distance to remain at.", (String)null);
this.getDouble(data, "TargetDistanceFactor", this.targetDistanceFactor, 0.5, DoubleRangeValidator.between(0.0, 1.0), BuilderDescriptorState.Stable, "A factor used to decide what distance to move to within the target range.", "A factor used to decide what distance to move to within the target range when the target falls outside of it. 0 will result in moving the shortest distance to fall within the range, 1 the furthest distance, and 0.5 roughly the middle of the range.");
this.getDouble(data, "MoveThreshold", this.moveThreshold, 1.0, DoubleSingleValidator.greater0(), BuilderDescriptorState.Stable, "An extra threshold distance on either side of the desired range before the NPC will trigger movement.", (String)null);
this.getDouble(data, "RelativeForwardsSpeed", this.relativeForwardsSpeed, 1.0, DoubleRangeValidator.fromExclToIncl(0.0, 2.0), BuilderDescriptorState.Stable, "Maximum relative speed for the NPC moving forwards", (String)null);
this.getDouble(data, "RelativeBackwardsSpeed", this.relativeBackwardsSpeed, 1.0, DoubleRangeValidator.fromExclToIncl(0.0, 2.0), BuilderDescriptorState.Stable, "Maximum relative speed for the NPC moving backwards", (String)null);
this.getDouble(data, "MoveTowardsSlowdownThreshold", this.moveTowardsSlowdownThreshold, 2.0, DoubleSingleValidator.greaterEqual0(), BuilderDescriptorState.Stable, "The distance away from the target stopping point at which the NPC will start to slow down while moving towards the target", (String)null);
this.getDoubleRange(data, "StrafingDurationRange", this.strafingDurationRange, DEFAULT_STRAFING_DURATION_RANGE, DoubleSequenceValidator.betweenWeaklyMonotonic(0.0, 1.7976931348623157E308), BuilderDescriptorState.Stable, "How long to strafe for.", "How long to strafe for (moving left or right around the target). If set to [ 0, 0 ], will not move horizontally at all.");
this.getDoubleRange(data, "StrafingFrequencyRange", this.strafingFrequencyRange, DEFAULT_STRAFING_FREQUENCY_RANGE, DoubleSequenceValidator.fromExclToInclWeaklyMonotonic(0.0, 1.7976931348623157E308), BuilderDescriptorState.Stable, "How frequently to execute strafing", (String)null);
this.requireFeature(Feature.AnyPosition);
returnthis;
}
publicbooleanvalidate(String configName, @Nonnull NPCLoadTimeValidationHelper validationHelper, ExecutionContext context, Scope globalScope, @Nonnull List<String> errors) {
booleanresult=super.validate(configName, validationHelper, context, globalScope, errors);
validationHelper.requireMotionControllerType(MotionControllerWalk.class);
return result;
}
publicdouble[] getDesiredDistanceRange(@Nonnull BuilderSupport support) {
returnthis.desiredDistanceRange.get(support.getExecutionContext());
}
publicdoublegetTargetDistanceFactor(@Nonnull BuilderSupport support) {
returnthis.targetDistanceFactor.get(support.getExecutionContext());
}
publicdoublegetMoveThreshold(@Nonnull BuilderSupport support) {
returnthis.moveThreshold.get(support.getExecutionContext());
}
publicdoublegetRelativeForwardsSpeed(@Nonnull BuilderSupport support) {
returnthis.relativeForwardsSpeed.get(support.getExecutionContext());
}
publicdoublegetRelativeBackwardsSpeed(@Nonnull BuilderSupport support) {
returnthis.relativeBackwardsSpeed.get(support.getExecutionContext());
}
publicdoublegetMoveTowardsSlowdownThreshold(@Nonnull BuilderSupport support) {
returnthis.moveTowardsSlowdownThreshold.get(support.getExecutionContext());
}
publicdouble[] getStrafingDurationRange(@Nonnull BuilderSupport support) {
returnthis.strafingDurationRange.get(support.getExecutionContext());
}
publicdouble[] getStrafingFrequencyRange(@Nonnull BuilderSupport support) {
returnthis.strafingFrequencyRange.get(support.getExecutionContext());
}
}