The Soul
Moderator
Number of posts : 8
Points :
Registration date : 2009-12-31
|
Subject: Improving Fishing Thu Dec 31, 2009 12:57 am |
|
|
Although very simple, this should improve your 'fishing system' on DeltaScape / Devolution derived servers. All explanations are done within the code tags.
We'll need to start off with importing this class: - Code:
-
import java.util.Random; Add this method: - Code:
-
public boolean randomFishTries(int fishID) { Random rand = new Random(); // creates new instance of Random class switch(fishID) { // creates switch statement using parameter variable 'fishID' case 316: // if the variable 'fishID' in the parameter is equal to '316', then it will carry out the action below if(playerLevel[playerFishing] > 0 && playerLevel[playerFishing] < 21) { // checks if fishing level is greater than 0 and less than 21 fishTries = rand.nextInt(18); // takes the instance of the Random class, 'rand', and sets it at a range of 18 (it will take 0-18 tries to fish something); this is assigned to the fishTries variable } if(playerLevel[playerFishing] > 20 && playerLevel[playerFishing] < 46) { // checks if fishing level is greater than 20 and less than 46 fishTries = rand.nextInt(14); // takes the instance of the Random class, 'rand', and sets it at a range of 14 (it will take 0-14 tries to fish something); this is assigned to the fishTries variable } if(playerLevel[playerFishing] > 45 && playerLevel[playerFishing] < 71) { // checks if fishing level is greater than 45 and less than 71 fishTries = rand.nextInt(11); // takes the instance of the Random class, 'rand', and sets it at a range of 11 (it will take 0-11 tries to fish something); this is assigned to the fishTries variable
} if(playerLevel[playerFishing] > 70 && playerLevel[playerFishing] < 94) { // checks if fishing level is greater than 70 and less than 94 fishTries = rand.nextInt(7); // takes the instance of the Random class, 'rand', and sets it at a range of 7 (it will take 0-7 tries to fish something); this is assigned to the fishTries variable } if(playerLevel[playerFishing] > 93 && playerLevel[playerFishing] < 100) { // checks if fishing level is greater than 93 and less than 100 fishTries = rand.nextInt(4); // takes the instance of the Random class, 'rand', and sets it at a range of 4 (it will take 0-4 tries to fish something); this is assigned to the fishTries variable } break; } return true; } You'll have to add the random fish tries for the rest of the fish, though.
In the startFishing() method, under the switch statement, under the case label that has the ID of '316', add: - Code:
-
randomFishTries(316); Add this method: - Code:
-
public void fishAdd(int fishID) { int exp = 0; // declaration of 'exp' variable switch(fishID) { //creates switch statement for the fishID parameter variable case 317: exp = 80; // sets the variable 'exp' to 80 sendMessage("You catch some " + getItemName(fishID)); // returns a message addItem(317, 1); // adds the item addSkillXP(exp, playerFishing); // adds the experience randomFishTries(316); // sets fishTries var to a random number depending on your level once again } } Replace your fish() method with the below: - Code:
-
public void fish(int id) { if (!playerHasItem(-1)) { resetAction(true); } if(fishTries > 0) // checks if var fishTries is greater than 0, and if so, it'll decrease fishTries--; required = -1; switch (fishId) { case 317: if(fishTries == 0) { // checks if var fishTries is equal to 0 fishAdd(317); // invokes the fishAdd method, '317' corresponds with the case label in the switch statement in that method, so it will carry out that action. } break; } }
|
|