Jump to content
Hope

Shooting Stars

Recommended Posts

Wrote this a long time ago for 718's, but just converted it to 637 for use in Dementhium. It's only missing a few minimal things, you can figure them out. :)

[B]ShootingStars.java[/B]

[code]
package org.dementhium.content.skills.mining;


import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.TimerTask;


import org.dementhium.Configurations;
import org.dementhium.content.DialogueManager;
import org.dementhium.model.Location;
import org.dementhium.model.World;
import org.dementhium.model.map.ObjectManager;
import org.dementhium.model.map.Region;
import org.dementhium.model.mask.Animation;
import org.dementhium.model.npc.NPC;
import org.dementhium.model.player.Player;
import org.dementhium.model.player.Skills;
import org.dementhium.net.ActionSender;
import org.dementhium.util.InterfaceSettings;
import org.dementhium.util.Timers;
import org.dementhium.util.Utils;


/**
*
* [MENTION=52317]auth[/MENTION]or Clayton Williams (Hope) <[email protected]>
* Date: Mar 14, 2014
*
*/
public class ShootingStars {

public static int SPRITE_CHILD = 8091, STAR_INTERFACE = 782;
public final static int[] STARS = {38660, 38661, 38662, 38663, 38664, 38665, 38666, 38667, 38668};

private static ShootingStar star = null;
private static long lastLandTime;
private static final int INITIAL_STARDUST = 180;

public enum LocationInfo {

STAR1(Location.locate(2672, 3363, 0), "Near a place where food is grown in Ardougne."),
STAR2(Location.locate(3566, 3321, 0), "Near the entrance of the 6 deadly brothers"),
STAR3(Location.locate(2591, 3389, 0), "Let's go fishin'."),
STAR4(Location.locate(3193, 3235, 0), "Behind one of the oldest castles in runescape!"),
STAR5(Location.locate(2548, 3569, 0), "This one might require some 'running'."),
STAR6(Location.locate(2342, 3635, 0), "Somewhere in the hunting lands of the north.");

private Location possibleLocation;
private String hint;

private LocationInfo(Location possibleLocation, String hint) {
this.possibleLocation = possibleLocation;
this.hint = hint;
}


public static LocationInfo getRandomStar() {
return Collections.unmodifiableList(Arrays.asList(values())).get(Utils.random(LocationInfo.values().length));
}


public Location getLocation() {
return possibleLocation;
}


public String getHint() {
return hint;
}

}

private static void crashStar() {
lastLandTime = Utils.currentTimeMillis();
LocationInfo newSpawn = LocationInfo.getRandomStar();
star = new ShootingStar(0, newSpawn);
ObjectManager.addCustomObject(STARS[0], star.getLocationInfo().getLocation().getX(), star.getLocationInfo().getLocation().getY(), star.getLocationInfo().getLocation().getZ(), 10, 0, true);
World.getWorld().sendWorldMessage("<col=33CC00>[ShootingStars] A new star has crashed on " + Configurations.SERVER_NAME + "!");
}

public static void init() {
System.out.println("Initializing Shooting Stars...");
lastLandTime = Utils.currentTimeMillis() - 3600000;
Timers.fastExecutor.schedule(new TimerTask() {
public void run() {
if (Utils.currentTimeMillis() - lastLandTime > 3600000) {
if (star == null) {
crashStar();
}
}
}
}, 60000, 10000);
}


public static int getStarLevel() {
int starId = star.currentId;
for (int i = 0; i < STARS.length; i++) {
if (STARS[i] == starId) {
return Math.abs(i - STARS.length);
}
}
return 0;
}


public static void handleDust(Player player) {
star.setStarDust(star.getStarDust() - 1);
player.getSkills().addExperience(Skills.MINING, 50); //TODO correct exp per star size
player.sendMessage("You get some star dust.");
for (int i = 0; i < STARS.length; i++) {
if (STARS[i] == star.currentId) {
if (star.getStarDust() <= (getStarLevel() * (INITIAL_STARDUST / STARS.length))) {
List<Player> miners = Region.getLocalPlayers(star.getLocationInfo().getLocation());
if (i != STARS.length) {
star.currentId = STARS[i + 1];
ObjectManager.addCustomObject(STARS[i + 1], star.getLocationInfo().getLocation().getX(), star.getLocationInfo().getLocation().getY(), star.getLocationInfo().getLocation().getZ(), 10, 0, true);
for (Player p : miners) {
p.getActionManager().stopAction();
p.sendMessage("<col=33CC00>[ShootingStars] You manage to crack the rock some... Only "+star.starDust+" star dust remaining");
}
} else {
ObjectManager.removeCustomObject(star.getLocationInfo().getLocation(), 10);
World.getWorld().register(SPRITE_CHILD, star.getLocationInfo().getLocation()).setDoesWalk(false).setUnrespawnable(true);
for (Player p : miners) {
p.getActionManager().stopAction();
}
World.getWorld().sendWorldMessage("<col=33CC00>[ShootingStars] The Star Child will only be visible for the next 10 minutes.");
Timers.fastExecutor.schedule(new TimerTask() {
[MENTION=15855]Over[/MENTION]ride
public void run() {
try {
for (NPC n : World.getWorld().getNpcs()) {
if (n == null || n.getId() != SPRITE_CHILD)
continue;
n.sendDead();
star = null;
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}, 600000); // 10 Minutes for sprite child
}
}
}
}
}


public static void handleTelescope(final Player player) {
//TODO don't have stuff for dialogue over window pane.
ActionSender.sendWindowsPane(player, STAR_INTERFACE, 0);
Timers.fastExecutor.schedule(new TimerTask() {
[MENTION=15855]Over[/MENTION]ride
public void run() {
player.animate(Animation.RESET);
player.setAttribute("resetCanvasAndRegionalData", true);
InterfaceSettings.switchWindow(player, player.getConnection().getDisplayMode());
if (star == null) {
DialogueManager.sendDialogue(player, DialogueManager.CALM_TALK, -1, -1, "Hmm, looks like the star hasn't landed yet.", "Maybe it'll land within the next hour...");
} else {
DialogueManager.sendDialogue(player, DialogueManager.CALM_TALK, -1, -1, "Wow, the star landed not too long ago!", "Hint: " + star.getLocationInfo().getHint());
}
}
}, 3000);
}

public static class ShootingStar {

private int currentId;
private int starDust;
private LocationInfo locationInfo;

private ShootingStar(int randomStarIndex, LocationInfo locationInfo) {
this.currentId = STARS[randomStarIndex];
this.setLocationInfo(locationInfo);
setStarDust((randomStarIndex + 1) * (INITIAL_STARDUST / STARS.length));
}

public int getStarDust() {
return starDust;
}


public void setStarDust(int starDust) {
this.starDust = starDust;
}


public LocationInfo getLocationInfo() {
return locationInfo;
}


public void setLocationInfo(LocationInfo locationInfo) {
this.locationInfo = locationInfo;
}
}

public static ShootingStar getStar() {
return star;
}
}
[/code]

[B]HarvestAction.java[/B]

[code]
if (level < ShootingStars.getStarLevel() * 10) {
player.sendMessage("You need a mining level of " + ShootingStars.getStarLevel() * 10 + " to mine this level " + ShootingStars.getStarLevel() + " star.");
stopHarvesting();
return;
}
[/code]

[code]

for (int i : ShootingStars.STARS){
if (i == gameObject.getId()) {
ShootingStars.handleDust(player);
return;
}
}
[/code]

[B]Mining.java[/B]

[code]
STAR(13727, 1, 1, -1, ShootingStars.STARS);
[/code] Edited by Hope

Share this post


Link to post
Share on other sites
omg this is the best thing you've ever written you're the best. Implementing this into my 508 right now.

(no troll luv u)

Share this post


Link to post
Share on other sites
[QUOTE=BMW';772426]omg this is the best thing you've ever written you're the best. Implementing this into my 508 right now.

(no troll luv u)[/QUOTE]

Thanks, lol. There's Shooting Stars in 508's?

Share this post


Link to post
Share on other sites
[quote name='Hope']Thanks, lol. There's Shooting Stars in 508's?[/QUOTE]

No I'm fucking with you. Do you know who I Iz?

Share this post


Link to post
Share on other sites

×