Skip to content

Commit

Permalink
Add pull duration filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota committed Dec 14, 2024
1 parent 1be33bb commit feb95b7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import gg.xp.xivsupport.events.misc.NpcYellEvent;
import gg.xp.xivsupport.events.misc.pulls.PullEndedEvent;
import gg.xp.xivsupport.events.misc.pulls.PullStartedEvent;
import gg.xp.xivsupport.events.misc.pulls.PullTracker;
import gg.xp.xivsupport.events.state.XivState;
import gg.xp.xivsupport.events.state.combatstate.CountdownCanceledEvent;
import gg.xp.xivsupport.events.state.combatstate.CountdownStartedEvent;
Expand Down Expand Up @@ -77,6 +78,7 @@
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.NpcYellIdFilter;
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.OrFilter;
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.PlayerHasStatusFilter;
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.PullDurationFilter;
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.RefireFilter;
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.SourceEntityNpcIdFilter;
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.SourceEntityTypeFilter;
Expand Down Expand Up @@ -459,8 +461,9 @@ private Component generic(Object object, Object trigger) {
new ConditionDescription<>(HitSeverityFilter.class, HasEffects.class, "Hit Severity (Crit/Direct Hit)", HitSeverityFilter::new, this::generic),
new ConditionDescription<>(TargetabilityChangeFilter.class, TargetabilityUpdate.class, "Combatant becomes (un)targetable", TargetabilityChangeFilter::new, this::generic),
new ConditionDescription<>(NpcYellIdFilter.class, NpcYellEvent.class, "NPC Yell ID", NpcYellIdFilter::new, this::generic),
new ConditionDescription<>(GroovyEventFilter.class, Event.class, "Make your own filter code with Groovy", () -> new GroovyEventFilter(inject(GroovyManager.class)), (a, b) -> new GroovyFilterEditor<>(a, b)),
new ConditionDescription<>(ZoneIdFilter.class, Object.class, "Restrict the Zone ID in which this trigger may run", () -> new ZoneIdFilter(inject(XivState.class)), this::generic)
new ConditionDescription<>(GroovyEventFilter.class, Event.class, "Make your own filter code with Groovy", () -> new GroovyEventFilter(inject(GroovyManager.class)), GroovyFilterEditor::new),
new ConditionDescription<>(ZoneIdFilter.class, Object.class, "Restrict the Zone ID in which this trigger may run", () -> new ZoneIdFilter(inject(XivState.class)), this::generic),
new ConditionDescription<>(PullDurationFilter.class, Object.class, "Restrict based on pull/combat duration", () -> new PullDurationFilter(inject(PullTracker.class)), this::generic)
));

// XXX - DO NOT CHANGE NAMES OF THESE CLASSES OR PACKAGE PATH - FQCN IS PART OF DESERIALIZATION!!!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package gg.xp.xivsupport.events.triggers.easytriggers.conditions;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.OptBoolean;
import gg.xp.xivsupport.events.misc.pulls.Pull;
import gg.xp.xivsupport.events.misc.pulls.PullTracker;
import gg.xp.xivsupport.events.triggers.easytriggers.model.SimpleCondition;
import org.jetbrains.annotations.Nullable;

import java.time.Duration;

public class PullDurationFilter implements SimpleCondition<Object> {

private final PullTracker pt;
@Description("Min Duration")
public double minDuration = 10.5;
@Description("Max Duration")
public double maxDuration = 30.8;
@Description("Only Consider Time In-Combat")
public boolean useCombatDuration = true;

public PullDurationFilter(@JacksonInject(useInput = OptBoolean.FALSE) PullTracker pt) {
this.pt = pt;
}


@JsonIgnore
private double getCurrentDuration() {
Pull currentPull = pt.getCurrentPull();
if (currentPull == null) {
return 0;
}
if (useCombatDuration) {
Duration cd = currentPull.getCombatDuration();
if (cd == null) {
return 0;
}
return durationToDouble(cd);
}
else {
return durationToDouble(currentPull.getDuration());
}
}

private static double durationToDouble(Duration duration) {
return duration.toSeconds() + duration.toMillisPart() * 0.001;
}

@Override
public boolean test(Object event) {
double cd = getCurrentDuration();
return minDuration <= cd && cd <= maxDuration;
}

@Override
public @Nullable String fixedLabel() {
return "Pull Duration";
}

@Override
public String dynamicLabel() {
return "Pull Duration Between %.1fs and %.1fs".formatted(minDuration, maxDuration);
}
}
4 changes: 4 additions & 0 deletions xivsupport/src/main/resources/te_changelog.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<html lang="en">
<body style="margin: 5px 20px 5px 20px">
<h2>December 13, 2024</h2>
<ul>
<li>Added pull duration easy triggers filter.</li>
</ul>
<h2>December 10, 2024</h2>
<ul>
<li>FRU triggers are complete.</li>
Expand Down

0 comments on commit feb95b7

Please sign in to comment.