uhhh go brrr?
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package plugin.drops;
|
||||
|
||||
import core.game.node.item.Item;
|
||||
import core.plugin.Plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class DropPlugin implements Plugin<Object> {
|
||||
|
||||
//the list of NPCs this plugin can effect, if left blank it effects all NPCs.
|
||||
public int[] accepted_npcs;
|
||||
|
||||
//allows a super constructor to define the npcs
|
||||
public DropPlugin(int... accepted_npcs){
|
||||
this.accepted_npcs = accepted_npcs;
|
||||
}
|
||||
|
||||
//necessary for the plugin framework, doesnt need to be changed ever.
|
||||
@Override
|
||||
public Object fireEvent(String identifier, Object... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//defines an abstract method all drop plugins must implement
|
||||
public abstract List<Item> handle();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package plugin.drops;
|
||||
|
||||
import core.game.node.item.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DropPlugins {
|
||||
public static HashMap<Integer,List<DropPlugin>> plugins = new HashMap<>();
|
||||
public static List<DropPlugin> globalPlugins = new ArrayList<>();
|
||||
public static List<Item> getDrops(int npc_id){
|
||||
List<Item> drops = new ArrayList<>();
|
||||
List<DropPlugin> toHandle = plugins.get(npc_id);
|
||||
if(toHandle != null) {
|
||||
for (DropPlugin plugin : toHandle) {
|
||||
drops.addAll(plugin.handle());
|
||||
}
|
||||
}
|
||||
if(!globalPlugins.isEmpty()) {
|
||||
for (DropPlugin plugin : globalPlugins) {
|
||||
drops.addAll(plugin.handle());
|
||||
}
|
||||
}
|
||||
return drops;
|
||||
}
|
||||
|
||||
public static void register(DropPlugin plugin){
|
||||
if(plugin.accepted_npcs.length > 0) {
|
||||
Arrays.stream(plugin.accepted_npcs).forEach(id -> {
|
||||
if (plugins.get(id) == null) {
|
||||
List<DropPlugin> newlist = new ArrayList<>();
|
||||
plugins.putIfAbsent(id, newlist);
|
||||
}
|
||||
plugins.get(id).add(plugin);
|
||||
});
|
||||
} else {
|
||||
globalPlugins.add(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package plugin.drops.mystery_box;
|
||||
|
||||
import core.game.node.item.Item;
|
||||
import core.plugin.Initializable;
|
||||
import core.plugin.Plugin;
|
||||
import core.plugin.PluginManifest;
|
||||
import core.tools.Items;
|
||||
import core.tools.RandomFunction;
|
||||
import plugin.drops.DropPlugin;
|
||||
import plugin.drops.DropPlugins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Initializable
|
||||
@PluginManifest(name="MysteryBox")
|
||||
public class MysteryBoxDropper extends DropPlugin {
|
||||
|
||||
//percentage chance of it dropping, between 1 and 100.
|
||||
private int chance = 15;
|
||||
List<Item> drops = new ArrayList<>(); //the list of dropped items
|
||||
|
||||
//standard way to initialize a drop plugin
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
DropPlugins.register(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
//default constructor used, called when the plugin manager initializes this plugin.
|
||||
//super() for a drop plugin simply means all NPCs can use this drop
|
||||
public MysteryBoxDropper(){
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> handle() {
|
||||
boolean willDrop = RandomFunction.random(chance) == RandomFunction.random(chance);
|
||||
drops.clear();
|
||||
if(willDrop){
|
||||
drops.add(new Item(Items.MYSTERY_BOX_6199));
|
||||
}
|
||||
return drops;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package plugin.drops.mystery_box;
|
||||
|
||||
import core.cache.def.impl.ItemDefinition;
|
||||
import core.game.interaction.OptionHandler;
|
||||
import core.game.node.Node;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.node.item.WeightedChanceItem;
|
||||
import core.plugin.Plugin;
|
||||
import core.plugin.PluginManifest;
|
||||
import core.tools.Items;
|
||||
import core.tools.RandomFunction;
|
||||
import core.plugin.Initializable;
|
||||
import core.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* Handles the mystery box item.
|
||||
* @author Ceikry
|
||||
*/
|
||||
@Initializable
|
||||
@PluginManifest(name="MysteryBox")
|
||||
public final class MysteryBoxPlugin extends OptionHandler {
|
||||
|
||||
/**
|
||||
* The rewards recieved from a mystery box.
|
||||
*/
|
||||
private static final WeightedChanceItem[] REWARDS = new WeightedChanceItem[] {
|
||||
|
||||
new WeightedChanceItem(Items.UNCUT_DIAMOND_1617,1,10),
|
||||
new WeightedChanceItem(Items.UNCUT_RUBY_1619,1,50),
|
||||
new WeightedChanceItem(Items.UNCUT_SAPPHIRE_1623,1,60),
|
||||
new WeightedChanceItem(Items.UNCUT_JADE_1627,1,150),
|
||||
new WeightedChanceItem(Items.UNCUT_DRAGONSTONE_1631,1,1),
|
||||
new WeightedChanceItem(Items.MOLTEN_GLASS_1776,25,5),
|
||||
new WeightedChanceItem(Items.UNCUT_EMERALD_1621,1,60),
|
||||
new WeightedChanceItem(Items.COINS_995,25,30),
|
||||
new WeightedChanceItem(Items.COINS_995,250,50),
|
||||
new WeightedChanceItem(Items.COINS_995,10,80),
|
||||
new WeightedChanceItem(0,1,100),
|
||||
new WeightedChanceItem(Items.UNCUT_OPAL_1625,1,150),
|
||||
new WeightedChanceItem(Items.VIAL_OF_WATER_228,10,25),
|
||||
new WeightedChanceItem(Items.VARROCK_TELEPORT_8007,10,5),
|
||||
new WeightedChanceItem(Items.FALADOR_TELEPORT_8009,10,5)
|
||||
};
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
ItemDefinition.forId(6199).getHandlers().put("option:open", this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(Player player, Node node, String option) {
|
||||
final Item item = RandomFunction.rollWeightedChanceTable(REWARDS);
|
||||
String name = item.getName().toLowerCase();
|
||||
if(item.getId() == 0){
|
||||
name = "nothing";
|
||||
}
|
||||
final Item box = (Item) node;
|
||||
if (player.getInventory().remove(box, box.getSlot(), true)) {
|
||||
String message;
|
||||
player.lock(1);
|
||||
if(name.equals("notithing")){
|
||||
message = "Inside the box you find nothing :(";
|
||||
} else {
|
||||
if(item.getAmount() > 1 && item.getId() != 995){
|
||||
name = name + "s";
|
||||
}
|
||||
message = "Inside the box you find " + (item.getAmount() > 1 ? "some" : (StringUtils.isPlusN(name) ? "an" : "a")) + " " + name + "!";
|
||||
}
|
||||
player.sendMessage(message);
|
||||
if(item.getId() != 0)
|
||||
player.getInventory().add(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isWalk() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user