Class Condition

java.lang.Object
com.hypixel.hytale.server.npc.decisionmaker.core.conditions.base.Condition
All Implemented Interfaces:
JsonAsset<String>, JsonAssetWithMap<String, IndexedLookupTableAssetMap<String, Condition>>
Direct Known Subclasses:
CurveCondition, RandomiserCondition, ScaledCurveCondition, SimpleCondition

public abstract class Condition extends Object implements JsonAssetWithMap<String, IndexedLookupTableAssetMap<String, Condition>>
An abstract Condition to be evaluated as part of an Option. Resulting utility is between 0 and 1.

Any condition returning 0 will result in the entire option being taken out of consideration for this execution.

The utility scores from individual conditions are multiplied together to produce a final score, with a compensation factor calculated to prevent bias against options with many conditions.

There are several important base condition types:

  • Condition.AlwaysTrueCondition: Returns maximum utility in all cases.
  • SimpleCondition: Boolean condition returning one value for false and another for true.
  • CurveCondition: Evaluates a percentage-based parameter (0-1) against a ResponseCurve and returns the corresponding value from the y-axis.
  • ScaledCurveCondition: As with the CurveCondition, except that the input parameter is a value range scaled down to be between 0-1.

Note: Conditions must not store instance information unique to an NPC as they are intended to be shared and run in parallel!

  • Field Details

  • Constructor Details

    • Condition

      public Condition(String id)
  • Method Details

    • getAssetStore

      @Nonnull public static AssetStore<String, Condition, IndexedLookupTableAssetMap<String, Condition>> getAssetStore()
    • getAssetMap

      public static IndexedLookupTableAssetMap<String, Condition> getAssetMap()
    • getId

      public String getId()
      Specified by:
      getId in interface JsonAsset<String>
    • setupNPC

      public void setupNPC(ExecutionSupport executionSupport)
      This method is called when an NPC is instantiated in order to initialise certain parameters on the NPC to be able to supply requisite information for the condition
      Parameters:
      executionSupport - the NPC executionSupport being instantiated
    • setupNPC

      public void setupNPC(Holder<EntityStore> holder)
    • getReference

      public WeakReference<Condition> getReference()
    • calculateUtility

      public abstract double calculateUtility(int selfIndex, ArchetypeChunk<EntityStore> archetypeChunk, Ref<EntityStore> target, CommandBuffer<EntityStore> commandBuffer, EvaluationContext context)
      Calculates a utility value based on parameters contained within the EvaluationContext. Utility values are normalised between 0 and 1.
      Parameters:
      selfIndex - the index of the self entity in the archetype chunk
      archetypeChunk - entity archetype chunk for fetching own components
      target - a ref to the target entity being evaluated
      commandBuffer - command buffer for read-only fetching of other entities components
      context - additional contextual information relating to the option
      Returns:
      a utility value
    • getSimplicity

      public abstract int getSimplicity()
      Returns a value representing the relative simplicity/cost to evaluate the condition, where lower numbers are simpler to compute.
      Returns:
      a simplicity value
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
    • getAlwaysTrueFor

      @Nonnull public static Condition getAlwaysTrueFor(String id)