Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map/replay improvements with new line264 functionality #572

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public XivCombatant getSource() {
return event.getSource();
}

@Override
public XivCombatant getAnimationTarget() {
return event.getTarget();
}

@Override
public String toString() {
return "CastLocationDataEvent{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gg.xp.reevent.events.Event;
import gg.xp.xivsupport.models.Position;
import gg.xp.xivsupport.models.XivCombatant;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -31,6 +32,8 @@ public interface DescribesCastLocation<X extends Event & HasSourceEntity & HasAb
@Nullable
Double getHeadingOnly();

XivCombatant getAnimationTarget();

default double getBestHeading() {
Double heading = getHeadingOnly();
if (heading != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gg.xp.xivsupport.models.Position;
import gg.xp.xivsupport.models.XivAbility;
import gg.xp.xivsupport.models.XivCombatant;
import gg.xp.xivsupport.models.XivEntity;
import org.jetbrains.annotations.Nullable;

import java.io.Serial;
Expand All @@ -17,25 +18,53 @@ public class SnapshotLocationDataEvent extends BaseEvent implements DescribesCas
private final AbilityUsedEvent event;
private final Position pos;
private final Double heading;
private final @Nullable XivCombatant animationTarget;

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

public SnapshotLocationDataEvent(AbilityUsedEvent event, @Nullable XivCombatant animationTarget, Position pos) {
this.event = event;
this.pos = pos;
this.heading = null;
this.animationTarget = animationTarget;
}

public SnapshotLocationDataEvent(AbilityUsedEvent event, @Nullable XivCombatant animationTarget, double heading) {
this.event = event;
this.pos = null;
this.heading = heading;
this.animationTarget = animationTarget;
}

@Deprecated // Use constructors with animationTarget
public SnapshotLocationDataEvent(AbilityUsedEvent event, DescribesCastLocation<?> other) {
this.event = event;
this.pos = other.getPos();
this.heading = other.getHeadingOnly();
this.animationTarget = null;
}

@Deprecated // Use constructors with animationTarget
public SnapshotLocationDataEvent(AbilityUsedEvent event, Position pos) {
this.event = event;
this.pos = pos;
this.heading = null;
this.animationTarget = null;
}

@Deprecated // Use constructors with animationTarget
public SnapshotLocationDataEvent(AbilityUsedEvent event, double heading) {
this.event = event;
this.pos = null;
this.heading = heading;
this.animationTarget = null;
}

@Override
public AbilityUsedEvent originalEvent() {
return event;
Expand Down Expand Up @@ -63,12 +92,18 @@ public XivCombatant getSource() {
return event.getSource();
}

@Override
public @Nullable XivCombatant getAnimationTarget() {
return animationTarget;
}

@Override
public String toString() {
return "SnapshotLocationDataEvent{" +
"id=" + event.getAbility().getId() +
", pos=" + pos +
", heading=" + heading +
", animTgt=" + animationTarget +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,36 @@ public int getInt(K key) {

public @Nullable Long getOptionalHex(K key) {
String rawStr = raw.get(key);
if (rawStr.isEmpty()) {
if (rawStr == null || rawStr.isEmpty()) {
return null;
}
return Long.parseLong(rawStr, 16);
}

public @Nullable Long getOptionalLong(K key) {
String rawStr = raw.get(key);
if (rawStr.isEmpty()) {
if (rawStr == null || rawStr.isEmpty()) {
return null;
}
return Long.parseLong(rawStr, 10);
}

public @Nullable Double getOptionalDouble(K key) {
String rawStr = raw.get(key);
if (rawStr.isEmpty()) {
if (rawStr == null || rawStr.isEmpty()) {
return null;
}
return Double.parseDouble(rawStr);
}

public @Nullable XivCombatant getOptionalEntity(K key) {
Long idMaybe = getOptionalHex(key);
if (idMaybe == null) {
return null;
}
return getEntity(idMaybe);
}

public int fieldCount() {
return rawLineSplit.length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected Event convert(FieldMapper<Fields> fields, int lineNumber, ZonedDateTim
if (match == null) {
return null;
}
// Logic: Ignore the position info if there is a real target for the cast, since we know that it is unit targeted in that case.
if ((match.getTarget().isEnvironment()
|| match.getTarget().equals(match.getSource()))
&& match.getSource().getId() == entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import gg.xp.xivsupport.events.actlines.events.DescribesCastLocation;
import gg.xp.xivsupport.events.actlines.events.SnapshotLocationDataEvent;
import gg.xp.xivsupport.models.Position;
import gg.xp.xivsupport.models.XivCombatant;
import org.picocontainer.PicoContainer;
import org.slf4j.LoggerFactory;

import java.time.ZonedDateTime;
import java.util.ArrayList;
Expand All @@ -24,7 +26,7 @@ public Line264Parser(PicoContainer container) {
}

enum Fields {
entityId, abilityId, sequence, hasData, x, y, z, rotation
entityId, abilityId, sequence, hasPositionMaybe, x, y, z, rotation, animationTargetId
}

private final Map<Long, List<AbilityUsedEvent>> lastAbilityByEntity = new HashMap<>();
Expand Down Expand Up @@ -66,12 +68,17 @@ protected Event convert(FieldMapper<Fields> fields, int lineNumber, ZonedDateTim
&& firstMatch.getAbility().getId() == ability
&& firstMatch.getSequenceId() == sequenceId) {

// Animation Target Id
// TODO: backwards compat? make sure this doesn't catch the hash
XivCombatant animationTarget = fields.getOptionalEntity(Fields.animationTargetId);
LoggerFactory.getLogger(Line264Parser.class).info("animation target: {}", animationTarget);

// Cast location/angle
// First, check if the line indicates that such data is actually present.
int hasData = fields.getInt(Fields.hasData);
int hasPositionMaybe = fields.getInt(Fields.hasPositionMaybe);
SnapshotLocationDataEvent slde;
// 0 = no data, 1 = data, 256 = error
if (hasData == 1) {
if (hasPositionMaybe == 1) {
double x = fields.getDouble(Fields.x);
double y = fields.getDouble(Fields.y);
double z = fields.getDouble(Fields.z);
Expand All @@ -80,20 +87,25 @@ protected Event convert(FieldMapper<Fields> fields, int lineNumber, ZonedDateTim
AbilityCastStart precursor = firstMatch.getPrecursor();
DescribesCastLocation<AbilityCastStart> castLocation;
if (precursor != null && (castLocation = precursor.getLocationInfo()) != null && castLocation.getPos() != null) {
slde = new SnapshotLocationDataEvent(firstMatch, castLocation);
}
else if (h == 0.0) {
slde = null;
slde = new SnapshotLocationDataEvent(firstMatch, animationTarget, castLocation);
}
else {
slde = new SnapshotLocationDataEvent(firstMatch, h);
slde = new SnapshotLocationDataEvent(firstMatch, animationTarget, h);
}
}
else {
Position pos = new Position(x, y, z, h);
slde = new SnapshotLocationDataEvent(firstMatch, pos);
slde = new SnapshotLocationDataEvent(firstMatch, animationTarget, pos);
}
if (slde != null) {
// Associate back to all events
allMatches.forEach(match -> match.setLocationInfo(slde));
return slde;
}
else {
Double h = fields.getOptionalDouble(Fields.rotation);
// Backwards compat with old OP
if (h != null) {
slde = new SnapshotLocationDataEvent(firstMatch, animationTarget, h);
// Associate back to all events
allMatches.forEach(match -> match.setLocationInfo(slde));
return slde;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public Instant happensAt() {
return pos;
}
Double heading = locInfo.getHeadingOnly();
if (heading != null && sourcePosSnapshot != null) {
return sourcePosSnapshot.facing(heading);
Position basis = locInfo.getAnimationTarget().getPos();
if (heading != null && basis != null) {
return basis.facing(heading);
}
}
if (info.type().locationType() == OmenLocationType.CASTER) {
Expand All @@ -75,7 +76,11 @@ public Instant happensAt() {
if (sourcePosSnapshot == null) {
return null;
}
return sourcePosSnapshot.facing(aue.getTarget().getPos());
Position faceTowards = aue.getTarget().getPos();
if (faceTowards != null) {
return sourcePosSnapshot.facing(faceTowards);
}
return null;
}
else {
return aue.getTarget().getPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public Instant happensAt() {
if (pos != null) {
return pos;
}
@Nullable XivCombatant animTgt = locInfo.getAnimationTarget();
if (animTgt != null) {
sourcePos = animTgt.getPos();
}
Double heading = locInfo.getHeadingOnly();
if (heading != null && sourcePos != null) {
return sourcePos.facing(heading);
Expand Down
Loading
Loading