iant06

Untitled

Sep 17th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. package scripts.moneymaking.iplankfarmer.equipment;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api2007.Banking;
  6. import org.tribot.api2007.Camera;
  7. import org.tribot.api2007.Equipment;
  8. import org.tribot.api2007.GroundItems;
  9. import org.tribot.api2007.Inventory;
  10. import org.tribot.api2007.NPCChat;
  11. import org.tribot.api2007.Player;
  12. import org.tribot.api2007.Skills;
  13. import org.tribot.api2007.Skills.SKILLS;
  14. import org.tribot.api2007.WebWalking;
  15. import org.tribot.api2007.types.RSGroundItem;
  16. import org.tribot.api2007.types.RSItem;
  17. import org.tribot.api2007.types.RSNPC;
  18.  
  19. import scripts.methods.Methods;
  20. import scripts.moneymaking.iplankfarmer.Script;
  21. import scripts.moneymaking.iplankfarmer.types.Plank;
  22. import scripts.moneymaking.iplankfarmer.types.ScriptTask;
  23. import scripts.moneymaking.iplankfarmer.types.State;
  24. import scripts.moneymaking.iplankfarmer.utils.Constants;
  25. import scripts.moneymaking.iplankfarmer.utils.Locations;
  26.  
  27. public class Axe {
  28.  
  29. private Script script;
  30.  
  31. public Axe(Script script) {
  32. setScript(script);
  33. switch(getScript().getTask()) {
  34. case CHOP_LOGS:
  35. case CHOP_AND_PLANK:
  36. setAxe();
  37. break;
  38. }
  39. }
  40.  
  41. public boolean setAxe() {
  42. return hasBrokenAxe() || hasBestAxe() || hasOtherAxe();
  43. }
  44.  
  45. public boolean isEquippable() {
  46. int wcLevel = Skills.getActualLevel(SKILLS.WOODCUTTING);
  47. int attackLevel = Skills.getActualLevel(SKILLS.ATTACK);
  48. int wcReq = getScript().getData().getAxeRequirement()[0];
  49. int attackReq = getScript().getData().getAxeRequirement()[1];
  50. if(wcLevel >= wcReq) {
  51. if(attackLevel >= attackReq) {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57.  
  58. public boolean hasBrokenAxe() {
  59. int[][] data = Constants.AXE_DATA;
  60. int broken = Constants.AXE_BROKEN_ID;
  61. for(int i = 0; i < data.length; i++) {
  62. int brokenId = data[i][broken];
  63. if(Equipment.isEquipped(brokenId)) {
  64. setAxeData(data[i]);
  65. return true;
  66. }
  67. RSItem[] item = Inventory.find(brokenId);
  68. if(item != null && item.length > 0) {
  69. setAxeData(data[i]);
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75.  
  76. public boolean hasAxe() {
  77. if(isAxeBroken()) {
  78. getScript().setState(State.WALKING_TO_BOB);
  79. return false;
  80. }
  81. RSItem[] axe = Inventory.find(getScript().getData().getAxeId());
  82. if(!wearing() && (axe == null || axe.length <= 0)) {
  83. return false;
  84. }
  85. return true;
  86. }
  87.  
  88. public boolean wearing() {
  89. if(isAxeBroken()) {
  90. getScript().setState(State.WALKING_TO_BOB);
  91. return false;
  92. }
  93. if(Equipment.isEquipped(getScript().getData().getAxeId())) {
  94. return true;
  95. }
  96. return false;
  97. }
  98.  
  99. public void walkToShop() {
  100. if(Locations.isInsideAxeShop()) {
  101. getScript().setState(State.REPAIRING_AXE);
  102. return;
  103. }
  104. WebWalking.walkTo(Locations.AXE_SHOP_TILE);
  105. if(isInAxeShop(3000)) {
  106. getScript().setState(State.REPAIRING_AXE);
  107. }
  108. }
  109.  
  110. public boolean isAxeBroken() {
  111. int brokenId = getScript().getData().getBrokenAxeId();
  112. if(Equipment.isEquipped(brokenId)) {
  113. return true;
  114. }
  115. RSItem[] i = Inventory.find(brokenId);
  116. if(i != null && i.length > 0) {
  117. return true;
  118. }
  119. return false;
  120. }
  121.  
  122. public boolean isHeadOnGround() {
  123. RSGroundItem[] head = GroundItems.find(getScript().getData().getAxeHeadId());
  124. if(head != null && head.length > 0) {
  125. return true;
  126. }
  127. return false;
  128. }
  129.  
  130. public void pickupHead() {
  131. RSGroundItem[] head = GroundItems.find(getScript().getData().getAxeHeadId());
  132. if(head != null && head.length > 0) {
  133. head[0].click("Take");
  134. }
  135. }
  136.  
  137. public void attachHead() {
  138. RSItem[] head = Inventory.find(getScript().getData().getAxeHeadId());
  139. RSItem[] handle = Inventory.find(Constants.AXE_HANDLE);
  140. if(head != null && head.length > 0
  141. && handle != null && handle.length > 0) {
  142. if(head[0].click("Use")) {
  143. if(handle[0].click("Use")){
  144. }
  145. }
  146. }
  147. }
  148.  
  149. public void repairAxe() {
  150. if(Locations.isInsideAxeShop()) {
  151. RSNPC bob = Methods.findNPCByModelPoints(new int[]{Constants.BOB});
  152. if(bob != null) {
  153. if(Inventory.isFull()) {
  154. switch(getScript().getPlank()) {
  155. case REGULAR:
  156. Inventory.drop(Constants.REG_LOGS);
  157. break;
  158. case OAK:
  159. Inventory.drop(Constants.OAK_LOGS);
  160. break;
  161. }
  162. }
  163. Camera.turnToTile(bob);
  164. int brokenId = getScript().getData().getBrokenAxeId();
  165. if(Equipment.isEquipped(brokenId)) {
  166. Equipment.remove(brokenId);
  167. }
  168. RSItem[] i = Inventory.find(brokenId);
  169. if(i != null && i.length > 0) {
  170. if(i[0].click("Use")) {
  171. if(bob.click("Use")) {
  172. if(bobInterface(1000)) {
  173. NPCChat.clickContinue(true);
  174. NPCChat.selectOption("Yes, please.", true);
  175. if(!isAxeBroken()) {
  176. int axesRepaired = getScript().getData().getAxesRepaired();
  177. getScript().getData().setAxesRepaired(axesRepaired + 1);
  178. getScript().setState(State.WALKING_TO_BANK);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. }
  187.  
  188. private int getBestAxeIndex() {
  189. int miningLevel = Skills.getActualLevel(Skills.SKILLS.WOODCUTTING);
  190. int[][] axes = Constants.AXE_DATA;
  191. for(int i = 0; i < axes.length; i++) {
  192. if(i == axes.length - 1) {
  193. if(miningLevel >= axes[i][1])
  194. return i;
  195. } else if(miningLevel > axes[i][1] && miningLevel >= axes[i + 1][1]) {
  196. continue;
  197. } else if(miningLevel >= axes[i][1] && i != axes.length - 1 && miningLevel < axes[i + 1][1]) {
  198. return i;
  199. }
  200. }
  201. return -1;
  202. }
  203.  
  204. private void equip(RSItem item) {
  205. getScript().getData().setTimeout(System.currentTimeMillis());
  206.  
  207. while(!Equipment.isEquipped(item.getID()) && !getScript().getData().isTimedOut(7000, 8000)) {
  208. item.click("Wield");
  209. isWieldingAxe(3000);
  210. }
  211. }
  212.  
  213. private void withdraw(RSItem item) {
  214. if(getScript().getBanking().openBankScreen()) {
  215. getScript().getData().setTimeout(System.currentTimeMillis());
  216.  
  217. while(Inventory.getCount(item.getID()) <= 0 && !getScript().getData().isTimedOut(7000, 8000)) {
  218. item.click("Withdraw-1");
  219. isAxeWithdrawn(2000);
  220. }
  221. Banking.close();
  222. }
  223. }
  224.  
  225. private void setAxeData(int[] data) {
  226. getScript().getData().setAxeId(data[Constants.AXE_ID]);
  227. getScript().getData().setAxeHeadId(data[Constants.AXE_HEAD_ID]);
  228. getScript().getData().setBrokenAxeId(data[Constants.AXE_BROKEN_ID]);
  229. getScript().getData().setAxeRequirement(new int[]{
  230. data[Constants.AXE_WOODCUT_REQ],
  231. data[Constants.AXE_ATTACK_REQ]});
  232. }
  233.  
  234. private boolean isInInventory(int index) {
  235. int[] data = Constants.AXE_DATA[index];
  236. if(Equipment.isEquipped(data[Constants.AXE_ID])) {
  237. setAxeData(data);
  238. return true;
  239. }
  240. int attackLevelRequired = data[1];
  241. RSItem[] axe = Inventory.find(data[0]);
  242.  
  243. if(axe != null && axe.length > 0) {
  244. setAxeData(data);
  245. if(Skills.getActualLevel(Skills.SKILLS.ATTACK) >= attackLevelRequired) {
  246. if(Banking.isBankScreenOpen()) {
  247. Banking.close();
  248. }
  249. equip(axe[0]);
  250. }
  251. return true;
  252. }
  253.  
  254. return false;
  255. }
  256.  
  257. private boolean isInBank(int index) {
  258. int[] data = Constants.AXE_DATA[index];
  259. if(Locations.isInsideBank() || Locations.isInsideCastleWars()) {
  260. if(getScript().getBanking().openBankScreen()) {
  261. RSItem[] axe = Banking.find(data[0]);
  262.  
  263. if(axe != null && axe.length > 0) {
  264. setAxeData(data);
  265. final ScriptTask TASK = getScript().getTask();
  266. final Plank PLANK = getScript().getPlank();
  267. if(TASK.equals(ScriptTask.CHOP_AND_PLANK)) {
  268. if(Locations.isInsideBank() && !PLANK.equals(Plank.TEAK) ||
  269. (Locations.isInsideCastleWars() && PLANK.equals(Plank.TEAK))) {
  270. withdraw(axe[0]);
  271. if(Banking.isBankScreenOpen()) {
  272. Banking.close();
  273. }
  274. if(isEquippable()) {
  275. equip(axe[0]);
  276. }
  277. return true;
  278. }
  279. }
  280. }
  281. }
  282. }
  283. return false;
  284. }
  285.  
  286. private boolean isWearing(int index) {
  287. if(Equipment.isEquipped(Constants.AXE_DATA[index][0])) {
  288. setAxeData(Constants.AXE_DATA[index]);
  289. return true;
  290. }
  291. return false;
  292. }
  293.  
  294. private boolean hasBestAxe() {
  295. int index = getBestAxeIndex();
  296. if(isWearing(index) || isInInventory(index) || isInBank(index)) {
  297. return true;
  298. }
  299. return false;
  300. }
  301.  
  302. private boolean hasOtherAxe() {
  303. for(int i = getBestAxeIndex(); i >= 0; i--) {
  304. if(isWearing(i) || isInInventory(i) || isInBank(i)) {
  305. return true;
  306. }
  307. }
  308. return false;
  309. }
  310.  
  311. private boolean bobInterface(int i) {
  312. long t = System.currentTimeMillis();
  313. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  314. if(NPCChat.getClickContinueInterface() != null) {
  315. return true;
  316. }
  317. getScript().sleep(50, 150);
  318. }
  319. return false;
  320. }
  321.  
  322. private boolean isInAxeShop(int time) {
  323. long t = System.currentTimeMillis();
  324. while (Timing.timeFromMark(t) < time + General.random(100, 200)) {
  325. if(Locations.isInsideAxeShop()) {
  326. return true;
  327. }
  328. if(!Player.isMoving()) {
  329. return false;
  330. }
  331. getScript().sleep(50, 150);
  332. }
  333. return false;
  334. }
  335.  
  336. private boolean isWieldingAxe(int time) {
  337. long t = System.currentTimeMillis();
  338. while (Timing.timeFromMark(t) < time + General.random(100, 200)) {
  339. if(Equipment.isEquipped(getScript().getData().getAxeId())) {
  340. return true;
  341. }
  342. getScript().sleep(50, 150);
  343. }
  344. return false;
  345. }
  346.  
  347. private boolean isAxeWithdrawn(int time) {
  348. long t = System.currentTimeMillis();
  349. while (Timing.timeFromMark(t) < time + General.random(100, 200)) {
  350. RSItem[] axe = Inventory.find(getScript().getData().getAxeId());
  351. if(axe != null && axe.length > 0) {
  352. return true;
  353. }
  354. getScript().sleep(50, 150);
  355. }
  356. return false;
  357. }
  358.  
  359. public void setScript(Script script) {
  360. this.script = script;
  361. }
  362.  
  363. public Script getScript() {
  364. return script;
  365. }
  366.  
  367. }
Advertisement
Add Comment
Please, Sign In to add comment