public double getDrainRate() {
double toRemove = 0.0;
for(int i = 0; i < c.PRAYER_DRAIN_RATE.length; i++) {
if(c.prayerActive[i]) {
toRemove += c.PRAYER_DRAIN_RATE[i]/10;
}
}
if (toRemove > 0) {
toRemove /= (1 + (0.035 * c.playerBonus[11]));
}
return toRemove;
}
public boolean hasPrayerActive() {
for (int i = 0; i < 18; i++) {
if(c.prayerActive[i])
return true;
}
return false;
}
public int getPrayerDelay() {
c.usingPrayer = false;
int delay = 4000;
for(int i = 0; i < c.prayerActive.length; i++) {
if(c.prayerActive[i] == true) {
c.usingPrayer = true;
delay -= c.PRAYER_DRAIN_RATE[i];
}
}
delay += c.playerBonus[11]*500;
return delay;
}
Code:
package rs2.main.cycle.event.impl;
import rs2.main.cycle.event.CycleEvent;
import rs2.main.cycle.event.CycleEventContainer;
import rs2.main.model.entity.players.Client;
/**
* The task to reduce prayer points for prayer activation
* @author Final Project
*
*/
public class ReducePrayerEvent extends CycleEvent {
/**
* Creates an instance of the client
*/
private Client client;
/**
* Constructs the class for the client
* @param client
* the client
*/
public ReducePrayerEvent(Client client) {
this.client = client;
}
@Override
public void execute(CycleEventContainer container) {
/*comment this out, just something i used to get the drain rates*/
client.sendMessage(""+client.getCombat().getDrainRate());
/*checks if player has no prayer points or has gone down to the negatives or if they have no prayers activated*/
if (client.playerLevel[5] == 0
|| client.playerLevel[5] < 0
|| !client.getCombat().hasPrayerActive()) {
container.stop();
return;
}
/*the prayer delay of when to drain the prayer point, needs to be more accurate as i kinda just did whatever*/
if(System.currentTimeMillis() - client.prayerDelay > client.getCombat().getPrayerDelay()
&& client.usingPrayer) {
client.prayerDelay = System.currentTimeMillis();
/*checks if the client has more than 0 prayer points then starts the draining process*/
if (client.playerLevel[5] > 0) {
client.playerLevel[5] = (int) (client.playerLevel[5] - client.getCombat().getDrainRate());
client.getSkills().refreshSkill(5);
}
}
}
@Override
public void stop() {
if (client.playerLevel[5] < 0) {
client.playerLevel[5] = 0;
client.getSkills().refreshSkill(5);
}
client.getCombat().resetPrayers();
}
}
now call the task in your activateprayer method after the switch or wherever you want after that, scratch not, not just anywhere lol.
i used this guide as a reference for the formula, [Only registered and activated users can see links. ] but i kinda didnt wanna do the math so you guys are welcomed to do that yourself.
edit: just noticed that i did something stupid, oh well