Rewrote PrayerEffect into kotlin

Corrected calculation used for prayer restoring effects
This commit is contained in:
bushtail
2023-02-22 08:25:16 +00:00
committed by Ryan
parent 50a9580505
commit dcaa980822
3 changed files with 32 additions and 19 deletions
@@ -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);
}
}
@@ -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)
}
}
+12
View File
@@ -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