BodyMotionFindWithTarget class

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

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

extends: BodyMotionFindBase<AStarWithTarget>

Поля (11)

МодификаторыТипИмя
final double minMoveDistanceWait
MovementStatesComponent var10
Entity var11
float var3
double var4
TransformComponent var4
BoundingBox var5
IPositionProvider var6
Ref var7
BoundingBox var8
NPCEntity var9

Методы (14)

МодификаторыВозвратСигнатура
protected Vector3d getLastAccessibleTargetPositionVector3d getLastAccessibleTargetPosition(@Nonnull MotionController var1, boolean var2, @Nonnull ComponentAccessor<EntityStore> var3)
protected Vector3d getLastTargetPositionVector3d getLastTargetPosition()
if if(var7 != null)
if if(this.minMoveDistanceRecomputeSquared > 0.0 && this.targetDeltaSquared > this.minMoveDistanceRecomputeSquared)
if if(this.dbgStatus)
if if(this.cosHalfRecomputeConeAngle < 1.0F)
if if(this.dbgStatus)
if if(this.dbgStatus)
if if(this.throttleCount > this.throttleIgnoreCount)
if if(var4 < 1.0000000000000002E-10 || this.waitForTargetMovement && var4 < this.minMoveDistanceWaitSquared)
if if(this.minMoveDistanceRecomputeSquared > 0.0 && this.targetDeltaSquared > this.minMoveDistanceRecomputeSquared)
if if(this.dbgMotionState)
if if(this.cosHalfRecomputeConeAngle < 1.0F)
abstract abstract boolean isGoalReachedboolean isGoalReached(Ref<EntityStore> var1, MotionController var2, Vector3d var3, Vector3d var4, ComponentAccessor<EntityStore> var5)

Исходный код

Показать/скрыть
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.Ref;
class="kw">import com.hypixel.hytale.math.shape.Box;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.math.util.TrigMathUtil;
class="kw">import com.hypixel.hytale.server.core.entity.Entity;
class="kw">import com.hypixel.hytale.server.core.entity.EntityUtils;
class="kw">import com.hypixel.hytale.server.core.entity.LivingEntity;
class="kw">import com.hypixel.hytale.server.core.entity.movement.MovementStatesComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
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.movement.builders.BuilderBodyMotionFindWithTarget;
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.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.navigation.AStarBase;
class="kw">import com.hypixel.hytale.server.npc.navigation.AStarWithTarget;
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.util.NPCPhysicsMath;
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="kw">abstract class BodyMotionFindWithTarget class="kw">extends BodyMotionFindBase<AStarWithTarget> {
   class="kw">protected class="kw">final double minMoveDistanceWait;
   class="kw">protected class="kw">final double minMoveDistanceWaitSquared;
   class="kw">protected class="kw">final double minMoveDistanceRecompute;
   class="kw">protected class="kw">final double minMoveDistanceRecomputeSquared;
   class="kw">protected class="kw">final float cosHalfRecomputeConeAngle;
   class="kw">protected class="kw">final double minMoveDistanceReproject;
   class="kw">protected class="kw">final double minMoveDistanceReprojectSquared;
   class="kw">protected class="kw">final boolean adjustRangeByHitboxSize;
   class="kw">protected class="kw">final Vector3d lastPathedPosition = new Vector3d();
   class="kw">protected class="kw">final Vector3d conePosition = new Vector3d();
   class="kw">protected class="kw">final Vector3d coneDirection = new Vector3d();
   @Nullable
   class="kw">protected Box targetBoundingBox;
   class="kw">protected Box selfBoundingBox;
   class="kw">protected boolean waitForTargetMovement = false;
   class="kw">private class="kw">final Vector3d lastTargetPosition = new Vector3d();
   class="kw">private class="kw">final Vector3d lastAccessibleTargetPosition = new Vector3d();
   class="kw">private boolean haveValidTargetPosition;
   class="kw">private boolean haveAccessibleTargetPosition;
   class="kw">private boolean lastAccessibleTargetPositionIsCurrent;
   class="kw">protected String self;
   class="kw">protected String other;
   @Nullable
   class="kw">protected Ref<EntityStore> lastDesiredTargetEntity;

   class="kw">public BodyMotionFindWithTarget(@Nonnull BuilderBodyMotionFindWithTarget var1, @Nonnull BuilderSupport var2) {
      super(var1, var2, new AStarWithTarget());
      this.adjustRangeByHitboxSize = var1.isAdjustRangeByHitboxSize(var2);
      this.minMoveDistanceWait = var1.getMinMoveDistanceWait(var2);
      this.minMoveDistanceWaitSquared = this.minMoveDistanceWait * this.minMoveDistanceWait;
      this.minMoveDistanceRecompute = var1.getMinMoveDistanceRecompute(var2);
      this.minMoveDistanceRecomputeSquared = this.minMoveDistanceRecompute * this.minMoveDistanceRecompute;
      this.minMoveDistanceReproject = var1.getMinMoveDistanceReproject(var2);
      this.minMoveDistanceReprojectSquared = this.minMoveDistanceReproject * this.minMoveDistanceReproject;
      float var3 = TrigMathUtil.cos(var1.getRecomputeConeAngle(var2) / 2.0);
      this.cosHalfRecomputeConeAngle = var3 == -1.0F ? 1.0F : var3;
   }

   @Override
   class="kw">public void activate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      super.activate(var1, var2, var3);
      this.haveValidTargetPosition = false;
      this.haveAccessibleTargetPosition = false;
      this.waitForTargetMovement = false;
      this.targetBoundingBox = null;
      this.lastPathedPosition.set(Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE);
      this.self = var2.getName();
      this.lastDesiredTargetEntity = null;
   }

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

   @Override
   class="kw">public boolean canComputeMotion(
      @Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, @Nonnull ComponentAccessor<EntityStore> var4
   ) {
      BoundingBox var5 = var4.getComponent(var1, BoundingBox.getComponentType());
      assert var5 != null;
      this.lastDesiredTargetEntity = null;
      this.targetBoundingBox = null;
      this.selfBoundingBox = var5.getBoundingBox();
      this.lastAccessibleTargetPositionIsCurrent = false;
      if (var3 != null && var3.hasPosition()) {
         IPositionProvider var6 = var3.getPositionProvider();
         if (var6.providePosition(this.lastTargetPosition)) {
            this.haveValidTargetPosition = true;
            Ref var7 = var6.getTarget();
            if (var7 != null) {
               BoundingBox var8 = var4.getComponent(var7, BoundingBox.getComponentType());
               assert var8 != null;
               NPCEntity var9 = var4.getComponent(var7, NPCEntity.getComponentType());
               this.other = var9 != null ? var9.getRoleName() : null;
               this.targetBoundingBox = var8.getBoundingBox();
               MovementStatesComponent var10 = var4.getComponent(var7, MovementStatesComponent.getComponentType());
               Entity var11 = EntityUtils.getEntity(var7, var7.getStore());
               if (var11 class="kw">instanceof LivingEntity && var10 != null && var10.getMovementStates().onGround) {
                  this.lastAccessibleTargetPosition.set(this.lastTargetPosition);
                  this.haveAccessibleTargetPosition = true;
                  this.lastAccessibleTargetPositionIsCurrent = true;
                  this.lastDesiredTargetEntity = var7;
               }
            } else {
               this.targetBoundingBox = null;
            }
         }
      }

      this.targetDeltaSquared = this.haveValidTargetPosition
         ? var2.getMotionContextSupport().getActiveMotionController().waypointDistanceSquared(this.getLastTargetPosition(), this.lastPathedPosition)
         : Double.MAX_VALUE;
      class="kw">return this.haveValidTargetPosition;
   }

   @Override
   class="kw">public boolean mustRecomputePath(@Nonnull Ref<EntityStore> var1, @Nonnull MotionController var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      if (super.mustRecomputePath(var1, var2, var3)) {
         class="kw">return true;
      }

      if (this.minMoveDistanceRecomputeSquared > 0.0 && this.targetDeltaSquared > this.minMoveDistanceRecomputeSquared) {
         if (this.dbgStatus) {
            NPCPlugin.get().getLogger().at(Level.INFO).log("Recomputing Path - Target moved");
         }

         this.resetThrottleCount();
         class="kw">return true;
      } else {
         if (this.cosHalfRecomputeConeAngle < 1.0F) {
            if (var2.is2D()) {
               if (NPCPhysicsMath.isInViewCone(
                  this.conePosition, this.coneDirection, this.cosHalfRecomputeConeAngle, this.getLastTargetPosition(), var2.getComponentSelector()
               )) {
                  if (this.dbgStatus) {
                     NPCPlugin.get().getLogger().at(Level.INFO).log("Recomputing Path - Target left 2D cone");
                  }

                  class="kw">return true;
               }
            } else if (NPCPhysicsMath.isInViewCone(this.conePosition, this.coneDirection, this.cosHalfRecomputeConeAngle, this.getLastTargetPosition())) {
               if (this.dbgStatus) {
                  NPCPlugin.get().getLogger().at(Level.INFO).log("Recomputing Path - Target left cone");
               }

               class="kw">return true;
            }
         }

         class="kw">return false;
      }
   }

   @Override
   class="kw">public void forceRecomputePath(MotionController var1) {
      super.forceRecomputePath(var1);
   }

   @Override
   class="kw">public boolean shouldDeferPathComputation(@Nonnull MotionController var1, Vector3d var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      if (this.throttleCount > this.throttleIgnoreCount) {
         double var4 = this.getLastTargetPosition().distanceSquared(this.lastPathedPosition);
         if (var4 < 1.0000000000000002E-10 || this.waitForTargetMovement && var4 < this.minMoveDistanceWaitSquared) {
            class="kw">return true;
         }
      }

      this.waitForTargetMovement = false;
      this.lastPathedPosition.set(this.getLastAccessibleTargetPosition(var1, false, var3));
      class="kw">return false;
   }

   @Override
   class="kw">protected boolean mustAbortThrottling(MotionController var1, Ref<EntityStore> var2) {
      if (super.mustAbortThrottling(var1, var2)) {
         class="kw">return true;
      }

      if (this.minMoveDistanceRecomputeSquared > 0.0 && this.targetDeltaSquared > this.minMoveDistanceRecomputeSquared) {
         if (this.dbgMotionState) {
            NPCPlugin.get().getLogger().at(Level.INFO).log("MotionFindWithTarget: Aborting throttling - Target moved");
         }

         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   @Override
   class="kw">public boolean isGoalReached(Ref<EntityStore> var1, MotionController var2, Vector3d var3, ComponentAccessor<EntityStore> var4) {
      class="kw">return this.isGoalReached(var1, var2, var3, this.getLastTargetPosition(), var4);
   }

   @Override
   class="kw">public AStarBase.Progress startComputePath(
      @Nonnull Ref<EntityStore> var1,
      ExecutionSupport var2,
      @Nonnull MotionController var3,
      @Nonnull Vector3d var4,
      @Nonnull ComponentAccessor<EntityStore> var5
   ) {
      if (this.cosHalfRecomputeConeAngle < 1.0F) {
         this.conePosition.set(var4);
         this.coneDirection.set(this.lastPathedPosition).sub(var4);
      }

      class="kw">return this.aStar.initComputePath(var1, var4, this.lastPathedPosition, this, var3, this.probeMoveData, this.sharedNodePoolProvider, var5);
   }

   @Override
   class="kw">public void onBlockedPath() {
      super.onBlockedPath();
   }

   @Override
   class="kw">public void onNoPathFound(MotionController var1) {
      super.onNoPathFound(var1);
      this.waitForTargetMovement = true;
   }

   @Override
   class="kw">protected void onSteering(MotionController var1, @Nonnull Ref<EntityStore> var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      TransformComponent var4 = var3.getComponent(var2, TransformComponent.getComponentType());
      assert var4 != null;
      this.lastPathedPosition.set(var4.getPosition());
   }

   @Override
   class="kw">protected void decorateDebugString(@Nonnull StringBuilder var1) {
      var1.append("D:").append(MathUtil.round(Math.sqrt(this.targetDeltaSquared), 1));
   }

   class="kw">protected class="kw">abstract boolean isGoalReached(Ref<EntityStore> var1, MotionController var2, Vector3d var3, Vector3d var4, ComponentAccessor<EntityStore> var5);

   class="kw">protected Vector3d getLastTargetPosition() {
      class="kw">return this.lastTargetPosition;
   }

   @Nullable
   @Override
   class="kw">protected Vector3d getSteeringTargetPosition() {
      class="kw">return this.haveValidTargetPosition ? this.lastTargetPosition : null;
   }

   class="kw">protected Vector3d getLastAccessibleTargetPosition(@Nonnull MotionController var1, boolean var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      if (!this.lastAccessibleTargetPositionIsCurrent
         && (
            !var2
               || !this.haveAccessibleTargetPosition
               || !(var1.waypointDistanceSquared(this.lastTargetPosition, this.lastAccessibleTargetPosition) < this.minMoveDistanceReprojectSquared)
         )) {
         if (this.dbgMotionState && var1.is2D()) {
            NPCPlugin.get().getLogger().at(Level.INFO).log("MotionFindWithTarget: Reprojecting %s -> %s", this.self, this.other);
         }

         this.lastAccessibleTargetPosition.set(this.lastTargetPosition);
         var1.translateToAccessiblePosition(this.lastAccessibleTargetPosition, this.targetBoundingBox, 0.0, 320.0, var3);
         this.haveAccessibleTargetPosition = true;
         this.lastAccessibleTargetPositionIsCurrent = true;
         class="kw">return this.lastAccessibleTargetPosition;
      } else {
         class="kw">return this.lastAccessibleTargetPosition;
      }
   }
}