Guest User

Untitled

a guest
May 4th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.48 KB | None | 0 0
  1.  
  2. /**
  3.  * Represents the various outfits a {@link Player} object can wield during the
  4.  * {@link Skilling} {@link Activity}, giving bonuses in the {@link Skill} they
  5.  * are training
  6.  *
  7.  * @author Jh_Angel
  8.  * @author Kaleem
  9.  * @version 1.1
  10.  *
  11.  */
  12. public enum SkillingOutfit {
  13.     CONSTRUCTION(21446, 21447, 21448, 21450, 21449),
  14.     COOKING(25180, 25181, 25182, 25183, 25184),
  15.     CRAFTING(25185, 25186, 25187, 215188, 21589),
  16.     FIREMAKING(new int[] { 13660, 13659 }, 0.05, 0.02),
  17.     FISHING(true, 24427, 24428, 24429, 24430),
  18.     HERBLORE(25190, 25191, 25192, 25193, 25194),
  19.     MINING(20789, 20791, 20790, 20788, 20787),
  20.     RUNECRAFTING(true, 21517, 21516, 21518, 21519),
  21.     SMITHING(25195, 25196, 25197, 25198, 25199),
  22.     THIEVING(true, 21480, 21481, 21482, 21483),
  23.     WOODCUTTING(true, 10941, 10939, 10940, 10933);
  24.  
  25.     /**
  26.      * Constructs a {@link SkillingOutfit} object
  27.      *
  28.      * @param other
  29.      *            Flags whether or not the {@link SkillingOutfit} is different
  30.      *            to others, causing the {@link #componentBonus} to be lower
  31.      * @param components
  32.      *            The {@link Item} components, done as a {@link Integer} array
  33.      *            to allow easier input
  34.      */
  35.     SkillingOutfit(boolean other, int... components) {
  36.         this(components, 0.05, 0.01);
  37.     }
  38.  
  39.     /**
  40.      * Constructs a {@link SkillingOutfit} object, defaulting at
  41.      * {@link #componentBonus 0.06}
  42.      *
  43.      * @param components
  44.      *            The {@link Item} components, done as a {@link Integer} array
  45.      *            to allow easier input
  46.      */
  47.     SkillingOutfit(int... components) {
  48.         this(components, 0.06, 0.01);
  49.     }
  50.  
  51.     /**
  52.      * Constructs a {@link SkillingOutfit} object
  53.      *
  54.      * @param components
  55.      *            The {@link Item} components, done as a {@link Integer} array
  56.      *            to allow easier input
  57.      * @param componentBonus
  58.      *            The {@link #componentBonus} of the {@link SkillingOutfit}
  59.      * @param defaultBonus
  60.      *            The {@link #defaultBonus} of the {@link SkillingOutfit}
  61.      */
  62.     SkillingOutfit(int[] components, double componentBonus, double defaultBonus) {
  63.         Preconditions.checkArgument(Skill.get(name()).isPresent(),
  64.                 "Name of enumeration must correspond to a Skill");
  65.         /*
  66.          * Preconditions.checkArgument(components.length == 5,
  67.          * "Component must compose of 5 items");
  68.          */
  69.         skill = Skill.get(name()).get();
  70.         for (int i = 0; i < components.length; i++) {
  71.             this.components[i] = new Item(i);
  72.         }
  73.         this.componentBonus = componentBonus;
  74.         this.defaultBonus = defaultBonus;
  75.     }
  76.  
  77.     /**
  78.      * Grabs the final modifier of a {@link Player} training a certain
  79.      * {@link Skill}
  80.      *
  81.      * @param player
  82.      *            The {@link Player} object
  83.      * @param skill
  84.      *            The {@link Skill} the {@link Player} is training
  85.      * @return A {@link double} representing the modifier
  86.      */
  87.     public static double get(Player player, Skill skill) {
  88.         double bonus = 1; // * Settings.MODIFIER;
  89.         Optional<SkillingOutfit> outfit = get(skill.name());
  90.         if (outfit.isPresent()) {
  91.             Item[] components = outfit.get().components;
  92.             if (player.equipment().containsAll(components)) {
  93.                 bonus = bonus * outfit.get().componentBonus;
  94.             } else if (player.equipment().contains(components, 1)) {
  95.                 bonus = bonus * outfit.get().defaultBonus;
  96.             }
  97.         }
  98.         return bonus;
  99.     }
  100.  
  101.     /**
  102.      * Gets a {@link Optional} based off input string
  103.      *
  104.      * @param string
  105.      *            The input string
  106.      * @return {@link Optional} consisting of an {@link SkillingOutfit} object
  107.      */
  108.     public static Optional<SkillingOutfit> get(String string) {
  109.         Predicate<SkillingOutfit> outfit = (SkillingOutfit s) -> s.name()
  110.                 .toLowerCase().equals(string);
  111.         return Arrays.stream(values()).filter(outfit).findFirst();
  112.     }
  113.  
  114.     /**
  115.      * The {@link Item} components that form a set
  116.      */
  117.     private Item[] components = new Item[5];
  118.  
  119.     /**
  120.      * The {@link Skill} required for the {@link #componentBonus} to take effect
  121.      */
  122.     private Skill skill;
  123.  
  124.     /**
  125.      * The modifier given once the {@link Player} is wielding all the
  126.      * {@link #components} in their {@link Player#equipment()}
  127.      */
  128.     private double componentBonus;
  129.  
  130.     /**
  131.      * The modifier given if the {@link Player} is not wielding all the
  132.      * {@link #components} in their {@link Player#equipment()}
  133.      */
  134.     private double defaultBonus;
  135.  
  136.     public Item[] getComponents() {
  137.         return components;
  138.     }
  139.  
  140.     public Skill getSkill() {
  141.         return skill;
  142.     }
  143.  
  144.     public double getComponentBonus() {
  145.         return componentBonus;
  146.     }
  147.  
  148.     public double getDefaultBonus() {
  149.         return defaultBonus;
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment