use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class BaseShopAction method giveCosts.
protected void giveCosts(CastContext context, ShopItem shopItem) {
Mage mage = context.getMage();
MageController controller = context.getController();
double worth = shopItem.getWorth();
if (isXP) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
mage.giveExperience((int) worth);
} else if (isItems) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
int amount = (int) Math.ceil(worth);
ItemStack worthItem = getWorthItem(controller);
while (amount > 0) {
worthItem = InventoryUtils.getCopy(worthItem);
worthItem.setAmount(Math.min(amount, 64));
amount -= worthItem.getAmount();
mage.giveItem(worthItem);
}
} else if (isSkillPoints) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
int amount = (int) Math.ceil(worth);
mage.addSkillPoints(amount);
} else {
worth = Math.ceil(costScale * worth * controller.getWorthBase());
VaultController.getInstance().depositPlayer(mage.getPlayer(), worth);
}
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class BaseShopAction method getItemCost.
protected String getItemCost(CastContext context, ShopItem shopItem) {
String amountString = "?";
MageController controller = context.getController();
Messages messages = controller.getMessages();
double worth = shopItem.getWorth();
if (isXP) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
amountString = Integer.toString((int) worth);
amountString = messages.get("costs.xp_amount").replace("$amount", amountString);
} else if (isItems) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
amountString = formatItemAmount(controller, worth);
} else if (isSkillPoints) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
amountString = Integer.toString((int) Math.ceil(worth));
amountString = messages.get("costs.sp_amount").replace("$amount", amountString);
} else {
worth = Math.ceil(costScale * worth * controller.getWorthBase());
amountString = VaultController.getInstance().format(worth);
}
return amountString;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class CastContext method messageTargets.
@Override
public void messageTargets(String messageKey) {
Mage mage = getMage();
if (mage.isStealth())
return;
Collection<Entity> targets = getTargetedEntities();
if (targets == null || targets.isEmpty())
return;
MageController controller = getController();
LivingEntity sourceEntity = mage.getLivingEntity();
String playerMessage = getMessage(messageKey);
if (playerMessage.length() > 0) {
playerMessage = playerMessage.replace("$spell", spell.getName());
for (Entity target : targets) {
UUID targetUUID = target.getUniqueId();
if (target instanceof Player && target != sourceEntity && !targetMessagesSent.contains(targetUUID)) {
targetMessagesSent.add(targetUUID);
Mage targetMage = controller.getRegisteredMage(target);
if (targetMage != null) {
targetMage.sendMessage(playerMessage);
}
}
}
}
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class AbsorbAction method perform.
@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
Block target = context.getTargetBlock();
Mage mage = context.getMage();
Wand wand = context.getWand();
if (wand == null) {
return SpellResult.FAIL;
}
MageController controller = context.getController();
Material material = target.getType();
byte data = target.getData();
MaterialSet buildingMaterials = controller.getBuildingMaterialSet();
MaterialSet restrictedMaterials = mage.getRestrictedMaterialSet();
if (material == null || material == Material.AIR) {
return SpellResult.NO_TARGET;
}
if (!mage.getCommandSender().hasPermission("Magic.bypass_restricted") && (!buildingMaterials.testBlock(target) || restrictedMaterials.testBlock(target))) {
return SpellResult.NO_TARGET;
}
// Add to the wand
MaterialAndData mat = new MaterialAndData(material, data);
if (!wand.addBrush(mat.getKey())) {
// Still try and activate it
wand.setActiveBrush(mat.getKey());
return SpellResult.NO_TARGET;
}
// And activate it
wand.setActiveBrush(mat.getKey());
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class ApplyCooldownAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage targetMage = context.getMage();
if (!targetCaster) {
Entity entity = context.getTargetEntity();
MageController controller = context.getController();
if (entity == null || !controller.isMage(entity)) {
return SpellResult.NO_TARGET;
}
targetMage = controller.getMage(entity);
}
int amount = cooldownAmount;
if (!bypassReduction && cooldownAmount > 0) {
double cooldownReduction = targetMage.getCooldownReduction();
if (cooldownReduction < 1) {
amount = (int) Math.ceil((1.0f - cooldownReduction) * amount);
} else {
amount = 0;
}
}
if (spells != null) {
Wand wand = targetMage.getActiveWand();
for (String spellName : spells) {
Spell spell = null;
if (wand != null) {
spell = wand.getSpell(spellName);
}
if (spell == null) {
spell = targetMage.getSpell(spellName);
}
if (spell != null) {
if (clear) {
spell.clearCooldown();
}
if (amount > 0) {
spell.setRemainingCooldown(amount);
}
}
}
} else if (excludeSpells != null) {
Collection<Spell> allSpells = targetMage.getSpells();
for (Spell spell : allSpells) {
if (!excludeSpells.contains(spell.getSpellKey().getBaseKey())) {
if (clear) {
spell.clearCooldown();
}
if (amount > 0) {
spell.setRemainingCooldown(amount);
}
}
}
} else {
if (clear) {
targetMage.clearCooldown();
}
if (amount > 0) {
targetMage.setRemainingCooldown(amount);
}
}
return SpellResult.CAST;
}
Aggregations