use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.
the class LootTable method getDrops.
/**
* @param loc
* @return The items the NPC dropped at a specified location.
*
* @implNote Probabilities are factored in to this, so identical
* calls may not produce identical results.
*/
public Set<Item> getDrops(Location loc) {
if (lootTable == null) {
return new HashSet<>();
}
double multiplier = Dragons.getInstance().getServerOptions().getDropChanceMultiplier();
Set<Region> regions = regionLoader.getRegionsByLocation(loc);
Set<Item> drops = new HashSet<>();
for (Region region : regions) {
Document regionLoots = (Document) lootTable.get(region.getName());
if (regionLoots == null) {
continue;
}
for (Entry<String, Object> loot : (Iterable<Entry<String, Object>>) regionLoots.entrySet()) {
double chance = (double) loot.getValue();
if (Math.random() < chance * multiplier / 100.0D) {
ItemClass itemClass = itemClassLoader.getItemClassByClassName(loot.getKey());
Item item = itemLoader.registerNew(itemClass);
drops.add(item);
}
}
}
return drops;
}
use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.
the class ItemCommand method setNameColor.
private void setNameColor(CommandSender sender, String[] args) {
ItemClass itemClass = lookupItemClass(sender, args[0]);
if (itemClass == null)
return;
ChatColor nameColor = StringUtil.parseChatColor(sender, args[2]);
if (nameColor == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setNameColor(nameColor);
sender.sendMessage(ChatColor.GREEN + "Updated item display name color successfully.");
AUDIT_LOG.saveEntry(itemClass, user(sender), base, "Set display name color to " + nameColor);
}
use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.
the class ItemCommand method manageAddons.
private void manageAddons(CommandSender sender, String[] args) {
ItemClass itemClass = lookupItemClass(sender, args[0]);
if (itemClass == null)
return;
User user = user(sender);
if (args.length == 2) {
sender.sendMessage(ChatColor.GREEN + "Listing addons for item class " + itemClass.getClassName() + ":");
for (ItemAddon addon : itemClass.getAddons()) {
sender.sendMessage(ChatColor.GRAY + "- " + addon.getName());
}
} else if (args.length == 3) {
sender.sendMessage(ChatColor.RED + "Specify an addon name! For a list of addons, do /addon -l");
} else {
Addon addon = addonRegistry.getAddonByName(args[3]);
if (addon == null) {
sender.sendMessage(ChatColor.RED + "Invalid addon name! For a list of addons, do /addon -l");
} else if (!(addon instanceof ItemAddon)) {
sender.sendMessage(ChatColor.RED + "Invalid addon type! Only Item Addons can be applied to items.");
} else if (args[2].equalsIgnoreCase("add")) {
Document base = Document.parse(itemClass.getData().toJson());
itemClass.addAddon((ItemAddon) addon);
sender.sendMessage(ChatColor.GREEN + "Added addon " + addon.getName() + " to item class " + itemClass.getClassName() + ".");
AUDIT_LOG.saveEntry(itemClass, user, base, "Added addon " + addon.getName());
} else if (args[2].equalsIgnoreCase("remove")) {
Document base = Document.parse(itemClass.getData().toJson());
itemClass.removeAddon((ItemAddon) addon);
sender.sendMessage(ChatColor.GREEN + "Removed addon " + addon.getName() + " from item class " + itemClass.getClassName() + ".");
AUDIT_LOG.saveEntry(itemClass, user, base, "Removed addon " + addon.getName());
} else {
sender.sendMessage(ChatColor.RED + "Invalid arguments! /item <ClassName> addon [<add|remove> <AddonName>]");
}
}
}
use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.
the class ItemCommand method createClass.
private void createClass(CommandSender sender, String[] args) {
if (args.length < 7) {
sender.sendMessage(ChatColor.RED + "Insufficient arguments! /item create <ClassName> <MaterialType> <LvMin> <Cooldown> <Damage> <Armor>");
return;
}
Material type = StringUtil.parseMaterialType(sender, args[2]);
if (type == null)
return;
Integer lvMin = parseInt(sender, args[3]);
Double cooldown = parseDouble(sender, args[4]);
Double damage = parseDouble(sender, args[5]);
Double armor = parseDouble(sender, args[6]);
if (lvMin == null || cooldown == null || damage == null || armor == null)
return;
ItemClass itemClass = itemClassLoader.registerNew(args[1], "Unnamed Item", ChatColor.GOLD, type, lvMin, cooldown, 0.0, false, false, damage, armor, new ArrayList<>(), 64);
if (itemClass == null) {
sender.sendMessage(ChatColor.RED + "An error occurred! Does an item class by this name already exist?");
return;
}
// MetadataConstants.addBlankMetadata(itemClass, user(sender));
AUDIT_LOG.saveEntry(itemClass, user(sender), "Created");
sender.sendMessage(ChatColor.GREEN + "Successfully created item class " + args[1]);
}
use of mc.dragons.core.gameobject.item.ItemClass in project DragonsOnline by UniverseCraft.
the class ItemCommand method setAttribute.
private void setAttribute(CommandSender sender, String[] args) {
ItemClass itemClass = lookupItemClass(sender, args[0]);
if (itemClass == null)
return;
User user = user(sender);
if (args.length == 2) {
sender.sendMessage(ChatColor.RED + "Invalid arguments! /item <ClassName> <Attribute> <Value>");
} else if (args[1].equalsIgnoreCase("type")) {
Material type = StringUtil.parseMaterialType(sender, args[2]);
if (type == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setMaterial(type);
sender.sendMessage(ChatColor.GREEN + "Updated item type successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item type to " + type);
} else if (args[1].equalsIgnoreCase("lvmin")) {
Integer lvMin = parseInt(sender, args[2]);
if (lvMin == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setLevelMin(lvMin);
sender.sendMessage(ChatColor.GREEN + "Updated level min successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item level min to " + lvMin);
} else if (args[1].equalsIgnoreCase("cooldown")) {
Double cooldown = parseDouble(sender, args[2]);
if (cooldown == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setCooldown(cooldown);
sender.sendMessage(ChatColor.GREEN + "Updated cooldown successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item cooldown to " + cooldown);
} else if (args[1].equalsIgnoreCase("unbreakable")) {
Boolean unbreakable = parseBoolean(sender, args[2]);
if (unbreakable == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setUnbreakable(unbreakable);
sender.sendMessage(ChatColor.GREEN + "Updated unbreakable status successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item unbreakability to " + unbreakable);
} else if (args[1].equalsIgnoreCase("undroppable")) {
Boolean undroppable = parseBoolean(sender, args[2]);
if (undroppable == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setUndroppable(undroppable);
sender.sendMessage(ChatColor.GREEN + "Updated undroppable status successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item undroppability to " + undroppable);
} else if (args[1].equalsIgnoreCase("gmlock")) {
Boolean gmLock = parseBoolean(sender, args[2]);
if (gmLock == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setGMLocked(gmLock);
sender.sendMessage(ChatColor.GREEN + "Updated GM Lock status successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item GM lock to " + gmLock);
} else if (args[1].equalsIgnoreCase("damage")) {
Double damage = parseDouble(sender, args[2]);
if (damage == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setDamage(damage);
sender.sendMessage(ChatColor.GREEN + "Updated damage successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item damage to " + damage);
} else if (args[1].equalsIgnoreCase("speedboost")) {
Double speedBoost = parseDouble(sender, args[2]);
if (speedBoost == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setSpeedBoost(speedBoost);
sender.sendMessage(ChatColor.GREEN + "Updated speed boost successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item speed boost to " + speedBoost);
} else if (args[1].equalsIgnoreCase("armor")) {
Double armor = parseDouble(sender, args[2]);
if (armor == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setArmor(armor);
sender.sendMessage(ChatColor.GREEN + "Updated armor successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item armor to " + armor);
} else if (args[1].equalsIgnoreCase("stacksize")) {
Integer stackSize = parseInt(sender, args[2]);
if (stackSize == null)
return;
Document base = Document.parse(itemClass.getData().toJson());
itemClass.setMaxStackSize(stackSize);
sender.sendMessage(ChatColor.GREEN + "Updated max. stack size successfully.");
AUDIT_LOG.saveEntry(itemClass, user, base, "Set item max stack size to " + stackSize);
} else {
sender.sendMessage(ChatColor.RED + "Invalid attribute! For usage info, do /item");
}
}
Aggregations