Jump to content
Sign in to follow this  
Arrogance

RuneEscape Fishing Class

Recommended Posts

[code]import com.rs.game.player.skills.Skill;
import com.rs.game.player.Player;
import com.rs.game.Animation;
import com.rs.game.npc.NPC;
import com.rs.utils.Utils;
import com.rs.cache.loaders.ItemDefinitions;
import com.rs.game.player.skills.SkillExecutor;
/**
* @author Ethan <Atlas Development Team>
* @version 1.0
* @since 2011
*/
public class Fishing extends Skill
{

private FishingDetails detail;

public enum FishingDetails
{
CRAY(1, 10, 13431, 619, new int[]{13435}, 20, 4, 5),
SHRIMP(1, 10, 303, 621, new int[]{317, 321}, 20, 4, 5),
SARDINE(5, 20, 309, 7261, new int[]{327}, 25, 4, 5),
HERRING(10, 30, 305, 620, new int[]{345}, 28, 4, 10),
TROUT(20, 50, 307, 622,new int[]{335, 331}, 35, 4, 10),
SHARK(76, 110, 311 | 10129, 618, new int[]{383}, 150, 21, 10);

private int level;
private double xp;
private int equipmentId;
private int emoteId;
private int[] fishId;
private int fishBaseTime;
private int randomCatchTime;
private int randomLifeProbability;

/**
* Enum's Constructor
*/
private FishingDetails(int level, double xp, int equipmentId, int emoteId, int[] fishId, int fishBaseTime, int randomCatchTime, int randomLifeProbability)
{
this.level = level;
this.xp = xp;
this.equipmentId = equipmentId;
this.emoteId = emoteId;
this.fishId = fishId;
this.fishBaseTime = fishBaseTime;
this.randomCatchTime = randomCatchTime;
this.randomLifeProbability = randomLifeProbability;
}

public int getLevel()
{
return level;
}

public double getXP()
{
return xp;
}

public int getEquipmentId()
{
return equipmentId;
}

public int getEmoteId()
{
return emoteId;
}

public int getFishId()
{
return fishId[(int)(Math.random() * fishId.length)];
}

public int getFishBaseTime()
{
return fishBaseTime;
}

public int getRandomCatchTime()
{
return randomCatchTime;
}

public int getRandomLifeProbability()
{
return randomLifeProbability;
}
}


/**
* Constructor
* @param detail is used to choose which detail in the enum to call
*/
public Fishing(FishingDetails detail)
{
this.detail = detail;
}

/**
* Starts the skill from the top
* @param player gets information from the Player class
* @return true, meaning that everything checks out
*/
@Override
public boolean start(Player player)
{
if(!checkAll(player)) {
return false;
}
player.getPackets().sendGameMessage("You plunge your hands into the cold fishing spot.");
return true;
}

/**
* Gets the delay time for the fish depending on the enum, and your level
* @param player gets information from the Player class
* @return fishingTimer, meaning the time it will take to catch the fish.
* @return used in the processWithDelay method
*/
private int getDelay(Player player)
{
int fishingTimer = detail.getFishBaseTime() - player.getSkills().getLevel(10);
if(fishingTimer < 1 + detail.getRandomCatchTime())
fishingTimer = 1 + Utils.getRandom(detail.getRandomCatchTime());
return fishingTimer;
}

/**
* Checks is the player has the equipment needed to fish
* @param player gets information from the Player class
* @return true, meaning that the player does have the equipment needed
*/
private boolean hasEquipment(Player player)
{
if(player.getInventory().containsOneItem(detail.getEquipmentId())) {
return true;
}
return false;
}

/**
* Checks multiple variables to see if the player has everything required to fish
* @param player gets information from the Player class
* @return true, meaning every thing is right for the player to fish
*/
public boolean checkAll(Player player)
{
if(!player.getInventory().hasFreeSlots()) {
player.getPackets().sendGameMessage("You can't carry any more fish.");
return false;
}
if(!hasEquipment(player)) {
player.getPackets().sendGameMessage("You don't have the needed equipment to fish here.");
return false;
}
if(!hasLevel(player)) {
return false;
}
if(detail == FishingDetails.TROUT) {
if(!player.getInventory().containsOneItem(314)) {
player.getPackets().sendGameMessage("You need feathers to fish with a rod here.");
return false;
}
}
if(detail == FishingDetails.SARDINE) {
if(!player.getInventory().containsOneItem(313)) {
player.getPackets().sendGameMessage("You need bait to fish with a rod here.");
return false;
}
}
return true;
}

/**
* Checks to see if the player has the level needed
* @param player gets information from the Player class
* @return true, meaning that the player has the level required
*/
public boolean hasLevel(Player player)
{
if(detail.getLevel() > player.getSkills().getLevel(10)) {
player.getPackets().sendGameMessage("You need a fishing level of " + detail.getLevel() + " fishing to fish at this spot.");
return false;
}
return true;
}

/**
* Handles animation, just that really..
* @param player gets information from the Player class
* @return true, meaning that the process is allowed to happen
*/
@Override
public boolean process(Player player)
{
player.setNextAnimation(new Animation(detail.getEmoteId()));
return true;
}

/**
* processes the players action using a delay that you set
* @param player gets information from the Player class
* @return getDelay @see getDelay
*/
@Override
public int processWithDelay(Player player)
{
addFish(player);
if(Utils.getRandom(detail.getRandomLifeProbability()) == 0) {
player.setNextAnimation(new Animation(-1));
return -1;
}
if(!player.getInventory().hasFreeSlots()) {
player.setNextAnimation(new Animation(-1));
player.getPackets().sendGameMessage("You can't carry any more fish.");
return -1;
}
return getDelay(player);
}

/**
* Handles adding fish, xp and what not
* @param player gets information from the Player class
*/
public void addFish(Player player)
{
if(detail == FishingDetails.TROUT) {
player.getInventory().deleteItem(314, 1);
}
if(detail == FishingDetails.SARDINE) {
player.getInventory().deleteItem(313, 1);
}
int fishId = detail.getFishId();
String fishName = ItemDefinitions.getItemDefinitions(fishId).getName().toLowerCase();
player.getInventory().addItem(fishId, 1);
player.getPackets().sendGameMessage("You catch a " + fishName + ".");
player.getSkills().addXp(10, detail.getXP());
}

/**
* Stops process
* @param player gets information from the Player class
*/
@Override
public void stop(Player player)
{
setSkillDelay(player, 3);
}
}[/code]

Share this post


Link to post
Share on other sites
Is this written by you?

Share this post


Link to post
Share on other sites
[quote name='iRepo']Is this written by you?[/QUOTE]

The only way to decide if it isn't is by comparing this one to the Matrix one. But I believe doubting him has no reason behind it.

Share this post


Link to post
Share on other sites
[quote name='iRepo']Is this written by you?[/QUOTE]

Look at the author tag. I thought everyone knew my name was Ethan.

[quote name='Haloofpower`']The only way to decide if it isn't is by comparing this one to the Matrix one. But I believe doubting him has no reason behind it.[/QUOTE]

I wrote this two weeks ago, it's impossible for it to be Matrix. You can ask people that have seen me write skills on T.V before.

Share this post


Link to post
Share on other sites
[quote name='Haloofpower`']The only way to decide if it isn't is by comparing this one to the Matrix one. But I believe doubting him has no reason behind it.[/QUOTE]

I don't doubt it. Ethan is a very skilled coder.

[quote name='Arrogance']Look at the author tag. I thought everyone knew my name was Ethan.[/QUOTE]

Now I do :O.

Share this post


Link to post
Share on other sites
[quote name='Arrogance']Look at the author tag. I thought everyone knew my name was Ethan.[/QUOTE]

I knows it!!

Share this post


Link to post
Share on other sites
[quote name='Arrogance']Look at the author tag. I thought everyone knew my name was Ethan.



I wrote this two weeks ago, it's impossible for it to be Matrix. You can ask people that have seen me write skills on T.V before.[/QUOTE]

Don't mean to be offensive, but I highly doubt thousands of people will know you're name is Ethan when you are not THAT active in the community.

OT: looks good

Share this post


Link to post
Share on other sites
@Author tags, anyone can change them.

OT: It's his.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×