Class ElementComponentImpl

java.lang.Object
io.github.xrickastley.sevenelements.component.ElementComponentImpl
All Implemented Interfaces:
ElementComponent, org.ladysnake.cca.api.v3.component.Component, org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent, org.ladysnake.cca.api.v3.component.sync.ComponentPacketWriter, org.ladysnake.cca.api.v3.component.sync.PlayerSyncPredicate, org.ladysnake.cca.api.v3.component.tick.ClientTickingComponent, org.ladysnake.cca.api.v3.component.tick.CommonTickingComponent, org.ladysnake.cca.api.v3.component.tick.ServerTickingComponent

public final class ElementComponentImpl extends Object implements ElementComponent
  • Field Details

  • Constructor Details

    • ElementComponentImpl

      public ElementComponentImpl(LivingEntity owner)
  • Method Details

    • canApplyElement

      public static <T extends LivingEntity> boolean canApplyElement(Class<T> entityClass)
    • isElectroChargedOnCD

      public boolean isElectroChargedOnCD()
      Specified by:
      isElectroChargedOnCD in interface ElementComponent
    • isBurningOnCD

      public boolean isBurningOnCD()
      Specified by:
      isBurningOnCD in interface ElementComponent
    • resetElectroChargedCD

      public void resetElectroChargedCD()
      Specified by:
      resetElectroChargedCD in interface ElementComponent
    • resetBurningCD

      public void resetBurningCD()
      Specified by:
      resetBurningCD in interface ElementComponent
    • setElectroChargedOrigin

      public void setElectroChargedOrigin(@Nullable @Nullable LivingEntity origin)
      Specified by:
      setElectroChargedOrigin in interface ElementComponent
    • setBurningOrigin

      public void setBurningOrigin(@Nullable @Nullable LivingEntity origin)
      Specified by:
      setBurningOrigin in interface ElementComponent
    • getElectroChargedOrigin

      @Nullable public @Nullable LivingEntity getElectroChargedOrigin()
      Specified by:
      getElectroChargedOrigin in interface ElementComponent
    • getBurningOrigin

      @Nullable public @Nullable LivingEntity getBurningOrigin()
      Specified by:
      getBurningOrigin in interface ElementComponent
    • getFreezeDecayTimeModifier

      public double getFreezeDecayTimeModifier()
      Description copied from interface: ElementComponent
      Gets the current decay time modifier for the Freeze aura.

      Freeze is a special element: its decay is unique.
      • Freeze's gauge decay starts with the standard rate: 0.4 GU/s
      • For every second the entity is frozen, the gauge decay increases by 0.1 GU/s, hence 0.1 GU/s² acceleration
      • When the entity is unfrozen, the gauge decay decreases by 0.2 GU/s until it is back at 0.4 GU/s, hence 0.2 GU/s² deceleration
      By extending the Freeze formula, we get a generalized Freeze duration formula for consecutive Frozen reactions.

      sum(max(0, t_frozen_i - 2 t_unfrozen_i))

      i is a Frozen and unfrozen instance, and since we reset only when it is 0 due to being negative, we could drop the sum() function, as this behaves exactly like the mathematical model, given that we update the frozenTime and unfrozenTime accordingly.

      Retrieved from: https://library.keqingmains.com/combat-mechanics/elemental-effects/transformative-reactions#frozen.
      Specified by:
      getFreezeDecayTimeModifier in interface ElementComponent
    • setCrystallizeShield

      public void setCrystallizeShield(Element element, double amount)
      Description copied from interface: ElementComponent
      Grants this entity a Crystallize shield.
      Specified by:
      setCrystallizeShield in interface ElementComponent
      Parameters:
      element - The element of this Crystallize shield.
      amount - The amount of HP this shield has.
    • getCrystallizeShield

      @Nullable public @Nullable Pair<Element,Double> getCrystallizeShield()
      Description copied from interface: ElementComponent
      Gets the current Crystallize Shield of this entity.
      Specified by:
      getCrystallizeShield in interface ElementComponent
    • reduceCrystallizeShield

      public float reduceCrystallizeShield(DamageSource source, float amount)
      Description copied from interface: ElementComponent
      Reduces the Crystallize shield and returns the effective amount of DMG reduced.
      Specified by:
      reduceCrystallizeShield in interface ElementComponent
      Parameters:
      source - The DamageSource. If this isn't an instance of ElementalDamageSource, 0 is returned.
      amount - The amount of damage to be dealt to the entity.
    • reducedCrystallizeShield

      public boolean reducedCrystallizeShield()
      Description copied from interface: ElementComponent
      Returns whether the Crystallize Shield has been reduced in the current tick.
      Specified by:
      reducedCrystallizeShield in interface ElementComponent
    • getOwner

      public LivingEntity getOwner()
      Specified by:
      getOwner in interface ElementComponent
    • getElementHolder

      public ElementHolder getElementHolder(Element element)
      Specified by:
      getElementHolder in interface ElementComponent
    • getLastReaction

      public Pair<ElementalReaction,Long> getLastReaction()
      Specified by:
      getLastReaction in interface ElementComponent
    • setLastReaction

      public void setLastReaction(Pair<ElementalReaction,Long> lastReaction)
    • canApplyElement

      public boolean canApplyElement(Element element, InternalCooldownContext icdContext, boolean handleICD)
      Description copied from interface: ElementComponent
      Checks if the element can be applied.
      Specified by:
      canApplyElement in interface ElementComponent
      Parameters:
      element - The element to check.
      icdContext - The InternalCooldownContext of the Element to be applied.
      handleICD - Whether the ICD should be handled. This will register a "hit" to the gauge sequence.
    • addElementalApplication

      public List<ElementalReaction> addElementalApplication(ElementalApplication application, InternalCooldownContext icdContext)
      Specified by:
      addElementalApplication in interface ElementComponent
    • getAppliedElements

      public Array<ElementalApplication> getAppliedElements()
      Description copied from interface: ElementComponent
      Gets all currently applied elements as a Array.
      Specified by:
      getAppliedElements in interface ElementComponent
    • applyFromDamageSource

      public List<ElementalReaction> applyFromDamageSource(ElementalDamageSource source)
      Description copied from interface: ElementComponent
      Applies an ElementalDamageSource to this entity, possibly triggering multiple ElementalReactions. If no reactions were triggered, the list will be empty.
      Specified by:
      applyFromDamageSource in interface ElementComponent
      Parameters:
      source - The ElementalDamageSource to apply to this entity.
      Returns:
      The triggered ElementalReactions.
    • writeData

      public void writeData(WriteView view)
      Specified by:
      writeData in interface org.ladysnake.cca.api.v3.component.Component
    • readData

      public void readData(ReadView view)
      Specified by:
      readData in interface org.ladysnake.cca.api.v3.component.Component
    • tick

      public void tick()
      Specified by:
      tick in interface org.ladysnake.cca.api.v3.component.tick.CommonTickingComponent
    • removeConsumedElements

      private void removeConsumedElements()
    • getHighestElementPriority

      public Optional<Integer> getHighestElementPriority()
      Description copied from interface: ElementComponent
      Gets the lowest priority value from the currently applied Elements as an Optional.

      If the Optional has no value, this means that there are no Elements currently applied.
      Specified by:
      getHighestElementPriority in interface ElementComponent
    • getPrioritizedElements

      public Array<ElementalApplication> getPrioritizedElements()
      Description copied from interface: ElementComponent
      Gets all currently prioritized applied elements as an Array.

      If there are applied Elements with multiple priority values, the most prioritized one has to be consumed first before the others can be consumed.

      Say that Element A has a priority of 1, while Element B has a priority of 2. Element A's application must be consumed entirely before Element B could be reacted with or reapplied.
      Specified by:
      getPrioritizedElements in interface ElementComponent
    • getTriggerableReactions

      private Stream<ElementalReaction> getTriggerableReactions(int priority, ElementalApplication triggeringElement)
    • attemptReapply

      private boolean attemptReapply(ElementalApplication application)
      Attempts to reapply an Elemental Application.

      This method returns whether the provided Elemental Application was "reapplied" in some way, where true means that the element has been "reapplied" and cannot be used in an Elemental Reaction and false means that the element has not been "reapplied" and can be used in an Elemental Reaction.

      This method also does not guarantee that all Elemental Applications provided are indeed reapplied to their respective Elements, as they can be discarded due to the current Element priority.

      Elements will only be reapplied if the Element in question has the same priority as the current "highest element priority".
      Parameters:
      application - The ElementalApplication to reapply.
      Returns:
      true if the Elemental Application was "reapplied", false otherwise.
    • triggerReactions

      private Set<ElementalReaction> triggerReactions(ElementalApplication application, @Nullable @Nullable LivingEntity origin)
      Triggers all possible Elemental Reactions.

      Elemental Reactions adhere to the rules of Element priority, where only triggerable reactions containing elements with the highest priority are considered.

      Triggering a Reaction

      When an element is already applied to this entity and another element is applied, an Elemental Reaction may be triggered.

      Each registered Elemental Reaction is filtered based on the priorities of the elements participating in that reaction, where reactions only containing elements with the same priority are considered.

      After that, the candidate reactions are once again sorted based on the currently applied element's priority. The reaction with the highest priority for the currently applied element will be the triggered reaction.

      Triggering Multiple Reactions

      After a reaction is triggered, so long as the currently applied element still contains leftover Gauge Units, an attempt to find another reaction that can be triggered is made. If a reaction is found, it is then triggered and the cycle repeats.

      Priority Upgrade

      If no reactions can be triggered, an attempt to upgrade the priority is made first, so long as the previous reaction allows it, where the newer priority must be greater than the previous one.

      Once the priority upgrade succeeds, an attempt is made again to find a triggerable reaction. If a reaction is found, it is then triggered and the cycle repeats with the higher priority. Otherwise, no more attempts are made to trigger reactions afterward.

      Applying as an Aura Element

      Normally, the triggering element is removed when at least one reaction has been triggered. However, the triggering element can be applied as an aura element afterward if all participating reactions have ElementalReaction#shouldApplyResultAsAura enabled.

      Do note that only GAUGE_UNIT Elemental Applications are subject to removal. DURATION Elemental Applications are not removed or accounted for by this method.
      Parameters:
      application - The ElementalApplication to apply to this entity.
      origin - The origin of the ElementalApplication.