public static bool regrowWeeds(Patch patch) { bool shouldRemoveFromList = false; if (!patch.patchOccupied()) { if (misc.random(4) != 0 || patch.isWeeding()) { return(false); } Player owner = Server.getPlayerForName(patch.getOwnerName()); patch.setHasWeeds(true); patch.setStatus(patch.getStatus() - 1); if (patch.getStatus() <= -1) { patch.setStatus(0); shouldRemoveFromList = true; } if (owner != null) { setConfig(owner, patch); } } return(shouldRemoveFromList); }
private static void rakePatch(Player p, Patch patch) { if (patch.isBlankPatch()) { p.getPackets().sendMessage("This patch is clear of weeds."); return; } if (!p.getInventory().hasItem(TOOLS[0])) { p.getPackets().sendMessage("You need a rake to clear the weeds from this patch."); return; } p.setLastAnimation(new Animation(2273)); patch.setWeeding(true); p.setTemporaryAttribute("harvesting", true); Event rakePatchEvent = new Event(1300); rakePatchEvent.setAction(() => { if (p.isDestroyed() || p.isDisconnected() || p.getTemporaryAttribute("harvesting") == null) { rakePatchEvent.stop(); patch.setWeeding(false); return; } if (!p.getInventory().hasItem(TOOLS[0])) { p.getPackets().sendMessage("You need a rake to clear the weeds from this patch."); patch.setWeeding(false); rakePatchEvent.stop(); return; } p.getInventory().addItemOrGround(6055); p.setLastAnimation(new Animation(2273)); setConfig(p, patch); patch.setStatus(patch.getStatus() + 1); if (patch.getStatus() >= 3) { p.getPackets().sendMessage("You clear the weeds from the patch, this patch is now suitable for farming."); patch.setHasWeeds(false); patch.setWeeding(false); patch.setStatus(2); setConfig(p, patch); p.setLastAnimation(new Animation(65535)); rakePatchEvent.stop(); return; } }); Server.registerEvent(rakePatchEvent); }
private static void harvestFruit(Player p, Patch patch) { if (p.getTemporaryAttribute("unmovable") != null) { return; } p.setLastAnimation(new Animation(2282)); p.setTemporaryAttribute("unmovable", true); patch.setWeeding(true); Event harvestFruitEvent = new Event(1700); harvestFruitEvent.setAction(() => { if (patch.getStatus() == patch.chopStatus() || p.isDisconnected() || p.isDestroyed() || p.isDead() || p.getTemporaryAttribute("teleporting") != null) { harvestFruitEvent.stop(); return; } p.setLastAnimation(new Animation(2282)); string s = patch.getSeedIndex() == 41 ? "leaf " : ""; Event harvestingFruitEvent = new Event(800); harvestingFruitEvent.setAction(() => { harvestingFruitEvent.stop(); p.getPackets().sendMessage("You pick " + (string)SEEDS[patch.getSeedIndex()][9] + " " + (string)SEEDS[patch.getSeedIndex()][7] + s + " from the tree."); p.getSkills().addXp(Skills.SKILL.FARMING, (double)SEEDS[patch.getSeedIndex()][8]); p.getInventory().addItemOrGround((int)SEEDS[patch.getSeedIndex()][2], 1); patch.setStatus(patch.getStatus() - 1); if (patch.getStatus() == 5) // We have taken all the fruit (it is 5 after we lower the status above) { patch.setStatus(13); // Chop option p.removeTemporaryAttribute("unmovable"); patch.setWeeding(false); } setConfig(p, patch); }); Server.registerEvent(harvestingFruitEvent); }); Server.registerEvent(harvestFruitEvent); }
public static void growPatch(Patch patch) { if (patch.isTree()) { if (patch.getStatus() == patch.checkHealthStatus()) { if (!patch.isHealthChecked()) { return; } } else if (patch.getStatus() == patch.chopStatus()) { return; } else if (patch.getStatus() == patch.stumpStatus()) { patch.setStatus(patch.chopStatus()); } else { patch.setStatus(patch.getStatus() + 1); } } else if (patch.isFruitTree()) { if (patch.isWeeding()) { return; } if (patch.getStatus() == patch.checkHealthStatus()) { if (!patch.isHealthChecked()) { return; } } if (patch.isHealthChecked()) { if (patch.getStatus() == patch.checkHealthStatus() - 1) // all fruit { return; } } if (patch.getStatus() == patch.stumpStatus()) { patch.setStatus(patch.chopStatus()); } else if (patch.getStatus() == patch.chopStatus()) { patch.setStatus(6); } else { patch.setStatus(patch.getStatus() + 1); } } else { patch.setStatus(patch.getStatus() + 1); } Player owner = Server.getPlayerForName(patch.getOwnerName()); if (owner != null) { setConfig(owner, patch); } patch.setLastUpdate(Environment.TickCount); }