Description: To add a base for 100% working prayer.
Difficulty: 3/10
Assumed Knowledge: Usage of 508 servers, where files are located etc.
Tested Server: palidino 508
Files/Classes Modified/Created: Player.java, ActionButtons.java, Prayer.java
Procedure
Step 1: First off we're going to create the Prayer class. Start by making a new file called Prayer.java in palidino76/rs2/io/packets.
Step 2: Now we're going to create the package and add our imports:
Code:
package palidino76.rs2.io.packets;
import palidino76.rs2.players.Player;
/*Add more imports when required*/
then open your class:
Code:
public class Prayer {
Step 3: Now for the most important method of the whole class. This method checks which button is being pressed and activates or de-activates the relevant prayer, Dependant on whether the player is high enough prayer, and has more than 0 prayer points. This method also checks for head icons on prayers that require it. There may be more efficient ways of doing this, I just felt this way was easier and less code. The code is pretty much self explanatory .
Code:
public void Prayer(Player p, int buttonId) {
int x = 0;
/*Prayer button id's range from 5-57, increasing by 2 each time.*/
for(int i = 5; i < 59; i += 2) {
/*Checks if the loop mathces the button pressed*/
/*Checks if the player has more than 0 prayer points*/
if(buttonId == i && p.skillLvl[5] > 0) {
/*Checks if the players prayer level is high enough*/
if(p.getLevelForXP(5) >= prayerLevel[x]) {
/*Switches off other prayers affected by the prayer selected*/
switchPrayers(p, x);
/*Changes prayer status on/off*/
p.prayOn[x] = !p.prayOn[x];
/*Changes prayer config status, 0 for off or 1 for on*/
p.frames.setConfig(p, prayerConfig[x], p.prayOn[x] ? 1 : 0);
/*Checks if the prayer requires a headicon*/
if(x >= 16 && x <= 18 || x >= 21 && x <= 24) {
if(p.prayOn[x]) {
/*Gets the required pray icon if prayer is being switched on*/
getHeadIcon(p, x);
}
else {
/*Removes head icon if prayer is being switched off*/
p.prayerIcon = -1;
}
}
if(p.prayOn[x]) {
/*Increases the rate at which prayer drains if switched on*/
p.drainRate += drainRate[x];
}
else {
/*Decreases the rate at which prayer drains if switched off*/
p.drainRate -= drainRate[x];
}
p.appearanceUpdateReq = true;
p.updateReq = true;
}
else {
p.frames.sendMessage(p, "You need a prayer level of "+prayerLevel[x]+" to use this.");
}
}
/*Counts which prayer is being used*/
x++;
}
}
Step 4: Now we need to add some more methods to make the above method work properly. Add these arrays, which check for prayer levels required, which config to turn on/off and what rate the corresponding prayer drains at:
Code:
/* Configs for prayers */
public int prayerConfig[] =
{83, 84, 85, 862, 863, 86, 87,
88, 89, 90, 91, 864, 865, 92,
93, 94, 95, 96, 97, 866, 867,
98, 99, 100, 1168, 1052, 1053};
/* Prayer levels required */
public int prayerLevel[] =
{1, 4, 7, 8, 9, 10, 13,
16, 19, 22, 25, 26, 27, 28,
31, 34, 37, 40, 43, 44, 45,
46, 49, 52, 35, 60, 70};
/* Drain rate of each prayer */
public int drainRate[] =
{3, 4, 5, 6, 7, 8, 9,
10, 6, 7, 6, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 15, 26, 28};
You'll also need to add this method, which checks for which head icon is required:
Code:
/* Method to check for head icon */
public void getHeadIcon(Player p, int i) {
switch(i) {
case 16:
p.prayerIcon = 2;
break;
case 17:
p.prayerIcon = 1;
break;
case 18:
p.prayerIcon = 0;
break;
case 21:
p.prayerIcon = 3;
break;
case 22:
p.prayerIcon = 5;
break;
case 23:
p.prayerIcon = 4;
break;
case 24:
p.prayerIcon = 7;
break;
}
}
Now for the longest method, which I'm sure there must be a more efficient way of doing, but this is my way of doing it . This method checks which prayers must be switched off when a new prayer is activated:
Code:
/* Method to switch prayers */
public void switchPrayers(Player p, int i) {
switch(i) {
/*i represents which prayer is being used*/
case 0:
/*Array created for prayers to switch off*/
int[] off = {5, 13, 3, 4, 11, 12, 19, 20};
/*Switches off all prayers in the array*/
prayerOff(p, off);
break;
case 1:
int[] off2 = {6, 14, 3, 4, 11, 12, 19, 20};
prayerOff(p, off2);
break;
case 2:
int[] off3 = {7, 15, 3, 4, 11, 12, 19, 20};
prayerOff(p, off3);
break;
case 3:
int[] off4 = {0, 1, 2, 5, 13, 6, 14, 7, 15, 4, 11, 12, 19, 20};
prayerOff(p, off4);
break;
case 4:
int[] off5 = {0, 1, 2, 5, 13, 6, 14, 7, 15, 3, 11, 12, 19, 20};
prayerOff(p, off5);
break;
case 5:
int[] off6 = {0, 13, 3, 4, 11, 12, 19, 20};
prayerOff(p, off6);
break;
case 6:
int[] off7 = {1, 14, 3, 4, 11, 12, 19, 20};
prayerOff(p, off7);
break;
case 7:
int[] off8 = {2, 15, 3, 4, 11, 12, 19, 20};
prayerOff(p, off8);
break;
case 8:
int[] off9 = {9};
prayerOff(p, off9);
break;
case 9:
int[] off10 = {8};
prayerOff(p, off10);
break;
case 11:
int[] off11 = {5, 13, 6, 14, 7, 15, 4, 3, 12, 19, 20};
prayerOff(p, off11);
break;
case 12:
int[] off12 = {5, 13, 6, 14, 7, 15, 3, 11, 4, 19, 20};
prayerOff(p, off12);
break;
case 13:
int[] off13 = {5, 0, 3, 4, 11, 12, 19, 20};
prayerOff(p, off13);
break;
case 14:
int[] off14 = {6, 1, 3, 4, 11, 12, 19, 20};
prayerOff(p, off14);
break;
case 15:
int[] off15 = {7, 2, 3, 4, 11, 12, 19, 20};
prayerOff(p, off15);
break;
case 16:
int[] off16 = {17, 18, 21, 22, 23, 24};
prayerOff(p, off16);
break;
case 17:
int[] off17 = {16, 18, 21, 22, 23, 24};
prayerOff(p, off17);
break;
case 18:
int[] off18 = {17, 16, 21, 22, 23, 24};
prayerOff(p, off18);
break;
case 19:
int[] off19 = {5, 13, 6, 14, 7, 15, 4, 11, 12, 3, 20};
prayerOff(p, off19);
break;
case 20:
int[] off20 = {5, 13, 6, 14, 7, 15, 3, 11, 12, 19, 4};
prayerOff(p, off20);
break;
case 21:
int[] off21 = {17, 18, 16, 22, 23, 24};
prayerOff(p, off21);
break;
case 22:
int[] off22 = {17, 18, 21, 16, 23, 24};
prayerOff(p, off22);
break;
case 23:
int[] off23 = {17, 18, 21, 22, 16, 24};
prayerOff(p, off23);
break;
case 24:
int[] off24 = {17, 18, 21, 22, 16, 23};
prayerOff(p, off24);
break;
case 25:
int[] off25 = {0, 1, 2, 5, 6, 7, 13, 14, 15, 26};
prayerOff(p, off25);
break;
case 26:
int[] off26 = {0, 1, 2, 5, 6, 7, 13, 14, 15, 25};
prayerOff(p, off26);
break;
}
}
And of course you need to add the prayerOff method to make that work:
Code:
/* Method to switch prayers off */
public void prayerOff(Player p, int[] prayers) {
for(int z = 0; z < prayers.length; z++) {
if(p.prayOn[prayers[z]]) {
p.prayOn[prayers[z]] = false;
p.frames.setConfig(p, prayerConfig[prayers[z]], 0);
p.drainRate -= drainRate[prayers[z]];
}
}
}
And the final method you will need is resetPrayers, which de-activates all prayers when a player dies or runs out of prayer points:
Code:
/*Resets all prayer configs*/
/*Turns off all prayers*/
/*Removes headicons*/
public void resetPrayers(Player p) {
for(int i = 0; i < 21; i++) {
if(p.prayOn[i]) {
p.prayOn[i] = false;
p.frames.setConfig(p, prayerConfig[i], 0);
}
}
p.drainRate = 0;
p.prayerIcon = -1;
p.appearanceUpdateReq = true;
p.updateReq = true;
}
Phew! That was alot of methods . Now close your whole prayer class by placing a final: }
Now save your final Prayer.java and lets start on some other files.
Step 5: Open up Player.java, declare all these:
Code:
public int prayerDrain = 100;
public int drainRate = 0;
public int defLow = 0;
public int strLow = 1;
public int atkLow = 2;
public int rangeLow = 3;
public int mageLow = 4;
public int defMid = 5;
public int strMid = 6;
public int atkMid = 7;
public int rapidRestore = 8;
public int rapidHeal = 9;
public int protItems = 10;
public int rangeMid = 11;
public int mageMid = 12;
public int defHigh = 13;
public int strHigh = 14;
public int atkHigh = 15;
public int prayMage = 16;
public int prayRange = 17;
public int prayMelee = 18;
public int rangeHigh = 19;
public int mageHigh = 20;
public int retribution = 21;
public int redepmtion = 22;
public int smite = 23;
public int praySummon = 24;
public int chivalry = 25;
public int piety = 26;
public boolean prayOn[] = new boolean[27];
Feel free to remove all the prayer names, I just used it for simplicity coz I couldn't remember all the numbers .
Now, add this import with the other imports at the top:
Code:
import palidino76.rs2.io.packets.Prayer;
Now, in your Player Process() method add this method, which drains prayer at intervals dependent on which prayers are being used, and resets all prayers when the player runs out of prayer points:
Code:
/*prayerDrain is set at 100, lowers by drainRate of all prayers being used*/
prayerDrain -= drainRate;
/*When prayerDrain becomes 0 or less, players prayer level is decreased by 1.*/
if(prayerDrain <= 0 && skillLvl[5] > 0) {
skillLvl[5]--;
frames.setSkillLvl(this, 5);
/*If the players prayer level becomes 0, it resets all prayers in use.*/
if(skillLvl[5] <= 0) {
Prayer pr = new Prayer();
pr.resetPrayers(this);
frames.sendMessage(this, "You have run out of prayer points.");
}
prayerDrain = 100;
}
Now find your applyDead method, or whatever it happens to be called (if you have one, if not ignore this step). And call the resetPrayer method again by adding this somewhere in there:
Code:
Prayer pr = new Prayer();
pr.resetPrayers(this);
Now you can close and save Player.java.
Step 6: Now open up ActionButtons.java and add this import:
Code:
import palidino76.rs2.io.packets.Prayer;
Then, under:
Code:
switch (interfaceId) {
add:
Code:
case 271:
Prayer pr = new Prayer();
pr.Prayer(p, buttonId);
break;
And you're finally done! Compile everything and voila!
Now all you have to do is make the prayers work, but I'm going to make
you do that yourself. An example of how it works would be:
Code:
if(p.prayOn[p.strLow]) {
//Code to increase max hit
}
or
Code:
if(p.prayOn[p.prayMelee]) {
//Code to make hit 0
}
congratulations you have added 100% prayer to your 508 woohoo!