Skip to content

Commit

Permalink
fix: improve statistics accuracy (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Oct 8, 2024
1 parent 587bb0b commit ba2de65
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/pickpockethelper/PickpocketHelperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,13 @@ public void resetConfiguration() {
@Subscribe
public void onGameStateChanged(GameStateChanged change) {
switch (change.getGameState()) {
case LOGIN_SCREEN:
session.reset();
// intentional fall-through
case CONNECTION_LOST:
case HOPPING:
case LOGIN_SCREEN:
session.clear();
session.getSplasher().reset();
session.getTarget().reset();
highlightManager.clearTargets();
break;
}
Expand Down Expand Up @@ -547,11 +550,11 @@ private void checkAndUpdateSplasher(Actor target) {

Player player = (Player) target;

if (!splashAnimations.contains(player.getAnimation()) || player.getInteracting() == null || !session.isTarget(player.getInteracting())) {
if (player.getInteracting() == null || !session.isTarget(player.getInteracting()) || !splashAnimations.contains(player.getAnimation())) {
return;
}

if (session.getSplasher().getPlayer() != null && session.getSplasher().getPlayer().equals(player)) {
if (player == session.getSplasher().getPlayer()) {
session.getSplasher().updateLastAttack();
} else {
session.getSplasher().updatePlayer(player);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/pickpockethelper/entity/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public void setupListeners() {
}

private void onTargetChange() {
sessionStart = Instant.now();
if (!isActive()) {
sessionStart = Instant.now();
}
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/pickpockethelper/entity/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ public int getSecondsBeforeDespawn() {
return secondsBeforeDespawn;
}

public void clear() {
npcListeners.clear();

public void reset() {
npc = null;
lastLocation = null;
lastMove = null;
lastDespawnNotify = null;
}

public void clear() {
npcListeners.clear();
reset();
}

private boolean isArdyKnight() {
return npc != null && "Knight of Ardougne".equals(npc.getName());
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/pickpockethelper/ui/StatisticOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public Dimension render(Graphics2D graphics) {
.left("Rate:")
.right(successRatio +"%")
.build());
panelComponent.getChildren().add(LineComponent.builder()
.left("Per hour:")
.right(String.valueOf(perHourCount))
.build());
if (totalCount > 1) {
panelComponent.getChildren().add(LineComponent.builder()
.left("Per hour:")
.right(String.valueOf(perHourCount))
.build());
}

panelComponent.getChildren().add(LineComponent.builder().build());

Expand Down

0 comments on commit ba2de65

Please sign in to comment.