Thread: [718] Basic Herb Diseasing Approach

Results 1 to 3 of 3
  1. #1 [718] Basic Herb Diseasing Approach 
    Registered Member
    Join Date
    Sep 2014
    Posts
    42
    Thanks given
    6
    Thanks received
    19
    Rep Power
    37
    So, I stress again as I do in the note up top that this is a rather elementary way of doing this, and can be applied to all of your crops. I just did it first for herbs, so that's why I'm posting it like this.
    I leave the implementation in Farming.java, along with what must be done to handle the curing of the herbs, up to you. I know it's not perfect, but it seems to work okay for me :/ Thoughts on how it can be improved?


    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;
    				}
    					
    			}
    		}
    	}
    
    }
    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    48 0x69

    Pax M's Avatar
    Join Date
    Oct 2013
    Posts
    2,008
    Thanks given
    36
    Thanks received
    488
    Rep Power
    2270
    Thanks for sharing
    Reply With Quote  
     

  4. #3  
    What?

    Luminous's Avatar
    Join Date
    Apr 2015
    Posts
    489
    Thanks given
    231
    Thanks received
    341
    Rep Power
    179
    Nice contribution, thanks for sharing.
    Reply With Quote  
     


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. [718+] Basic LootShare System
    By kalo93 in forum Tutorials
    Replies: 49
    Last Post: 02-20-2016, 01:31 AM
  2. [718 basic boss rating/points system 718 snippet]
    By im insane in forum Snippets
    Replies: 15
    Last Post: 08-29-2013, 06:22 AM
  3. 718 Basic compiler problem.
    By Apouzou in forum Help
    Replies: 64
    Last Post: 06-24-2013, 02:03 AM
  4. [718] Basic Version System
    By Benji in forum Snippets
    Replies: 13
    Last Post: 05-17-2013, 12:14 PM
  5. [718] Basic Prestige Dialogue
    By izaazkothawala in forum Snippets
    Replies: 7
    Last Post: 09-30-2012, 06:58 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •