From 34f8db2557f6ed61725494565c43d7c3531a7666 Mon Sep 17 00:00:00 2001 From: Swizey Date: Thu, 16 Feb 2023 22:47:18 +0000 Subject: [PATCH] Implemented authentic dragon axe special attack and enabled it by default, osrs style is toggle via worldprop world config dragon_axe_use_osrs_spec = true --- .../special/ClobberSpecialHandler.java | 65 ---------- .../special/ClobberSpecialHandler.kt | 122 ++++++++++++++++++ Server/src/main/core/ServerConstants.kt | 3 + .../game/system/config/ServerConfigParser.kt | 1 + 4 files changed, 126 insertions(+), 65 deletions(-) delete mode 100644 Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.java create mode 100644 Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.kt diff --git a/Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.java b/Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.java deleted file mode 100644 index 1c6ad1100..000000000 --- a/Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -package content.global.handlers.item.equipment.special; - -import core.game.node.entity.skill.Skills; -import core.game.node.entity.Entity; -import core.game.node.entity.combat.BattleState; -import core.game.node.entity.combat.CombatStyle; -import core.game.node.entity.combat.MeleeSwingHandler; -import core.game.node.entity.impl.Animator.Priority; -import core.game.node.entity.player.Player; -import core.game.world.update.flag.context.Animation; -import core.game.world.update.flag.context.Graphics; -import core.plugin.Initializable; -import core.plugin.Plugin; - -/** - * Handles the Dragon axe special attack. - * @author Crash - */ -@Initializable -public final class ClobberSpecialHandler extends MeleeSwingHandler implements Plugin { - - /** - * The special energy required. - */ - private static final int SPECIAL_ENERGY = 100; - - /** - * The attack animation. - */ - private static final Animation ANIMATION = new Animation(2876, Priority.HIGH); - - /** - * The graphic. - */ - private static final Graphics GRAPHIC = new Graphics(479, 96); - - - @Override - public Object fireEvent(String identifier, Object... args) { - switch (identifier) { - case "instant_spec": - case "ncspec": - return true; - } - return null; - } - - @Override - public Plugin newInstance(Object arg) throws Throwable { - CombatStyle.MELEE.getSwingHandler().register(6739, this); - return this; - } - - @Override - public int swing(Entity entity, Entity victim, BattleState state) { - Player p = (Player) entity; - if (!p.getSettings().drainSpecial(SPECIAL_ENERGY)) - return -1; - p.sendChat("Chop chop!"); - p.visualize(ANIMATION, GRAPHIC); - p.getSkills().updateLevel(Skills.WOODCUTTING, 3, p.getSkills().getStaticLevel(Skills.WOODCUTTING) + 3); - return -1; - } - -} diff --git a/Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.kt b/Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.kt new file mode 100644 index 000000000..25ff591a5 --- /dev/null +++ b/Server/src/main/content/global/handlers/item/equipment/special/ClobberSpecialHandler.kt @@ -0,0 +1,122 @@ +package content.global.handlers.item.equipment.special + +import core.ServerConstants +import core.game.container.impl.EquipmentContainer +import core.game.node.entity.Entity +import core.game.node.entity.combat.BattleState +import core.game.node.entity.combat.CombatStyle +import core.game.node.entity.combat.MeleeSwingHandler +import core.game.node.entity.combat.equipment.Weapon +import core.game.node.entity.impl.Animator.Priority +import core.game.node.entity.player.Player +import core.game.node.entity.player.link.audio.Audio +import core.game.node.entity.skill.Skills +import core.game.node.item.Item +import core.game.world.update.flag.context.Animation +import core.game.world.update.flag.context.Graphics +import core.plugin.Initializable +import core.plugin.Plugin +import core.tools.RandomFunction +import org.rs09.consts.Items + + +/** + * Handles the Dragon axe special attack. + * The OSRS special attack can be used instead by setting dragon_axe_use_osrs_spec server constant to true + * @author Crash + */ +@Initializable +class ClobberSpecialHandler : MeleeSwingHandler(), Plugin { + override fun newInstance(arg: Any?): Plugin { + CombatStyle.MELEE.swingHandler.register(ITEM.id, this) + return this + } + + override fun fireEvent(identifier: String, vararg args: Any): Any { + return if (ServerConstants.DRAGON_AXE_USE_OSRS_SPEC && identifier == "instant_spec") true else Unit + } + + override fun visualize(entity: Entity, victim: Entity?, state: BattleState?) { + entity.visualize(ANIMATION, GRAPHIC) + } + + override fun swing(entity: Entity?, victim: Entity?, state: BattleState?): Int { + return if (ServerConstants.DRAGON_AXE_USE_OSRS_SPEC) { + swingOSRS(entity) + } else { + swingAuthentic(entity, victim, state) + } + } + + /** + * https://runescape.wiki/w/Dragon_hatchet?oldid=1107166 + */ + private fun swingAuthentic(entity: Entity?, victim: Entity?, state: BattleState?): Int { + val player = entity as? Player ?: return -1 + if (victim == null) return -1 + if (state == null) return -1 + if (!player.settings.drainSpecial(SPECIAL_ENERGY)) return -1 + + state.style = CombatStyle.MELEE + state.weapon = Weapon(player.equipment[EquipmentContainer.SLOT_WEAPON]) + var hit = 0 + if (isAccurateImpact(entity, victim, CombatStyle.MELEE)) { + val max = calculateHit(entity, victim, 1.0) + state.maximumHit = max + hit = RandomFunction.random(max + 1) + } + state.estimatedHit = hit + + victim.skills.updateLevel(Skills.DEFENCE, -hit, 0) + victim.skills.updateLevel(Skills.MAGIC, -hit, 0) + + player.audioManager.send(AUTHENTIC_AUDIO) + return 1 + } + + /** + * https://oldschool.runescape.wiki/w/Dragon_axe + */ + private fun swingOSRS(entity: Entity?): Int { + val player = entity as? Player ?: return -1 + if (!player.settings.drainSpecial(SPECIAL_ENERGY)) return -1 + + player.sendChat("Chop chop!") + player.skills.updateLevel(Skills.WOODCUTTING, 3, player.skills.getStaticLevel(Skills.WOODCUTTING) + 3) + visualize(player, null, null) + player.audioManager.send(OSRS_AUDIO) + return -1 + } + + companion object { + /** + * The special energy required. + */ + private const val SPECIAL_ENERGY = 100 + + /** + * The attack animation. + */ + private val ANIMATION = Animation(2876, Priority.HIGH) + + /** + * The graphic. + */ + private val GRAPHIC = Graphics(479, 96) + + /** + * The authentic sound. + */ + private val AUTHENTIC_AUDIO = Audio(2531) + + /** + * The OSRS sound. + */ + private val OSRS_AUDIO = Audio(2530) + + /** + * The item. + */ + private val ITEM = Item(Items.DRAGON_AXE_6739) + } +} \ No newline at end of file diff --git a/Server/src/main/core/ServerConstants.kt b/Server/src/main/core/ServerConstants.kt index f8889d41b..5823be465 100644 --- a/Server/src/main/core/ServerConstants.kt +++ b/Server/src/main/core/ServerConstants.kt @@ -261,5 +261,8 @@ class ServerConstants { @JvmField var PERSIST_ACCOUNTS = false + + @JvmField + var DRAGON_AXE_USE_OSRS_SPEC = false } } diff --git a/Server/src/main/core/game/system/config/ServerConfigParser.kt b/Server/src/main/core/game/system/config/ServerConfigParser.kt index ffedb1f65..a486db759 100644 --- a/Server/src/main/core/game/system/config/ServerConfigParser.kt +++ b/Server/src/main/core/game/system/config/ServerConfigParser.kt @@ -132,6 +132,7 @@ object ServerConfigParser { ServerConstants.DAILY_ACCOUNT_LIMIT = data.getLong("server.daily_accounts_per_ip", 3L).toInt() ServerConstants.DISCORD_MOD_WEBHOOK = data.getString("server.moderation_webhook", "") ServerConstants.NOAUTH_DEFAULT_ADMIN = data.getBoolean("server.noauth_default_admin", false) + ServerConstants.DRAGON_AXE_USE_OSRS_SPEC = data.getBoolean("world.dragon_axe_use_osrs_spec", false) }