Implemented custom ::dps command to combine the information from ::calcmaxhit and ::calcaccuracy

This commit is contained in:
randy 2025-08-25 16:00:14 -06:00
parent b372d5e963
commit bfa62864fa

View file

@ -36,6 +36,7 @@ import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import core.game.node.entity.combat.CombatStyle
import core.game.node.entity.combat.equipment.WeaponInterface
import kotlin.math.floor
@Initializable
@ -130,7 +131,7 @@ class MiscCommandSet : CommandSet(Privilege.ADMIN){
val hit = swingHandler.calculateHit(player, player, 1.0)
notify(player, "max hit: ${hit} (${(swingHandler as Object).getClass().getName()})")
// Snowescape: calculate the min damage on hit for melee attacks (see MeleeSwingHandler.swing() for the custom minimum damage).
// Snowscape: calculate the min damage on hit for melee attacks (see MeleeSwingHandler.swing() for the custom minimum damage).
if (swingHandler.type == CombatStyle.MELEE) {
val speedMod = (player.getProperties().getAttackSpeed() - 4)
val min = floor(speedMod * 0.1 * hit).toInt()
@ -648,6 +649,53 @@ class MiscCommandSet : CommandSet(Privilege.ADMIN){
notify(player, "Setting plaques read to: ${args[1]}")
}
//Snowscape custom commands
define("dps", Privilege.STANDARD, "::dps <lt>NPC ID<gt>", "Calculates and prints your current damage, accuracy, and DPS against the given NPC ID."){ player, args ->
// If NPC ID is specified, save as attribute. If unspecified, use last saved ID (defaults to Chicken)
if (args.size > 1) {
setAttribute(player, "snowscape:dpscalc", args[1].toInt())
}
val npcId: Int = getAttribute(player, "snowscape:dpscalc", 41)
val npc = NPC(npcId)
npc.initConfig()
val handler = player.getSwingHandler(false)
var attackSpeed = player.getProperties().getAttackSpeed()
var maxHit = handler.calculateHit(player, npc, 1.0)
var minHit = 0
if (handler.type == CombatStyle.MELEE) {
minHit = floor((attackSpeed - 4) * 0.1 * maxHit).toInt()
} else if (handler.type == CombatStyle.RANGE) {
if (player.getProperties().getAttackStyle().getStyle() == WeaponInterface.STYLE_RAPID) {
attackSpeed--
}
} else if (handler.type == CombatStyle.MAGIC) {
val spell = player.getProperties().getAutocastSpell()
maxHit = if (spell != null) spell.getMaximumImpact(player, npc, null) else 0
}
val avgHit = ((maxHit + 1) * maxHit) / 2 / (maxHit - minHit + 1)
val accuracy = handler.calculateAccuracy(player)
val defence = handler.calculateDefence(npc, player)
val hitChance: Double = if (accuracy > defence) {
1.0 - ((defence + 2.0) / (2.0 * (accuracy + 1.0)))
} else {
accuracy / (2.0 * (defence + 1.0))
}
val dps = (1/(attackSpeed * 0.6)) * hitChance * avgHit
val color = "00fffff"
player.sendMessage("------ DPS vs <col=${color}>${npc.name}</col> ------")
player.sendMessage("Attack Style: <col=${color}>${handler.type}</col>")
player.sendMessage("Attack Speed: <col=${color}>${attackSpeed}</col>")
player.sendMessage("Damage: <col=${color}>${minHit}</col> - <col=${color}>${maxHit}</col>")
player.sendMessage("Chance to hit: <col=${color}>${floor(hitChance*100).toInt()}%</col>")
player.sendMessage("Average DPS: <col=${color}>${floor(dps*100)/100}</col>")
}
}
fun setPlaqueReadStatus(player: Player, status: Boolean){