Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.29 KB | None | 0 0
  1. package com.rs.game.player.skills;
  2.  
  3. import com.rs.cache.loaders.ItemDefinitions;
  4. import com.rs.game.Animation;
  5. import com.rs.game.World;
  6. import com.rs.game.WorldObject;
  7. import com.rs.game.player.Player;
  8. import com.rs.utils.Utils;
  9.  
  10. public final class Woodcutting extends Skill {
  11.  
  12.     public static enum TreeDefinitions {
  13.         Normal_Tree(1, 25, 1511, 20, 4, 1341, 8, 0),
  14.         Oak_Tree(15, 37.5, 1521, 30, 4, 5554, 15, 15),
  15.         Willow_Tree(30,  67.5, 1519, 60, 4, 7399, 51, 15),
  16.         Maple_Tree(45,  100, 1517, 83, 16, 7400, 72, 10),
  17.         Yew_Tree(60,  175, 1515, 120, 17, 7402, 94, 10),
  18.         Ivy(68,  332.5, -1, 120, 17, 46319, 58, 10),
  19.         Magic_Tree(75,  250, 1513, 150, 21, 7401, 121, 10);
  20.         private int level;
  21.         private double xp;
  22.         private int logsId;
  23.         private int logBaseTime;
  24.         private int logRandomTime;
  25.         private int stumpId;
  26.         private int respawnDelay;
  27.         private int randomLifeProbability;
  28.        
  29.         private TreeDefinitions(int level, double xp, int logsId, int logBaseTime, int logRandomTime, int stumpId, int respawnDelay, int randomLifeProbability) {
  30.             this.level = level;
  31.             this.xp = xp;
  32.             this.logsId = logsId;
  33.             this.logBaseTime = logBaseTime;
  34.             this.logRandomTime = logRandomTime;
  35.             this.stumpId = stumpId;
  36.             this.respawnDelay = respawnDelay;
  37.             this.randomLifeProbability = randomLifeProbability;
  38.         }
  39.        
  40.         public int getLevel() {
  41.             return level;
  42.         }
  43.         public double getXp() {
  44.             return xp;
  45.         }
  46.  
  47.         public int getLogsId() {
  48.             return logsId;
  49.         }
  50.  
  51.         public int getLogBaseTime() {
  52.             return logBaseTime;
  53.         }
  54.  
  55.         public int getLogRandomTime() {
  56.             return logRandomTime;
  57.         }
  58.  
  59.         public int getStumpId() {
  60.             return stumpId;
  61.         }
  62.  
  63.         public int getRespawnDelay() {
  64.             return respawnDelay;
  65.         }
  66.  
  67.         public int getRandomLifeProbability() {
  68.             return randomLifeProbability;
  69.         }
  70.     }
  71.    
  72.     private WorldObject tree;
  73.     private TreeDefinitions definitions;
  74.    
  75.     private int emoteId;
  76.     private int axeTime;
  77.    
  78.     public Woodcutting(WorldObject tree, TreeDefinitions definitions) {
  79.         this.tree = tree;
  80.         this.definitions = definitions;
  81.     }
  82.    
  83.     @Override
  84.     public boolean start(Player player) {
  85.         if(!checkAll(player))
  86.             return false;
  87.         player.getPackets().sendGameMessage("You swing your hatchet at the "+(TreeDefinitions.Ivy == definitions ? "ivy" : "tree")+".");
  88.         //setWoodcuttingTime(player);
  89.         setSkillDelay(player, getWoodcuttingDelay(player));
  90.         return true;
  91.     }
  92.  
  93.     private int getWoodcuttingDelay(Player player) {
  94.         int wcTimer = definitions.getLogBaseTime() - player.getSkills().getLevel(8) - Utils.getRandom(axeTime);
  95.         if(wcTimer < 1+definitions.getLogRandomTime())
  96.             wcTimer = 1 + Utils.getRandom(definitions.getLogRandomTime());
  97.         return wcTimer;
  98.     }
  99.     private boolean checkAll(Player player) {
  100.         if(!hasAxe(player)) {
  101.             player.getPackets().sendGameMessage("You need a hatchet to chop down this tree.");
  102.             return false;
  103.         }
  104.         if(!setAxe(player)) {
  105.             player.getPackets().sendGameMessage("You dont have the required level to use that axe.");
  106.             return false;
  107.         }
  108.         if(!hasWoodcuttingLevel(player))
  109.             return false;
  110.         if (!player.getInventory().hasFreeSlots()){
  111.             player.getPackets().sendGameMessage("Not enough space in your inventory.");
  112.             return false;
  113.         }
  114.         return true;
  115.     }
  116.     private boolean hasWoodcuttingLevel(Player player) {
  117.         if(definitions.getLevel() > player.getSkills().getLevel(8)) {
  118.             player.getPackets().sendGameMessage( "You need a woodcutting level of " + definitions.getLevel() + " to chop down this tree.");
  119.             return false;
  120.         }
  121.         return true;
  122.     }
  123.     private boolean setAxe(Player player) {
  124.         int level = player.getSkills().getLevel(8);
  125.         int weaponId = player.getEquipment().getWeaponId();
  126.         if(weaponId != -1) {
  127.         switch(weaponId) {
  128.         case 6739: //dragon axe
  129.             if(level >= 61) {
  130.                 emoteId = 2846;
  131.                 axeTime = 13;
  132.                 return true;
  133.             }
  134.         break;
  135.         case 1359: //rune axe
  136.             if(level >= 41) {
  137.                 emoteId = 867;
  138.                 axeTime = 10;
  139.                 return true;
  140.             }
  141.         break;
  142.         case 1357: //adam axe
  143.             if(level >= 31) {
  144.                 emoteId = 869;
  145.                 axeTime = 7;
  146.                 return true;
  147.             }
  148.         break;
  149.         case 1355: //mit axe
  150.             if(level >= 21) {
  151.                 emoteId = 871;
  152.                 axeTime = 5;
  153.                 return true;
  154.             }
  155.         break;
  156.         case 1361: //black axe
  157.             if(level >= 11) {
  158.                 emoteId = 873;
  159.                 axeTime = 4;
  160.                 return true;
  161.             }
  162.         break;
  163.         case 1353: //steel axe
  164.             if(level >= 6) {
  165.                 emoteId = 875;
  166.                 axeTime = 3;
  167.                 return true;
  168.             }
  169.         break;
  170.         case 1349: //iron axe
  171.             emoteId = 877;
  172.             axeTime = 2;
  173.         return true;
  174.         case 1351: //bronze axe
  175.             emoteId = 879;
  176.             axeTime = 1;
  177.         return true;
  178.         case 13661: //Inferno adze
  179.             if(level >= 61) {
  180.                 emoteId = 10251;
  181.                 axeTime = 13;
  182.                 return true;
  183.             }
  184.         break;
  185.         }
  186.         }
  187.         if(player.getInventory().containsOneItem(6739)) {
  188.             if(level >= 61) {
  189.                 emoteId = 2846;
  190.                 axeTime = 13;
  191.                 return true;
  192.             }
  193.         }
  194.         if(player.getInventory().containsOneItem(1359)) {
  195.             if(level >= 41) {
  196.                 emoteId = 867;
  197.                 axeTime = 10;
  198.                 return true;
  199.             }
  200.         }
  201.         if(player.getInventory().containsOneItem(1357)) {
  202.             if(level >= 31) {
  203.                 emoteId = 869;
  204.                 axeTime = 7;
  205.                 return true;
  206.             }
  207.         }
  208.         if(player.getInventory().containsOneItem(1355)) {
  209.             if(level >= 21) {
  210.                 emoteId = 871;
  211.                 axeTime = 5;
  212.                 return true;
  213.             }
  214.         }
  215.         if(player.getInventory().containsOneItem(1361)) {
  216.             if(level >= 11) {
  217.                 emoteId = 873;
  218.                 axeTime = 4;
  219.                 return true;
  220.             }
  221.         }
  222.         if(player.getInventory().containsOneItem(1353)) {
  223.             if(level >= 6) {
  224.                 emoteId = 875;
  225.                 axeTime = 3;
  226.                 return true;
  227.             }
  228.         }
  229.         if(player.getInventory().containsOneItem(1349)) {
  230.             emoteId = 877;
  231.             axeTime = 2;
  232.             return true;
  233.         }
  234.         if(player.getInventory().containsOneItem(1351)) {
  235.             emoteId = 879;
  236.             axeTime = 1;
  237.             return true;
  238.         }
  239.         if(player.getInventory().containsOneItem(13661)) {
  240.             if(level >= 61) {
  241.                 emoteId = 10251;
  242.                 axeTime = 13;
  243.                 return true;
  244.             }
  245.         }
  246.         return false;
  247.        
  248.     }
  249.    
  250.     private boolean hasAxe(Player player) {
  251.         if(player.getInventory().containsOneItem(1351, 1349, 1353, 1355, 1357, 1361, 1359, 6739, 13661))
  252.             return true;
  253.         int weaponId = player.getEquipment().getWeaponId();
  254.         if(weaponId == -1)
  255.             return false;
  256.         switch(weaponId) {
  257.         case 1351://Bronze Axe
  258.         case 1349://Iron Axe
  259.         case 1353://Steel Axe
  260.         case 1361://Black Axe
  261.         case 1355://Mithril Axe
  262.         case 1357://Adamant Axe
  263.         case 1359://Rune Axe
  264.         case 6739://Dragon Axe
  265.         case 13661: //Inferno adze
  266.         return true;
  267.         default:
  268.             return false;
  269.         }
  270.        
  271.     }
  272.    
  273.  
  274.  
  275.     @Override
  276.     public boolean process(Player player) {
  277.         player.setNextAnimation(new Animation(emoteId));
  278.         return checkTree(player);
  279.     }
  280.    
  281.     @Override
  282.     public int processWithDelay(Player player) {
  283.         addLog(player);
  284.         if(Utils.getRandom(definitions.getRandomLifeProbability()) == 0) {
  285.             World.spawnTemporaryObject(new WorldObject(definitions.getStumpId(), tree.getType(), tree.getRotation(), tree.getX(), tree.getY(), tree.getPlane()), definitions.respawnDelay*600);
  286.             player.setNextAnimation(new Animation(-1));
  287.             return -1;
  288.         }
  289.         if (!player.getInventory().hasFreeSlots()){
  290.             player.setNextAnimation(new Animation(-1));
  291.             player.getPackets().sendGameMessage("Not enough space in your inventory.");
  292.             return -1;
  293.         }
  294.         return getWoodcuttingDelay(player);
  295.     }
  296.    
  297.     private void addLog(Player player) {
  298.         double xpBoost = 1.0;
  299.         if(player.getEquipment().getChestId() == 10939)
  300.             xpBoost += 0.8;
  301.         if(player.getEquipment().getLegsId() == 10940)
  302.             xpBoost += 0.6;
  303.         if(player.getEquipment().getHatId() == 10941)
  304.             xpBoost += 0.4;
  305.         if(player.getEquipment().getBootsId() == 10933)
  306.             xpBoost += 0.2;
  307.         player.getSkills().addXp(8, definitions.getXp()*xpBoost);
  308.         player.getInventory().addItem(definitions.getLogsId(), 1);
  309.         if(definitions == TreeDefinitions.Ivy) {
  310.             player.getPackets().sendGameMessage("You succesfully cut an ivy vine.", true);
  311.             //todo gfx
  312.         }else{
  313.             String logName = ItemDefinitions.getItemDefinitions(definitions.getLogsId()).getName().toLowerCase();
  314.             player.getPackets().sendGameMessage("You get some "+logName+ ".", true);
  315.             //todo infernal adze
  316.         }
  317.     }
  318.  
  319.    
  320.     private boolean checkTree(Player player) {
  321.         return World.getRegion(tree.getRegionId()).containsObject(tree.getId(), tree);
  322.     }
  323.  
  324.     @Override
  325.     public void stop(Player player) {
  326.         setSkillDelay(player, 3); //prevents from wc,att,wc,att without delay XD
  327.     }
  328.  
  329. }
Add Comment
Please, Sign In to add comment