diff --git a/Server/src/main/core/game/system/command/sets/MiscCommandSet.kt b/Server/src/main/core/game/system/command/sets/MiscCommandSet.kt index f62d8e87b..5e3a5a39b 100644 --- a/Server/src/main/core/game/system/command/sets/MiscCommandSet.kt +++ b/Server/src/main/core/game/system/command/sets/MiscCommandSet.kt @@ -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 NPC ID", "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 ${npc.name} ------") + player.sendMessage("Attack Style: ${handler.type}") + player.sendMessage("Attack Speed: ${attackSpeed}") + player.sendMessage("Damage: ${minHit} - ${maxHit}") + player.sendMessage("Chance to hit: ${floor(hitChance*100).toInt()}%") + player.sendMessage("Average DPS: ${floor(dps*100)/100}") + } } fun setPlaqueReadStatus(player: Player, status: Boolean){