Code:
public class ShootingStar {
private static final int TIME = 1800000;
private static final int TIME2 = 600;
public static final int MAXIMUM_MINING_AMOUNT = 450;
private static Stopwatch timer = new Stopwatch().reset();
public static CrashedStar CRASHED_STAR = null;
private static LocationData LAST_LOCATION = null;
public static class CrashedStar {
public CrashedStar(GameObject starObject, LocationData starLocation) {
this.starObject = starObject;
this.starLocation = starLocation;
}
private GameObject starObject;
private LocationData starLocation;
public GameObject getStarObject() {
return starObject;
}
public LocationData getStarLocation() {
return starLocation;
}
}
public static enum LocationData {
LOCATION_1(new Position(3053, 3301), "south of the Falador Farming patches", "Farming"),
LOCATION_2(new Position(3094, 3484), "south of the Edgeville bank", "Edgeville"),
LOCATION_3(new Position(2480, 3433), "at the Gnome Agility Course", "Gnome Course"),
LOCATION_4(new Position(2745, 3445), "in the middle of the Flax field", "Flax Field"),
LOCATION_5(new Position(3363, 3270), "in the Duel Arena", "Duel Arena"),
LOCATION_6(new Position(2594, 4326), "in Puro Puro", "Puro Puro"),
LOCATION_7(new Position(2731, 5092), "in the Strykewyrm cavern", "Strykewyrms"),
LOCATION_8(new Position(1746, 5327), "in the Ancient cavern", "Ancient Cavern"),
LOCATION_9(new Position(2882, 9800), "in the Taverly dungeon", "Taverly Dung."),
LOCATION_10(new Position(2666, 2648), "at the Void knight island", "Pest Control"),
LOCATION_11(new Position(3566, 3297), "on the Barrows hills", "Barrows"),
LOCATION_12(new Position(2986, 3599), "in the Wilderness (near the western dragons)", "West Dragons"),
LOCATION_13(new Position(3664, 3493), "in the Wilderness (Ghost Town)", "Ghost Town"),
LOCATION_14(new Position(2995, 3911), "outside the Wilderness Agility Course", "Wild. Course"),
LOCATION_15(new Position(3172, 3435), "next to Varocks West Bank", "Varock Bank"),
LOCATION_16(new Position(3269, 2967), "west of the Dust Devils", "Dust Devils"),
LOCATION_17(new Position(2758, 3480), "outside of the Camelot Castle", "Camelot Castle"),
LOCATION_18(new Position(3202, 3259), "In a Field of Yaks", "Yaks"),
LOCATION_19(new Position(3305, 3491), "at the Lumber Mill", "Varrock"),
LOCATION_20(new Position(3167, 3301), "at the Lumbridge Flour Mill", "Lumbridge"),
LOCATION_21(new Position(3109, 3350), "at the Draynor Mansion", "Draynor Mansion"),
LOCATION_22(new Position(3079, 3250), "at the Draynor Market", "Draynor Market"),
LOCATION_23(new Position(3027, 3217), "at the Port Sarim Docks", "Port Sarim"),
LOCATION_24(new Position(2956, 3216), "at Rimmington Well", "Rimmington"),
LOCATION_25(new Position(3275, 3164), "outside Al-Kharid Bank", "Al-Kharid"),
LOCATION_26(new Position(3303, 3123), "at Shantay's Pass", "Shantay's Pass"),
LOCATION_27(new Position(3008, 3478), "at Ice Mountain", "Ice Mountain"),
LOCATION_28(new Position(2956, 3507), "at the Goblin Village", "Goblin Village"),
LOCATION_29(new Position(2900, 3547), "at Burthorpe Castle", "Burthorpe"),
LOCATION_30(new Position(2657, 3439), "at the Ranging Guild", "Ranging Guild"),
LOCATION_31(new Position(2609, 3392), "at the Fishing Guild", "Fishing Guild"),
LOCATION_32(new Position(2605, 3225), "at the Ardougne Monastary", "Ardougne Monastary"),
LOCATION_33(new Position(2661, 3157), "at Port Khazard", "Port Khazard"),
LOCATION_34(new Position(2459, 3090), "at Castle Wars", "Castle Wars"),
LOCATION_35(new Position(3551, 3529), "at Fenkenstrain's Castle", "Fenkenstrain's Castle");
private LocationData(Position spawnPos, String clue, String playerPanelFrame) {
this.spawnPos = spawnPos;
this.clue = clue;
this.playerPanelFrame = playerPanelFrame;
}
private Position spawnPos;
private String clue;
public String playerPanelFrame;
}
public static LocationData getRandom() {
LocationData star = LocationData.values()[Misc.getRandom(LocationData.values().length - 1)];
return star;
}
public static void sequence() {
if(CRASHED_STAR == null) {
if(timer.elapsed(TIME2)) {
//if(timer.elapsed(TIME2)) {
LocationData locationData = getRandom();
if(LAST_LOCATION != null) {
if(locationData == LAST_LOCATION) {
locationData = getRandom();
}
}
LAST_LOCATION = locationData;
CRASHED_STAR = new CrashedStar(new GameObject(38660, locationData.spawnPos), locationData);
CustomObjects.spawnGlobalObject(CRASHED_STAR.starObject);
World.sendMessage("<img=10> <shad=1><col=FF9933>A shooting star has just crashed "+locationData.clue+"!");
World.getPlayers().forEach(p -> p.getPacketSender().sendString(39162, "@cya@Crashed star: @whi@"+ShootingStar.CRASHED_STAR.getStarLocation().playerPanelFrame+""));
timer.reset();
}
} else {
if(CRASHED_STAR.starObject.getPickAmount() >= MAXIMUM_MINING_AMOUNT) {
despawn(false);
timer.reset();
}
}
}
//}
public static void despawn(boolean respawn) {
if(respawn) {
timer.reset(0);
} else {
timer.reset();
}
if(CRASHED_STAR != null) {
for(Player p : World.getPlayers()) {
if(p == null) {
continue;
}
p.getPacketSender().sendString(39162, "@cya@Crashed star: @whi@[ @cya@N/A@whi@ ]");
if(p.getInteractingObject() != null && p.getInteractingObject().getId() == CRASHED_STAR.starObject.getId()) {
p.performAnimation(new Animation(65535));
p.getPacketSender().sendClientRightClickRemoval();
p.getSkillManager().stopSkilling();
p.getPacketSender().sendMessage("The star has been fully mined.");
}
}
CustomObjects.deleteGlobalObject(CRASHED_STAR.starObject);
CRASHED_STAR = null;
}
}
}
Mining.java
Code:
public class Mining {
public static final int[] GOLDEN_MINING_SUIT = { 20787, 20788, 20789, 20790, 20791 };
public static final int[] ITEMS = { 20787, 20788, 20789, 20790, 20791};
public static final int INFERNO_ADZE = 13661;
public static void startMining(final Player player, final GameObject oreObject) {
player.getSkillManager().stopSkilling();
player.getPacketSender().sendInterfaceRemoval();
if(!Locations.goodDistance(player.getPosition().copy(), oreObject.getPosition(), 1) && oreObject.getId() != 24444 && oreObject.getId() != 24445 && oreObject.getId() != 38660)
return;
if(player.busy() || player.getCombatBuilder().isBeingAttacked() || player.getCombatBuilder().isAttacking()) {
player.getPacketSender().sendMessage("You cannot do that right now.");
return;
}
if(player.getInventory().getFreeSlots() == 0) {
player.getPacketSender().sendMessage("You do not have any free inventory space left.");
return;
}
player.setInteractingObject(oreObject);
player.setPositionToFace(oreObject.getPosition());
final Ores o = MiningData.forRock(oreObject.getId());
final boolean giveGem = o != Ores.Rune_essence && o != Ores.Pure_essence;
final int reqCycle = o == Ores.Runite ? 6 + Misc.getRandom(2) : Misc.getRandom(o.getTicks() - 1);
if (o != null) {
final int pickaxe = MiningData.getPickaxe(player);
final int miningLevel = player.getSkillManager().getCurrentLevel(Skill.MINING);
if (pickaxe > 0) {
if (miningLevel >= o.getLevelReq()) {
final MiningData.Pickaxe p = MiningData.forPick(pickaxe);
if (miningLevel >= p.getReq()) {
player.performAnimation(new Animation(p.getAnim()));
final int delay = o.getTicks() - MiningData.getReducedTimer(player, p);
player.setCurrentTask(new Task(delay >= 2 ? delay : 1, player, false) {
int cycle = 0;
@Override
public void execute() {
if(player.getInteractingObject() == null || player.getInteractingObject().getId() != oreObject.getId()) {
player.getSkillManager().stopSkilling();
player.performAnimation(new Animation(65535));
stop();
return;
}
if(player.getInventory().getFreeSlots() == 0) {
player.performAnimation(new Animation(65535));
stop();
player.getPacketSender().sendMessage("You do not have any free inventory space left.");
return;
}
if (cycle != reqCycle) {
cycle++;
player.performAnimation(new Animation(p.getAnim()));
}
if(giveGem) {
boolean onyx = (o == Ores.Runite || o == Ores.CRASHED_STAR) && Misc.getRandom(o == Ores.CRASHED_STAR ? 20000 : 5000) == 1;
if(onyx || Misc.getRandom(o == Ores.CRASHED_STAR ? 35 : 50) == 15) {
int gemId = onyx ? 6571 : MiningData.RANDOM_GEMS[(int)(MiningData.RANDOM_GEMS.length * Math.random())];
player.getInventory().add(gemId, 1);
player.getPacketSender().sendMessage("You've found a gem!");
if(gemId == 6571) {
String s = o == Ores.Runite ? "Runite ore" : "Crashed star";
World.sendMessage("<img=10><col=009966> "+player.getUsername()+" has just received an Uncut Onyx from mining a "+s+"!");
}
}
}
int random = Misc.getRandom(100);
if (cycle == reqCycle) {
if(o == Ores.Iron) {
Achievements.finishAchievement(player, AchievementData.MINE_SOME_IRON);
} else if(o == Ores.Runite) {
Achievements.doProgress(player, AchievementData.MINE_25_RUNITE_ORES);
Achievements.doProgress(player, AchievementData.MINE_2000_RUNITE_ORES);
}
random = Misc.getRandom(100);
if(o.getItemId() != -1) {
player.getInventory().add(o.getItemId(), 1);
}
if(player.isInfernoSmelt() && random >= 1 && random <= 10 && player.getEquipment().contains(INFERNO_ADZE)) {
for(int[] data : SmithingData.SmeltData) {
int barId = data[1];
int oreId1 = data[1];
int oreId2 = data[1];
if(oreId1 == o.getItemId() && oreId2 == -1) {
player.getInventory().add(barId, 1);
player.getPacketSender().sendMessage("You mine some ore and your inferno adze smelts it to a bar.");
break;
}
}
}
else if(player.getEquipment().containsAll(20787, 20788, 20789, 20790, 20791)) {
if(o.getItemId() != -1) {
player.getInventory().add(o.getItemId(), 1);
}
int extra = 1;
if(extra > player.getInventory().getFreeSlots()) {
extra = player.getInventory().getFreeSlots();
}
player.getPacketSender().sendFilterMessage("Your golden mining suit has given you extra loot!");
player.getInventory().add(o.getItemId(), extra);
if (Misc.getRandom(100) >= 91) {
player.getPacketSender().sendMessage("<img=10><col=6600CC>@blu@ Your golden mining suit has given you more loot than usual loot!");
player.getInventory().add(o.getItemId(), extra);
}
if (player.getEquipment().contains(13995) || player.getEquipment().contains(13661)) {
player.getSkillManager().addExperience(Skill.MINING, (int) (o.getXpAmount()));
}
}
if(player.getEquipment().containsAll(20149, 20150, 20151, 20274)) {
player.getSkillManager().addExperience(Skill.MINING, (int) (o.getXpAmount()));
}
player.getSkillManager().addExperience(Skill.MINING, (int) (o.getXpAmount()));
if(o == Ores.CRASHED_STAR) {
player.getPacketSender().sendFilterMessage("You mine the crashed star..");
} else {
player.getPacketSender().sendFilterMessage("You mine some ore.");
if (Misc.getRandom(100) >= 84) {
player.getPointsHandler().getSkillPoints();
player.getPointsHandler().setSkillPoints(1, true);
player.getPacketSender().sendFilterMessage("<img=10>You now have @red@" + player.getPointsHandler().getSkillPoints() + " Skill Points!");
}
else if (player.getGameMode() == GameMode.EXTREME || player.getGameMode() == GameMode.EXTREME_IRONMAN || player.getGameMode() == GameMode.EXTREME_HARDCORE_IRONMAN) {
player.getPointsHandler().getSkillPoints();
player.getPointsHandler().setSkillPoints(1, true);
player.getPacketSender().sendFilterMessage("<img=10>You now have @red@" + player.getPointsHandler().getSkillPoints() + " Skill Points!");
}
if (Misc.getRandom(100) >= 90) {
player.getBank(0).add(2995, 1);
player.getPacketSender().sendFilterMessage("<img=10><col=6600CC>@blu@ Skilling Tickets have been added to your bank.");
}
}
Sounds.sendSound(player, Sound.MINE_ITEM);
cycle = 0;
this.stop();
if(o.getRespawn() > 0) {
player.performAnimation(new Animation(65535));
oreRespawn(player, oreObject, o);
} else {
if(oreObject.getId() == 38660) {
if(ShootingStar.CRASHED_STAR == null || ShootingStar.CRASHED_STAR.getStarObject().getPickAmount() >= ShootingStar.MAXIMUM_MINING_AMOUNT) {
player.getPacketSender().sendClientRightClickRemoval();
player.getSkillManager().stopSkilling();
return;
} else {
ShootingStar.CRASHED_STAR.getStarObject().incrementPickAmount();
}
} else {
player.performAnimation(new Animation(65535));
}
startMining(player, oreObject);
}
}
}
});
TaskManager.submit(player.getCurrentTask());
} else {
player.getPacketSender().sendMessage("You need a Mining level of at least "+p.getReq()+" to use this pickaxe.");
}
} else {
player.getPacketSender().sendMessage("You need a Mining level of at least "+o.getLevelReq()+" to mine this rock.");
}
} else {
player.getPacketSender().sendMessage("You don't have a pickaxe to mine this rock with.");
}
}
}
public static void oreRespawn(final Player player, final GameObject oldOre, Ores o) {
if(oldOre == null || oldOre.getPickAmount() >= 1)
return;
oldOre.setPickAmount(1);
for(Player players : player.getLocalPlayers()) {
if(players == null)
continue;
if(players.getInteractingObject() != null && players.getInteractingObject().getPosition().equals(player.getInteractingObject().getPosition().copy())) {
players.getPacketSender().sendClientRightClickRemoval();
players.getSkillManager().stopSkilling();
}
}
player.getPacketSender().sendClientRightClickRemoval();
player.getSkillManager().stopSkilling();
CustomObjects.globalObjectRespawnTask(new GameObject(452, oldOre.getPosition().copy(), 10, 0), oldOre, respawnTime(o));
}
private static int respawnTime(Ores o) {
if(o == Ores.Clay) {
return 2;
}
double baseTime = o.getRespawn();
int max = 2048;
int playersOnline = World.getPlayers().size();
if(playersOnline >= max - 100)
return o.getRespawn();
int factor = 8 - (playersOnline / 250 == 0 ? 1 : playersOnline / 250);
double timeInS = (o.getRespawn() * 600)/ 1000;
double secondFactor = Math.sqrt(baseTime);
for(int i = 0; i < factor; i++) {
timeInS += secondFactor;
}
return (int) Math.floor((timeInS * 1000) / 600) + 5;
}
}