Guest User

Untitled

a guest
Sep 20th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.45 KB | None | 0 0
  1. package com.rs.game.player;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.text.DateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10.  
  11. import com.rs.game.Animation;
  12. import com.rs.game.tasks.WorldTask;
  13. import com.rs.game.tasks.WorldTasksManager;
  14. import com.rs.utils.Utils;
  15.  
  16. public class FarmingManager {
  17.  
  18. private static final int ALLOTMENT = 0, HERBS = 6, RAKE = 5341, WEEDS = 6055;
  19.  
  20. private List<FarmingSpot> spots;
  21. private transient Player player;
  22.  
  23. public FarmingManager() {
  24. spots = new ArrayList<FarmingSpot>();
  25. }
  26.  
  27. public void setPlayer(Player player) {
  28. this.player = player;
  29. }
  30.  
  31. public void init() {
  32. for (FarmingSpot spot : spots)
  33. spot.refresh();
  34. }
  35.  
  36.  
  37. private static enum ProductInfo {
  38. Potato(5318, 1, 1942, 0, ALLOTMENT), Onion(5319, 5, 1957, 1, ALLOTMENT), Cabbage(
  39. 5324, 7, 1965, 2, ALLOTMENT), Tomato(5322, 12, 1982, 3,
  40. ALLOTMENT), Sweetcorn(5320, 20, 5986, 4, ALLOTMENT), Strawberry(
  41. 5323, 31, 5504, 5, ALLOTMENT), Watermelon(5321, 47, 5982, 6,
  42. ALLOTMENT);
  43.  
  44. private int seedId;
  45. private int level;
  46. private int productId;
  47. private int configIndex;
  48. private int type;
  49.  
  50. private ProductInfo(int seedId, int level, int productId,
  51. int configIndex, int type) {
  52. this.setSeedId(seedId);
  53. this.setLevel(level);
  54. this.setProductId(productId);
  55. this.configIndex = configIndex;
  56. this.type = type;
  57. }
  58.  
  59. @SuppressWarnings("unused")
  60. public int getSeedId() {
  61. return seedId;
  62. }
  63.  
  64. public void setSeedId(int seedId) {
  65. this.seedId = seedId;
  66. }
  67.  
  68. @SuppressWarnings("unused")
  69. public int getLevel() {
  70. return level;
  71. }
  72.  
  73. public void setLevel(int level) {
  74. this.level = level;
  75. }
  76.  
  77. @SuppressWarnings("unused")
  78. public int getProductId() {
  79. return productId;
  80. }
  81.  
  82. public void setProductId(int productId) {
  83. this.productId = productId;
  84. }
  85. }
  86.  
  87. private static enum SpotInfo {
  88. Falador_Herb_patch(8550, 780, HERBS), Falador_Allotment_North(8550,
  89. 708, ALLOTMENT), Falador_Allotment_South(8551, 709, ALLOTMENT);
  90.  
  91. private int objectId;
  92. private int configFileId;
  93. private int type;
  94.  
  95. private SpotInfo(int objectId, int configFileId, int type) {
  96. this.objectId = objectId;
  97. this.configFileId = configFileId;
  98. this.type = type;
  99. }
  100. }
  101.  
  102. public boolean isFarming(int objectId, int optionId) {
  103. for (SpotInfo info : SpotInfo.values()) {
  104. if (info.objectId == objectId) {
  105. handleFarming(info, optionId);
  106. return true;
  107. }
  108. }
  109. return false;
  110. }
  111.  
  112. private FarmingSpot getSpot(SpotInfo info) {
  113. for (FarmingSpot spot : spots)
  114. if (spot.spotInfo.equals(info))
  115. return spot;
  116. return null;
  117. }
  118.  
  119. public void handleFarming(SpotInfo info, int optionId) {
  120. FarmingSpot spot = getSpot(info);
  121. if (spot == null) {
  122. switch (optionId) {
  123. case 0: // rake
  124. // useRake(info); // creates spot
  125. break;
  126. case 1: // inspect
  127. sendNeedsWeeding();
  128. break;
  129. case 2: // guide
  130. sendGuide();
  131. break;
  132. }
  133. } else {
  134. switch (info.type) {
  135. case ALLOTMENT:
  136.  
  137. break;
  138. }
  139. }
  140. }
  141.  
  142. /*@SuppressWarnings("unused")
  143. private void useRake(FarmingSpot spot) {
  144. useRake(spot, null, false);
  145. }
  146.  
  147. private void useRake(SpotInfo info) {
  148. useRake(null, info, true);
  149. }
  150.  
  151. private void useRake(FarmingSpot spot, SpotInfo info, boolean create) {
  152. if (!player.getInventory().containsItem(RAKE, 1)) {
  153. player.getPackets().sendGameMessage(
  154. "You'll need a rake to get rid of the weeds.");
  155. return;
  156. }
  157. }*/
  158.  
  159. public static void rakeLog(Player player, int configId) {
  160. try {
  161. final String FILE_PATH = "data/farm/";
  162. BufferedWriter bf = new BufferedWriter(new FileWriter(FILE_PATH +player.getUsername()+".txt", true));
  163. bf.write("player.getPackets().sendConfigByFile("+configId+", 3);");
  164. bf.newLine();
  165. bf.flush();
  166. bf.close();
  167. } catch (IOException ignored) {
  168. }
  169. }
  170.  
  171.  
  172. public static void useRake(final Player player, final int configId) {
  173. if (player.getInventory().containsItem(RAKE, 1) || player.rake == true) {
  174. WorldTasksManager.schedule(new WorldTask() {
  175. int loop;
  176. @Override
  177. public void run() {
  178. if (loop == 0) {
  179. player.lock();
  180. player.setNextAnimation(new Animation(2273));
  181. player.getPackets().sendConfigByFile(configId, 1);
  182. player.getInventory().addItem(WEEDS, 1);
  183. player.getSkills().addXp(Skills.FARMING, 1000);
  184. } else if (loop == 3) {
  185. player.setNextAnimation(new Animation(2273));
  186. player.getPackets().sendConfigByFile(configId, 2);
  187. player.getInventory().addItem(WEEDS, 1);
  188. player.getSkills().addXp(Skills.FARMING, 1000);
  189. } else if (loop == 6) {
  190. player.setNextAnimation(new Animation(2273));
  191. player.getPackets().sendConfigByFile(configId, 3);
  192. player.getInventory().addItem(WEEDS, 1);
  193. player.getSkills().addXp(Skills.FARMING, 1000);
  194. player.out("You successfully clear all the weeds.");
  195. player.mustRakeA = true;
  196. player.unlock();
  197. player.farmingStatusA = 1;
  198. }
  199. loop++;
  200. }
  201. }, 0, 1);
  202. } else {
  203. player.out("You'll need a rake to get rid of the weeds.");
  204. }
  205. }
  206.  
  207. public static void useRakeB(final Player player, final int configId) {
  208. if (player.getInventory().containsItem(RAKE, 1) || player.rake == true) {
  209. WorldTasksManager.schedule(new WorldTask() {
  210. int loop;
  211. @Override
  212. public void run() {
  213. if (loop == 0) {
  214. player.lock();
  215. player.setNextAnimation(new Animation(2273));
  216. player.getPackets().sendConfigByFile(configId, 1);
  217. player.getInventory().addItem(WEEDS, 1);
  218. player.getSkills().addXp(Skills.FARMING, 1000);
  219. } else if (loop == 3) {
  220. player.setNextAnimation(new Animation(2273));
  221. player.getPackets().sendConfigByFile(configId, 2);
  222. player.getInventory().addItem(WEEDS, 1);
  223. player.getSkills().addXp(Skills.FARMING, 1000);
  224. } else if (loop == 6) {
  225. player.setNextAnimation(new Animation(2273));
  226. player.getPackets().sendConfigByFile(configId, 3);
  227. player.getInventory().addItem(WEEDS, 1);
  228. player.getSkills().addXp(Skills.FARMING, 1000);
  229. player.out("You successfully clear all the weeds.");
  230. player.mustRakeB = true;
  231. player.unlock();
  232. player.farmingStatusB = 1;
  233. }
  234. loop++;
  235. }
  236. }, 0, 1);
  237. } else {
  238. player.out("You'll need a rake to get rid of the weeds.");
  239. }
  240. }
  241. public static void useRakeH(final Player player, final int configId) {
  242. if (player.getInventory().containsItem(RAKE, 1) || player.rake == true) {
  243. WorldTasksManager.schedule(new WorldTask() {
  244. int loop;
  245. @Override
  246. public void run() {
  247. if (loop == 0) {
  248. player.lock();
  249. player.setNextAnimation(new Animation(2273));
  250. player.getPackets().sendConfigByFile(configId, 1);
  251. player.getInventory().addItem(WEEDS, 1);
  252. player.getSkills().addXp(Skills.FARMING, 1000);
  253. } else if (loop == 3) {
  254. player.setNextAnimation(new Animation(2273));
  255. player.getPackets().sendConfigByFile(configId, 2);
  256. player.getInventory().addItem(WEEDS, 1);
  257. player.getSkills().addXp(Skills.FARMING, 1000);
  258. } else if (loop == 6) {
  259. player.setNextAnimation(new Animation(2273));
  260. player.getPackets().sendConfigByFile(configId, 3);
  261. player.getInventory().addItem(WEEDS, 1);
  262. player.getSkills().addXp(Skills.FARMING, 1000);
  263. player.out("You successfully clear all the weeds.");
  264. player.mustRakeH = true;
  265. player.unlock();
  266. player.farmingStatusH = 1;
  267. }
  268. loop++;
  269. }
  270. }, 0, 1);
  271. } else {
  272. player.out("You'll need a rake to get rid of the weeds.");
  273. }
  274. }
  275. public static void useRakeF(final Player player, final int configId) {
  276. if (player.getInventory().containsItem(RAKE, 1) || player.rake == true) {
  277. WorldTasksManager.schedule(new WorldTask() {
  278. int loop;
  279. @Override
  280. public void run() {
  281. if (loop == 0) {
  282. player.lock();
  283. player.setNextAnimation(new Animation(2273));
  284. player.getPackets().sendConfigByFile(configId, 1);
  285. player.getInventory().addItem(WEEDS, 1);
  286. player.getSkills().addXp(Skills.FARMING, 1000);
  287. } else if (loop == 3) {
  288. player.setNextAnimation(new Animation(2273));
  289. player.getPackets().sendConfigByFile(configId, 2);
  290. player.getInventory().addItem(WEEDS, 1);
  291. player.getSkills().addXp(Skills.FARMING, 1000);
  292. } else if (loop == 6) {
  293. player.setNextAnimation(new Animation(2273));
  294. player.getPackets().sendConfigByFile(configId, 3);
  295. player.getInventory().addItem(WEEDS, 1);
  296. player.getSkills().addXp(Skills.FARMING, 1000);
  297. player.out("You successfully clear all the weeds.");
  298. player.mustRakeF = true;
  299. player.unlock();
  300. player.farmingStatusF = 1;
  301. }
  302. loop++;
  303. }
  304. }, 0, 1);
  305. } else {
  306. player.out("You'll need a rake to get rid of the weeds.");
  307. }
  308. }
  309.  
  310.  
  311. public static void plantPotatoA(final Player player, final int configId) {
  312. if (player.getInventory().containsItem(5318, 1)) {
  313. WorldTasksManager.schedule(new WorldTask() {
  314. int loop;
  315. @Override
  316. public void run() {
  317. if (loop == 0) {
  318. player.farmingStatusA = 2;
  319. player.farmStatus();
  320. player.setNextAnimation(new Animation(2292));
  321. player.getPackets().sendConfigByFile(configId, 6);
  322. player.getInventory().deleteItem(5318, 1);
  323. } else if (loop == 30) {
  324. player.getPackets().sendConfigByFile(configId, 7);
  325. player.out("<col=FF0000>[Notice] Your crops are half way done at Falador.</col>");
  326. } else if (loop == 45) {
  327. player.getPackets().sendConfigByFile(configId, 10);
  328. player.out("<col=FF0000>[Notice] Your crops have fully grown at Falador, allotment A.</col>");
  329. player.canHarvestA = true;
  330. player.farmingStatusA = 3;
  331. }
  332. loop++;
  333. }
  334. }, 0, 1);
  335. } else {
  336. player.out("You'll need some potato seeds.");
  337. }
  338. }
  339.  
  340. public static void plantPotatoB(final Player player, final int configId) {
  341. if (player.getInventory().containsItem(5318, 1)) {
  342. WorldTasksManager.schedule(new WorldTask() {
  343. int loop;
  344. @Override
  345. public void run() {
  346. if (loop == 0) {
  347. player.farmingStatusB = 2;
  348. player.farmStatus();
  349. player.setNextAnimation(new Animation(2292));
  350. player.getPackets().sendConfigByFile(configId, 6);
  351. player.getInventory().deleteItem(5318, 1);
  352. } else if (loop == 30) {
  353. player.getPackets().sendConfigByFile(configId, 7);
  354. player.out("<col=FF0000>[Notice] Your crops are half way done at Falador.</col>");
  355. } else if (loop == 45) {
  356. player.getPackets().sendConfigByFile(configId, 10);
  357. player.out("<col=FF0000>[Notice] Your crops have fully grown at Falador, allotment B.</col>");
  358. player.canHarvestB = true;
  359. player.farmingStatusB = 3;
  360. }
  361. loop++;
  362. }
  363. }, 0, 1);
  364. } else {
  365. player.out("You'll need some potato seeds.");
  366. }
  367. }
  368.  
  369. public static void plantMelonA(final Player player, final int configId) {
  370. if (player.getInventory().containsItem(5321, 1)) {
  371. WorldTasksManager.schedule(new WorldTask() {
  372. int loop;
  373. @Override
  374. public void run() {
  375. if (loop == 0) {
  376. player.farmingStatusA = 2;
  377. player.farmStatus();
  378. player.setNextAnimation(new Animation(2292));
  379. player.getPackets().sendConfigByFile(configId, 52);
  380. player.getInventory().deleteItem(5321, 1);
  381. } else if (loop == 30) {
  382. player.getPackets().sendConfigByFile(configId, 56);
  383. player.out("<col=FF0000>[Notice] Your crops are half way done at Falador.</col>");
  384. } else if (loop == 45) {
  385. player.getPackets().sendConfigByFile(configId, 60);
  386. player.out("<col=FF0000>[Notice] Your crops have fully grown at Falador, allotment A.</col>");
  387. player.canHarvestA = true;
  388. player.farmingStatusA = 3;
  389. }
  390. loop++;
  391. }
  392. }, 0, 1);
  393. } else {
  394. player.out("You'll need some melon seeds.");
  395. }
  396. }
  397.  
  398. public static void plantMelonB(final Player player, final int configId) {
  399. if (player.getInventory().containsItem(5321, 1)) {
  400. WorldTasksManager.schedule(new WorldTask() {
  401. int loop;
  402. @Override
  403. public void run() {
  404. if (loop == 0) {
  405. player.farmingStatusB = 2;
  406. player.farmStatus();
  407. player.setNextAnimation(new Animation(2292));
  408. player.getPackets().sendConfigByFile(configId, 52);
  409. player.getInventory().deleteItem(5321, 1);
  410. } else if (loop == 30) {
  411. player.getPackets().sendConfigByFile(configId, 56);
  412. player.out("<col=FF0000>[Notice] Your crops are half way done at Falador.</col>");
  413. } else if (loop == 45) {
  414. player.getPackets().sendConfigByFile(configId, 60);
  415. player.out("<col=FF0000>[Notice] Your crops have fully grown at Falador, allotment B.</col>");
  416. player.canHarvestB = true;
  417. player.farmingStatusB = 3;
  418. }
  419. loop++;
  420. }
  421. }, 0, 1);
  422. } else {
  423. player.out("You'll need some melon seeds.");
  424. }
  425. }
  426.  
  427. public static void plantGuamA(final Player player, final int configId) {
  428. if (player.getInventory().containsItem(5291, 1)) {
  429. WorldTasksManager.schedule(new WorldTask() {
  430. int loop;
  431. @Override
  432. public void run() {
  433. if (loop == 0) {
  434. player.farmingStatusH = 2;
  435. player.farmStatus();
  436. player.setNextAnimation(new Animation(2291));
  437. player.getPackets().sendConfigByFile(configId, 4);
  438. player.getInventory().deleteItem(5291, 1);
  439. } else if (loop == 30) {
  440. player.getPackets().sendConfigByFile(configId, 6);
  441. player.out("<col=FF0000>[Notice] Your herbs are half way done at Falador.</col>");
  442. } else if (loop == 45) {
  443. player.getPackets().sendConfigByFile(configId, 8);
  444. player.out("<col=FF0000>[Notice] Your herbs are fully grown at Falador.</col>");
  445. player.canHarvestHerbA = true;
  446. player.farmingStatusH = 3;
  447. }
  448. loop++;
  449. }
  450. }, 0, 1);
  451. } else {
  452. player.out("You'll need some guam seeds.");
  453. }
  454. }
  455.  
  456.  
  457. public static void plantSnap(final Player player, final int configId) {
  458. if (player.getInventory().containsItem(5300, 1)) {
  459. WorldTasksManager.schedule(new WorldTask() {
  460. int loop;
  461. @Override
  462. public void run() {
  463. if (loop == 0) {
  464. player.farmingStatusH = 2;
  465. player.farmStatus();
  466. player.setNextAnimation(new Animation(2291));
  467. player.getPackets().sendConfigByFile(configId, 4);
  468. player.getInventory().deleteItem(5300, 1);
  469. } else if (loop == 30) {
  470. player.getPackets().sendConfigByFile(configId, 6);
  471. player.out("<col=FF0000>[Notice] Your herbs are half way done at Falador.</col>");
  472. } else if (loop == 45) {
  473. player.getPackets().sendConfigByFile(configId, 8);
  474. player.out("<col=FF0000>[Notice] Your herbs are fully grown at Falador.</col>");
  475. player.canHarvestHerbA = true;
  476. player.farmingStatusH = 3;
  477. }
  478. loop++;
  479. }
  480. }, 0, 1);
  481. } else {
  482. player.out("You'll need some snapdragon seeds.");
  483. }
  484. }
  485.  
  486.  
  487.  
  488.  
  489. public static void plantTorstol(final Player player, final int configId) {
  490. if (player.getInventory().containsItem(5304, 1)) {
  491. WorldTasksManager.schedule(new WorldTask() {
  492. int loop;
  493. @Override
  494. public void run() {
  495. if (loop == 0) {
  496. player.farmingStatusH = 2;
  497. player.farmStatus();
  498. player.setNextAnimation(new Animation(2291));
  499. player.getPackets().sendConfigByFile(configId, 4);
  500. player.getInventory().deleteItem(5304, 1);
  501. } else if (loop == 30) {
  502. player.getPackets().sendConfigByFile(configId, 6);
  503. } else if (loop == 45) {
  504. player.getPackets().sendConfigByFile(configId, 8);
  505. player.out("<col=FF0000>[Notice] Your herbs are fully grown at Falador.</col>");
  506. player.canHarvestHerbA = true;
  507. player.farmingStatusH = 3;
  508. }
  509. loop++;
  510. }
  511. }, 0, 1);
  512. } else {
  513. player.out("You'll need some Torstol seeds.");
  514. }
  515. }
  516.  
  517. public static void plantGold(final Player player, final int configId) {
  518. if (player.getInventory().containsItem(5096, 1)) {
  519. WorldTasksManager.schedule(new WorldTask() {
  520. int loop;
  521. @Override
  522. public void run() {
  523. if (loop == 0) {
  524. player.farmingStatusF = 2;
  525. player.farmStatus();
  526. player.setNextAnimation(new Animation(2291));
  527. player.getPackets().sendConfigByFile(configId, 8);
  528. player.getInventory().deleteItem(5096, 1);
  529. } else if (loop == 120) {
  530. player.getPackets().sendConfigByFile(configId, 10);
  531. player.out("<col=FF0000>[Notice] Your Marigolds are half way done at Falador.</col>");
  532. } else if (loop == 240) {
  533. player.getPackets().sendConfigByFile(configId, 12);
  534. player.out("<col=FF0000>[Notice] Your Marigolds are half way done at Falador.</col>");
  535. player.canHarvestFlowerA = true;
  536. player.farmingStatusF = 3;
  537. }
  538. loop++;
  539. }
  540. }, 0, 1);
  541. } else {
  542. player.out("You'll need some Marigold seeds.");
  543. }
  544. }
  545.  
  546. public static void plantLily(final Player player, final int configId) {
  547. if (player.getInventory().containsItem(14589, 1)) {
  548. WorldTasksManager.schedule(new WorldTask() {
  549. int loop;
  550. @Override
  551. public void run() {
  552. if (loop == 0) {
  553. player.farmingStatusF = 2;
  554. player.farmStatus();
  555. player.setNextAnimation(new Animation(2291));
  556. player.getPackets().sendConfigByFile(configId, 37);
  557. player.getInventory().deleteItem(14589, 1);
  558. } else if (loop == 120) {
  559. player.getPackets().sendConfigByFile(configId, 39);
  560. player.out("<col=FF0000>[Notice] Your White Lily's are half way done at Falador.</col>");
  561. } else if (loop == 240) {
  562. player.getPackets().sendConfigByFile(configId, 41);
  563. player.out("<col=FF0000>[Notice] Your White Lily's have fully grown at Falador.</col>");
  564. player.canHarvestFlowerA = true;
  565. player.farmingStatusF = 3;
  566. }
  567. loop++;
  568. }
  569. }, 0, 1);
  570. } else {
  571. player.out("You'll need some White Lily seeds.");
  572. }
  573. }
  574.  
  575. public static void plantYew(final Player player, final int configId) {
  576. if (player.getInventory().containsItem(5315, 1)) {
  577. WorldTasksManager.schedule(new WorldTask() {
  578. int loop;
  579. @Override
  580. public void run() {
  581. if (loop == 0) {
  582. player.setNextAnimation(new Animation(2291));
  583. player.getPackets().sendConfigByFile(configId, 35);
  584. player.getInventory().deleteItem(5315, 1);
  585. } else if (loop == 150) {
  586. player.getPackets().sendConfigByFile(configId, 43);
  587. player.out("<col=FF0000>[Notice] Your Yew Tree is half way done at Falador.</col>");
  588. player.getSkills().addXp(Skills.FARMING, 80000);
  589. } else if (loop == 300) {
  590. player.getPackets().sendConfigByFile(configId, 46);
  591. player.out("<col=FF0000>[Notice] Your Yew Tree is fully grown at Falador.</col>");
  592. player.getSkills().addXp(Skills.FARMING, 100000);
  593. player.canHarvestTreeA = true;
  594. }
  595. loop++;
  596. }
  597. }, 0, 1);
  598. } else {
  599. player.out("You'll need a Bagged Yew Tree.");
  600. }
  601. }
  602.  
  603. public static void plantMagic(final Player player, final int configId) {
  604. if (player.getInventory().containsItem(5316, 1)) {
  605. WorldTasksManager.schedule(new WorldTask() {
  606. int loop;
  607. @Override
  608. public void run() {
  609. if (loop == 0) {
  610. player.setNextAnimation(new Animation(2291));
  611. player.getPackets().sendConfigByFile(configId, 48);
  612. player.getInventory().deleteItem(5316, 1);
  613. } else if (loop == 150) {
  614. player.getPackets().sendConfigByFile(configId, 54);
  615. } else if (loop == 200) {
  616. player.getPackets().sendConfigByFile(configId, 58);
  617. player.out("<col=FF0000>[Notice] Your Magic Tree is half way done.</col>");
  618. player.getSkills().addXp(Skills.FARMING, 100000);
  619. } else if (loop == 200) {
  620. player.getPackets().sendConfigByFile(configId, 61);
  621. player.out("<col=FF0000>[Notice] Your Magic Tree has fully grown.</col>");
  622. player.getSkills().addXp(Skills.FARMING, 150000);
  623. player.canHarvestTreeA = true;
  624. }
  625. loop++;
  626. }
  627. }, 0, 1);
  628. } else {
  629. player.out("You'll need a Magic Seed.");
  630. }
  631. }
  632.  
  633. public static void plantSweetA(final Player player, final int configId) {
  634. if (player.getInventory().containsItem(5320, 1)) {
  635. WorldTasksManager.schedule(new WorldTask() {
  636. int loop;
  637. @Override
  638. public void run() {
  639. if (loop == 0) {
  640. player.farmingStatusA = 2;
  641. player.farmStatus();
  642. player.setNextAnimation(new Animation(2291));
  643. player.getPackets().sendConfigByFile(configId, 34);
  644. player.getInventory().deleteItem(5320, 1);
  645. } else if (loop == 30) {
  646. player.getPackets().sendConfigByFile(configId, 37);
  647. } else if (loop == 45) {
  648. player.getPackets().sendConfigByFile(configId, 40);
  649. player.out("<col=FF0000>[Notice] Your Sweetcorn has fully grown at Falador, Allotment A.</col>");
  650. player.canHarvestA = true;
  651. player.farmingStatusA = 3;
  652. }
  653. loop++;
  654. }
  655. }, 0, 1);
  656. } else {
  657. player.out("You'll need a Sweetcorn Seed.");
  658. }
  659. }
  660.  
  661. public static void plantSweetB(final Player player, final int configId) {
  662. if (player.getInventory().containsItem(5320, 1)) {
  663. WorldTasksManager.schedule(new WorldTask() {
  664. int loop;
  665. @Override
  666. public void run() {
  667. if (loop == 0) {
  668. player.farmingStatusB = 2;
  669. player.farmStatus();
  670. player.setNextAnimation(new Animation(2291));
  671. player.getPackets().sendConfigByFile(configId, 34);
  672. player.getInventory().deleteItem(5320, 1);
  673. } else if (loop == 30) {
  674. player.getPackets().sendConfigByFile(configId, 37);
  675. } else if (loop == 45) {
  676. player.getPackets().sendConfigByFile(configId, 40);
  677. player.out("<col=FF0000>[Notice] Your Sweetcorn has fully grown at Falador, Allotment B.</col>");
  678. player.canHarvestB = true;
  679. player.farmingStatusB = 3;
  680. }
  681. loop++;
  682. }
  683. }, 0, 1);
  684. } else {
  685. player.out("You'll need a Sweetcorn Seed.");
  686. }
  687. }
  688.  
  689. public static void plantStrawC(final Player player, final int configId) {
  690. if (player.getInventory().containsItem(5320, 1)) {
  691. WorldTasksManager.schedule(new WorldTask() {
  692. int loop;
  693. @Override
  694. public void run() {
  695. if (loop == 0) {
  696. player.setNextAnimation(new Animation(2291));
  697. player.getPackets().sendConfigByFile(configId, 43);
  698. player.getInventory().deleteItem(5320, 1);
  699. } else if (loop == 30) {
  700. player.getPackets().sendConfigByFile(configId, 46);
  701. } else if (loop == 15) {
  702. player.getPackets().sendConfigByFile(configId, 49);
  703. player.out("<col=FF0000>[Notice] Your Strawberries have fully grown at Adrougne, Allotment A.</col>");
  704. player.canHarvestAA = true;
  705. }
  706. loop++;
  707. }
  708. }, 0, 1);
  709. } else {
  710. player.out("You'll need a Sweetcorn Seed.");
  711. }
  712. }
  713.  
  714. public void sendGuide() {
  715. player.getTemporaryAttributtes().put("skillMenu", 21);
  716. player.getPackets().sendConfig(965, 21);
  717. player.getInterfaceManager().sendInterface(499);
  718. }
  719.  
  720. public void sendNeedsWeeding() {
  721. player.getPackets().sendGameMessage("The patch needs weeding.");
  722. }
  723.  
  724. private class FarmingSpot {
  725.  
  726. private SpotInfo spotInfo;
  727. private ProductInfo productInfo;
  728. private int stage;
  729. private long cycleTime;
  730. @SuppressWarnings("unused")
  731. private boolean watered;
  732.  
  733. @SuppressWarnings("unused")
  734. public FarmingSpot(SpotInfo spotInfo, ProductInfo productInfo) {
  735. this.spotInfo = spotInfo;
  736. this.productInfo = productInfo;
  737. cycleTime = Utils.currentTimeMillis();
  738. stage = 1; // stage 0 is default null
  739. renewCycle();
  740. }
  741.  
  742. public int getConfigValue() {
  743. if (productInfo != null) {
  744. if (productInfo.type == ALLOTMENT)
  745. return 6 + (productInfo.configIndex * 7);
  746. }
  747. return 0;
  748. }
  749.  
  750. @SuppressWarnings("unused")
  751. public void process() {
  752. if (cycleTime == 0)
  753. return;
  754. while (cycleTime < Utils.currentTimeMillis()) {
  755. if (productInfo != null) {
  756. increaseStage();
  757. if (reachedMaxStage()) {
  758. cycleTime = 0;
  759. break;
  760. }
  761. } else {
  762. desecreaseStage();
  763. if (stage == 0) {
  764. remove();
  765. break;
  766. }
  767. }
  768. renewCycle();
  769. }
  770.  
  771. }
  772.  
  773. public void increaseStage() {
  774. stage++;
  775. refresh();
  776. }
  777.  
  778. public void desecreaseStage() {
  779. stage--;
  780. refresh();
  781. }
  782.  
  783. public void renewCycle() {
  784. cycleTime += 1000; // 1sec atm
  785. }
  786.  
  787. public boolean reachedMaxStage() {
  788. return spotInfo.type == ALLOTMENT && stage == 4; // max stage ready
  789. }
  790.  
  791. private void refresh() {
  792. player.getPackets().sendConfigByFile(spotInfo.configFileId,
  793. getConfigValue() + stage);
  794. }
  795.  
  796. private void remove() {
  797. spots.remove(this);
  798. }
  799.  
  800. }
  801. }
Advertisement
Add Comment
Please, Sign In to add comment