public void processPatches() { /* * If something has to be removed from the ArrayList in this loop, use it.remove() not patches.remove() * or else we end up with a ConcurrentModificationException and it'll break out the loop :$. */ Event processPatchesEvent = new Event(3000); processPatchesEvent.setAction(() => { foreach (Patch patch in patches) { if (patch == null) { removedPatches.Add(patch); } else if (patch.isSapling()) { if (Farming.growSapling(patch)) { removedPatches.Add(patch); } } else if (!patch.patchOccupied()) { if (Farming.regrowWeeds(patch)) { // true if we should remove from the list removedPatches.Add(patch); } } else if (!patch.isFullyGrown() && patch.patchOccupied()) { long currentTime = Environment.TickCount; long lastUpdatedTime = patch.getLastUpdate(); int delay = (int)(patch.getTimeToGrow() / patch.getConfigLength()); //if (currentTime - lastUpdatedTime >= delay) { Farming.growPatch(patch); //} } } patches.RemoveAll(new Predicate <Patch>(delegate(Patch x) { return(removedPatches.Contains(x)); })); }); Server.registerEvent(processPatchesEvent); }
public static bool interactWithPatch(Player p, int objectId, int objectX, int objectY, int seedId) { for (int i = 0; i < PATCHES.Length; i++) { if (objectId == (int)PATCHES[i][1]) { Location patchLocation = new Location(objectX, objectY, 0); int j = i; int[] data = Farming.getPatchDistances(i, objectX, objectY); AreaEvent interactWithPatchAreaEvent = new AreaEvent(p, data[0], data[1], data[2], data[3]); interactWithPatchAreaEvent.setAction(() => { tendToPatch(p, patchLocation, seedId, j); }); Server.registerCoordinateEvent(interactWithPatchAreaEvent); return(true); } } return(false); }