Thread: How would i do multi-fishing

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 How would i do multi-fishing 
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,890
    Thanks given
    612
    Thanks received
    207
    Rep Power
    551
    alright so for fishing with spots that have more than 1 possible fish to catch, how would i make it so there is a possibility to get both? I have included factors into the enum maybe that's a start but if someone could help me that would be great

    heres the class


    Code:
    package org.rs2server.rs2.model.skills;
    
    
    
    import java.util.HashMap;
    import java.util.Map;
    
    
    
    
    import org.rs2server.rs2.action.impl.HarvestingAction;
    import org.rs2server.rs2.model.Animation;
    import org.rs2server.rs2.model.GameObject;
    import org.rs2server.rs2.model.Item;
    import org.rs2server.rs2.model.Mob;
    import org.rs2server.rs2.model.NPC;
    import org.rs2server.rs2.model.Player;
    import org.rs2server.rs2.model.Skills;
    
    
    public class Fishing extends HarvestingAction {
    	
    	private Spot spot;
    	private NPC npc;
    	
    	public Fishing(Mob mob, NPC npc, Spot spot) { 
    		super(mob);
    		this.spot =  spot;
    		this.npc = npc;
    	} 
    	
    	
    	public enum Spot {
    
    
    		SHRIMP(332, 1, 0.50, 317, new short[] {303}, 100, 620),
    		TROUT(310, 20, 0.050, 335, new short[] {309, 314}, 100, 622),
    		SALMON(310, 30, 0.50, 331, new short[] {309, 314}, 100, 622),
    		LOBSTER(333, 40, 0.50, 377, new short[] {301}, 100, 619),
    		MONK(313, 62, 0.50, 7944, new short[] {305}, 100, 620);
    
    		/**
    		 * The npc id.
    		 */
    		private int npc;
    
    		/**
    		 * The level required to fish this.
    		 */
    		private int level;
    		
    		private double rate;
    		
    		/**
    		 * The Fish given
    		 */
    		private int fish;
    		
    		/**
    		 * The gear required
    		 */
    		
    		private short[] gear;
    		
    		private double exp;
    		private int anim;
    
    		/**
    		 * A list of spots.
    		 */
    		private static Map<Integer, Spot> spots = new HashMap<>();
    		
    		/**
    		 * Gets the list of hatchets.
    		 * @return The list of hatchets.
    		 */
    		  public static Spot forId(int npc) {
    	            return spots.get(npc);
    	        }
    	        
    	        /**
    	         * Populates the fish map.
    	         */
    	        static {
    	            for (Spot spot : Spot.values()) {
    	                spots.put(spot.npc, spot);
    	            }
    	        }
    		
    		
    		private Spot(int npc, int level, double rate, int fish, short[] gear, double exp, int anim) {
    			this.npc = npc;
    			this.level = level;
    			this.rate = rate;
    			this.fish = fish;
    			this.gear = gear;
    			this.exp = exp;
    			this.anim = anim;
    		}
    
    		/**
    		 * @return the id
    		 */
    		public int getNpc() {
    			return npc;
    		}
    		
    		/**
    		 * @return the level
    		 */
    		public int getLevel() {
    			return level;
    		}
    		public double getRate() {
    			return rate;
    		}
    		
    		/**
    		 * @return the animation
    		 */
    		public int getFish() {
    			return fish;
    		}
    		public short[] getGear() {
    			return gear;
    		}
    		public double getExp() {
    			return exp;
    		}
    		public int getAnim() {
    			return anim;
    		}
    	}
    	//if((spot.getLevel() * spot.rate) <= getMob().getSkills().getLevelForExperience(getSkill()) * (spot.rate/2))
    	
    	@Override
    	public Animation getAnimation() {
    		return Animation.create(spot.getAnim());
    	}
    
    	@Override
    	public int getCycleCount() {	
    		return 3;
    		//return (int) (getMob().getSkills().getLevelForExperience(getSkill()) * spot.getRate());
    	}
    
    	@Override
    	public double getExperience() {
    		return spot.getExp();
    	}
    
    	@Override
    	public GameObject getGameObject() {
    		return null;
    	}
    
    	@Override
    	public int getGameObjectMaxHealth() {
    		return 100;
    	}
    
    	@Override
    	public String getHarvestStartedMessage() {
    		return "you attempt to catch some fish";
    	}
    
    	@Override
    	public String getLevelTooLowMessage() {
    		return "You need a " + Skills.SKILL_NAME[getSkill()] + " level of " + spot.getLevel() + " to fish here.";
    	}
    
    
    	@Override
    	public int getRequiredLevel() {
    		return spot.getLevel();
    	}
    
    	@Override
    	public Item getReward() {
    		return new Item(spot.getFish(), 1);
    	}
    	@Override
    	public Item[] getConsumedItems() {
    		if(spot.gear.length > 1) {
    		return new Item[] { new Item(spot.gear[1])};
    		} else {
    			return new Item[] { new Item(spot.gear[0], 0)};
    		}
    	}
    
    	@Override
    	public int getSkill() {
    		return Skills.FISHING;
    	}
    
    	@Override
    	public String getSuccessfulHarvestMessage() {
    		return "You catch a " + getReward().getDefinition().getName().toLowerCase() + ".";
    	}
    
    	@Override
    	public boolean canHarvest() {
    		/**for(Spot spot : Spot.values()) {
    			if((getMob().getInventory().contains(spot.gear[0]))
    							&& getMob().getSkills().getLevelForExperience(getSkill()) >= spot.getRequiredLevel()) {
    				this.spot = spot;
    				break;
    			}
    		}**/
    		for(int item : spot.gear) {
    			if(!getMob().getInventory().contains(item)) {
    				getMob().getActionSender().sendMessage("You do not have the proper gear to fish here.");
    				return false;
    			}
    		}
    		return true;
    	}
    	
    	@Override
    	public String getInventoryFullMessage() {
    		return "Your inventory is too full to hold any more " + getReward().getDefinition().getName().toLowerCase() + ".";
    	}
    
    	@Override
    	public GameObject getReplacementObject() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@Override
    	public int getObjectRespawnTimer() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    	
    	public NPC getNPC() {
    		return npc;
    	}
    
    }
    Reply With Quote  
     

  2. #2  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Generate a random number anywhere from 0 to the size of the length of the array and have that be the index.
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Donator


    Join Date
    Sep 2011
    Posts
    1,086
    Thanks given
    390
    Thanks received
    406
    Rep Power
    327
    Code:
    		private int[] fish;
    
    		private Spot(int npc, int level, double rate, short[] gear, double exp, int anim, int... fish) {
    			this.npc = npc;
    			this.level = level;
    			this.rate = rate;
    			this.fish = fish;
    			this.gear = gear;
    			this.exp = exp;
    			this.anim = anim;
    		}
    
    		public int getFish() {
    			return fish[Your random number generator.nextInt(fish.length)];
    		}
    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,890
    Thanks given
    612
    Thanks received
    207
    Rep Power
    551
    Quote Originally Posted by Shamon King View Post
    Generate a random number anywhere from 0 to the size of the length of the array and have that be the index.
    should i also make trout and salmon in the same part of the enum like put them in array in 1 code of the enum? if that makes sense
    Reply With Quote  
     

  7. #5  
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,890
    Thanks given
    612
    Thanks received
    207
    Rep Power
    551
    Quote Originally Posted by Aphelion View Post
    Code:
    		private int[] fish;
    
    		private Spot(int npc, int level, double rate, , short[] gear, double exp, int anim, int... fish) {
    			this.npc = npc;
    			this.level = level;
    			this.rate = rate;
    			this.fish = fish;
    			this.gear = gear;
    			this.exp = exp;
    			this.anim = anim;
    		}
    
    		public int getFish() {
    			return fish[random.nextInt(fish.length)];
    		}
    so i should put salmon and trout in 1 array? like new int {salmon, trout} --- inside the enum?
    Reply With Quote  
     

  8. #6  
    Donator


    Join Date
    Sep 2011
    Posts
    1,086
    Thanks given
    390
    Thanks received
    406
    Rep Power
    327
    Quote Originally Posted by Andrew View Post
    so i should put salmon and trout in 1 array? like new int {salmon, trout} --- inside the enum?
    That is done for you by
    Code:
    int... fish
    Code:
    		SHRIMP(332, 1, 0.50, new short[] {303}, 100, 620, 317),
    		SALMON_TROUT(310, 30, 0.50, , new short[] {309, 314}, 100, 622, 331, TROUT ID HERE),
    		LOBSTER(333, 40, 0.50, new short[] {301}, 100, 619, 377),
    		MONK(313, 62, 0.50, new short[] {305}, 100, 620, 7944);
    Reply With Quote  
     

  9. Thankful user:


  10. #7  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Quote Originally Posted by Andrew View Post
    so i should put salmon and trout in 1 array? like new int {salmon, trout} --- inside the enum?
    Yes that's what "int... fish" does (refering to above poster) it's basicly the same as int[] fish. except all your ids would be at the end so it'd look like.

    Code:
    		MONK(313, 62, 0.50, new short[] {305}, 100, 620, fish1, fish2, fish3, fish anything else);
    Instead of.
    Code:
    		MONK(313, 62, 0.50, new short[] {305}, 100, 620, new short[] {fish1, fish2, fish3, fish anything else});
    Reply With Quote  
     

  11. Thankful user:


  12. #8  
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,890
    Thanks given
    612
    Thanks received
    207
    Rep Power
    551
    Quote Originally Posted by Aphelion View Post
    That is done for you by int...

    Code:
    		SHRIMP(332, 1, 0.50, new short[] {303}, 100, 620, 317),
    		SALMON_TROUT(310, 30, 0.50, , new short[] {309, 314}, 100, 622, 331, TROUT ID HERE),
    		LOBSTER(333, 40, 0.50, new short[] {301}, 100, 619, 377),
    		MONK(313, 62, 0.50, new short[] {305}, 100, 620, 7944);
    okay that makes sense, but i just am a little confused as to why not put an array in it, considering trout and salmon have different fishing levels and factors? rather than just placin the trout id in there.(sorry if this doesn't make sense, just trying to understand this rather than just copying and pasting)
    Reply With Quote  
     

  13. #9  
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,890
    Thanks given
    612
    Thanks received
    207
    Rep Power
    551
    Quote Originally Posted by Shamon King View Post
    Yes that's what "int... fish" does (refering to above poster) it's basicly the same as int[] fish. except all your ids would be at the end so it'd look like.

    Code:
    		MONK(313, 62, 0.50, new short[] {305}, 100, 620, fish1, fish2, fish3, fish anything else);
    Instead of.
    Code:
    		MONK(313, 62, 0.50, new short[] {305}, 100, 620, new short[] {fish1, fish2, fish3, fish anything else});
    ohhh thats really cool, thank you for explaing that to me, so if i were to lets say make a specific factor for each i would just do int[]{factor1, factor 2, factor 3} and it will link up with int...?
    Reply With Quote  
     

  14. #10  
    Donator


    Join Date
    Sep 2011
    Posts
    1,086
    Thanks given
    390
    Thanks received
    406
    Rep Power
    327
    Quote Originally Posted by Andrew View Post
    ohhh thats really cool, thank you for explaing that to me, so if i were to lets say make a specific factor for each i would just do int[]{factor1, factor 2, factor 3} and it will link up with int...?
    The only thing that is different is the level since the should also be 0.50 for trout. But yes you can do that.
    Reply With Quote  
     

  15. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. how would i do this
    By Lord Stark in forum Help
    Replies: 4
    Last Post: 01-12-2010, 01:02 AM
  2. Replies: 13
    Last Post: 12-22-2009, 04:43 AM
  3. how would i do this? Simplicity_Official/devo
    By u kno i owns in forum Help
    Replies: 4
    Last Post: 10-28-2009, 01:24 AM
  4. How Would I Do This?
    By Canownueasy` in forum Help
    Replies: 2
    Last Post: 10-16-2009, 05:29 PM
  5. How would i do a timer? [508]
    By Pie in forum Help
    Replies: 6
    Last Post: 03-25-2009, 02:09 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •