Skip to content
Open
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Arrays;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import static matsyir.pvpperformancetracker.PvpPerformanceTrackerPlugin.CONFIG;
Expand All @@ -45,10 +46,13 @@
import matsyir.pvpperformancetracker.models.FightType;
import matsyir.pvpperformancetracker.models.oldVersions.FightPerformance__1_5_5;
import net.runelite.api.AnimationID;
import net.runelite.api.Client;
import net.runelite.api.Player;
import net.runelite.api.Skill;
import matsyir.pvpperformancetracker.PvpPerformanceTrackerConfig;
import net.runelite.api.kit.KitType;
import net.runelite.client.hiscore.HiscoreManager;

import static matsyir.pvpperformancetracker.utils.PvpPerformanceTrackerUtils.fixItemId;
import static matsyir.pvpperformancetracker.controllers.PvpDamageCalc.RANGE_DEF;

Expand All @@ -59,9 +63,9 @@
public class FightPerformance implements Comparable<FightPerformance>
{
private static final int[] DEATH_ANIMATIONS = {
AnimationID.DEATH, // Default
10629, // League IV
11902, // League V
AnimationID.DEATH, // Default
10629, // League IV
11902, // League V
};
// Delay to assume a fight is over. May seem long, but sometimes people barrage &
// stand under for a while to eat. Fights will automatically end when either competitor dies.
Expand Down Expand Up @@ -107,22 +111,39 @@ public class FightPerformance implements Comparable<FightPerformance>
private transient double competitorSurvivalProb = 1.0;
private transient double opponentSurvivalProb = 1.0;

@Getter
private CombatLevels playersStats = new CombatLevels(PLUGIN.getClient());

@Getter
@Setter
private CombatLevels opponentsStats = CombatLevels.getConfigLevels();

// shouldn't be used, just here so we can make a subclass, weird java thing
public FightPerformance()
{

}

// constructor which initializes a fight from the 2 Players, starting stats at 0. Regular use constructor.
public FightPerformance(Player competitor, Player opponent)
public FightPerformance(Player competitor, Player opponent, HiscoreManager hiscoreManager)
{
int defLvl = PLUGIN.getClient().getBoostedSkillLevel(Skill.DEFENCE);

// determine fight type based on being at LMS areas & use def level to check for LMS builds.
this.fightType = !PLUGIN.isAtLMS() ? FightType.NORMAL :
defLvl <= FightType.LMS_1DEF.getCombatLevelsForType().def ? FightType.LMS_1DEF :
defLvl <= FightType.LMS_ZERK.getCombatLevelsForType().def ? FightType.LMS_ZERK :
FightType.LMS_MAXMED;
boolean fightIsAtLMS = PLUGIN.isAtLMS();
boolean fightIsAtArena = PLUGIN.isAtArena();
this.fightType = FightType.NORMAL;
if(fightIsAtLMS) {
this.fightType = defLvl <= FightType.LMS_1DEF.getCombatLevelsForType().def ? FightType.LMS_1DEF :
defLvl <= FightType.LMS_ZERK.getCombatLevelsForType().def ? FightType.LMS_ZERK :
FightType.LMS_MAXMED;
}
if(fightIsAtArena) {
defLvl = PLUGIN.getClient().getRealSkillLevel(Skill.DEFENCE);
this.fightType = defLvl <= FightType.ARENA_1DEF.getCombatLevelsForType().def ? FightType.ARENA_1DEF :
defLvl <= FightType.ARENA_ZERK.getCombatLevelsForType().def ? FightType.ARENA_ZERK :
FightType.ARENA_MAXMED;
}

// initialize world
this.world = PLUGIN.getClient().getWorld();
Expand All @@ -134,6 +155,12 @@ public FightPerformance(Player competitor, Player opponent)
this.competitor = new Fighter(this, competitor);
this.opponent = new Fighter(this, opponent);

if(!fightIsAtLMS && !fightIsAtArena) {
setOpponentsStats(new CombatLevels(opponent.getName(), hiscoreManager));
} else {
setOpponentsStats(fightType.getCombatLevelsForType());
}

this.competitorPrevHp = PLUGIN.getClient().getBoostedSkillLevel(Skill.HITPOINTS);
this.competitor.setLastGhostBarrageCheckedMageXp(PLUGIN.getClient().getSkillExperience(Skill.MAGIC));
}
Expand All @@ -150,9 +177,9 @@ public FightPerformance(FightPerformance__1_5_5 old)
{
int defLvl = competitor.getFightLogEntries().get(0).getAttackerLevels().def;
this.fightType =
defLvl <= FightType.LMS_1DEF.getCombatLevelsForType().def ? FightType.LMS_1DEF :
defLvl <= FightType.LMS_ZERK.getCombatLevelsForType().def ? FightType.LMS_ZERK :
FightType.LMS_MAXMED;
defLvl <= FightType.LMS_1DEF.getCombatLevelsForType().def ? FightType.LMS_1DEF :
defLvl <= FightType.LMS_ZERK.getCombatLevelsForType().def ? FightType.LMS_ZERK :
FightType.LMS_MAXMED;
}
else
{
Expand Down Expand Up @@ -239,10 +266,10 @@ public void checkForAttackAnimations(Player eventSource, CombatLevels competitor
{
int offensivePray = PLUGIN.currentlyUsedOffensivePray();
competitor.addAttack(
opponent.getPlayer(),
animationData,
offensivePray,
competitorLevels);
opponent.getPlayer(),
animationData,
offensivePray,
competitorLevels, opponentsStats);
lastFightTime = Instant.now().toEpochMilli();
addedAttack = true;

Expand All @@ -255,7 +282,7 @@ else if (eName.equals(opponent.getName()) && Objects.equals(interactingName, com
if (animationData != null)
{
// there is no offensive prayer data for the opponent so hardcode 0
opponent.addAttack(competitor.getPlayer(), animationData, 0);
opponent.addAttack(competitor.getPlayer(), animationData, 0, competitorLevels, opponentsStats);
addedAttack = true;
// add a defensive log for the competitor while the opponent is attacking, to be used with the fight analysis/merge
competitor.addDefensiveLogs(competitorLevels, PLUGIN.currentlyUsedOffensivePray());
Expand Down Expand Up @@ -296,10 +323,10 @@ public void checkForLocalGhostBarrage(CombatLevels competitorLevels, Player loca

int offensivePray = PLUGIN.currentlyUsedOffensivePray();
competitor.addGhostBarrage(opponent.getPlayer().getOverheadIcon() != animationData.attackStyle.getProtection(),
opponent.getPlayer(),
AnimationData.MAGIC_ANCIENT_MULTI_TARGET,
offensivePray,
competitorLevels);
opponent.getPlayer(),
AnimationData.MAGIC_ANCIENT_MULTI_TARGET,
offensivePray,
competitorLevels);
}
}

Expand Down Expand Up @@ -419,19 +446,19 @@ public boolean opponentDmgDealtIsGreater()
public boolean competitorMagicHitsLuckier()
{
double competitorRate = (competitor.getMagicHitCountDeserved() == 0) ? 0 :
(competitor.getMagicHitCount() / competitor.getMagicHitCountDeserved());
(competitor.getMagicHitCount() / competitor.getMagicHitCountDeserved());
double opponentRate = (opponent.getMagicHitCountDeserved() == 0) ? 0 :
(opponent.getMagicHitCount() / opponent.getMagicHitCountDeserved());
(opponent.getMagicHitCount() / opponent.getMagicHitCountDeserved());

return competitorRate > opponentRate;
}

public boolean opponentMagicHitsLuckier()
{
double competitorRate = (competitor.getMagicHitCountDeserved() == 0) ? 0 :
(competitor.getMagicHitCount() / competitor.getMagicHitCountDeserved());
(competitor.getMagicHitCount() / competitor.getMagicHitCountDeserved());
double opponentRate = (opponent.getMagicHitCountDeserved() == 0) ? 0 :
(opponent.getMagicHitCount() / opponent.getMagicHitCountDeserved());
(opponent.getMagicHitCount() / opponent.getMagicHitCountDeserved());

return opponentRate > competitorRate;
}
Expand All @@ -455,7 +482,7 @@ public int compareTo(FightPerformance o)
// if diff = 0, return 0. Otherwise, divide diff by its absolute value. This will result in
// -1 for negative numbers, and 1 for positive numbers, keeping the sign and a safely small int.
return diff == 0 ? 0 :
(int)(diff / Math.abs(diff));
(int)(diff / Math.abs(diff));
}

/**
Expand Down Expand Up @@ -558,7 +585,7 @@ else if (defender == opponent)
}
}

public void updateKoChanceStats(FightLogEntry entry)
public void updateKoChanceStats(FightLogEntry entry)
{
if (entry.getDisplayKoChance() == null) { return; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Fighter
@Expose
@SerializedName("s")
private int offPraySuccessCount; // total number of successful off-pray attacks
// (when you use a different combat style than your opponent's overhead)
// (when you use a different combat style than your opponent's overhead)
@Expose
@SerializedName("d")
private double deservedDamage; // total deserved damage based on gear & opponent's pray
Expand Down Expand Up @@ -195,11 +195,11 @@ public Fighter(FightPerformance fight, String name)
// Used for regular, ongoing fights
void addAttack(Player opponent, AnimationData animationData, int offensivePray)
{
addAttack(opponent, animationData, offensivePray, null);
addAttack(opponent, animationData, offensivePray, null, null);
}

// Levels can be null
void addAttack(Player opponent, AnimationData animationData, int offensivePray, CombatLevels levels)
void addAttack(Player opponent, AnimationData animationData, int offensivePray, CombatLevels levels, CombatLevels opponentLevels)
{
int[] attackerItems = player.getPlayerComposition().getEquipmentIds();

Expand Down Expand Up @@ -251,7 +251,7 @@ else if (weapon == EquipmentData.DRAGON_CROSSBOW &&
animationData = animationData.isSpecial ? AnimationData.MELEE_VLS_SPEC : AnimationData.MELEE_SCIM_SLASH;
}

pvpDamageCalc.updateDamageStats(player, opponent, successful, animationData);
pvpDamageCalc.updateDamageStats(player, opponent, successful, animationData, levels, opponentLevels);
deservedDamage += pvpDamageCalc.getAverageHit();

if (animationData.attackStyle == AnimationData.AttackStyle.MAGIC)
Expand All @@ -265,7 +265,7 @@ else if (weapon == EquipmentData.DRAGON_CROSSBOW &&
}
}

FightLogEntry fightLogEntry = new FightLogEntry(player, opponent, pvpDamageCalc, offensivePray, levels, animationData);
FightLogEntry fightLogEntry = new FightLogEntry(player, opponent, pvpDamageCalc, offensivePray, levels, opponentLevels, animationData);
fightLogEntry.setGmaulSpecial(isGmaulSpec);
if (PvpPerformanceTrackerPlugin.CONFIG.fightLogInChat())
{
Expand Down Expand Up @@ -311,7 +311,7 @@ public void addGhostBarrage(boolean successful, Player opponent, AnimationData a
}
lastGhostBarrageCheckedTick = currentTick;

pvpDamageCalc.updateDamageStats(player, opponent, successful, animationData);
pvpDamageCalc.updateDamageStats(player, opponent, successful, animationData, levels, levels);

ghostBarrageCount++;
ghostBarrageDeservedDamage += pvpDamageCalc.getAverageHit();
Expand Down Expand Up @@ -382,8 +382,8 @@ public String getOffPrayStats(boolean shortString)
{
nf.setMaximumFractionDigits(1);
return shortString ?
offPraySuccessCount + "/" + attackCount :
offPraySuccessCount + "/" + attackCount + " (" + nf.format(calculateOffPraySuccessPercentage()) + "%)";
offPraySuccessCount + "/" + attackCount :
offPraySuccessCount + "/" + attackCount + " (" + nf.format(calculateOffPraySuccessPercentage()) + "%)";
}

public String getOffPrayStats()
Expand All @@ -399,8 +399,8 @@ public String getMagicHitStats()
stats += "/" + nf.format(magicAttackCount);
nf.setMaximumFractionDigits(1);
String luckPercentage = magicHitCountDeserved != 0 ?
nf.format(((double)magicHitCount / magicHitCountDeserved) * 100.0) :
"0";
nf.format(((double)magicHitCount / magicHitCountDeserved) * 100.0) :
"0";
stats += " (" + luckPercentage + "%)";
return stats;
}
Expand All @@ -409,16 +409,16 @@ public String getShortMagicHitStats()
{
nf.setMaximumFractionDigits(1);
return magicHitCountDeserved != 0 ?
nf.format(((double)magicHitCount / magicHitCountDeserved) * 100.0) + "%" :
"0%";
nf.format(((double)magicHitCount / magicHitCountDeserved) * 100.0) + "%" :
"0%";
}

public String getDeservedDmgString(Fighter opponent, int precision, boolean onlyDiff)
{
nf.setMaximumFractionDigits(precision);
double difference = deservedDamage - opponent.deservedDamage;
return onlyDiff ? (difference > 0 ? "+" : "") + nf.format(difference) :
nf.format(deservedDamage) + " (" + (difference > 0 ? "+" : "") + nf.format(difference) + ")";
nf.format(deservedDamage) + " (" + (difference > 0 ? "+" : "") + nf.format(difference) + ")";
}
public String getDeservedDmgString(Fighter opponent)
{
Expand All @@ -430,7 +430,7 @@ public String getDmgDealtString(Fighter opponent, boolean onlyDiff)
{
int difference = damageDealt - opponent.damageDealt;
return onlyDiff ? (difference > 0 ? "+" : "") + difference:
damageDealt + " (" + (difference > 0 ? "+" : "") + difference + ")";
damageDealt + " (" + (difference > 0 ? "+" : "") + difference + ")";
}
public String getDmgDealtString(Fighter opponent)
{
Expand All @@ -440,13 +440,13 @@ public String getDmgDealtString(Fighter opponent)
public double calculateOffPraySuccessPercentage()
{
return attackCount == 0 ? 0 :
(double) offPraySuccessCount / attackCount * 100.0;
(double) offPraySuccessCount / attackCount * 100.0;
}

public double calculateOffensivePraySuccessPercentage()
{
return attackCount == 0 ? 0 :
(double) offensivePraySuccessCount / attackCount * 100.0;
(double) offensivePraySuccessCount / attackCount * 100.0;
}

public int getMagicAttackCount()
Expand All @@ -461,8 +461,8 @@ public String getOffensivePrayStats(boolean shortString)
{
nf.setMaximumFractionDigits(1);
return shortString ?
offensivePraySuccessCount + "/" + attackCount :
offensivePraySuccessCount + "/" + attackCount + " (" + nf.format(calculateOffensivePraySuccessPercentage()) + "%)";
offensivePraySuccessCount + "/" + attackCount :
offensivePraySuccessCount + "/" + attackCount + " (" + nf.format(calculateOffensivePraySuccessPercentage()) + "%)";
}

public String getOffensivePrayStats()
Expand Down
Loading