Jump to content

The RuneLocus forum has been archived and does not accept new registrations.
Click here for more information, and click here to join the community on Discord.

100% Mystery Box & Caskets (Like RuneScape using Common, Uncommon, Rare, Very Rare)


Shadowpker
 Share

Recommended Posts

I've seen other releases, but not one's that work just like RuneScape. I used the items and descriptions from here and here to complete these classes. Hope these can be useful for some of you. Good luck


/**
*
* @author Thee Lion / Letters
*
*/
public class Casket {

/**
* Opens up the box.
* [MENTION=75098]Para[/MENTION]m c
* [MENTION=75098]Para[/MENTION]m id
*/
public static void openCasket(Client c, int id) {
int item = 405;
if (id == item) {
c.getItems().deleteItem(405, 1);
getPrize(c);
getPrize(c);
} else {
c.sendMessage("Not enough space in your inventory.");
}
}

/**
* Common
*/
public static int COMMON [] = {
1623, 1454
};




/**
* Uncommon
*/
public static int UNCOMMON [] = {
1621, 1619, 1452
};

/**
* Rare
*/
public static int[] RARE = {
1617, 987, 985
};




/**
* Places the prizes Common, Uncommon, Rare and Very Rare into the players bank.
* [MENTION=75098]Para[/MENTION]m c
* [MENTION=184045]return[/MENTION]
*/
public static int getPrize(final Client c) {
int random = Misc.random(100);
int coinAmount = 8000 + Misc.random(4000);
int common = COMMON[(int) (Math.random() * COMMON.length)];
int uncommon = UNCOMMON[(int) (Math.random() * UNCOMMON.length)];
int rare = RARE[(int) (Math.random() * RARE.length)];
if (random <= 10) {
c.getItems().addItem(common, 1);
c.sendMessage("Inside the Casket you find a "+c.getItems().getItemName(common) + " and "+coinAmount+" coins! Excellent!");
c.getItems().addItem(995, coinAmount);
} else if (random >= 65 && random <= 89) {
c.getItems().addItem(uncommon, 1);
c.sendMessage("Inside the Casket you find a "+c.getItems().getItemName(uncommon) + " and "+coinAmount+" coins! Awesome!");
c.getItems().addItem(995, coinAmount);
} else if (random >= 90 && random <= 100) {
c.getItems().addItem(rare, 1);
c.sendMessage("Inside the Casket you find a "+c.getItems().getItemName(rare) + " and "+coinAmount+" coins! Excellent!");
c.getItems().addItem(995, coinAmount);
}
return common;
}
}


/** *
* @author Thee Lion / Letters
*
*/
public class MysteryBox {

/**
* Opens up the box.
* [MENTION=75098]Para[/MENTION]m c
* [MENTION=75098]Para[/MENTION]m id
*/
public static void openBox(Client c, int id) {
int item = 6199;
if (id == item) {
c.getItems().deleteItem(6199, 1);
getPrize(c);
} else {
c.sendMessage("Not enough space in your inventory.");
}
}


/**
* Common
*/
public static int COMMON [] =
{685, 1623, 6438, 8986, 1965, 956, 1061, 1957, 592, 359};




/**
* Uncommon
*/
public static int UNCOMMON [] =
{405, 1621, 7937, 1119, 1442, 1444};

/**
* Rare
*/
public static int[] RARE = {
1601, 563, 561, 1329, 1315, 1123, 1454
};




/**
* Very Rare
*/
public static int[] VERY_RARE = {
1128, 985, 987
};




/**
* Places the prizes Common, Uncommon, Rare and Very Rare into the players bank.
* Param c
* return
*/
public static int getPrize(final Client c) {
int random = Misc.random(100);
int coinAmount = 5000 + Misc.random(2500);
int common = COMMON[(int) (Math.random() * COMMON.length)];
int uncommon = UNCOMMON[(int) (Math.random() * UNCOMMON.length)];
int rare = RARE[(int) (Math.random() * RARE.length)];
int very_rare = VERY_RARE[(int) (Math.random() * VERY_RARE.length)];
if(rare == 563 || rare == 561 || common == 7937) {
c.getItems().addItem(563, 10);
c.getItems().addItem(561, 20);
c.getItems().addItem(7937, 30);
}
if (random <= 10) {
c.getItems().addItem(common, 1);
c.sendMessage("Inside the box you find a "+c.getItems().getItemName(common) + " and "+coinAmount+" coins! Awesome!");
c.getItems().addItem(995, coinAmount);
} else if (random >= 65 && random <= 89) {
c.getItems().addItem(uncommon, 1);
c.sendMessage("Inside the box you find a "+c.getItems().getItemName(uncommon) + " and "+coinAmount+" coins! Excellent!");
c.getItems().addItem(995, coinAmount);
} else if (random >= 90 && random <= 100) {
c.getItems().addItem(rare, 1);
c.sendMessage("Inside the box you find a "+c.getItems().getItemName(rare) + " and "+coinAmount+" coins! Awesome!");
c.getItems().addItem(995, coinAmount);
} else if (random >= 100 && random <= 110) {
c.getItems().addItem(very_rare, 1);
c.sendMessage("Inside the box you find a "+c.getItems().getItemName(very_rare) + " and "+coinAmount+" coins! Awesome!");
c.getItems().addItem(995, coinAmount);
}
return common;
}
}
-----
  

MysteryBox.openBox(c, itemId);
Casket.openCasket(c, itemId);

 

Link to comment
Share on other sites

[quote name='Game Master']If you wanted to put a percentage on each individual item, you could load them as a map, or make it into an enumeration. That would be pretty nifty.





Or just an annotation.[/QUOTE]NO. Reloadable files all the way.
Link to comment
Share on other sites

Well if you use an annotation and save the properties in, say, an XML file - that would be quite efficient. This could also allow you to make changes to it without having to restart your server. Edited by Game Master
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
7 hours ago, Teek said:

Why not use chance?

 

	int random = Math.getRandom();
	if (random < 0.1)//chance
	

 

There's hardly a difference between Misc.random(int); and Math.getRandom(); You're correct by saying Math.getRandom() is a chance, however Misc.random(int) does the very same thing basically, slightly pro-longed though as it'll do a few more steps. Barely a difference between the two.

 

On-topic though. I really can't see the point in posting the same thing twice here, the only thing that changed are the sent strings and ids within the arrays.

Another thing I'm struggling to find here is the check for mystery box and the removal of mystery box.

PS: Since these two are almost identical, you could've just made them both in one class, through different arrays. Could've saved an entire class. Nonetheless though, thank you for contributing. Minor improvements could be done as you can tell but it's nothing bad, good job.

Link to comment
Share on other sites

Just now, Eldritch said:

There's hardly a difference between Misc.random(int); and Math.getRandom(); You're correct by saying Math.getRandom() is a chance, however Misc.random(int) does the very same thing basically, slightly pro-longed though as it'll do a few more steps. Barely a difference between the two.

 

On-topic though. I really can't see the point in posting the same thing twice here, the only thing that changed are the sent strings and ids within the arrays.

Another thing I'm struggling to find here is the check for mystery box and the removal of mystery box.

PS: Since these two are almost identical, you could've just made them both in one class, through different arrays. Could've saved an entire class. Nonetheless though, thank you for contributing. Minor improvements could be done as you can tell but it's nothing bad, good job.

 

It's 1000000000000000x better than having if statements everyone, math.random is simple..

	int percent = Math.random();
	if (percent < 0.001)
	item = VERY_RARE;
	else if (percent < 0.005)
	item = RARE;
	else 
	item = COMMON;
	

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...