Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package
- import server.game.content.skills.impl.SkillTask;
- import server.game.player.Player;
- import server.task.Stackable;
- import server.task.Walkable;
- /**
- * Fishing for fish that live in the sea.
- *
- * @author Tim
- *
- */
- public class Fishing extends SkillTask {
- /**
- * The data for the fish to be fished.
- */
- private final FishingData data;
- /**
- * Creates an unwalkable task for the player
- *
- * @param player
- * The player fishing for fish
- * @param data
- * The data for the fish to be fished
- */
- public Fishing(Player player, FishingData data) {
- super(player, 4, Walkable.NON_WALKABLE, Stackable.NON_STACKABLE, false);
- this.data = data;
- }
- /**
- * Attempts to fish
- *
- * @param player
- * The player attempting to fish
- * @return
- */
- public static boolean attemptFishing(Player player) {
- int spotId = data.getSpotId();
- FishingData data = FishingData.forId(spotId);
- if (!meetsRequirements(player, data)) {
- return false;
- }
- player.getPA().closeAllWindows();
- player.setSkillTask(new Fishing(player, data));
- return true;
- }
- /**
- * Meets the requirements to start fishing
- *
- * @param player
- * The player fishing
- * @param data
- * The data for fishing
- * @return The player can start to fish the spot
- */
- private static boolean meetsRequirements(Player player, FishingData data) {
- if (data == null) {
- return false;
- }
- if (player.playerLevel[10] < data.getLevelRequired()) {
- player.sendMessage("You need a fishing level of " + data.getLevelRequired() + " to fish here.");
- return false;
- }
- if (data.isBaitRequired() && player.getItems().playerHasItem(313)) {
- player.sendMessage("You need some fishing bait to fish here.");
- return false;
- }
- return true;
- }
- @Override
- public void execute() {
- if (getPlayer() == null || !getPlayer().isActive()) {
- stop();
- return;
- }
- if (!getPlayer().getItems().playerHasItem(data.getToolId(), 1)) {
- getPlayer().sendMessage("You need a " + player.getItems().getItemName(data.getToolId()) + " to fish here.");
- stop();
- return;
- }
- getPlayer().startAnimation(data.getAnimationId());
- getPlayer().getItems().addItem(data.getFishId(), 1);
- if (data.isSecondFishAvailable()) {
- getPlayer().getItems().addItem(data.getSecondFishId(), 1);
- }
- getPlayer().getPA().addSkillXP(data.getExperience(), Player.playerFishing);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement