Jump to content
Sign in to follow this  
Hope

Shooting Stars

Recommended Posts

Title pretty much says it all. Here's a class I wrote awhile back for shooting stars. Matrix has a problem with spawning objects on top of each other (don't know if anyone has fixed it yet, and never tried to look since I last wrote it). Anyway, everything works perfectly, except the rock won't *visually* show it being degraded. All players near it will be informed of a degrade in the rock though.

Keep in mind that this is a snippet, and I'm not going to give you a tutorial on how to implement it.

[CODE]
package com.rs.game.player.actions.mining;

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

import com.rs.cores.CoresManager;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.npc.NPC;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
import com.rs.utils.Logger;
import com.rs.utils.Utils;

/*
* @Author Clayton Williams (Hope)
*/

public class ShootingStars {

public static ShootingStar star;
private static long lastLandTime;
public static int SPRITE_CHILD = 8091;
private final static int[] STARS = {38660, 38661, 38662, 38663, 38664, 38665, 38666, 38667, 38668};

public static class ShootingStar {

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

private ShootingStar(int currentId, LocationInfo locationInfo) {
this.currentId = currentId;
this.setLocationInfo(locationInfo);
setStarDust(180);
}

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 enum LocationInfo {

STAR1(new WorldTile(2672, 3363, 0), "South of Ardougne Farming", "Near a place where food is grown."),
STAR2(new WorldTile(3809, 3570, 0), "North Side of the Skilling Island", "On a far away Island with lots of trees and fishing spots."),
STAR3(new WorldTile(3566, 3321, 0), "Near the entrance of barrows", "Near the entrance of the 6 deadly brothers"),
STAR4(new WorldTile(2680, 3717, 0), "Near rock crabs", "Near a place where a new player might train."),
STAR5(new WorldTile(3193, 3235, 0), "Behind Lumbridge Castle", "Behind one of the oldest castles in runescape!"),
STAR6(new WorldTile(2548, 3569, 0), "North of Barbarian Agility", "This one might require some 'running'."),
STAR7(new WorldTile(2342, 3635, 0), "Far north of the Hunting spawn", "Somewhere in the hunting lands.");

private WorldTile possibleLocation;
private String location;
private String hint;

private LocationInfo(WorldTile possibleLocation, String location, String hint) {
this.possibleLocation = possibleLocation;
this.setLocation(location);
this.setHint(hint);
}

private final static List<LocationInfo> values = Collections.unmodifiableList(Arrays.asList(values()));

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

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

public String getHint() {
return hint;
}

public void setHint(String hint) {
this.hint = hint;
}

}

public static void crashStar() {
lastLandTime = Utils.currentTimeMillis();
LocationInfo newSpawn = LocationInfo.getRandomStar();
star = new ShootingStar(38660, newSpawn);
World.spawnObject(new WorldObject(STARS[4], 10, 0, newSpawn.possibleLocation.getX(), newSpawn.possibleLocation.getY(), newSpawn.possibleLocation.getPlane()), false);
World.sendWorldMessage("<col=33CC00>[ShootingStars] A new star has crashed on QuantumX!", false);
}

public static void init() {
crashStar();
WorldTasksManager.schedule(new WorldTask() {
public void run() {
if (Utils.currentTimeMillis() - lastLandTime > 3600000) {
if (star == null) {
crashStar();
}
}
}
}, 0, 1);
}

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

public static void handleDust(Player player) {
star.setStarDust(star.getStarDust() - 1);
player.getInventory().addItem(13727, 1);
player.getInventory().addItem(995, 10000);
player.getSkills().addXp(Skills.MINING, 30);
player.sm("You get some star dust and some money.");
for (int i = 0; i < STARS.length; i++) {
if (STARS[i] == star.currentId) {
if (star.getStarDust() <= Math.abs(i - 8) * 20 ) {
if (i != 8) {
star.currentId = STARS[i + 1]; //Would be i + 1
World.spawnObject(new WorldObject(STARS[4] /*Would be STARS[i + 1], but objects on top of object spawning are fucked*/, 10, 0, star.getLocationInfo().possibleLocation.getX(), star.getLocationInfo().possibleLocation.getY(), star.getLocationInfo().possibleLocation.getPlane()), false);
List<Integer> miners = World.getRegion(player.getRegionId()).getPlayerIndexes();
for (int i1 = 0; i1 < miners.size(); i1++) {
Player m = World.getPlayers().get(miners.get(i1));
m.getActionManager().forceStop();
m.sm("<col=33CC00>[ShootingStars] You manage to crack the rock some... Only "+star.starDust+" star dust remaining");
}
//Would also be i + 1
} else {
World.spawnObject(new WorldObject(-1, 10, 2, star.getLocationInfo().possibleLocation.getX(), star.getLocationInfo().possibleLocation.getY(), star.getLocationInfo().possibleLocation.getPlane()), false);
World.spawnNPC(SPRITE_CHILD, star.getLocationInfo().possibleLocation, -1, true);
List<Integer> miners = World.getRegion(player.getRegionId()).getPlayerIndexes();
for (int i1 = 0; i1 < miners.size(); i1++) {
Player m = World.getPlayers().get(miners.get(i1));
m.getActionManager().forceStop();
}
World.sendWorldMessage("<col=33CC00>[ShootingStars] The Star Child will only be visible for the next 10 minutes.", false);
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != SPRITE_CHILD)
continue;
n.sendDeath(n);
star = null;
}
} catch (Throwable t) {
Logger.handle(t);
}
}
}, 600000);
}
}
}
}
}

public static void handleOption2(Player player) {
player.sm("Only "+star.starDust+" star dust remaining.");
}
}

[/CODE]

Share this post


Link to post
Share on other sites
It looks alright although it gets a bit bunched up in the handleDust method, also You could just use an array for storing the Stars location instead of an enum, as it looks like your not even using the Strings in the enum. But good job

Share this post


Link to post
Share on other sites
[quote name='xi s p e c']It looks alright although it gets a bit bunched up in the handleDust method, also You could just use an array for storing the Stars location instead of an enum, as it looks like your not even using the Strings in the enum. But good job[/QUOTE]

The strings in the enum are used, just not in this class. They're solely for giving the player hints of where the star is. Anyone who implements this can easily use the hints and apply them to whatever they wish, whether it may be an NPC, Item, or Object.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×