public static void mineRock(Player p, ushort rockId, Location rockLocation, int i, bool newMine) { if (!newMine && p.getTemporaryAttribute("miningRock") == null) { return; } if (newMine) { if (!Server.getGlobalObjects().objectExists(rockId, rockLocation)) { //misc.WriteError(p.getUsername() + " tried to mine a non existing rock!"); //return; } Rock newRock = new Rock(i, rockId, rockLocation, ORES[i], ROCK_LEVEL[i], NAME[i], ROCK_XP[i]); p.setTemporaryAttribute("miningRock", newRock); } Rock rockToMine = (Rock)p.getTemporaryAttribute("miningRock"); bool essRock = rockToMine.getRockIndex() == 0; if (!canMine(p, rockToMine, null)) { resetMining(p); return; } if (newMine) { string s = essRock ? "You begin to mine Essence.." : "You swing your pick at the rock.."; p.getPackets().sendMessage(s); } p.getPackets().closeInterfaces(); p.setLastAnimation(new Animation(getPickaxeAnimation(p))); p.setFaceLocation(rockLocation); int delay = getMineTime(p, rockToMine.getRockIndex()); Event mineRockEvent = new Event(delay); mineRockEvent.setAction(() => { mineRockEvent.stop(); // Stop the event no matter what if (p.getTemporaryAttribute("miningRock") == null) { return; } Rock rock = (Rock)p.getTemporaryAttribute("miningRock"); if (!canMine(p, rockToMine, rock)) { return; } if (!essRock) { Server.getGlobalObjects().lowerHealth(rock.getRockId(), rock.getRockLocation()); if (!Server.getGlobalObjects().originalObjectExists(rock.getRockId(), rock.getRockLocation())) { resetMining(p); stopAllOtherMiners(p, rock); p.setLastAnimation(new Animation(65535)); mineRockEvent.stop(); } } bool addGem = (!essRock && Misc.random(getGemChance(p)) == 0) ? true : false; if (p.getInventory().addItem(addGem ? randomGem() : rock.getOre())) { p.getSkills().addXp(Skills.SKILL.MINING, rock.getXp()); if (addGem) { p.getPackets().sendMessage("You manage to mine a sparkling gem!"); } else { if (!essRock) { p.getPackets().sendMessage("You manage to mine some " + rock.getName() + "."); } } } if (rock.isContinueMine()) { mineRock(p, rock.getRockId(), rock.getRockLocation(), rock.getRockIndex(), false); } }); Server.registerEvent(mineRockEvent); if (delay >= 9000 && !rockToMine.isContinueMine()) { Event mineMoreRockEvent = new Event(9000); mineMoreRockEvent.setAction(() => { mineMoreRockEvent.stop(); Rock rock = (Rock)p.getTemporaryAttribute("miningRock"); if (!canMine(p, rockToMine, rock)) { return; } p.setFaceLocation(rock.getRockLocation()); p.setLastAnimation(new Animation(getPickaxeAnimation(p))); }); Server.registerEvent(mineMoreRockEvent); } }