use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method hasItemCosts.
protected boolean hasItemCosts(CastContext context, ShopItem shopItem) {
Mage mage = context.getMage();
MageController controller = context.getController();
double worth = shopItem.getWorth();
boolean hasCosts = true;
if (worth > 0) {
if (isXP) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
hasCosts = mage.getExperience() >= (int) worth;
} else if (isItems) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
int hasAmount = getItemAmount(controller, mage);
hasCosts = hasAmount >= worth;
} else if (isSkillPoints) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
hasCosts = mage.getSkillPoints() >= Math.ceil(worth);
} else {
worth = Math.ceil(costScale * worth * controller.getWorthBase());
hasCosts = VaultController.getInstance().has(mage.getPlayer(), worth);
}
}
return hasCosts;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method getBalanceDescription.
protected String getBalanceDescription(CastContext context) {
Mage mage = context.getMage();
MageController controller = context.getController();
Messages messages = controller.getMessages();
String description = "";
if (isXP) {
String xpAmount = Integer.toString(mage.getExperience());
description = messages.get("costs.xp_amount").replace("$amount", xpAmount);
} else if (isItems) {
int itemAmount = getItemAmount(controller, mage);
description = formatItemAmount(controller, itemAmount);
} else if (isSkillPoints) {
String spAmount = Integer.toString(mage.getSkillPoints());
description = messages.get("costs.sp_amount").replace("$amount", spAmount);
} else {
double balance = VaultController.getInstance().getBalance(mage.getPlayer());
description = VaultController.getInstance().format(balance);
}
return description;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BrushAction method step.
@Override
public SpellResult step(CastContext context) {
if (brushes.size() == 0 && !sample) {
return startActions();
}
if (sample) {
Block targetBlock = context.getTargetBlock();
if (targetBlock != null) {
Mage mage = context.getMage();
MaterialBrush brush = new MaterialBrush(mage, targetBlock);
actionContext.setBrush(brush);
}
} else {
String brushKey = brushes.get(context.getRandom().nextInt(brushes.size()));
MaterialBrush brush = new MaterialBrush(context.getMage(), context.getLocation(), brushKey);
actionContext.setBrush(brush);
}
return startActions();
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BrushSelectAction method clicked.
@Override
public void clicked(InventoryClickEvent event) {
event.setCancelled(true);
InventoryAction action = event.getAction();
if (context != null) {
Mage mage = context.getMage();
if (action == InventoryAction.NOTHING) {
int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
page = page + direction;
mage.deactivateGUI();
perform(context);
event.setCancelled(true);
return;
}
ItemStack item = event.getCurrentItem();
String set = InventoryUtils.getMetaString(item, "brush_set", null);
if (set != null) {
if (set.equals("schematics")) {
String inventoryTitle = context.getMessage("schematics_title", "Schematics");
int invSize = ((schematics.size() + 9) / 9) * 9;
Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
for (ItemStack schematicItem : schematics) {
displayInventory.addItem(schematicItem);
}
mage.deactivateGUI();
mage.activateGUI(this, displayInventory);
return;
} else if (set.equals("variants")) {
MaterialAndData baseMaterial = new MaterialAndData(item);
String baseName = baseMaterial.getBaseName();
String inventoryTitle = context.getMessage("variants_title", "$variant Types").replace("$variant", baseName);
String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
MaterialAndData brushMaterial = new MaterialAndData(brushKey);
List<ItemStack> variantList = variants.get(brushMaterial.getMaterial());
int invSize = ((variantList.size() + 9) / 9) * 9;
Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
for (ItemStack variantItem : variantList) {
displayInventory.addItem(variantItem);
}
mage.deactivateGUI();
mage.activateGUI(this, displayInventory);
return;
}
}
mage.deactivateGUI();
Wand wand = context.getWand();
if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isBrush(item)) {
String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
wand.setActiveBrush(brushKey);
}
}
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class CancelAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
MageController controller = context.getController();
if (targetEntity == null || !controller.isMage(targetEntity)) {
return SpellResult.NO_TARGET;
}
SpellResult result = SpellResult.NO_TARGET;
Mage targetMage = controller.getMage(targetEntity);
if (spellKeys == null) {
Batch batch = targetMage.cancelPending(force);
if (batch != null) {
result = SpellResult.CAST;
undoListName = batch.getName();
}
} else {
for (String spellKey : spellKeys) {
Batch batch = targetMage.cancelPending(spellKey, force);
if (batch != null) {
result = SpellResult.CAST;
undoListName = batch.getName();
}
}
}
return result;
}
Aggregations