mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-31 11:01:21 +01:00
Added random items to MMOCore drop tables
This commit is contained in:
parent
49cd441d71
commit
bf6c986ba4
BIN
lib/MMOCore.jar
BIN
lib/MMOCore.jar
Binary file not shown.
@ -92,10 +92,10 @@ public class MMOCoreMMOLoader extends MMOLoader {
|
||||
if (config.getKey().equals("mmoitem"))
|
||||
return new MMOItemDropItem(config);
|
||||
|
||||
if (config.getKey().equals("mitemplate"))
|
||||
if (config.getKey().equals("gentemplate"))
|
||||
return new ItemTemplateDropItem(config);
|
||||
|
||||
if (config.getKey().equals("mirandomitem") || config.getKey().equals("miri"))
|
||||
if (config.getKey().equals("miloot"))
|
||||
return new RandomItemDropItem(config);
|
||||
|
||||
return null;
|
||||
|
@ -0,0 +1,28 @@
|
||||
package net.Indyuce.mmoitems.comp.mmocore.load;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmocore.api.droptable.dropitem.DropItem;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ItemTier;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
public abstract class ItemGenerationDropItem extends DropItem {
|
||||
protected final boolean matchLevel;
|
||||
protected final int level;
|
||||
protected final ItemTier tier;
|
||||
|
||||
public ItemGenerationDropItem(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
matchLevel = config.getBoolean("match-level", false);
|
||||
level = config.getInt("level", 1);
|
||||
|
||||
if (config.contains("tier")) {
|
||||
String format = config.getString("tier").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
Validate.isTrue(MMOItems.plugin.getTiers().has(format), "Could not find item tier with ID '" + format + "'");
|
||||
tier = MMOItems.plugin.getTiers().get(format);
|
||||
} else
|
||||
tier = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package net.Indyuce.mmoitems.comp.mmocore.load;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.itemgen.GenerationTemplate;
|
||||
import net.Indyuce.mmoitems.api.itemgen.tier.RolledTier;
|
||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
public class ItemTemplateDropItem extends ItemGenerationDropItem {
|
||||
private final GenerationTemplate template;
|
||||
|
||||
public ItemTemplateDropItem(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
config.validate("id");
|
||||
|
||||
String id = config.getString("id");
|
||||
Validate.isTrue(MMOItems.plugin.getItemGenerator().hasTemplate(id), "Could not find gen template with ID '" + id + "'");
|
||||
template = MMOItems.plugin.getItemGenerator().getTemplate(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collect(LootBuilder builder) {
|
||||
RPGPlayer rpgPlayer = builder.getEntity().getMMOPlayerData().getMMOItems().getRPG();
|
||||
|
||||
int itemLevel = MMOItems.plugin.getItemGenerator().rollLevel(matchLevel ? rpgPlayer.getLevel() : this.level);
|
||||
RolledTier itemTier = this.tier != null ? new RolledTier(MMOItems.plugin.getItemGenerator().getTierInfo(this.tier), itemLevel)
|
||||
: MMOItems.plugin.getItemGenerator().rollTier(itemLevel);
|
||||
|
||||
builder.addLoot(template.newBuilder(itemLevel, itemTier).build().newBuilder().build());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package net.Indyuce.mmoitems.comp.mmocore.load;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmocore.api.loot.LootBuilder;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.itemgen.loot.restriction.ClassFilter;
|
||||
import net.Indyuce.mmoitems.api.itemgen.loot.restriction.TypeFilter;
|
||||
import net.Indyuce.mmoitems.api.itemgen.tier.RolledTier;
|
||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
import net.mmogroup.mmolib.api.MMOLineConfig;
|
||||
|
||||
public class RandomItemDropItem extends ItemGenerationDropItem {
|
||||
|
||||
// generation options
|
||||
private final boolean matchClass;
|
||||
private final String profess;
|
||||
private final Type type;
|
||||
|
||||
public RandomItemDropItem(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
matchClass = config.getBoolean("match-class", false);
|
||||
profess = config.getString("class", "");
|
||||
|
||||
if (config.contains("type")) {
|
||||
String format = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type with ID '" + format + "'");
|
||||
type = MMOItems.plugin.getTypes().get(format);
|
||||
} else
|
||||
type = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collect(LootBuilder builder) {
|
||||
RPGPlayer rpgPlayer = builder.getEntity().getMMOPlayerData().getMMOItems().getRPG();
|
||||
|
||||
int itemLevel = MMOItems.plugin.getItemGenerator().rollLevel(matchLevel ? rpgPlayer.getLevel() : this.level);
|
||||
RolledTier itemTier = this.tier != null ? new RolledTier(MMOItems.plugin.getItemGenerator().getTierInfo(this.tier), itemLevel)
|
||||
: MMOItems.plugin.getItemGenerator().rollTier(itemLevel);
|
||||
|
||||
net.Indyuce.mmoitems.api.itemgen.loot.LootBuilder loot = new net.Indyuce.mmoitems.api.itemgen.loot.LootBuilder(itemLevel, itemTier);
|
||||
|
||||
if (matchClass)
|
||||
loot.applyFilter(new ClassFilter(rpgPlayer));
|
||||
else if (!profess.isEmpty())
|
||||
loot.applyFilter(new ClassFilter(profess));
|
||||
|
||||
if (type != null)
|
||||
loot.applyFilter(new TypeFilter(type));
|
||||
|
||||
MMOItem rolled = loot.rollLoot();
|
||||
if (rolled == null)
|
||||
return;
|
||||
|
||||
ItemStack gen = rolled.newBuilder().build();
|
||||
gen.setAmount(rollAmount());
|
||||
builder.addLoot(gen);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user