Simple Mystery Box With A Simple Rarity System.
I am creating this snippet as requested by a friend and got bored.
It's pretty simple & easy to follow.
Step 1 - Create A File called MysteryBox.java inside your player directory for instance mines is (ardi.model.players)
In this file add this code:
Code:
package ardi.model.players;
import ardi.model.players.Client;
import ardi.util.Misc;
/*
* Mystery Box by Mikey.
* Please make sure you package the class at the right place and import client.java.
* You'll also need to Import this into ClickItem.java
*/
public class MysteryBox {
private Client c;
public MysteryBox(Client Client) {
this.c = Client;
}
public void LowReward() {
int LowReward[] = { 1065, 1081, 1099 };
int getLowReward = LowReward[Misc.random(LowReward.length - 1)];
String itemNameLow = c.getItems().getItemName(getLowReward).toString();
c.getItems().addItem(getLowReward, 1);
c.getItems().deleteItem(6199, 1);
c.sendMessage("You receive a " + itemNameLow + " in your Mystery Box.");
}
public void MediumReward() {
int MediumReward[] = { 1079, 1128, 1333 };
int getMediumReward = MediumReward[Misc.random(MediumReward.length - 1)];
String itemNameMedium = c.getItems().getItemName(getMediumReward).toString();
c.getItems().addItem(getMediumReward, 1);
c.getItems().deleteItem(6199, 1);
c.sendMessage("You receive a " + itemNameMedium + " in your Mystery Box.");
}
public void HighReward() {
int HighReward[] = { 1038, 1040, 1042 };
int getHighReward = HighReward[Misc.random(HighReward.length - 1)];
String itemNameHigh = c.getItems().getItemName(getHighReward).toString();
c.getItems().addItem(getHighReward, 1);
c.getItems().deleteItem(6199, 1);
c.sendMessage("You receive a " + itemNameHigh + " in your Mystery Box.");
}
}
Just a brief explanation, the arrays LowReward, MediumReward & HighReward is where the item id's of the items you want in the box go. Just change or add onto what I have in there.
Step 2:
In client.java make sure to import your MysteryBox.java class for instance mines would be.
Code:
import ardi.model.players.MysteryBox;
You then you need to search for "cooking" and Under that add:
Code:
private MysteryBox mysterybox = new MysteryBox(this);
Now search for "cooking" again and under that add:
Code:
public MysteryBox getBox() {
return mysterybox;
}
That's step 2 done.
Step 3: Initializing the code, this is done in ClickItem.java and under where similar items are handled add.
Code:
/*
* Caution you may have to import the MysteryBox.java class.
*/
if (itemId == 6199) {
int rewardRoll = Misc.random(10);
if (rewardRoll <= 6) {
c.getBox().LowReward();
}
else
if (rewardRoll > 6 && rewardRoll <= 9) {
c.getBox().MediumReward();
}
else
if (rewardRoll == 10) {
c.getBox().HighReward();
}
}
That should be you done, hopefully the snippet was clear enough to fully let me know of any errors and/or any criticism.
Thanks,
Mikey.