BuilderInstructionRandomized class

Пакет: com.hypixel.hytale.server.npc.instructions.builders

Файл: com/hypixel/hytale/server/npc/instructions/builders/BuilderInstructionRandomized.java

extends: BuilderInstruction

Поля (7)

МодификаторыТипИмя
final double[] DEFAULT_EXECUTION_RANGE
Sensor var2
var2
var2
FeatureEvaluatorHelper var2
Instruction[] var3
BuilderValidationHelper var3

Методы (8)

МодификаторыВозвратСигнатура
abstract return new InstructionRandomizedreturn new InstructionRandomized(this, var2, var3, var1)
public double[] getExecuteFordouble[] getExecuteFor(@Nonnull BuilderSupport var1)
public boolean getResetOnStateChangeboolean getResetOnStateChange(@Nonnull BuilderSupport var1)
if if(var2 == null)
if if(this.currentStateName != null)
if if(var3 == null)
if if(this.currentStateName != null)
if if(this.currentStateName != null)

Исходный код

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

class="kw">import com.google.gson.JsonElement;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.Builder;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderValidationHelper;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.FeatureEvaluatorHelper;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.holder.BooleanHolder;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.holder.NumberArrayHolder;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSequenceValidator;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.validators.StringNullOrNotEmptyValidator;
class="kw">import com.hypixel.hytale.server.npc.instructions.Instruction;
class="kw">import com.hypixel.hytale.server.npc.instructions.InstructionRandomized;
class="kw">import com.hypixel.hytale.server.npc.instructions.Sensor;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class BuilderInstructionRandomized class="kw">extends BuilderInstruction {
   class="kw">public class="kw">static class="kw">final double[] DEFAULT_EXECUTION_RANGE = new double[]{Double.MAX_VALUE, Double.MAX_VALUE};
   class="kw">protected class="kw">final BooleanHolder resetOnStateChange = new BooleanHolder();
   class="kw">protected class="kw">final NumberArrayHolder executeFor = new NumberArrayHolder();

   class="kw">public BuilderInstructionRandomized() {
   }

   @Nonnull
   @Override
   class="kw">public String getShortDescription() {
      class="kw">return "Randomised list of weighted instructions.";
   }

   @Nonnull
   @Override
   class="kw">public String getLongDescription() {
      class="kw">return "Randomised list of weighted instructions. One will be selected at random and executed until the NPC state changes.";
   }

   @Nullable
   class="kw">public InstructionRandomized build(@Nonnull BuilderSupport var1) {
      if (!this.enabled.get(var1.getExecutionContext())) {
         class="kw">return null;
      }

      Sensor var2;
      if (this.sensorBuilderObjectReferenceHelper.isPresent()) {
         var2 = this.getSensor(var1);
         if (var2 == null) {
            class="kw">return null;
         }
      } else {
         var2 = Sensor.NULL;
      }

      if (this.currentStateName != null) {
         var1.pushCurrentStateName(this.currentStateName);
      }

      Instruction[] var3 = this.hasNestedInstructions() ? this.getSteps(var1) : null;
      if (var3 == null) {
         if (this.currentStateName != null) {
            var1.popCurrentStateName();
         }

         class="kw">return null;
      } else {
         if (this.currentStateName != null) {
            var1.popCurrentStateName();
         }

         class="kw">return new InstructionRandomized(this, var2, var3, var1);
      }
   }

   @Nonnull
   @Override
   class="kw">public Builder<Instruction> readConfig(@Nonnull JsonElement var1) {
      FeatureEvaluatorHelper var2 = new FeatureEvaluatorHelper();
      BuilderValidationHelper var3 = new BuilderValidationHelper(
         this.fileName, var2, this.internalReferenceResolver, this.stateHelper, this.instructionContextHelper, this.extraInfo, this.evaluators, this.readErrors
      );
      this.increaseDepth();
      if (this.requiresName()) {
         this.requireString(var1, "Name", var1x -> this.name = var1x, null, BuilderDescriptorState.Stable, "Name for referencing", null);
      } else {
         this.getString(var1, "Name", var1x -> this.name = var1x, null, null, BuilderDescriptorState.Stable, "Optional name for descriptor", null);
      }

      this.getString(
         var1,
         "Tag",
         var1x -> this.tag = var1x,
         null,
         StringNullOrNotEmptyValidator.get(),
         BuilderDescriptorState.Experimental,
         "Internal identifier tag for debugging",
         null
      );
      this.getBoolean(var1, "Enabled", this.enabled, true, BuilderDescriptorState.Stable, "Whether this instruction should be enabled on the NPC", null);
      this.getObject(
         var1,
         "Sensor",
         this.sensorBuilderObjectReferenceHelper,
         BuilderDescriptorState.Stable,
         "Sensor for testing if instruction can be applied",
         "Sensor for testing if instruction can be applied. If not supplied, will always match",
         var3
      );
      var2.lock();
      this.getArray(
         var1,
         "Instructions",
         this.steps,
         null,
         BuilderDescriptorState.Stable,
         "List of weighted instructions to select from",
         null,
         new BuilderValidationHelper(
            this.fileName,
            null,
            this.internalReferenceResolver,
            this.stateHelper,
            this.instructionContextHelper,
            this.extraInfo,
            this.evaluators,
            this.readErrors
         )
      );
      this.getBoolean(
         var1,
         "Continue",
         var1x -> this.continueAfter = var1x,
         false,
         BuilderDescriptorState.WorkInProgress,
         "Continue after this instruction was executed",
         null
      );
      this.getDouble(
         var1,
         "Weight",
         this.chance,
         1.0,
         DoubleSingleValidator.greater0(),
         BuilderDescriptorState.Stable,
         "Weighted chance of picking this instruction in a random instruction",
         null
      );
      this.getBoolean(
         var1,
         "TreeMode",
         var1x -> this.treeMode = var1x,
         false,
         BuilderDescriptorState.Stable,
         "Whether this instruction and its contents should be treated like a traditional behaviour tree.",
         "Whether this instruction and its contents should be treated like a traditional behaviour tree, i.e. will class="kw">continue if all child instructions fail"
      );
      this.getBoolean(
         var1,
         "InvertTreeModeResult",
         this.invertTreeModeResult,
         false,
         BuilderDescriptorState.Stable,
         "Whether or not to invert the result of TreeMode evaluation when passing up to parent TreeMode instructions",
         null
      );
      this.getBoolean(var1, "ResetOnStateChange", this.resetOnStateChange, true, BuilderDescriptorState.Stable, "Whether to reset when NPC state changes", null);
      this.getDoubleRange(
         var1,
         "ExecuteFor",
         this.executeFor,
         DEFAULT_EXECUTION_RANGE,
         DoubleSequenceValidator.fromExclToInclWeaklyMonotonic(0.0, Double.MAX_VALUE),
         BuilderDescriptorState.Stable,
         "How long to execute the chosen instruction before picking another",
         null
      );
      this.decreaseDepth();
      this.validateBooleanImplicationAnyAntecedent(ANTECEDENT, new boolean[]{this.treeMode}, true, SUBSEQUENT, new boolean[]{this.continueAfter}, false);
      class="kw">return this;
   }

   @Nonnull
   @Override
   class="kw">public BuilderDescriptorState getBuilderDescriptorState() {
      class="kw">return BuilderDescriptorState.Stable;
   }

   class="kw">public boolean getResetOnStateChange(@Nonnull BuilderSupport var1) {
      class="kw">return this.resetOnStateChange.get(var1.getExecutionContext());
   }

   class="kw">public double[] getExecuteFor(@Nonnull BuilderSupport var1) {
      class="kw">return this.executeFor.get(var1.getExecutionContext());
   }
}