Code:
package com.rs.game.player.content.farming;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.player.content.farming.Farming.Herbs;
import com.rs.game.player.content.farming.Farming.Patches;
import com.rs.utils.Utils;
/**
*
* @author dlo3
* Here is a simple way of determining if a crop will disease. This can be implemented in your
* Farming.java class, assuming your base is similar to @author Jordan's.
* I know it isn't perfect, but it gets the job done. I think it might be a little bit harder
* than real RS... I will only be using this for my Ultimate Ironmen and Hard mode players.
*
*/
public class HerbDisease
{
public static boolean decideHerbDisease(Player player, int patchId, int seedId)
{
Herbs herb = Herbs.forId(seedId);
Patches patch = Patches.forId(patchId);
int levelRequired = herb.getLevelReq();
int maxSelection = levelRequired*100;
int selection = Utils.random(0, maxSelection);
boolean disease = false;
switch(herb){
case GUAM:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 14,
selection, maxSelection, player, patch);
break;
case MARRENTILL:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 19,
selection, maxSelection, player, patch);
break;
case TARROMIN:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 26,
selection, maxSelection, player, patch);
break;
case HARRALANDER:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 35,
selection, maxSelection, player, patch);
break;
case RANARR:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 38,
selection, maxSelection, player, patch);
break;
case TOADFLAX:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 48,
selection, maxSelection, player, patch);
break;
case IRIT:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 50,
selection, maxSelection, player, patch);
break;
case AVANTOE:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 56,
selection, maxSelection, player, patch);
break;
case KWUARM:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 62,
selection, maxSelection, player, patch);
break;
case SNAPDRAGON:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 67,
selection, maxSelection, player, patch);
break;
case CADANTINE:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 73,
selection, maxSelection, player, patch);
break;
case LANTADYME:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 79,
selection, maxSelection, player, patch);
break;
case DWARF_WEED:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 85,
selection, maxSelection, player, patch);
break;
case TORSTOL:
disease = determineRisk(player.getSkills().getLevel(Skills.FARMING) >= 91,
selection, maxSelection, player, patch);
break;
case FELLSTALK:
disease = determineRisk(true, selection, maxSelection, player, patch);
break;
}
return disease;
}
/**
*
* @param canPlantNext determines if the player can plant the next seed
* @param selection determins the roll range
* @param maxSelection determines the highest int in the roll,
* and correlates to the level of the seed
* @param player is the player
* @param patchUsing is the patch in use (needed to check for compost)
* @return if the crop will disease or not
*/
private static boolean determineRisk(boolean canPlantNext,
int selection, int maxSelection, Player player, Patches patchUsing)
{
/**
* If the player can plant the next highest herb, there is less of a chance of
* disease.
*/
if(!canPlantNext){
//if the patch is composted, less chance of disease
if(patchUsing.getComposted()){
// ~20-25% chance of disease depending on level of herb
if(selection < maxSelection/( maxSelection > 5000 ? 4 : 5)){
player.getPackets().sendGameMessage("<col=ffff00>One of "
+ "your herb patches has diseased. You have about 3 minutes before it dies!");
return true;
}
else {
player.out("" + selection);
return false;
}
}
else
{
// ~25-33% chance of disease depending on level of herb
if(selection < maxSelection/( maxSelection > 5000 ? 3 : 4)){
player.getPackets().sendGameMessage("<col=ffff00>One of "
+ "your herb patches has diseased. You have about 3 minutes before it dies!");
return true;
}
else{
player.out("" + selection);
return false;
}
}
}
else
{
if(patchUsing.getComposted()){
// ~9-10% chance of disease depending on level of herb
if(selection < maxSelection/( maxSelection > 5000 ? 10 : 11)){
player.getPackets().sendGameMessage("<col=ffff00>One of "
+ "your herb patches has diseased. You have about 3 minutes before it dies!");
return true;
}
else {
player.out("" + selection);
return false;
}
}
else
{
// ~12.5-14% chance of disease depending on level of herb
if(selection < maxSelection/( maxSelection > 5000 ? 7 : 8)){
player.getPackets().sendGameMessage("<col=ffff00>One of "
+ "your herb patches has diseased. You have about 3 minutes before it dies!");
return true;
}
else {
player.out("" + selection);
return false;
}
}
}
}
}