Option class
Пакет: com.hypixel.hytale.server.npc.decisionmaker.core
Файл: com/hypixel/hytale/server/npc/decisionmaker/core/Option.java
Поля (15)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
BuilderCodec<Option> |
ABSTRACT_CODEC |
|
private final int |
index |
|
private WeakReference<Condition> |
reference |
|
Condition |
var1 |
|
|
var1 |
|
double |
var10 |
|
HytaleLogger.Api |
var12 |
|
Condition |
var17 |
|
double |
var18 |
|
Condition |
var2 |
|
NPCEntity |
var6 |
|
|
var6 |
|
UUIDComponent |
var7 |
|
|
var7 |
|
double |
var8 |
Методы (18)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
private |
ConditionReferenceprivate ConditionReference(int var1, @Nonnull Condition var2) |
abstract |
throw new |
IllegalStateExceptionthrow new IllegalStateException("Condition '" + this.conditions[var1] + "' does not exist!") |
public |
double |
calculateUtilitydouble calculateUtility(int var1, @Nonnull ArchetypeChunk<EntityStore> var2, Ref<EntityStore> var3, CommandBuffer<EntityStore> var4, @Nonnull EvaluationContext var5) |
|
|
for for(int var1 = 0; var1 < this.conditions.length; var1++) |
|
|
for for(Option.ConditionReference var5 : this.sortedConditions) |
|
|
for for(Option.ConditionReference var5 : this.sortedConditions) |
|
|
for for(Option.ConditionReference var16 : this.sortedConditions) |
|
private Condition |
getprivate Condition get() |
public |
String[] |
getConditionsString[] getConditions() |
|
private int |
getSimplicityprivate int getSimplicity() |
public |
double |
getWeightCoefficientdouble getWeightCoefficient() |
|
|
if if(var2 == null) |
|
|
if if(var6 == null) |
|
|
if if(var7 == null) |
|
|
if if(var1 == null) |
public |
void |
setupNPCvoid setupNPC(ExecutionSupport var1) |
public |
void |
setupNPCvoid setupNPC(Holder<EntityStore> var1) |
public |
void |
sortConditionsvoid sortConditions() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.decisionmaker.core;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.ArchetypeChunk;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.decisionmaker.core.conditions.base.Condition;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import java.lang.ref.WeakReference;
class="kw">import java.util.Arrays;
class="kw">import java.util.Comparator;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">public class="kw">abstract class Option {
class="kw">public class="kw">static class="kw">final BuilderCodec<Option> ABSTRACT_CODEC = BuilderCodec.abstractBuilder(Option.class)
.append(new KeyedCodec<>("Description", Codec.STRING), (var0, var1) -> var0.description = var1, var0 -> var0.description)
.documentation("A friendly description of this option's outcome.")
.add()
.<String[]>appendInherited(
new KeyedCodec<>("Conditions", Condition.CHILD_ASSET_CODEC_ARRAY),
(var0, var1) -> var0.conditions = var1,
var0 -> var0.conditions,
(var0, var1) -> var0.conditions = var1.conditions
)
.documentation("The list of conditions for evaluating this option's utility.")
.addValidator(Validators.nonNull())
.addValidator(Validators.nonEmptyArray())
.addValidator(Condition.VALIDATOR_CACHE.getArrayValidator())
.add()
.<Double>appendInherited(
new KeyedCodec<>("WeightCoefficient", Codec.DOUBLE),
(var0, var1) -> var0.weightCoefficient = var1,
var0 -> var0.weightCoefficient,
(var0, var1) -> var0.weightCoefficient = var1.weightCoefficient
)
.documentation("An additional weighted ranking that can be used to greatly increase the utility of this option.")
.addValidator(Validators.greaterThanOrEqual(1.0))
.add()
.build();
class="kw">protected String description;
class="kw">protected String[] conditions;
class="kw">protected double weightCoefficient = 1.0;
class="kw">protected Option.ConditionReference[] sortedConditions;
class="kw">protected Option() {
}
class="kw">public String[] getConditions() {
class="kw">return this.conditions;
}
class="kw">public double getWeightCoefficient() {
class="kw">return this.weightCoefficient;
}
class="kw">public void sortConditions() {
this.sortedConditions = new Option.ConditionReference[this.conditions.length];
for (int var1 = 0; var1 < this.conditions.length; var1++) {
Condition var2 = Condition.getAssetMap().getAsset(this.conditions[var1]);
if (var2 == null) {
throw new IllegalStateException("Condition '" + this.conditions[var1] + "' does not exist!");
}
this.sortedConditions[var1] = new Option.ConditionReference(Condition.getAssetMap().getIndex(this.conditions[var1]), var2);
}
Arrays.sort(this.sortedConditions, Comparator.comparingInt(Option.ConditionReference::getSimplicity));
}
class="kw">public void setupNPC(ExecutionSupport var1) {
for (Option.ConditionReference var5 : this.sortedConditions) {
var5.get().setupNPC(var1);
}
}
class="kw">public void setupNPC(Holder<EntityStore> var1) {
for (Option.ConditionReference var5 : this.sortedConditions) {
var5.get().setupNPC(var1);
}
}
class="kw">public double calculateUtility(
int var1, @Nonnull ArchetypeChunk<EntityStore> var2, Ref<EntityStore> var3, CommandBuffer<EntityStore> var4, @Nonnull EvaluationContext var5
) {
NPCEntity var6 = null;
UUIDComponent var7 = null;
double var8 = 1.0 - 1.0 / this.sortedConditions.length;
double var10 = 1.0;
HytaleLogger.Api var12 = Evaluator.LOGGER.at(Level.FINE);
for (Option.ConditionReference var16 : this.sortedConditions) {
Condition var17 = var16.get();
double var18 = var17.calculateUtility(var1, var2, var3, var4, var5);
if (var12.isEnabled()) {
if (var6 == null) {
var6 = var2.getComponent(var1, NPCEntity.getComponentType());
assert var6 != null;
}
if (var7 == null) {
var7 = var2.getComponent(var1, UUIDComponent.getComponentType());
assert var7 != null;
}
var12.log("%s with uuid %s: Scored condition %s at %s", var6.getRoleName(), var7.getUuid(), var17, var18);
}
var10 *= var18 + (1.0 - var18) * var8 * var18;
if (var10 == 0.0 || var10 < var5.getMinimumUtility()) {
class="kw">return 0.0;
}
}
class="kw">return var10 * this.weightCoefficient;
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "Option{description="
+ this.description
+ ", conditions="
+ Arrays.toString(this.conditions)
+ ", sortedConditions="
+ Arrays.toString(this.sortedConditions)
+ ", weightCoefficient="
+ this.weightCoefficient
+ "}";
}
class="kw">private class="kw">static class ConditionReference {
class="kw">private class="kw">final int index;
class="kw">private WeakReference<Condition> reference;
class="kw">private ConditionReference(int var1, @Nonnull Condition var2) {
this.index = var1;
this.reference = var2.getReference();
}
@Nonnull
class="kw">private Condition get() {
Condition var1 = this.reference.get();
if (var1 == null) {
var1 = Condition.getAssetMap().getAsset(this.index);
this.reference = var1.getReference();
}
class="kw">return var1;
}
class="kw">private int getSimplicity() {
class="kw">return this.get().getSimplicity();
}
}
}