InstructionHolder class

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

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

Поля (2)

МодификаторыТипИмя
protected static final InstructionRandomized.InstructionHolder[] EMPTY_ARRAY
private final Instruction instruction

Исходный код

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

class="kw">import com.hypixel.hytale.common.map.IWeightedMap;
class="kw">import com.hypixel.hytale.common.map.WeightedMap;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.instructions.builders.BuilderInstructionRandomized;
class="kw">import java.util.concurrent.ThreadLocalRandom;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class InstructionRandomized class="kw">extends Instruction {
   @Nonnull
   class="kw">protected class="kw">final IWeightedMap<InstructionRandomized.InstructionHolder> weightedInstructionMap;
   class="kw">protected class="kw">final boolean resetOnStateChange;
   class="kw">protected class="kw">final double minExecuteTime;
   class="kw">protected class="kw">final double maxExecuteTime;
   class="kw">protected double timeout;
   @Nullable
   class="kw">protected InstructionRandomized.InstructionHolder current;

   class="kw">public InstructionRandomized(@Nonnull BuilderInstructionRandomized var1, Sensor var2, @Nonnull Instruction[] var3, @Nonnull BuilderSupport var4) {
      super(var1, var2, var3, var4);
      WeightedMap.Builder var5 = WeightedMap.builder(InstructionRandomized.InstructionHolder.EMPTY_ARRAY);

      for (Instruction var9 : var3) {
         var5.put(new InstructionRandomized.InstructionHolder(var9), var9.getWeight());
      }

      this.weightedInstructionMap = var5.build();
      this.resetOnStateChange = var1.getResetOnStateChange(var4);
      double[] var10 = var1.getExecuteFor(var4);
      this.minExecuteTime = var10[0];
      this.maxExecuteTime = var10[1];
   }

   @Override
   class="kw">public void execute(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, double var3, @Nonnull Store<EntityStore> var5) {
      if (this.instructionList.length != 0) {
         this.timeout -= var3;
         if (this.timeout <= 0.0 || this.current == null) {
            ThreadLocalRandom var6 = ThreadLocalRandom.current();
            this.current = this.weightedInstructionMap.get(var6.nextDouble());
            this.timeout = RandomExtra.randomRange(this.minExecuteTime, this.maxExecuteTime);
         }

         Instruction var7 = this.current.instruction;
         if (var7.matches(var1, var2, var3, var5)) {
            var7.onMatched(var2);
            var7.execute(var1, var2, var3, var5);
            var7.onCompleted(var2);
         }
      }
   }

   @Override
   class="kw">public void clearOnce() {
      super.clearOnce();
      if (this.resetOnStateChange) {
         this.current = null;
      }
   }

   @Override
   class="kw">public void reset() {
      super.clearOnce();
      this.current = null;
   }

   class="kw">protected class="kw">static class InstructionHolder {
      class="kw">protected class="kw">static class="kw">final InstructionRandomized.InstructionHolder[] EMPTY_ARRAY = new InstructionRandomized.InstructionHolder[0];
      class="kw">private class="kw">final Instruction instruction;

      class="kw">protected InstructionHolder(Instruction var1) {
         this.instruction = var1;
      }
   }
}