From dcaa98082264382ebda4ce7a7d46a1e1a59efdcf Mon Sep 17 00:00:00 2001 From: bushtail Date: Wed, 22 Feb 2023 08:25:16 +0000 Subject: [PATCH] Rewrote PrayerEffect into kotlin Corrected calculation used for prayer restoring effects --- .../consumables/effects/PrayerEffect.java | 19 ------------------ .../data/consumables/effects/PrayerEffect.kt | 20 +++++++++++++++++++ Server/src/main/core/api/ContentAPI.kt | 12 +++++++++++ 3 files changed, 32 insertions(+), 19 deletions(-) delete mode 100644 Server/src/main/content/data/consumables/effects/PrayerEffect.java create mode 100644 Server/src/main/content/data/consumables/effects/PrayerEffect.kt diff --git a/Server/src/main/content/data/consumables/effects/PrayerEffect.java b/Server/src/main/content/data/consumables/effects/PrayerEffect.java deleted file mode 100644 index 65d5516aa..000000000 --- a/Server/src/main/content/data/consumables/effects/PrayerEffect.java +++ /dev/null @@ -1,19 +0,0 @@ -package content.data.consumables.effects; - -import core.game.consumable.ConsumableEffect; -import core.game.node.entity.player.Player; -import core.game.node.entity.skill.Skills; - -public class PrayerEffect extends ConsumableEffect { - double base, bonus; - public PrayerEffect(double base, double bonus){ - this.base = base; - this.bonus = bonus; - } - @Override - public void activate(Player p) { - int level = p.getSkills().getStaticLevel(Skills.PRAYER); - double amt = base + (level * bonus); - p.getSkills().incrementPrayerPoints(amt); - } -} diff --git a/Server/src/main/content/data/consumables/effects/PrayerEffect.kt b/Server/src/main/content/data/consumables/effects/PrayerEffect.kt new file mode 100644 index 000000000..9f636bc27 --- /dev/null +++ b/Server/src/main/content/data/consumables/effects/PrayerEffect.kt @@ -0,0 +1,20 @@ +package content.data.consumables.effects + +import core.api.* +import core.game.consumable.ConsumableEffect +import core.game.node.entity.player.Player +import core.game.node.entity.skill.Skills +import org.rs09.consts.Items +import kotlin.math.floor + +class PrayerEffect(var base: Double, var bonus: Double) : ConsumableEffect() { + override fun activate(player: Player?) { + if(player == null) return + val level = getStatLevel(player, Skills.PRAYER) + var b = bonus + if(inInventory(player, Items.HOLY_WRENCH_6714)) + b += 0.02 // Leaving this in for futureproofing. Current update is for properly rounding down. + val amount = floor(base + (level * b)) + modPrayerPoints(player, amount) + } +} \ No newline at end of file diff --git a/Server/src/main/core/api/ContentAPI.kt b/Server/src/main/core/api/ContentAPI.kt index 51dcf255d..ba8b61c15 100644 --- a/Server/src/main/core/api/ContentAPI.kt +++ b/Server/src/main/core/api/ContentAPI.kt @@ -61,6 +61,7 @@ import core.game.system.config.ServerConfigParser import core.game.world.GameWorld import core.game.world.GameWorld.Pulser import core.game.world.repository.Repository +import kotlin.math.absoluteValue /** * Gets a skilling tool which the player has the level to use and is in their inventory. @@ -2260,4 +2261,15 @@ fun addDialogueAction(player: Player, action: core.game.dialogue.DialogueAction) player.dialogueInterpreter.addAction(action) } +/** + * Modifies prayer points by value + * @param player the player to modify prayer points + * @param amount the amount of points to modify by (positive for increment, negative for decrement) + */ +fun modPrayerPoints(player: Player, amount: Double) { + if(amount > 0) player.skills.incrementPrayerPoints(amount) + else if(amount < 0) player.skills.decrementPrayerPoints(amount.absoluteValue) + else return +} + private class ContentAPI \ No newline at end of file