ActionRandom class
Пакет: com.hypixel.hytale.server.npc.corecomponents.utility
Файл: com/hypixel/hytale/server/npc/corecomponents/utility/ActionRandom.java
extends: ActionBase
Поля (3)
| Модификаторы | Тип | Имя |
|---|---|---|
|
return this.availableActionsCount > |
0 |
|
int |
var7 |
|
boolean |
var8 |
Методы (18)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("WeightedAction in Random actions list can't be null") |
|
|
for for(WeightedAction var6 : this.actions) |
|
|
for for(WeightedAction var11 : this.actions) |
|
|
for for(int var7 = 1; var7 < this.availableActionsCount && this.totalWeight >= 0.0; var7++) |
|
|
for for(WeightedAction var5 : this.actions) |
|
|
for for(WeightedAction var8 : this.actions) |
|
|
for for(WeightedAction var5 : this.actions) |
|
|
for for(WeightedAction var5 : this.actions) |
|
|
for for(WeightedAction var5 : this.actions) |
|
|
for for(WeightedAction var5 : this.actions) |
|
|
for for(WeightedAction var7 : this.actions) |
|
|
for for(WeightedAction var4 : this.actions) |
|
|
if if(var6 == null) |
|
|
if if(this.current != null) |
|
|
if if(this.availableActionsCount == 0) |
|
|
if if(this.current == null) |
|
|
if if(var8) |
abstract |
|
super super(var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.corecomponents.utility;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
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.corecomponents.ActionBase;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.WeightedAction;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.utility.builders.BuilderActionRandom;
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.sensorinfo.InfoProvider;
class="kw">import java.util.concurrent.ThreadLocalRandom;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class ActionRandom class="kw">extends ActionBase {
@Nonnull
class="kw">protected class="kw">final WeightedAction[] actions;
@Nonnull
class="kw">protected class="kw">final WeightedAction[] availableActions;
class="kw">protected int availableActionsCount;
class="kw">protected double totalWeight;
@Nullable
class="kw">protected WeightedAction current;
class="kw">public ActionRandom(@Nonnull BuilderActionRandom var1, @Nonnull BuilderSupport var2) {
super(var1);
this.actions = var1.getActions(var2).toArray(WeightedAction[]::new);
for (WeightedAction var6 : this.actions) {
if (var6 == null) {
throw new IllegalArgumentException("WeightedAction in Random actions list can't be null");
}
}
this.availableActions = new WeightedAction[this.actions.length];
this.availableActionsCount = 0;
}
@Override
class="kw">public boolean canExecute(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
) {
int var7 = this.actions.length;
if (super.canExecute(var1, var2, var3, var4, var6) && var7 != 0) {
if (this.current != null) {
class="kw">return this.current.canExecute(var1, var2, var3, var4, var6);
}
this.availableActionsCount = 0;
this.totalWeight = 0.0;
for (WeightedAction var11 : this.actions) {
if (var11.canExecute(var1, var2, var3, var4, var6)) {
this.availableActions[this.availableActionsCount++] = var11;
this.totalWeight = this.totalWeight + var11.getWeight();
}
}
class="kw">return this.availableActionsCount > 0;
} else {
class="kw">return false;
}
}
@Override
class="kw">public boolean execute(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nullable InfoProvider var3, double var4, @Nonnull Store<EntityStore> var6
) {
super.execute(var1, var2, var3, var4, var6);
if (this.availableActionsCount == 0) {
class="kw">return true;
}
if (this.current == null) {
this.current = this.availableActions[0];
this.totalWeight = this.totalWeight * ThreadLocalRandom.current().nextDouble();
this.totalWeight = this.totalWeight - this.current.getWeight();
for (int var7 = 1; var7 < this.availableActionsCount && this.totalWeight >= 0.0; var7++) {
this.current = this.availableActions[var7];
this.totalWeight = this.totalWeight - this.current.getWeight();
}
this.current.activate(var2, var3);
}
boolean var8 = this.current.execute(var1, var2, var3, var4, var6);
if (var8) {
this.current.clearOnce();
this.current.deactivate(var2, var3);
this.current = null;
}
class="kw">return var8;
}
@Override
class="kw">public void registerWithSupport(ExecutionSupport var1) {
for (WeightedAction var5 : this.actions) {
var5.registerWithSupport(var1);
}
}
@Override
class="kw">public void motionControllerChanged(
@Nullable Ref<EntityStore> var1, @Nonnull NPCEntity var2, MotionController var3, @Nullable ComponentAccessor<EntityStore> var4
) {
for (WeightedAction var8 : this.actions) {
var8.motionControllerChanged(var1, var2, var3, var4);
}
}
@Override
class="kw">public void loaded(ExecutionSupport var1) {
for (WeightedAction var5 : this.actions) {
var5.loaded(var1);
}
}
@Override
class="kw">public void spawned(ExecutionSupport var1) {
for (WeightedAction var5 : this.actions) {
var5.spawned(var1);
}
}
@Override
class="kw">public void unloaded(ExecutionSupport var1) {
for (WeightedAction var5 : this.actions) {
var5.unloaded(var1);
}
}
@Override
class="kw">public void removed(ExecutionSupport var1) {
for (WeightedAction var5 : this.actions) {
var5.removed(var1);
}
}
@Override
class="kw">public void teleported(ExecutionSupport var1, World var2, World var3) {
for (WeightedAction var7 : this.actions) {
var7.teleported(var1, var2, var3);
}
}
@Override
class="kw">public boolean isBusy() {
for (WeightedAction var4 : this.actions) {
if (var4.isBusy()) {
class="kw">return true;
}
}
class="kw">return false;
}
}