Skip to content

Commit

Permalink
Merge pull request #524 from xpdota/cast-location-fix
Browse files Browse the repository at this point in the history
Ignore snapshot location if a cast location is better
  • Loading branch information
xpdota authored Jul 22, 2024
2 parents 0bf9b46 + d2bc965 commit fbbdc39
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
import gg.xp.reevent.events.BaseEvent;
import gg.xp.xivsupport.models.XivAbility;
import gg.xp.xivsupport.models.XivCombatant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.Serial;

/**
* Represents an ability cast being cancelled/interrupted/etc
*/
public class AbilityCastCancel extends BaseEvent implements HasSourceEntity, HasAbility {
public class AbilityCastCancel extends BaseEvent implements HasSourceEntity, HasAbility, HasCastPrecursor {

@Serial
private static final long serialVersionUID = -5704173639583049362L;
private final XivCombatant source;
private final XivAbility ability;
private final String reason;
private @Nullable AbilityCastStart precursor;

public AbilityCastCancel(XivCombatant source, XivAbility ability, String reason) {
this.source = source;
Expand All @@ -36,4 +39,14 @@ public XivAbility getAbility() {
public String getReason() {
return reason;
}

@Override
public @Nullable AbilityCastStart getPrecursor() {
return precursor;
}

@Override
public void setPrecursor(@NotNull AbilityCastStart precursor) {
this.precursor = precursor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Represents an ability snapshotting
*/
public class AbilityUsedEvent extends BaseEvent implements HasSourceEntity, HasTargetEntity, HasAbility, HasEffects, HasTargetIndex {
public class AbilityUsedEvent extends BaseEvent implements HasSourceEntity, HasTargetEntity, HasAbility, HasEffects, HasTargetIndex, HasCastPrecursor {

@Serial
private static final long serialVersionUID = -4539070760062288496L;
Expand All @@ -28,6 +28,7 @@ public class AbilityUsedEvent extends BaseEvent implements HasSourceEntity, HasT
private final long numberOfTargets;
private @Nullable Duration animationLock;
private @Nullable DescribesCastLocation<AbilityUsedEvent> locationInfo;
private @Nullable AbilityCastStart precursor;

public AbilityUsedEvent(XivAbility ability, XivCombatant caster, XivCombatant target, List<AbilityEffect> effects, long sequenceId, long targetIndex, long numberOfTargets) {
this.ability = ability;
Expand Down Expand Up @@ -91,6 +92,16 @@ public void setLocationInfo(@NotNull DescribesCastLocation<AbilityUsedEvent> loc
this.locationInfo = locationInfo;
}

@Override
public @Nullable AbilityCastStart getPrecursor() {
return precursor;
}

@Override
public void setPrecursor(@NotNull AbilityCastStart precursor) {
this.precursor = precursor;
}

/**
* Get the animation lock.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gg.xp.xivsupport.events.actlines.events;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface HasCastPrecursor {
@Nullable
AbilityCastStart getPrecursor();

void setPrecursor(@NotNull AbilityCastStart precursor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class SnapshotLocationDataEvent extends BaseEvent implements DescribesCas
private final Position pos;
private final Double heading;

public SnapshotLocationDataEvent(AbilityUsedEvent event, DescribesCastLocation<?> other) {
this.event = event;
this.pos = other.getPos();
this.heading = other.getHeadingOnly();
}

public SnapshotLocationDataEvent(AbilityUsedEvent event, Position pos) {
this.event = event;
this.pos = pos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import gg.xp.reevent.events.Event;
import gg.xp.reevent.scan.HandleEvents;
import gg.xp.xivsupport.events.actlines.events.AbilityCastStart;
import gg.xp.xivsupport.events.actlines.events.AbilityUsedEvent;
import gg.xp.xivsupport.events.actlines.events.AnimationLockEvent;
import gg.xp.xivsupport.events.actlines.events.DescribesCastLocation;
import gg.xp.xivsupport.events.actlines.events.SnapshotLocationDataEvent;
import gg.xp.xivsupport.events.misc.OverwritingRingBuffer;
import gg.xp.xivsupport.models.Position;
Expand Down Expand Up @@ -56,7 +58,12 @@ protected Event convert(FieldMapper<Fields> fields, int lineNumber, ZonedDateTim
double z = fields.getDouble(Fields.z);
double h = fields.getDouble(Fields.rotation);
if (x == 0.0 && y == 0.0 && z == 0.0) {
if (h == 0.0) {
AbilityCastStart precursor = last.getPrecursor();
DescribesCastLocation<AbilityCastStart> castLocation;
if (precursor != null && (castLocation = precursor.getLocationInfo()) != null && castLocation.getPos() != null) {
slde = new SnapshotLocationDataEvent(last, castLocation);
}
else if (h == 0.0) {
slde = null;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gg.xp.xivsupport.events.actlines.events.AbilityCastStart;
import gg.xp.xivsupport.events.actlines.events.AbilityUsedEvent;
import gg.xp.xivsupport.events.actlines.events.HasAbility;
import gg.xp.xivsupport.events.actlines.events.HasCastPrecursor;
import gg.xp.xivsupport.events.actlines.events.HasSourceEntity;
import gg.xp.xivsupport.events.misc.pulls.PullStartedEvent;
import gg.xp.xivsupport.models.XivCombatant;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void pullStartedEvent(EventContext ctx, PullStartedEvent event) {
}
}

private <X extends Event & HasSourceEntity & HasAbility> void doEnd(X event) {
private <X extends Event & HasSourceEntity & HasAbility & HasCastPrecursor> void doEnd(X event) {
CastTracker tracker;
synchronized (lock) {
tracker = cbtCasts.get(event.getSource());
Expand All @@ -74,6 +75,7 @@ private <X extends Event & HasSourceEntity & HasAbility> void doEnd(X event) {
return;
}
if (tracker.getCast().getAbility().equals(event.getAbility())) {
event.setPrecursor(tracker.getCast());
tracker.setEnd(event);
}

Expand Down

0 comments on commit fbbdc39

Please sign in to comment.