armark1ng

Untitled

Jul 21st, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.88 KB | None | 0 0
  1. package com.rs.game.player;
  2.  
  3. import java.io.Serializable;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.concurrent.CopyOnWriteArrayList;
  8.  
  9. import com.rs.Settings;
  10. import com.rs.cache.loaders.ItemDefinitions;
  11. import com.rs.cache.loaders.ObjectDefinitions;
  12. import com.rs.game.Animation;
  13. import com.rs.game.item.Item;
  14. import com.rs.game.player.actions.Action;
  15. import com.rs.game.player.actions.WaterFilling;
  16. import com.rs.game.player.actions.Woodcutting;
  17. import com.rs.game.player.actions.Woodcutting.HatchetDefinitions;
  18. import com.rs.game.player.actions.Woodcutting.TreeDefinitions;
  19. import com.rs.game.player.dialogues.Dialogue;
  20. import com.rs.game.tasks.WorldTask;
  21. import com.rs.game.tasks.WorldTasksManager;
  22. import com.rs.net.decoders.handlers.ButtonHandler;
  23. import com.rs.utils.Utils;
  24.  
  25. public class FarmingManager implements Serializable {
  26.  
  27. private static final long serialVersionUID = -6487741852718632170L;
  28.  
  29. private static final int REGENERATION_CONSTANT = Settings.DEBUG ? 5000 : 120000; // Twelve
  30. // minutes
  31. private static final int ALLOTMENT = 0, TREES = 1, HOPS = 2, FLOWERS = 3, FRUIT_TREES = 4, BUSHES = 5, HERBS = 6,
  32. COMPOST = 7, RAKE = 5341, EMPTY_BUCKET = 1925;
  33.  
  34. private static final String[] PATCH_NAMES = { "allotment", "tree", "hops", "flower", "fruit tree", "bush", "herb" };
  35. private static final int[][] HARVEST_AMOUNTS = { { 3, 53 }, { 1, 1 }, { 3, 41 }, { 1, 3 }, { 3, 5 }, { 3, 5 },
  36. { 3, 18 } };
  37. public static final int[] COMPOST_ORGANIC = { 6055, 1942, 1957, 1965, 5986, 5504, 5982, 249, 251, 253, 255, 257,
  38. 2998, 259, 261, 263, 3000, 265, 2481, 267, 269, 1951, 753, 2126, 247, 239, 6018 };
  39. public static final int[] SUPER_COMPOST_ORGANIC = { 2114, 5978, 5980, 5982, 6004, 247, 6469 };
  40. private static final Animation RAKING_ANIMATION = new Animation(2273), WATERING_ANIMATION = new Animation(2293),
  41. SEED_DIPPING_ANIMATION = new Animation(2291), SPADE_ANIMATION = new Animation(830),
  42. HERB_PICKING_ANIMATION = new Animation(2282), MAGIC_PICKING_ANIMATION = new Animation(2286),
  43. CURE_PLANT_ANIMATION = new Animation(2288), CHECK_TREE_ANIMATION = new Animation(832),
  44. PRUNING_ANIMATION = new Animation(2275), FLOWER_PICKING_ANIMATION = new Animation(2292),
  45. FRUIT_PICKING_ANIMATION = new Animation(2280), COMPOST_ANIMATION = new Animation(2283),
  46. BUSH_PICKING_ANIMATION = new Animation(2281), FILL_COMPOST_ANIMATION = new Animation(832);
  47.  
  48. private List<FarmingSpot> spots;
  49. private transient Player player;
  50.  
  51. public boolean isAlwaysWeeded = false;
  52.  
  53. public FarmingManager() {
  54. spots = new CopyOnWriteArrayList<FarmingSpot>();
  55. }
  56.  
  57. public void setPlayer(Player player) {
  58. this.player = player;
  59. }
  60.  
  61. public void init() {
  62. for (FarmingSpot spot : spots)
  63. spot.refresh();
  64. }
  65.  
  66. public void process() {
  67. for (FarmingSpot spot : spots)
  68. spot.process();
  69. }
  70.  
  71. public static enum ProductInfo {
  72.  
  73. /**
  74. * Allotments
  75. */
  76. Potato(5318, 1, 1942, 0, 8, 9, 10, new Item(6032, 2), ALLOTMENT), Onion(5319, 5, 1957, 1, 9.5, 10.5, 10, new Item(5438, 1), ALLOTMENT), Cabbage(5324, 7, 1965, 2, 10, 11.5, 10, new Item(5458, 1), ALLOTMENT), Tomato(5322, 12, 1982, 3, 12.5, 14, 10, new Item(5478, 2), ALLOTMENT), Sweetcorn(5320, 20, 5986, 4, 17, 19, 10, 6, new Item(5931, 10), ALLOTMENT), Strawberry(5323, 31, 5504, 5, 26, 29, 10, 6, 2, new Item(5386, 1), ALLOTMENT), Watermelon(5321, 47, 5982, 6, 48.5, 54.5, 10, 8, 4, new Item(5970, 10), ALLOTMENT),
  77.  
  78. /**
  79. * Herbs
  80. */
  81. Guam(5291, 9, 199, 0, 11, 12.5, 20, HERBS), Marrentill(5292, 14, 201, 1, 13.5, 15, 20, HERBS), Tarromin(5293, 19, 203, 2, 16, 18, 20, HERBS), Harralander(5294, 26, 205, 3, 21.5, 24, 20, HERBS), Rannar(5295, 32, 207, 4, 27, 30.5, 20, HERBS), Toadflax(5296, 38, 3049, 5, 34, 38.5, 20, HERBS), Irit(5297, 44, 209, 6, 43, 48.5, 20, HERBS), Avantoe(5298, 50, 211, 7, 54.4, 61.5, 20, HERBS), Kwuarm(5299, 56, 213, 6, 69, 78, 20, HERBS), Snapdragon(5300, 62, 3051, 6, 87.5, 98.5, 20, HERBS), Cadantine(5301, 67, 215, 6, 106.5, 120, 20, HERBS), Lantadyme(5302, 73, 2485, 6, 134.5, 151.5, 20, HERBS), Dwarf(5303, 79, 217, 6, 170.5, 192, 20, HERBS), Torstol(5304, 85, 219, 6, 199.5, 224.5, 20, HERBS), Fellstalk(21621, 91, 21626, 6, 225, 315.6, 20, HERBS), Wergali(14870, 46, 213, 8, 52.8, 52.8, 20, HERBS), Gout(6311, 65, 3261, 27, 105, 45, 20, HERBS),
  82.  
  83. /**
  84. * Flowers
  85. */
  86. Marigold(5096, 2, 6010, 0, 8.5, 47, 5, FLOWERS), Rosemary(5097, 11, 6014, 1, 12, 66.5, 5, FLOWERS), Nasturtium(5098, 24, 6012, 2, 19.5, 111, 5, FLOWERS), Woad(5099, 25, 1793, 3, 20.5, 115.5, 5, FLOWERS), Limpwurt(5100, 26, 225, 4, 21.5, 120, 5, FLOWERS), White_lily(14589, 52, 14583, 6, 70, 250, 20, 4, -1, FLOWERS),
  87.  
  88. /**
  89. * Hops
  90. */
  91. Barley(5305, 3, 6006, 9, 8.5, 9.5, 10, 4, 1, new Item(6032, 3), HOPS), Hammerstone(5307, 4, 5994, 0, 9, 10, 10, 4, 1, new Item(6010, 1), HOPS), Asgarnian(5308, 8, 5996, 1, 10.9, 12, 10, 5, 3, new Item(5458, 1), HOPS), Jute(5306, 13, 5931, 10, 13, 14.5, 10, 5, 3, new Item(6008, 6), HOPS), Yanillian(5309, 16, 5998, 3, 14.5, 16, 10, 6, 1, new Item(5968, 1), HOPS), Krandorian(5310, 21, 6000, 5, 17.5, 19.5, 10, 7, new Item(5478, 3), HOPS), Wildbood(5311, 28, 6002, 7, 23, 26, 10, 7, 1, new Item(6012, 1), HOPS),
  92.  
  93. /**
  94. * Trees
  95. */
  96. Oak(5370, 15, 6043, 1, 467.3, 14, 40, new Item(5968, 1), TREES), Willow(5371, 30, 6045, 6, 1456.5, 25, 40, 6, new Item(5386, 1), TREES), Maple(5372, 45, 6047, 17, 3403.4, 45, 40, 8, new Item(5396, 1), TREES), Yew(5373, 60, 6049, 26, 7069.9, 81, 40, 10, new Item(6016, 10), TREES), Magic(5374, 75, 6051, 41, 13768.3, 145.5, 40, 12, new Item(5974, 25), TREES),
  97.  
  98. /**
  99. * Trees of the fruits :)
  100. */
  101. Apple(5496, 27, 1955, 1, 1199.5, 22, 160, 6, new Item(5986, 9), FRUIT_TREES), Banana(5497, 33, 1963, 26, 1841.5, 28, 160, 6, new Item(5386, 4), FRUIT_TREES), Orange(5498, 39, 2108, 65, 2470.2, 35.5, 160, 6, new Item(5406, 3), FRUIT_TREES), Curry(5499, 42, 5970, 90, 2906.9, 40, 160, 6, new Item(5416, 5), FRUIT_TREES), Pineapple(5500, 51, 2114, 129, 4605.7, 57, 160, 6, new Item(5982, 10), FRUIT_TREES), Papaya(5501, 57, 5972, 154, 6146.4, 72, 160, 6, new Item(2114, 10), FRUIT_TREES), Palm(5502, 68, 5974, 193, 10150.1, 110.5, 160, 6, new Item(5972, 15), FRUIT_TREES),
  102.  
  103. /**
  104. * Bushes of the bush
  105. */
  106. Redberry(5101, 10, 1951, -4, 64, 11.5, 20, 5, new Item(5478, 4), BUSHES), Cadavaberry(5102, 22, 753, 6, 102.5, 18, 20, 6, new Item(5968, 3), BUSHES), Dwellberry(5103, 36, 2126, 19, 177.5, 31.5, 20, 7, new Item(5406, 3), BUSHES), Jangerberry(5104, 48, 247, 31, 284.5, 50.5, 20, 8, new Item(5982, 6), BUSHES), Whiteberry(5105, 59, 239, 42, 437.5, 78, 20, 8, new Item(6004, 8), BUSHES), Poison_ivy(5106, 70, 6018, 188, 675, 120, 20, 8, BUSHES),
  107.  
  108. Compost_Bin(7836, 1, -1, 0, 8, 14, 2, 15, COMPOST);
  109.  
  110. private static Map<Short, ProductInfo> products = new HashMap<Short, ProductInfo>();
  111.  
  112. public static ProductInfo getProduct(int itemId) {
  113. return products.get((short) itemId);
  114. }
  115.  
  116. static {
  117. for (ProductInfo product : ProductInfo.values()) {
  118. products.put((short) product.seedId, product);
  119. }
  120. }
  121.  
  122. private int seedId;
  123. private int level;
  124. private int productId;
  125. private int configIndex;
  126. private int type;
  127. private int maxStage;
  128. private int stageSkip;
  129. private double experience, plantingExperience;
  130. private int cycleTime;
  131. private Item protectionItem;
  132.  
  133. private ProductInfo(int seedId, int level, int productId, int configIndex, double plantingExperience,
  134. double experience, int cycleTime, int maxStage, int stageSkip, Item protectionItem, int type) {
  135. this.seedId = seedId;
  136. this.level = level;
  137. this.productId = productId;
  138. this.configIndex = configIndex;
  139. this.plantingExperience = plantingExperience;
  140. this.experience = experience;
  141. this.cycleTime = cycleTime;
  142. this.maxStage = maxStage;
  143. this.stageSkip = stageSkip;
  144. this.protectionItem = protectionItem;
  145. this.type = type;
  146. }
  147.  
  148. private ProductInfo(int seedId, int level, int productId, int configIndex, double plantingExperience,
  149. double experience, int cycleTime, int maxStage, int stageSkip, int type) {
  150. this(seedId, level, productId, configIndex, plantingExperience, experience, cycleTime, maxStage, stageSkip,
  151. null, type);
  152. }
  153.  
  154. private ProductInfo(int seedId, int level, int productId, int configIndex, double plantingExperience,
  155. double experience, int cycleTime, int maxStage, Item protectionItem, int type) {
  156. this(seedId, level, productId, configIndex, plantingExperience, experience, cycleTime, maxStage, 0,
  157. protectionItem, type);
  158. }
  159.  
  160. private ProductInfo(int seedId, int level, int productId, int configIndex, double plantingExperience,
  161. double experience, int cycleTime, int maxStage, int type) {
  162. this(seedId, level, productId, configIndex, plantingExperience, experience, cycleTime, maxStage, 0, null,
  163. type);
  164. }
  165.  
  166. private ProductInfo(int seedId, int level, int productId, int configIndex, double plantingExperience,
  167. double experience, int cycleTime, Item protectionItem, int type) {
  168. this(seedId, level, productId, configIndex, plantingExperience, experience, cycleTime, 4, 0, protectionItem,
  169. type);
  170. }
  171.  
  172. private ProductInfo(int seedId, int level, int productId, int configIndex, double plantingExperience,
  173. double experience, int cycleTime, int type) {
  174. this(seedId, level, productId, configIndex, plantingExperience, experience, cycleTime, 4, 0, null, type);
  175. }
  176.  
  177. public Item getProtectionItem() {
  178. return protectionItem;
  179. }
  180. }
  181.  
  182. public static enum SpotInfo {
  183.  
  184. Talvery_Tree(8388, TREES), Falador_Garden_Tree(8389, TREES), Varrock_Tree(8390, TREES), Lumbridge_Tree(8391,
  185. TREES), Gnome_Tree(19147, TREES),
  186.  
  187. Gnome_Strong_Fruit_Tree(7962, FRUIT_TREES), Gnome_Fruit_Tree(7963, FRUIT_TREES), Brimhaven_Fruit_Tree(7964,
  188. FRUIT_TREES), Catherby_Fruit_Tree(7965, FRUIT_TREES), Lletya_Fruit_Tree(28919, FRUIT_TREES),
  189.  
  190. Falador_Allotment_North(8550, ALLOTMENT), Falador_Allotment_South(8551, ALLOTMENT), Catherby_Allotment_North(
  191. 8552, ALLOTMENT), Catherby_Allotment_South(8553, ALLOTMENT), Ardougne_Allotment_North(8554,
  192. ALLOTMENT), Ardougne_Allotment_South(8555, ALLOTMENT), Canfis_Allotment_North(8556,
  193. ALLOTMENT), Canfis_Allotment_South(8557,
  194. ALLOTMENT), Harmony_Allotment(21950, ALLOTMENT),
  195.  
  196. Yannile_Hops_Patch(8173, HOPS), Talvery_Hops_Patch(8174, HOPS), Lumbridge_Hops_Patch(8175,
  197. HOPS), McGrubor_Hops_Patch(8176, HOPS),
  198.  
  199. Falador_Flower(7847, FLOWERS), Catherby_Flower(7848, FLOWERS), Ardougne_Flower(7849,
  200. FLOWERS), Canfis_Flower(7850, FLOWERS), wildy_ruins(37988, FLOWERS),
  201.  
  202. Champions_Bush(7577, BUSHES), Rimmington_Bush(7578, BUSHES), Etceteria_Bush(7579,
  203. BUSHES), South_Arddougne_Bush(7580, BUSHES),
  204.  
  205. Falador_Herb_Patch(8150, HERBS), Catherby_Herb_Patch(8151, HERBS), Ardougne_Herb_Patch(8152,
  206. HERBS), Canfis_Herb_Patch(8153, HERBS), TROLL_HEIM(18816, HERBS),
  207.  
  208. Falador_Compost_Bin(7836, COMPOST), Catherby_Bin(7837, COMPOST), Port_Phasymatis_Bin(7838,
  209. COMPOST), Ardougn_Bin(7839, COMPOST), Taverly_Bin(66577, COMPOST);
  210.  
  211. private static Map<Short, SpotInfo> informations = new HashMap<Short, SpotInfo>();
  212.  
  213. public static SpotInfo getInfo(int objectId) {
  214. return informations.get((short) objectId);
  215. }
  216.  
  217. static {
  218. for (SpotInfo information : SpotInfo.values())
  219. informations.put((short) information.objectId, information);
  220. }
  221.  
  222. private int objectId;
  223. private int configFileId;
  224. private int type;
  225.  
  226. private SpotInfo(int objectId, int type) {
  227. this.objectId = objectId;
  228. this.configFileId = ObjectDefinitions.getObjectDefinitions(objectId).configFileId;
  229. this.type = type;
  230. }
  231. }
  232.  
  233. public enum Gardeners {// We need type and object id and npcId
  234. ALAIN(2339, 8388, TREES), BOLONGO(2343, 7962, FRUIT_TREES), DANTAERA(2324, 8552, ALLOTMENT), DREVEN(2335, 7577,
  235. BUSHES), ELLENA(2331, 7965, FRUIT_TREES), ELSTAN(2323, 8550, ALLOTMENT), FAYETH(2342, 8391,
  236. TREES), GARTH(2330, 7964, FRUIT_TREES), GILETH(2344, 7963, FRUIT_TREES), AMAETHWR(2860, 28919,
  237. FRUIT_TREES), HESKEL(2340, 8389, TREES), KRAGEN(2325, 8554, ALLOTMENT), LYRA(2326, 8556,
  238. ALLOTMENT), PRISSY_SCILLA(1037, 19147, TREES), Francis(2327, 8174,
  239. HOPS), RHAZIEN(2337, 7579, BUSHES), RHONEN(2334, 8176, HOPS), SELENA(
  240. 2332, 8173, HOPS), TARIA(2336, 7578, BUSHES), TORRELL(2338,
  241. 7580, BUSHES), TREZNOR(2341, 8390, TREES), MY_ARM(4947,
  242. 18816, HERBS), VASQUEN(2333, 8175, HOPS);
  243.  
  244. private static Map<Integer, Gardeners> GARDENERS = new HashMap<Integer, Gardeners>();// NpcId/ObjectId
  245.  
  246. static {
  247. for (Gardeners GARDENER : Gardeners.values())
  248. GARDENERS.put(GARDENER.npcId, GARDENER);
  249. }
  250.  
  251. private int npcId;
  252. private int objectId;
  253. private int objectId2;
  254. private int type;
  255.  
  256. // private Item[] payment;
  257.  
  258. private Gardeners(int npcId, int objectId, int type) {
  259. this.npcId = npcId;
  260. this.objectId = objectId;
  261. this.objectId2 = objectId + 1;
  262. this.type = type;
  263. // this.payment = payment;
  264. }
  265.  
  266. public int getNpcId() {
  267. return npcId;
  268. }
  269.  
  270. public int getObjectId() {
  271. return objectId;
  272. }
  273.  
  274. public int getSouthObject() {
  275. return objectId2;
  276. }
  277.  
  278. public int getType() {
  279. return type;
  280. }
  281.  
  282. public static Gardeners getGardeners(int npcId) {
  283. return GARDENERS.get(npcId);
  284. }
  285. }
  286.  
  287. public boolean isGardening(int npcId, int option) {
  288. for (Gardeners garnder : Gardeners.values()) {
  289. if (npcId == garnder.getNpcId()) {
  290. switch (option) {
  291. case 1:
  292. player.getDialogueManager().startDialogue("GardenersD", npcId, -1);
  293. break;
  294. case 2:
  295. player.getDialogueManager().startDialogue("GardenersD", npcId, 1);
  296. break;
  297. case 3:
  298. player.getDialogueManager().startDialogue("GardenersD", npcId, 2);
  299. break;
  300. }
  301. return true;
  302. }
  303. }
  304. return false;
  305. }
  306.  
  307. public FarmingSpot getSpot(SpotInfo info) {
  308. for (FarmingSpot spot : spots)
  309. if (spot.spotInfo.equals(info))
  310. return spot;
  311. return null;
  312. }
  313.  
  314. public boolean isFarming(int objectId, Item item, int optionId) {
  315. SpotInfo info = SpotInfo.getInfo(objectId);
  316. if (info != null) {
  317. handleFarming(info, item, optionId);
  318. // player.getPackets().sendGameMessage("objectid = "+objectId+",
  319. // optionid = "
  320. // +optionId+".");
  321. return true;
  322. }
  323.  
  324. return false;
  325. }
  326.  
  327. public void handleFarming(SpotInfo info, Item item, int optionId) {// TODO
  328.  
  329. FarmingSpot spot = getSpot(info);
  330. if (spot == null)
  331. spot = new FarmingSpot(info);
  332. if (!spot.isCleared()) {
  333. if (item != null) {
  334. if (info.type == COMPOST)
  335. fillCompostBin(spot, item);
  336. else
  337. player.getPackets().sendGameMessage("The patch needs weeding first.");
  338. } else {
  339. switch (optionId) {
  340. case 1: // rake
  341. if (info.type == COMPOST) {
  342. if (spot.getHarvestAmount() == 15) {
  343. spot.setCleared(true);
  344. spot.setActive(ProductInfo.Compost_Bin);
  345. spot.setHarvestAmount(15);
  346. spot.refresh();
  347. player.getPackets().sendGameMessage("You close the compost bin.");
  348. player.getPackets().sendGameMessage("The vegetation begins to decompose.");
  349. }
  350. } else
  351. startRakeAction(spot); // creates usable spot
  352. break;
  353. case 2: // inspect
  354. sendInspect(spot);
  355. break;
  356. case 3: // guide
  357. openGuide();
  358. break;
  359. }
  360. }
  361. } else {
  362. if (item != null) {
  363. String itemName = item.getName().toLowerCase();
  364. if (itemName.startsWith("watering can ("))
  365. startWateringAction(spot, item);
  366. else if (itemName.contains("compost"))
  367. startCompostAction(spot, item, itemName.equals("supercompost"));
  368. else if (item.getId() == 6036)
  369. startCureAction(spot, item);
  370. else if (WaterFilling.isFilling(player, item.getId(), true)
  371. && player.getInventory().containsItemToolBelt(5325))
  372. return;
  373. else
  374. startFarmingCycle(spot, item);
  375. } else if (spot.productInfo != null) {
  376. switch (optionId) {
  377. case 1:
  378. if (info.type == TREES) {
  379. if (spot.reachedMaxStage() && !spot.hasChecked())
  380. checkHealth(spot);
  381. else if (spot.reachedMaxStage() && !spot.isEmpty())
  382. collectTreeProducts(spot, TreeDefinitions.valueOf(spot.productInfo.name().toUpperCase()));
  383. else if (spot.reachedMaxStage() && spot.isEmpty())
  384. startHarvestingAction(spot);
  385. else if (spot.isDead())
  386. clearFarmingPatch(spot);
  387. else if (spot.isDiseased())
  388. startCureAction(spot, null);
  389. } else if (info.type == FRUIT_TREES) {
  390. if (spot.reachedMaxStage() && !spot.hasChecked())
  391. checkHealth(spot);
  392. else if (spot.reachedMaxStage() && !spot.hasEmptyHarvestAmount())
  393. startPickingAction(spot);
  394. else if (spot.reachedMaxStage() && !spot.isEmpty())
  395. collectTreeProducts(spot, TreeDefinitions.FRUIT_TREES);
  396. else if (spot.reachedMaxStage() && spot.isEmpty() || spot.isDead())
  397. clearFarmingPatch(spot);
  398. else if (spot.isDiseased())
  399. startCureAction(spot, null);
  400. } else if (info.type == BUSHES) {
  401. if (spot.reachedMaxStage() && !spot.hasChecked())
  402. checkHealth(spot);
  403. else if (spot.reachedMaxStage() && !spot.hasEmptyHarvestAmount())
  404. startPickingAction(spot);
  405. else if (spot.isDead())
  406. clearFarmingPatch(spot);
  407. else if (spot.isDiseased())
  408. startCureAction(spot, null);
  409. } else if (info.type == COMPOST) {
  410. if (spot.reachedMaxStage() && !spot.hasChecked()) {
  411. spot.setChecked(true);
  412. spot.refresh();
  413. player.getPackets().sendGameMessage("You open the compost bin.");
  414. } else if (!spot.reachedMaxStage())
  415. player.getDialogueManager().startDialogue("SimpleMessage",
  416. "The vegetation hasn't finished rotting yet.");
  417. else
  418. clearCompostAction(spot);
  419. } else {
  420. if (spot.reachedMaxStage() && !spot.isDead())
  421. startHarvestingAction(spot);
  422. else if (spot.isDead())
  423. clearFarmingPatch(spot);
  424. }
  425. break;
  426. case 2:// inspect... usless tbh
  427. this.sendInspect(spot);
  428. break;
  429. case 3:// clear & guide
  430. if (spot.isDiseased() || spot.reachedMaxStage()) {
  431. if (info.type == TREES) {
  432. if (spot.isEmpty()) // stump
  433. startHarvestingAction(spot);
  434. else {
  435. player.getPackets()
  436. .sendGameMessage("You need to chop the tree down before removing it.");
  437. return;
  438. }
  439. } else
  440. clearFarmingPatch(spot);
  441. } else if (spot.productInfo.type == FRUIT_TREES) {
  442. if (spot.reachedMaxStage())
  443. return;
  444. clearFarmingPatch(spot);
  445. } else
  446. openGuide();
  447. break;
  448. }
  449. } else
  450. sendInspect(spot);
  451. }
  452. }
  453.  
  454. private void startRakeAction(final FarmingSpot spot) {
  455. player.getActionManager().setAction(new Action() {
  456.  
  457. @Override
  458. public boolean start(Player player) {
  459. if (!player.getInventory().containsItemToolBelt(RAKE)) {
  460. player.getPackets().sendGameMessage("You'll need a rake to get rid of the weeds.");
  461. return false;
  462. }
  463. spot.setInAction(true);
  464. return true;
  465. }
  466.  
  467. @Override
  468. public boolean process(Player player) {
  469. return spot.stage != 3;
  470. }
  471.  
  472. @Override
  473. public int processWithDelay(Player player) {
  474. player.setNextAnimation(RAKING_ANIMATION);
  475. if (Utils.random(1) == 0) {
  476. spot.increaseStage();
  477. if (spot.stage == 3)
  478. spot.setCleared(true);
  479. player.getInventory().addItemDrop(6055, 1);
  480. player.getSkills().addXp(Skills.FARMING, 8);
  481. }
  482. return 2;
  483. }
  484.  
  485. @Override
  486. public void stop(Player player) {
  487. setActionDelay(player, 3);
  488. spot.setInAction(false);
  489. }
  490. });
  491. }
  492.  
  493. public void startHarvestingAction(final FarmingSpot spot) {
  494. final String patchName = getPatchName(spot.productInfo.type);
  495. player.getActionManager().setAction(new Action() {
  496.  
  497. @Override
  498. public boolean start(Player player) {
  499. if (!player.getInventory().containsItemToolBelt(952)) {
  500. player.getPackets().sendGameMessage("You need a spade to harvest your crops.");
  501. return false;
  502. }
  503. if (spot.hasEmptyHarvestAmount() && !spot.hasGivenAmount()) {
  504. spot.setHarvestAmount(getRandomHarvestAmount(spot.productInfo.type));
  505. spot.setHasGivenAmount(true);
  506. } else if (spot.harvestAmount <= 0) {
  507. player.getPackets().sendGameMessage("You have successfully harvested this patch for new crops.");
  508. player.setNextAnimation(new Animation(-1));
  509. spot.setIdle();
  510. return false;
  511. }
  512. player.getPackets().sendGameMessage("You begin to harvest the " + patchName + " patch.");
  513. setActionDelay(player, 1);
  514. spot.setInAction(true);
  515. return true;
  516. }
  517.  
  518. @Override
  519. public boolean process(Player player) {
  520. if (spot.harvestAmount > 0)
  521. return true;
  522. else {
  523. player.getPackets().sendGameMessage("You have successfully harvested this patch for new crops.");
  524. player.setNextAnimation(new Animation(-1));
  525. spot.setIdle();
  526. return false;
  527. }
  528. }
  529.  
  530. @Override
  531. public int processWithDelay(Player player) {
  532. spot.harvestAmount--;
  533. player.setNextAnimation(getHarvestAnimation(spot.productInfo.type));
  534. player.getSkills().addXp(Skills.FARMING, spot.productInfo.experience);
  535. player.getInventory().addItemDrop(spot.productInfo.productId, 1);
  536. return 2;
  537. }
  538.  
  539. @Override
  540. public void stop(Player player) {
  541. setActionDelay(player, 3);
  542. spot.setInAction(false);
  543. }
  544. });
  545. }
  546.  
  547. private void startPickingAction(final FarmingSpot spot) {
  548. player.getActionManager().setAction(new Action() {
  549.  
  550. @Override
  551. public boolean start(Player player) {
  552. spot.setInAction(true);
  553. return true;
  554. }
  555.  
  556. @Override
  557. public boolean process(Player player) {
  558. if (spot.harvestAmount > 0)
  559. return true;
  560. else {
  561. player.getPackets()
  562. .sendGameMessage("You pick all of the "
  563. + (spot.productInfo.type == FRUIT_TREES ? "fruits" : "berries") + " from the "
  564. + getPatchName(spot.productInfo.type) + " patch.");
  565. player.setNextAnimation(new Animation(-1));
  566. return false;
  567. }
  568. }
  569.  
  570. @Override
  571. public int processWithDelay(Player player) {
  572. player.getPackets().sendGameMessage("You pick a "
  573. + ItemDefinitions.getItemDefinitions(spot.productInfo.productId).getName().toLowerCase() + ".");
  574. player.setNextAnimation(getHarvestAnimation(spot.productInfo.type));
  575. player.getSkills().addXp(Skills.FARMING, spot.productInfo.experience);
  576. player.getInventory().addItemDrop(spot.productInfo.productId, 1);
  577. spot.harvestAmount--;
  578. spot.refresh();
  579. if (spot.cycleTime < Utils.currentTimeMillis())
  580. spot.setCycleTime(REGENERATION_CONSTANT);
  581. return 2;
  582. }
  583.  
  584. @Override
  585. public void stop(Player player) {
  586. setActionDelay(player, 1);
  587. spot.setInAction(false);
  588. }
  589. });
  590. }
  591.  
  592. public void clearCompostAction(final FarmingSpot spot) {
  593. player.getActionManager().setAction(new Action() {
  594.  
  595. @Override
  596. public boolean start(Player player) {
  597. if (spot == null)
  598. return false;
  599. else if (!player.getInventory().containsItem(EMPTY_BUCKET, 1)) {
  600. player.getPackets().sendGameMessage("You'll need an empty bucket.");
  601. return false;
  602. }
  603. return true;
  604. }
  605.  
  606. @Override
  607. public boolean process(Player player) {
  608. if (!player.getInventory().containsItem(EMPTY_BUCKET, 1)) {
  609. player.getPackets().sendGameMessage("You'll need an empty bucket.");
  610. return false;
  611. } else if (spot.harvestAmount > 0)
  612. return true;
  613. else {
  614. spot.setCleared(false);
  615. spot.refresh();
  616. spot.setProductInfo(null);
  617. spot.remove();
  618. player.setNextAnimation(new Animation(-1));
  619. return false;
  620. }
  621. }
  622.  
  623. @Override
  624. public int processWithDelay(Player player) {
  625. player.setNextAnimation(FILL_COMPOST_ANIMATION);
  626. player.getSkills().addXp(Skills.FARMING, 5);
  627. player.getInventory().addItemDrop(spot.getCompost() ? 6032 : 6034, 1);
  628. player.getInventory().deleteItem(EMPTY_BUCKET, 1);
  629. spot.harvestAmount--;
  630. spot.refresh();
  631. return 2;
  632. }
  633.  
  634. @Override
  635. public void stop(Player player) {
  636. setActionDelay(player, 1);
  637. }
  638. });
  639. }
  640.  
  641. public void clearFarmingPatch(final FarmingSpot spot) {
  642. final String patchName = getPatchName(spot.productInfo.type);
  643. player.getDialogueManager().startDialogue(new Dialogue() {
  644.  
  645. @Override
  646. public void start() {
  647. sendOptionsDialogue("CLEAR FARMING PATCH?", "Yes", "No");
  648. }
  649.  
  650. @Override
  651. public void run(int interfaceId, int componentId) {
  652. if (componentId == Dialogue.OPTION_1) {
  653. player.getActionManager().setAction(new Action() {
  654.  
  655. private int stage;
  656.  
  657. @Override
  658. public boolean start(Player player) {
  659. if (!player.getInventory().containsItemToolBelt(952)) {
  660. player.getPackets().sendGameMessage("You need a spade to clear this farming patch.");
  661. return false;
  662. }
  663. player.getPackets().sendGameMessage("You start digging the " + patchName + " patch...");
  664. spot.setInAction(true);
  665. return true;
  666. }
  667.  
  668. @Override
  669. public boolean process(Player player) {
  670. if (stage != 2)
  671. return true;
  672. else {
  673. player.getPackets()
  674. .sendGameMessage("You have successfully cleared this patch for new crops.");
  675. player.setNextAnimation(new Animation(-1));
  676. spot.setIdle();
  677. return false;
  678. }
  679. }
  680.  
  681. @Override
  682. public int processWithDelay(Player player) {
  683. player.setNextAnimation(SPADE_ANIMATION);
  684. if (Utils.random(2) == 0)
  685. stage++;
  686. return 2;
  687. }
  688.  
  689. @Override
  690. public void stop(Player player) {
  691. setActionDelay(player, 3);
  692. spot.setInAction(false);
  693. }
  694. });
  695. end();
  696. } else
  697. end();
  698. }
  699.  
  700. @Override
  701. public void finish() {
  702. // TODO Auto-generated method stub
  703.  
  704. }
  705.  
  706. });
  707. }
  708.  
  709. // TODO
  710. public boolean startFarmingCycle(FarmingSpot spot, Item item) { // check if
  711. // weeded
  712. ProductInfo productInfo = ProductInfo.getProduct(item.getId());
  713. if (item.getId() == 5350)
  714. return false;
  715. if (spot == null || productInfo == null || spot.spotInfo.type != productInfo.type || !spot.isCleared()
  716. || spot.productInfo != null || spot.spotInfo.type == COMPOST) {
  717. player.getPackets()
  718. .sendGameMessage(spot == null ? "The patch needs weeding first."
  719. : !spot.isCleared() ? "The patch needs weeding first."
  720. : (productInfo == null) ? "Nothing intresting happens."
  721. : spot.spotInfo.type != productInfo.type
  722. ? "You can only plant " + item.getName().toLowerCase() + "s in "
  723. + (beginsWithVowel(getPatchName(productInfo.type)) ? "an "
  724. : "a ")
  725. + getPatchName(productInfo.type) + "."
  726. : "");
  727. return false;
  728. }
  729. String patchName = getPatchName(productInfo.type);
  730. String itemName = item.getDefinitions().getName().toLowerCase();
  731. int requiredAmount = (productInfo.type == ALLOTMENT || productInfo.type == HOPS) ? 3 : 1;
  732. boolean isTree = productInfo.type == TREES || productInfo.type == FRUIT_TREES;
  733. int level = productInfo.level;
  734. if (!player.getInventory().containsItemToolBelt(isTree ? 952 : 5343)) {
  735. player.getPackets().sendGameMessage(isTree ? "You need a spade to plant the sappling into the dirt."
  736. : "You need a seed dibber to plant the seed in the dirt.");
  737. return true;
  738. } else if (!player.getInventory().containsItem(item.getId(), requiredAmount)) {
  739. player.getPackets().sendGameMessage("You don't have enough " + item.getDefinitions().getName().toLowerCase()
  740. + " to plant " + (beginsWithVowel(patchName) ? "an" : "a") + " " + patchName + " patch.");
  741. return true;
  742. } else if (player.getSkills().getLevel(Skills.FARMING) < level) {
  743. player.getPackets().sendGameMessage(
  744. "You need a farming level of " + level + " to plant this " + (isTree ? "sapling" : "seed") + ".");
  745. return true;
  746. }
  747. player.getPackets().sendGameMessage("You plant the " + itemName + " in the " + patchName + " patch.");
  748. player.setNextAnimation(isTree ? SPADE_ANIMATION : SEED_DIPPING_ANIMATION);
  749. player.getSkills().addXp(Skills.FARMING, isTree ? productInfo.experience : productInfo.plantingExperience);
  750. player.getInventory().deleteItem(new Item(item.getId(), requiredAmount));
  751. spot.setActive(productInfo);
  752. return true;
  753. }
  754.  
  755. public String getDetails(FarmingSpot spot) {
  756. String patchName = getPatchName(spot.spotInfo.type);
  757. return ("This is " + (beginsWithVowel(patchName) ? "an" : "a") + " " + patchName + " patch." + " The soil has "
  758. + (!spot.hasCompost() ? "not been treated."
  759. : spot.getCompost() ? "been treated with compost."
  760. : spot.getSuperCompost() ? "been treated with supercompost." : ""));
  761. }
  762.  
  763. private boolean beginsWithVowel(String s) {
  764. return (s.startsWith("a") || s.startsWith("e") || s.startsWith("i") || s.startsWith("o") || s.startsWith("u"));
  765. }
  766.  
  767. private void sendInspect(FarmingSpot spot) {// TODO
  768. if (spot == null)
  769. return;
  770. if (spot.productInfo == null && spot.isCleared()) {
  771. player.getPackets().sendGameMessage(getDetails(spot) + " The patch is empty and weeded.");
  772. } else if (spot.productInfo == null && !spot.isCleared()) {
  773. player.getPackets().sendGameMessage(getDetails(spot) + " The patch needs weeding.");
  774. } else if (spot.productInfo != null) {
  775. if (spot.isDead()) {
  776. player.getPackets().sendGameMessage(
  777. getDetails(spot) + " The patch has become diseased and dead for not curing it.");
  778. } else if (spot.isDiseased()) {
  779. player.getPackets().sendGameMessage(getDetails(spot) + " The patch has become diseased.");
  780. } else if (!spot.reachedMaxStage()) {
  781. player.getPackets().sendGameMessage(getDetails(spot) + " The patch has something growing in it.");
  782. } else {
  783. player.getPackets().sendGameMessage(getDetails(spot) + " The patch is fully grown.");
  784. }
  785. }
  786.  
  787. }
  788.  
  789. public boolean startWateringAction(final FarmingSpot spot, final Item item) {
  790. if (spot == null || spot.productInfo == null)
  791. return false;
  792. if (item.getName().toLowerCase().startsWith("watering can(")) {
  793. player.getPackets().sendGameMessage("Your watering can is empty and cannot water the plants.");
  794. return true;
  795. } else if (spot.isWatered()) {
  796. player.getPackets().sendGameMessage("This patch is already watered.");
  797. return true;
  798. } else if (spot.reachedMaxStage() || spot.productInfo.type == HERBS || spot.productInfo.type == COMPOST
  799. || spot.productInfo.type == TREES || spot.productInfo.type == FRUIT_TREES
  800. || spot.productInfo == ProductInfo.White_lily || spot.productInfo.type == BUSHES) {
  801. player.getPackets().sendGameMessage("This patch doesn't need watering.");
  802. return true;
  803. } else if (spot.isDiseased()) {
  804. player.getPackets().sendGameMessage("This crop is diseased and needs cure, not water!");
  805. return true;
  806. } else if (spot.isDead()) {
  807. player.getPackets().sendGameMessage("This crop is dead and needs to be removed, not watered!");
  808. return true;
  809. }
  810. player.getPackets().sendGameMessage("You begin to tip the can over...");
  811. player.setNextAnimation(WATERING_ANIMATION);
  812. spot.setWatered(true);
  813. WorldTasksManager.schedule(new WorldTask() {
  814.  
  815. @Override
  816. public void run() {
  817. useWateringCan(item);
  818. player.getPackets().sendGameMessage("... and the patch becomes moist with water.");
  819. spot.refresh();
  820. }
  821. }, 2);
  822. return true;
  823. }
  824.  
  825. public void useWateringCan(Item item) {
  826. player.getInventory().deleteItem(item);
  827. if (item.getId() != 5333) {
  828. player.getInventory().addItem(item.getId() - 1, 1);
  829. return;
  830. }
  831. player.getInventory().addItem(item.getId() - 2, 1);
  832. }
  833.  
  834. public boolean startCureAction(final FarmingSpot spot, final Item item) {
  835. if (spot == null || spot.productInfo == null || spot.productInfo.type == COMPOST)
  836. return false;
  837. final boolean isTree = spot.productInfo.type == TREES || spot.productInfo.type == FRUIT_TREES;
  838. final boolean isBush = spot.productInfo.type == BUSHES;
  839. if (!spot.isDiseased()) {
  840. player.getPackets().sendGameMessage("This patch doesn't need to be cured.");
  841. return true;
  842. } else if (isTree || isBush) {
  843. if (!(player.getInventory().containsItemToolBelt(5329)
  844. || player.getInventory().containsItemToolBelt(7409))) {
  845. player.getPackets().sendGameMessage("You need a pair of secatures to prune the tree.");
  846. }
  847. }
  848. player.getPackets()
  849. .sendGameMessage(isTree
  850. ? "You prune the " + spot.productInfo.name().toLowerCase() + " tree's diseased branches."
  851. : isBush ? "You prune the " + spot.productInfo.name().toLowerCase() + " bush's diseased leaves."
  852. : "You treat the " + getPatchName(spot.spotInfo.type) + " patch with the plant cure.");
  853. player.setNextAnimation((isTree || isBush) ? PRUNING_ANIMATION : CURE_PLANT_ANIMATION);
  854. spot.setDiseased(false);
  855. WorldTasksManager.schedule(new WorldTask() {
  856.  
  857. @Override
  858. public void run() {
  859. if (!isTree && !isBush) {
  860. player.getInventory().deleteItem(item);
  861. player.getInventory().addItem(new Item(229, 1));
  862. } else
  863. player.setNextAnimation(new Animation(-1));
  864. player.getPackets().sendGameMessage("It is restored to health.");
  865. spot.refresh();
  866. }
  867. }, 2);
  868. return true;
  869. }
  870.  
  871. public boolean startCompostAction(final FarmingSpot spot, final Item item, boolean superCompost) {
  872. if (spot == null || spot.spotInfo.type == COMPOST)
  873. return false;
  874. if (spot.hasCompost()) {
  875. player.getPackets().sendGameMessage("This patch is already saturated with a compost.");
  876. return true;
  877. } else if (!spot.isCleared()) {
  878. player.getPackets().sendGameMessage("The patch needs to be cleared in order to saturate it with compost.");
  879. return true;
  880. }
  881. player.getPackets()
  882. .sendGameMessage("You dump a bucket of " + (superCompost ? "supercompost" : "compost") + "...");
  883. player.setNextAnimation(COMPOST_ANIMATION);
  884. if (superCompost)
  885. spot.setSuperCompost(true);
  886. else
  887. spot.setCompost(true);
  888. WorldTasksManager.schedule(new WorldTask() {
  889.  
  890. @Override
  891. public void run() {
  892. player.getInventory().deleteItem(item);
  893. player.getInventory().addItem(EMPTY_BUCKET, 1);
  894. player.getSkills().addXp(Skills.FARMING, 8);
  895. player.getPackets().sendGameMessage("... and the patch becomes saturated with nutrients.");
  896. spot.refresh();
  897. }
  898. }, 2);
  899. return true;
  900. }
  901.  
  902. private void collectTreeProducts(final FarmingSpot spot, final TreeDefinitions definitions) {
  903. player.getActionManager().setAction(new Action() {
  904.  
  905. private HatchetDefinitions hatchet;
  906.  
  907. @Override
  908. public boolean start(Player player) {
  909. if (!checkAll(player))
  910. return false;
  911. player.getPackets().sendGameMessage("You swing your hatchet at the tree...", true);
  912. setActionDelay(player, getWoodcuttingDelay(player));
  913. spot.setInAction(true);
  914. return true;
  915. }
  916.  
  917. private int getWoodcuttingDelay(Player player) {
  918. int summoningBonus = player.getFamiliar() != null
  919. ? (player.getFamiliar().getId() == 6808 || player.getFamiliar().getId() == 6807) ? 10 : 0 : 0;
  920. int wcTimer = definitions.getLogBaseTime() - (player.getSkills().getLevel(8) + summoningBonus)
  921. - Utils.getRandom(hatchet.getAxeTime());
  922. if (wcTimer < 1 + definitions.getLogRandomTime())
  923. wcTimer = 1 + Utils.getRandom(definitions.getLogRandomTime());
  924. wcTimer /= player.getAuraManager().getWoodcuttingAccurayMultiplier();
  925. return wcTimer;
  926. }
  927.  
  928. private boolean checkAll(Player player) {
  929. for (HatchetDefinitions def : HatchetDefinitions.values()) {
  930. if (player.getInventory().containsItemToolBelt(def.getItemId())
  931. || player.getEquipment().getWeaponId() == def.getItemId()) {
  932. hatchet = def;
  933. if (player.getSkills().getLevel(Skills.WOODCUTTING) < hatchet.getLevelRequried()) {
  934. hatchet = null;
  935. break;
  936. }
  937. }
  938. }
  939. if (hatchet == null) {
  940. player.getPackets().sendGameMessage(
  941. "You dont have the required level to use that axe or you don't have a hatchet.");
  942. return false;
  943. }
  944. if (!hasWoodcuttingLevel(player))
  945. return false;
  946. if (!player.getInventory().hasFreeSlots()) {
  947. player.getPackets().sendGameMessage("Not enough space in your inventory.");
  948. return false;
  949. }
  950. return true;
  951. }
  952.  
  953. private boolean hasWoodcuttingLevel(Player player) {
  954. if (definitions.getLevel() > player.getSkills().getLevel(8)) {
  955. player.getPackets().sendGameMessage(
  956. "You need a woodcutting level of " + definitions.getLevel() + " to chop down this tree.");
  957. return false;
  958. }
  959. return true;
  960. }
  961.  
  962. @Override
  963. public boolean process(Player player) {
  964. player.setNextAnimation(new Animation(hatchet.getEmoteId()));
  965. return checkTree(player);
  966. }
  967.  
  968. private boolean usedDeplateAurora;
  969.  
  970. @Override
  971. public int processWithDelay(Player player) {
  972. Woodcutting.addLog(definitions, false, false, player);
  973. if (!usedDeplateAurora && (1 + Math.random()) < player.getAuraManager().getChanceNotDepleteMN_WC()) {
  974. usedDeplateAurora = true;
  975. } else if (Utils.getRandom(definitions.getRandomLifeProbability()) == 0) {
  976. int time = definitions.getRespawnDelay();
  977. spot.setEmpty(true);
  978. spot.refresh();
  979. spot.setCycleTime(true, time * 1000); // time in seconds
  980. player.setNextAnimation(new Animation(-1));
  981. return -1;
  982. }
  983. if (!player.getInventory().hasFreeSlots()) {
  984. player.setNextAnimation(new Animation(-1));
  985. player.getPackets().sendGameMessage("Not enough space in your inventory.");
  986. return -1;
  987. }
  988. return getWoodcuttingDelay(player);
  989. }
  990.  
  991. private boolean checkTree(Player player) {
  992. return spot != null && !spot.isEmpty();
  993. }
  994.  
  995. @Override
  996. public void stop(Player player) {
  997. setActionDelay(player, 3);
  998. spot.setInAction(false);
  999. }
  1000. });
  1001. }
  1002.  
  1003. private void fillCompostBin(final FarmingSpot spot, final Item item) {
  1004. final boolean[] attributes = isOrganicItem(item.getId());
  1005. player.getActionManager().setAction(new Action() {
  1006.  
  1007. @Override
  1008. public boolean start(Player player) {
  1009. if (item == null || !player.getInventory().containsItem(item.getId(), 1) || spot.isCleared())
  1010. return false;
  1011. else if (!attributes[0]) {
  1012. player.getPackets().sendGameMessage("You cannot use this item to make compost.");
  1013. return false;
  1014. }
  1015. return true;
  1016. }
  1017.  
  1018. @Override
  1019. public boolean process(Player player) {
  1020. return spot.harvestAmount != 15 && player.getInventory().containsItem(item.getId(), 1);
  1021. }
  1022.  
  1023. @Override
  1024. public int processWithDelay(Player player) {
  1025. player.setNextAnimation(FILL_COMPOST_ANIMATION);
  1026. player.getInventory().deleteItem(item);
  1027. spot.harvestAmount++;
  1028. spot.refresh();
  1029. return 2;
  1030. }
  1031.  
  1032. @Override
  1033. public void stop(Player player) {
  1034. setActionDelay(player, 3);
  1035. }
  1036. });
  1037. }
  1038.  
  1039. private void checkHealth(final FarmingSpot spot) {
  1040. player.getPackets()
  1041. .sendGameMessage("You examine the "
  1042. + ((spot.productInfo.type == TREES || spot.productInfo.type == FRUIT_TREES) ? "tree" : "bush")
  1043. + " for signs of disease and find that it is in perfect health.");
  1044. player.getSkills().addXp(Skills.FARMING, spot.productInfo.plantingExperience);
  1045. player.setNextAnimation(CHECK_TREE_ANIMATION);
  1046. spot.setChecked(true);
  1047. spot.refresh();
  1048. }
  1049.  
  1050. private String getPatchName(int type) {
  1051. return PATCH_NAMES[type];
  1052. }
  1053.  
  1054. private int getRandomHarvestAmount(int type) {
  1055. int maximumAmount = 0, baseAmount = 0, totalAmount = 0;
  1056. baseAmount = HARVEST_AMOUNTS[type][0];
  1057. maximumAmount = HARVEST_AMOUNTS[type][1];
  1058. totalAmount = Utils.random(baseAmount, maximumAmount);
  1059. if (player.getEquipment().getWeaponId() == 7409)
  1060. totalAmount *= 1.1;
  1061. return totalAmount;
  1062. }
  1063.  
  1064. private Animation getHarvestAnimation(int type) {
  1065. if (type == ALLOTMENT || type == HOPS || type == TREES)
  1066. return SPADE_ANIMATION;
  1067. else if (type == HERBS || type == FLOWERS) {
  1068. if (player.getEquipment().getWeaponId() == 7409)
  1069. return MAGIC_PICKING_ANIMATION;
  1070. return type == HERBS ? HERB_PICKING_ANIMATION : FLOWER_PICKING_ANIMATION;
  1071. } else if (type == FRUIT_TREES) {
  1072. return FRUIT_PICKING_ANIMATION;
  1073. } else if (type == BUSHES) {
  1074. return BUSH_PICKING_ANIMATION;
  1075. }
  1076. return null;
  1077. }
  1078.  
  1079. private void openGuide() {
  1080. player.getTemporaryAttributtes().put("skillMenu", 21);
  1081. player.getVarsManager().sendVar(965, 21);
  1082. ButtonHandler.openSkillGuide(player);
  1083. }
  1084.  
  1085. private boolean[] isOrganicItem(int itemId) {
  1086. boolean[] bools = new boolean[2];
  1087. for (int organicId : COMPOST_ORGANIC) {
  1088. if (itemId == organicId) {
  1089. bools[0] = true;
  1090. bools[1] = false;
  1091. }
  1092. }
  1093. for (int organicId : SUPER_COMPOST_ORGANIC) {
  1094. if (itemId == organicId) {
  1095. bools[0] = true;
  1096. bools[1] = false;
  1097. }
  1098. }
  1099. return bools;
  1100. }
  1101.  
  1102. public void resetSpots() {
  1103. spots.clear();
  1104. }
  1105.  
  1106. public void resetTreeTrunks() {
  1107. for (FarmingSpot spot : spots) {
  1108. if (spot.spotInfo.type == TREES || spot.spotInfo.type == FRUIT_TREES) {
  1109. if (spot.isEmpty()) {
  1110. spot.setEmpty(false);
  1111. spot.refresh();
  1112. }
  1113. }
  1114. }
  1115. }
  1116.  
  1117. public class FarmingSpot implements Serializable {
  1118.  
  1119. private static final long serialVersionUID = -732322970478931771L;
  1120.  
  1121. private SpotInfo spotInfo;
  1122. public ProductInfo productInfo;
  1123. private int stage;
  1124. private long cycleTime;
  1125. private int harvestAmount;
  1126. private boolean[] attributes;
  1127.  
  1128. public FarmingSpot(SpotInfo spotInfo) {
  1129. this.spotInfo = spotInfo;
  1130. cycleTime = Utils.currentTimeMillis();
  1131. stage = 0; // stage 0 is default null
  1132. harvestAmount = 0;
  1133. attributes = new boolean[12]; // diseased, watered, dead,
  1134. // firstCycle, usingCompost,
  1135. // usingSuperCompost, isProtected, inAction;
  1136. renewCycle();
  1137. spots.add(this);
  1138. }
  1139.  
  1140. public void setActive(ProductInfo productInfo) {
  1141. setProductInfo(productInfo);
  1142. stage = -1;
  1143. resetCycle();
  1144. }
  1145.  
  1146. private void resetCycle() {
  1147. cycleTime = Utils.currentTimeMillis();
  1148. harvestAmount = 0;
  1149. for (int index = 0; index < attributes.length; index++) {
  1150. if (index == 4 || ((index == 7 || index == 8) && productInfo != null))
  1151. continue;
  1152. attributes[index] = false;
  1153. }
  1154. }
  1155.  
  1156. public void setCycleTime(long cycleTime) {
  1157. setCycleTime(false, cycleTime);
  1158. }
  1159.  
  1160. public void setCycleTime(boolean reset, long cycleTime) {
  1161. if (reset)
  1162. this.cycleTime = 0;
  1163. if (this.cycleTime == 0)
  1164. this.cycleTime = Utils.currentTimeMillis();
  1165. this.cycleTime += cycleTime;
  1166. }
  1167.  
  1168. public void setIdle() {
  1169. resetCycle();
  1170. setCycleTime(true, 0);
  1171. renewCycle();
  1172. setProductInfo(null);
  1173. stage = 3;
  1174. refresh();
  1175. }
  1176.  
  1177. public void process() {
  1178. if (cycleTime == 0)
  1179. return;
  1180. if (inAction())
  1181. return;
  1182. while (cycleTime < Utils.currentTimeMillis()) {
  1183. if (productInfo != null) {
  1184. if (hasChecked() && (isEmpty() || !hasMaximumRegeneration())) {
  1185. if (isEmpty()) {
  1186. setEmpty(false);
  1187. if (productInfo.type == FRUIT_TREES)
  1188. setCycleTime(REGENERATION_CONSTANT);
  1189. else
  1190. cycleTime = 0;
  1191. } else if (!hasMaximumRegeneration()) {
  1192. if (harvestAmount == 5)
  1193. cycleTime = 0;
  1194. else
  1195. cycleTime += REGENERATION_CONSTANT;
  1196. harvestAmount++;
  1197. } else
  1198. cycleTime = 0;
  1199. refresh();
  1200. return;
  1201. } else {
  1202. increaseStage();
  1203. if (reachedMaxStage() || isDead()) {
  1204. cycleTime = 0;
  1205. break;
  1206. }
  1207. }
  1208. } else {
  1209. if (spotInfo.type != COMPOST) {
  1210. desecreaseStage();
  1211. if (stage <= 0) {
  1212. remove();
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. renewCycle();
  1218. }
  1219. }
  1220.  
  1221. public int getConfigBaseValue() {
  1222. if (productInfo != null) {
  1223. if (productInfo.type == ALLOTMENT)
  1224. return 6 + (productInfo.configIndex * 7);
  1225. else if (productInfo.type == HERBS)
  1226. return 4 + (productInfo.configIndex * 7);
  1227. else if (productInfo.type == FLOWERS)
  1228. return 8 + (productInfo.configIndex * 5);
  1229. else if (productInfo.type == HOPS)
  1230. return 3 + (productInfo.configIndex * 5);
  1231. else if (productInfo.type == TREES || productInfo.type == FRUIT_TREES || productInfo.type == BUSHES)
  1232. return 8 + (productInfo.configIndex ^ 2 - 1);
  1233. }
  1234. return stage;
  1235. }
  1236.  
  1237. private int getConfigValue(int type) {
  1238. if (type == HERBS)
  1239. return isDead() ? stage + 169
  1240. : getConfigBaseValue() + ((isDiseased() && stage != 0) ? stage + 127 : stage);
  1241. else if (type == TREES) {
  1242. int baseValue = getConfigBaseValue()
  1243. + (isDead() ? stage + 128 : (isDiseased() && stage != 0) ? stage + 64 : stage);
  1244. if (hasChecked()) {
  1245. baseValue += 2;
  1246. if (!isEmpty())
  1247. baseValue--;
  1248. }
  1249. return baseValue;
  1250. } else if (type == FRUIT_TREES) {
  1251. int baseValue = stage + getConfigBaseValue();
  1252. if (hasChecked())
  1253. baseValue += getHarvestAmount();
  1254. else if (isDead())
  1255. baseValue += 20;
  1256. else if (isDiseased())
  1257. baseValue += 12;
  1258. else if (!hasChecked() && reachedMaxStage())
  1259. baseValue += 20;
  1260. if (isEmpty())
  1261. baseValue += 19;
  1262. return baseValue;
  1263. } else if (type == BUSHES) {
  1264. int baseValue = stage + getConfigBaseValue();
  1265. if (hasChecked())
  1266. baseValue += getHarvestAmount();
  1267. else if (isDead())
  1268. baseValue += 128;
  1269. else if (isDiseased())
  1270. baseValue += 65;
  1271. else if (!hasChecked() && reachedMaxStage()) // 250
  1272. baseValue += 240;
  1273. return baseValue;
  1274. } else if (type == COMPOST) {
  1275. return isCleared() ? harvestAmount + 16 + (hasChecked() ? -1 : 0)
  1276. : productInfo != null && reachedMaxStage() ? 0 : harvestAmount - stage;
  1277. } else if (type == FLOWERS || type == HOPS || type == ALLOTMENT)
  1278. return getConfigBaseValue() + (isDead() ? stage + 192
  1279. : (isDiseased() && stage != 0) ? stage + 128 : isWatered() ? 64 + stage : stage);
  1280. return stage + getConfigBaseValue();
  1281. }
  1282.  
  1283. private void checkFactors() {
  1284. if (isDiseased()) {
  1285. if (reachedMaxStage()) {
  1286. setDead(false);
  1287. setDiseased(false);
  1288. } else {
  1289. if (isFirstCycle())
  1290. setFirstCycle(false);
  1291. else {
  1292. if (!isProtected())
  1293. setDead(true);
  1294. else {
  1295. setDiseased(false);
  1296. }
  1297. }
  1298. }
  1299. }
  1300. if (productInfo.type == FRUIT_TREES || productInfo.type == BUSHES) {
  1301. if (reachedMaxStage())
  1302. setHarvestAmount(productInfo.type == BUSHES || productInfo == ProductInfo.Palm ? 4 : 6);
  1303. }
  1304. setWatered(false);
  1305. checkDisease();
  1306. }
  1307.  
  1308. public boolean reachedMaxStage() {
  1309. return stage == productInfo.maxStage;
  1310. }
  1311.  
  1312. private boolean hasMaximumRegeneration() {
  1313. if (spotInfo.type != FRUIT_TREES && spotInfo.type != BUSHES)
  1314. return true;
  1315. else if (getHarvestAmount() != HARVEST_AMOUNTS[productInfo.type][1])
  1316. return false;
  1317. return true;
  1318. }
  1319.  
  1320. public void renewCycle() {
  1321. long constant = 30000L;
  1322. if (productInfo != null)
  1323. cycleTime += Settings.DEBUG ? constant * 2 : constant * productInfo.cycleTime;
  1324. else
  1325. cycleTime += constant * 3;
  1326. }
  1327.  
  1328. public void renewCycle(boolean resetAttributes) {
  1329. long constant = 30000L;
  1330. if (productInfo != null)
  1331. cycleTime += Settings.DEBUG ? constant * 2 : constant * productInfo.cycleTime;
  1332. else
  1333. cycleTime += constant * 3;
  1334. }
  1335.  
  1336. public boolean canBeDiseased() {
  1337. if (stage == 0 && productInfo.type != BUSHES || reachedMaxStage() || isDiseased()
  1338. || productInfo == ProductInfo.White_lily || productInfo == ProductInfo.Poison_ivy
  1339. || productInfo.type == COMPOST)
  1340. return false;
  1341. return true;
  1342. }
  1343.  
  1344. private void checkDisease() {
  1345. if (canBeDiseased()) {
  1346. int baseValue = 35;
  1347. if (isWatered())
  1348. baseValue += 10;
  1349. if (getCompost())
  1350. baseValue += 10;
  1351. else if (getSuperCompost())
  1352. baseValue += 20;
  1353. if (Utils.getRandom(baseValue) == 0) {
  1354. setDiseased(true);
  1355. refresh();
  1356. }
  1357. }
  1358. }
  1359.  
  1360. public void increaseStage() {
  1361. stage++;
  1362. if (productInfo != null)
  1363. checkFactors();
  1364. refresh();
  1365. }
  1366.  
  1367. public void desecreaseStage() {
  1368. setCleared(false);
  1369. stage--;
  1370. refresh();
  1371. }
  1372.  
  1373. private void remove() {
  1374. spots.remove(this);
  1375. }
  1376.  
  1377. public void refresh() {
  1378. int value = spotInfo.type == COMPOST ? getConfigValue(spotInfo.type)
  1379. : productInfo != null ? getConfigValue(spotInfo.type) + productInfo.stageSkip : stage;
  1380. player.getVarsManager().sendVarBit(spotInfo.configFileId, value);
  1381. if (Settings.DEBUG)
  1382. System.out.println(value);
  1383. }
  1384.  
  1385. public void setProductInfo(ProductInfo productInfo) {
  1386. this.productInfo = productInfo;
  1387. }
  1388.  
  1389. public boolean isDiseased() {
  1390. return attributes[0];
  1391. }
  1392.  
  1393. public void setDiseased(boolean diseased) {
  1394. this.attributes[0] = diseased;
  1395. }
  1396.  
  1397. public boolean isWatered() {
  1398. return attributes[1];
  1399. }
  1400.  
  1401. public void setWatered(boolean watered) {
  1402. this.attributes[1] = watered;
  1403. }
  1404.  
  1405. public boolean isDead() {
  1406. return attributes[2];
  1407. }
  1408.  
  1409. public void setDead(boolean dead) {
  1410. this.attributes[2] = dead;
  1411. if (dead)
  1412. setDiseased(false);
  1413. }
  1414.  
  1415. public boolean isFirstCycle() {
  1416. return attributes[3];
  1417. }
  1418.  
  1419. public void setFirstCycle(boolean firstCycle) {
  1420. this.attributes[3] = firstCycle;
  1421. }
  1422.  
  1423. public boolean isCleared() {
  1424. return attributes[4];
  1425. }
  1426.  
  1427. public void setCleared(boolean cleared) {
  1428. this.attributes[4] = cleared;
  1429. }
  1430.  
  1431. public boolean hasChecked() {
  1432. return attributes[5];
  1433. }
  1434.  
  1435. public void setChecked(boolean checked) {
  1436. this.attributes[5] = checked;
  1437. }
  1438.  
  1439. public boolean isEmpty() {
  1440. return attributes[6];
  1441. }
  1442.  
  1443. public void setEmpty(boolean empty) {
  1444. this.attributes[6] = empty;
  1445. }
  1446.  
  1447. public boolean hasCompost() {
  1448. return attributes[7] || attributes[8];
  1449. }
  1450.  
  1451. public boolean getSuperCompost() {
  1452. return attributes[8];
  1453. }
  1454.  
  1455. public void setSuperCompost(boolean superCompost) {
  1456. this.attributes[8] = superCompost;
  1457. }
  1458.  
  1459. public boolean hasGivenAmount() {
  1460. return attributes[9];
  1461. }
  1462.  
  1463. public void setHasGivenAmount(boolean amount) {
  1464. this.attributes[9] = amount;
  1465. }
  1466.  
  1467. public boolean getCompost() {
  1468. return attributes[7];
  1469. }
  1470.  
  1471. public void setCompost(boolean compost) {
  1472. this.attributes[7] = compost;
  1473. }
  1474.  
  1475. public void setIsProtected(boolean isProtected) {
  1476. this.attributes[10] = isProtected;
  1477. }
  1478.  
  1479. public boolean isProtected() {
  1480. return attributes[10];
  1481. }
  1482.  
  1483. public void setInAction(boolean inAction) {
  1484. this.attributes[11] = inAction;
  1485. }
  1486.  
  1487. public boolean inAction() {
  1488. return attributes[11];
  1489. }
  1490.  
  1491. public void setHarvestAmount(int harvestAmount) {
  1492. this.harvestAmount = harvestAmount;
  1493. }
  1494.  
  1495. public boolean hasEmptyHarvestAmount() {
  1496. return harvestAmount == 0;
  1497. }
  1498.  
  1499. public int getHarvestAmount() {
  1500. return harvestAmount;
  1501. }
  1502. }
  1503. }
Advertisement
Add Comment
Please, Sign In to add comment