BodyMotionMaintainDistance class

Пакет: com.hypixel.hytale.server.npc.corecomponents.movement

Файл: com/hypixel/hytale/server/npc/corecomponents/movement/BodyMotionMaintainDistance.java

extends: BodyMotionBase

Поля (46)

МодификаторыТипИмя
final ComponentType<EntityStore, TransformComponent> TRANSFORM_COMPONENT_TYPE
double var10
double var12
double var13
double var14
Vector3d var15
double var16
double var18
var18
var18
double var20
float var22
MotionController var23
Ref var24
TransformComponent var25
float var26
float var27
double var29
double var3
boolean var33
var33
var33
double var34
double var35
var35
double var36
NPCEntity var37
TransformComponent var38
IPositionProvider var39
double var40
MotionController var41
double var42
MotionController var43
double var44
float var45
var45
var45
Vector3d var46
double var47
double var5
ParameterProvider var8
var8
var8
boolean var9
var9
var9

Методы (26)

МодификаторыВозвратСигнатура
if if(!this.initialised)
if if(var3 != null)
if if(var8 instanceof DoubleParameterProvider)
if if(var8 instanceof DoubleParameterProvider)
if if(var8 instanceof DoubleParameterProvider)
if if(this.cachedMinRangeProvider != null)
if if(var10 != -Double.MAX_VALUE)
if if(var12 != this.desiredDistanceRange[0])
if if(this.cachedMaxRangeProvider != null)
if if(var34 != -Double.MAX_VALUE)
if if(var36 != this.desiredDistanceRange[1])
if if(this.cachedPositioningAngleProvider != null)
if if(this.desiredDistanceRange[0] > this.desiredDistanceRange[1])
if if(var33)
if if(var9)
if if(var16 > this.thresholdDistanceRangeSquared[1])
if if(this.approaching || this.movingAway)
if if(!this.movingAway)
if if(!this.approaching)
if if(this.strafingDurationRange[1] > 0.0 || var35 != Double.MAX_VALUE)
if if(var35 == Double.MAX_VALUE)
if if(this.pauseStrafing)
if if(!this.pauseStrafing)
if if(this.strafingDelay > 0.0)
abstract super super(var1)
protected boolean tickStrafingDelayboolean tickStrafingDelay(double var1)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.corecomponents.movement;

class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.physics.util.PhysicsMath;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.NPCPlugin;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.BodyMotionBase;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.movement.builders.BuilderBodyMotionMaintainDistance;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.movement.Steering;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionControllerWalk;
class="kw">import com.hypixel.hytale.server.npc.movement.steeringforces.SteeringForceEvade;
class="kw">import com.hypixel.hytale.server.npc.movement.steeringforces.SteeringForcePursue;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.IPositionProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.parameterproviders.DoubleParameterProvider;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.parameterproviders.ParameterProvider;
class="kw">import com.hypixel.hytale.server.npc.util.NPCPhysicsMath;
class="kw">import java.util.concurrent.TimeUnit;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class BodyMotionMaintainDistance class="kw">extends BodyMotionBase {
   class="kw">protected class="kw">static class="kw">final ComponentType<EntityStore, TransformComponent> TRANSFORM_COMPONENT_TYPE = TransformComponent.getComponentType();
   class="kw">protected class="kw">static class="kw">final float POSITIONING_ANGLE_THRESHOLD = 0.08726646F;
   class="kw">protected class="kw">final double[] initialDesiredDistanceRange;
   class="kw">protected class="kw">final double moveThreshold;
   @Nonnull
   class="kw">protected class="kw">final double[] thresholdDistanceRangeSquared;
   class="kw">protected class="kw">final double targetDistanceFactor;
   class="kw">protected class="kw">final double relativeForwardsSpeed;
   class="kw">protected class="kw">final double relativeBackwardsSpeed;
   class="kw">protected class="kw">final double moveTowardsSlowdownThreshold;
   class="kw">protected class="kw">final double[] strafingDurationRange;
   class="kw">protected class="kw">final double[] strafingFrequencyRange;
   class="kw">protected class="kw">final int minRangeProviderSlot;
   class="kw">protected class="kw">final int maxRangeProviderSlot;
   class="kw">protected class="kw">final int positioningAngleProviderSlot;
   class="kw">protected class="kw">final double[] desiredDistanceRange = new double[2];
   class="kw">protected double minThresholdDistance;
   class="kw">protected double targetDistanceSquared;
   class="kw">protected boolean approaching;
   class="kw">protected boolean movingAway;
   class="kw">protected int strafingDirection = 1;
   class="kw">protected double strafingDelay;
   class="kw">protected boolean pauseStrafing;
   class="kw">protected class="kw">final SteeringForceEvade flee = new SteeringForceEvade();
   class="kw">protected class="kw">final SteeringForcePursue seek = new SteeringForcePursue();
   class="kw">protected class="kw">final Vector3d targetPosition = new Vector3d();
   class="kw">protected class="kw">final Vector3d toTarget = new Vector3d();
   @Nullable
   class="kw">protected Ref<EntityStore> lastTargetEntity;
   class="kw">protected DoubleParameterProvider cachedMinRangeProvider;
   class="kw">protected DoubleParameterProvider cachedMaxRangeProvider;
   class="kw">protected DoubleParameterProvider cachedPositioningAngleProvider;
   class="kw">protected boolean initialised;

   class="kw">public BodyMotionMaintainDistance(@Nonnull BuilderBodyMotionMaintainDistance var1, @Nonnull BuilderSupport var2) {
      super(var1);
      this.initialDesiredDistanceRange = var1.getDesiredDistanceRange(var2);
      this.desiredDistanceRange[0] = this.initialDesiredDistanceRange[0];
      this.desiredDistanceRange[1] = this.initialDesiredDistanceRange[1];
      this.targetDistanceFactor = var1.getTargetDistanceFactor(var2);
      this.moveThreshold = var1.getMoveThreshold(var2);
      double var3 = Math.max(0.0, this.initialDesiredDistanceRange[0] - this.moveThreshold);
      double var5 = this.initialDesiredDistanceRange[1] + this.moveThreshold;
      this.minThresholdDistance = var3;
      this.thresholdDistanceRangeSquared = new double[2];
      this.thresholdDistanceRangeSquared[0] = var3 * var3;
      this.thresholdDistanceRangeSquared[1] = var5 * var5;
      this.relativeForwardsSpeed = var1.getRelativeForwardsSpeed(var2);
      this.relativeBackwardsSpeed = var1.getRelativeBackwardsSpeed(var2);
      this.moveTowardsSlowdownThreshold = var1.getMoveTowardsSlowdownThreshold(var2);
      this.strafingDurationRange = var1.getStrafingDurationRange(var2);
      this.strafingFrequencyRange = var1.getStrafingFrequencyRange(var2);
      this.minRangeProviderSlot = var2.getParameterSlot("MinRange");
      this.maxRangeProviderSlot = var2.getParameterSlot("MaxRange");
      this.positioningAngleProviderSlot = var2.getParameterSlot("PositioningAngle");
   }

   @Override
   class="kw">public boolean computeSteering(
      @Nonnull Ref<EntityStore> var1,
      @Nonnull ExecutionSupport var2,
      @Nullable InfoProvider var3,
      double var4,
      @Nonnull Steering var6,
      @Nonnull ComponentAccessor<EntityStore> var7
   ) {
      var6.clear();
      this.lastTargetEntity = null;
      if (!var2.getMotionContextSupport().getActiveMotionController().matchesType(MotionControllerWalk.class)) {
         var2.getRole().setBackingAway(false);
         class="kw">return false;
      }

      if (!this.initialised) {
         if (var3 != null) {
            ParameterProvider var8 = var3.getParameterProvider(this.minRangeProviderSlot);
            if (var8 class="kw">instanceof DoubleParameterProvider) {
               this.cachedMinRangeProvider = (DoubleParameterProvider)var8;
            }

            var8 = var3.getParameterProvider(this.maxRangeProviderSlot);
            if (var8 class="kw">instanceof DoubleParameterProvider) {
               this.cachedMaxRangeProvider = (DoubleParameterProvider)var8;
            }

            var8 = var3.getParameterProvider(this.positioningAngleProviderSlot);
            if (var8 class="kw">instanceof DoubleParameterProvider) {
               this.cachedPositioningAngleProvider = (DoubleParameterProvider)var8;
            }
         }

         this.initialised = true;
      }

      boolean var33 = false;
      boolean var9 = false;
      if (this.cachedMinRangeProvider != null) {
         double var10 = this.cachedMinRangeProvider.getDoubleParameter();
         double var12 = this.desiredDistanceRange[0];
         if (var10 != -Double.MAX_VALUE) {
            this.desiredDistanceRange[0] = this.cachedMinRangeProvider.getDoubleParameter();
         } else {
            this.desiredDistanceRange[0] = this.initialDesiredDistanceRange[0];
         }

         var33 = true;
         if (var12 != this.desiredDistanceRange[0]) {
            var9 = true;
         }
      }

      if (this.cachedMaxRangeProvider != null) {
         double var34 = this.cachedMaxRangeProvider.getDoubleParameter();
         double var36 = this.desiredDistanceRange[1];
         if (var34 != -Double.MAX_VALUE) {
            this.desiredDistanceRange[1] = this.cachedMaxRangeProvider.getDoubleParameter();
         } else {
            this.desiredDistanceRange[1] = this.initialDesiredDistanceRange[1];
         }

         double var14 = this.desiredDistanceRange[1] + this.moveThreshold;
         this.thresholdDistanceRangeSquared[1] = var14 * var14;
         if (var36 != this.desiredDistanceRange[1]) {
            var9 = true;
         }
      }

      double var35 = Double.MAX_VALUE;
      if (this.cachedPositioningAngleProvider != null) {
         var35 = this.cachedPositioningAngleProvider.getDoubleParameter();
      }

      NPCEntity var37 = var7.getComponent(var1, NPCEntity.getComponentType());
      assert var37 != null;
      if (this.desiredDistanceRange[0] > this.desiredDistanceRange[1]) {
         ((HytaleLogger.Api)NPCPlugin.get().getLogger().at(Level.WARNING).atMostEvery(1, TimeUnit.MINUTES))
            .log(
               "Attempting to set min distance for %s to a value higher than its max distance [min=%s max=%s]",
               var37.getRoleName(),
               this.desiredDistanceRange[0],
               this.desiredDistanceRange[1]
            );
         this.desiredDistanceRange[0] = this.desiredDistanceRange[1];
         var33 = true;
      }

      if (var33) {
         double var13 = Math.max(0.0, this.desiredDistanceRange[0] - this.moveThreshold);
         this.minThresholdDistance = var13;
         this.thresholdDistanceRangeSquared[0] = var13 * var13;
      }

      if (var3 != null && var3.hasPosition()) {
         TransformComponent var38 = var7.getComponent(var1, TRANSFORM_COMPONENT_TYPE);
         assert var38 != null;
         IPositionProvider var39 = var3.getPositionProvider();
         var39.providePosition(this.targetPosition);
         Vector3d var15 = var38.getPosition();
         double var16 = var15.distanceSquared(this.targetPosition);
         if (var9) {
            double var18;
            if (var16 > this.thresholdDistanceRangeSquared[1]) {
               var18 = MathUtil.lerp(this.desiredDistanceRange[0], this.desiredDistanceRange[1], 1.0 - this.targetDistanceFactor);
            } else {
               var18 = MathUtil.lerp(this.desiredDistanceRange[0], this.desiredDistanceRange[1], this.targetDistanceFactor);
            }

            this.targetDistanceSquared = var18 * var18;
         }

         if (!(var16 > this.thresholdDistanceRangeSquared[1]) && (!this.approaching || !(var16 > this.targetDistanceSquared))) {
            if (!(var16 < this.thresholdDistanceRangeSquared[0]) && (!this.movingAway || !(var16 < this.targetDistanceSquared))) {
               if (this.approaching || this.movingAway) {
                  this.approaching = false;
                  this.movingAway = false;
               }
            } else {
               if (!this.movingAway) {
                  double var42 = MathUtil.lerp(this.desiredDistanceRange[0], this.desiredDistanceRange[1], this.targetDistanceFactor);
                  this.targetDistanceSquared = var42 * var42;
                  this.movingAway = true;
                  this.approaching = false;
                  var2.getRole().setBackingAway(true);
               }

               this.flee.setPositions(var15, this.targetPosition);
               MotionController var43 = var2.getMotionContextSupport().getActiveMotionController();
               this.flee.setComponentSelector(var43.getComponentSelector());
               this.flee.compute(var6);
               var6.scaleTranslation(this.relativeBackwardsSpeed);
            }
         } else {
            if (!this.approaching) {
               double var40 = MathUtil.lerp(this.desiredDistanceRange[0], this.desiredDistanceRange[1], 1.0 - this.targetDistanceFactor);
               this.targetDistanceSquared = var40 * var40;
               this.seek.setDistances(var40 + this.moveTowardsSlowdownThreshold, var40);
               this.approaching = true;
               this.movingAway = false;
               var2.getRole().setBackingAway(false);
            }

            this.seek.setPositions(var15, this.targetPosition);
            MotionController var41 = var2.getMotionContextSupport().getActiveMotionController();
            this.seek.setComponentSelector(var41.getComponentSelector());
            this.seek.compute(var6);
            var6.scaleTranslation(this.relativeForwardsSpeed);
         }

         double var44 = this.targetPosition.x() - var15.x();
         double var20 = this.targetPosition.z() - var15.z();
         float var22 = PhysicsMath.normalizeTurnAngle(PhysicsMath.headingFromDirection(var44, var20));
         MotionController var23 = var2.getMotionContextSupport().getActiveMotionController();
         Ref var24 = var39.getTarget();
         if (this.strafingDurationRange[1] > 0.0 || var35 != Double.MAX_VALUE) {
            if (var35 == Double.MAX_VALUE) {
               if (!this.tickStrafingDelay(var4)) {
                  if (this.pauseStrafing) {
                     this.strafingDelay = RandomExtra.randomRange(this.strafingDurationRange);
                     this.strafingDirection = RandomExtra.randomBoolean() ? 1 : -1;
                     this.pauseStrafing = false;
                  } else {
                     this.strafingDelay = RandomExtra.randomRange(this.strafingFrequencyRange);
                     this.pauseStrafing = true;
                  }
               }
            } else if (var24 != null) {
               TransformComponent var25 = var7.getComponent(var24, TRANSFORM_COMPONENT_TYPE);
               assert var25 != null;
               float var26 = NPCPhysicsMath.lookatHeading(var15, this.targetPosition, var38.getRotation().yaw());
               float var27 = PhysicsMath.normalizeTurnAngle(var25.getRotation().yaw() - var26 - (float)var35);
               if (Math.abs(var27) > 0.08726646F) {
                  this.strafingDirection = var27 > 0.0F ? -1 : 1;
                  this.pauseStrafing = false;
               } else {
                  this.pauseStrafing = true;
               }
            } else {
               this.pauseStrafing = true;
            }

            if (!this.pauseStrafing) {
               float var45;
               if (!var6.hasTranslation()) {
                  this.toTarget.set(this.targetPosition).sub(var15).y = 0.0;
                  this.toTarget.normalize();
                  var6.setTranslation(this.toTarget);
                  Vector3d var46 = var6.getTranslation();
                  double var47 = var46.z() * this.strafingDirection;
                  double var29 = var46.x() * -this.strafingDirection;
                  var46.x = var47;
                  var46.z = var29;
                  var6.scaleTranslation(this.relativeForwardsSpeed);
                  var45 = this.strafingDirection * (float) (Math.PI / 4);
               } else {
                  var45 = this.strafingDirection * (this.movingAway ? (float) (-Math.PI / 4) : (float) (Math.PI / 4));
                  var6.getTranslation().rotateY(var45);
               }

               var2.getRole().setBackingAway(true);
               if (!var23.isObstructed()) {
                  var22 += var45;
               }
            }
         }

         if (var24 != null && var24.isValid()) {
            this.lastTargetEntity = var24;
         }

         var6.setYaw(var22);
         class="kw">return false;
      } else {
         class="kw">return false;
      }
   }

   class="kw">protected boolean tickStrafingDelay(double var1) {
      if (this.strafingDelay > 0.0) {
         this.strafingDelay -= var1;
         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   @Override
   class="kw">public void deactivate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      super.deactivate(var1, var2, var3);
      this.lastTargetEntity = null;
      var2.getRole().setBackingAway(false);
   }

   @Override
   class="kw">public double getDesiredTargetDistance() {
      class="kw">return this.minThresholdDistance;
   }

   @Nullable
   @Override
   class="kw">public Ref<EntityStore> getDesiredTargetEntity() {
      class="kw">return this.lastTargetEntity;
   }
}