use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method takeCosts.
protected boolean takeCosts(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.removeExperience((int) worth);
} else if (isItems) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
removeItems(controller, mage, (int) Math.ceil(worth));
} else if (isSkillPoints) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
mage.addSkillPoints(-(int) Math.ceil(worth));
} else {
worth = Math.ceil(costScale * worth * controller.getWorthBase());
VaultController.getInstance().withdrawPlayer(mage.getPlayer(), worth);
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method showItems.
public SpellResult showItems(CastContext context, List<ShopItem> items) {
Mage mage = context.getMage();
this.context = context;
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
this.showingItems = new HashMap<>();
// Load items
itemStacks = new ArrayList<>();
String costString = context.getMessage("cost_lore", "Costs: $cost");
for (ShopItem shopItem : items) {
int currentSlot = itemStacks.size();
if (filterBound && shopItem != null) {
String template = com.elmakers.mine.bukkit.wand.Wand.getWandTemplate(shopItem.getItem());
if (template != null && mage.getBoundWand(template) != null) {
shopItem = null;
}
}
if (shopItem == null) {
this.showingItems.put(currentSlot, null);
itemStacks.add(new ItemStack(Material.AIR));
continue;
}
ItemStack item = InventoryUtils.getCopy(shopItem.getItem());
if (item == null)
continue;
String permission = shopItem.getPermission();
if (permission != null && !permission.isEmpty() && !player.hasPermission(permission)) {
continue;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) {
itemStacks.add(item);
continue;
}
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<>();
}
String costs = costString.replace("$cost", getItemCost(context, shopItem));
lore.add(ChatColor.GOLD + costs);
meta.setLore(lore);
item.setItemMeta(meta);
item = InventoryUtils.makeReal(item);
InventoryUtils.setMeta(item, "shop", Integer.toString(currentSlot));
if (showConfirmation) {
InventoryUtils.setMeta(item, "confirm", "true");
}
this.showingItems.put(currentSlot, shopItem);
itemStacks.add(item);
}
if (itemStacks.size() == 0) {
context.showMessage("no_items", getDefaultMessage(context, "no_items"));
return SpellResult.FAIL;
}
isActive = true;
finalResult = SpellResult.NO_ACTION;
Inventory displayInventory = getInventory(context);
mage.activateGUI(this, displayInventory);
return SpellResult.PENDING;
}
use of com.elmakers.mine.bukkit.api.magic.Mage 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.Mage in project MagicPlugin by elBukkit.
the class CastContext method playEffects.
@Override
public void playEffects(String effectName, float scale, Location sourceLocation, Entity sourceEntity, Location targetLocation, Entity targetEntity, Block sourceBlock) {
if (targetEntity != null) {
String entityKey = effectName + "_" + targetEntity.getType().name().toLowerCase();
if (baseSpell != null && baseSpell.hasEffects(entityKey)) {
effectName = entityKey;
}
}
Collection<EffectPlayer> effects = getEffects(effectName);
if (effects.size() > 0) {
Location location = getLocation();
Collection<Entity> targeted = getTargetedEntities();
for (EffectPlayer player : effects) {
// Set scale
player.setScale(scale);
Mage mage = getMage();
Location source = sourceLocation;
if (source == null) {
if (mage.getEntity() == sourceEntity && player.playsAtOrigin()) {
source = player.getSourceLocation(this);
} else {
source = location;
}
}
Location target = targetLocation;
if (target == null) {
target = player.getTargetLocation(this);
}
if (sourceBlock != null) {
player.setMaterial(sourceBlock);
}
player.start(source, sourceEntity, target, targetEntity, targeted);
}
}
}
use of com.elmakers.mine.bukkit.api.magic.Mage 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);
}
}
}
}
}
Aggregations