use of com.elmakers.mine.bukkit.api.spell.CastingCost in project MagicPlugin by elBukkit.
the class Mage method updateHotbarStatus.
public void updateHotbarStatus() {
Player player = getPlayer();
if (player != null) {
Location location = getLocation();
for (int i = 0; i < Wand.HOTBAR_SIZE; i++) {
ItemStack spellItem = player.getInventory().getItem(i);
String spellKey = Wand.getSpell(spellItem);
String classKey = Wand.getSpellClass(spellItem);
if (spellKey != null) {
Spell spell = getSpell(spellKey);
if (spell != null) {
int targetAmount = 1;
long remainingCooldown = 0;
CastingCost requiredCost = null;
boolean canCastSpell = false;
if (classKey != null && !classKey.isEmpty()) {
MageClass mageClass = getClass(classKey);
if (mageClass != null && spell instanceof BaseSpell) {
BaseSpell baseSpell = (BaseSpell) spell;
baseSpell.setMageClass(mageClass);
remainingCooldown = spell.getRemainingCooldown();
requiredCost = spell.getRequiredCost();
canCastSpell = spell.canCast(location);
baseSpell.setMageClass(null);
}
} else {
remainingCooldown = spell.getRemainingCooldown();
requiredCost = spell.getRequiredCost();
canCastSpell = spell.canCast(location);
}
boolean canCast = canCastSpell;
if (canCastSpell && remainingCooldown == 0 && requiredCost == null) {
targetAmount = 1;
} else if (canCastSpell) {
canCast = remainingCooldown == 0;
targetAmount = Wand.LiveHotbarCooldown ? (int) Math.min(Math.ceil((double) remainingCooldown / 1000), 99) : 99;
if (Wand.LiveHotbarCooldown && requiredCost != null) {
int mana = requiredCost.getMana();
if (mana > 0) {
if (mana <= getEffectiveManaMax() && getEffectiveManaRegeneration() > 0) {
float remainingMana = mana - getMana();
canCast = canCast && remainingMana <= 0;
int targetManaTime = (int) Math.min(Math.ceil(remainingMana / getEffectiveManaRegeneration()), 99);
targetAmount = Math.max(targetManaTime, targetAmount);
} else {
canCastSpell = false;
canCast = false;
}
}
}
}
if (targetAmount == 0)
targetAmount = 1;
boolean setAmount = false;
MaterialAndData disabledIcon = spell.getDisabledIcon();
MaterialAndData spellIcon = spell.getIcon();
String urlIcon = spell.getIconURL();
String disabledUrlIcon = spell.getDisabledIconURL();
boolean usingURLIcon = (controller.isUrlIconsEnabled() || spellIcon == null || spellIcon.getMaterial() == Material.AIR) && urlIcon != null && !urlIcon.isEmpty();
if (disabledIcon != null && spellIcon != null && !usingURLIcon) {
if (!canCast) {
if (disabledIcon.isValid() && (disabledIcon.getMaterial() != spellItem.getType() || disabledIcon.getData() != spellItem.getDurability())) {
disabledIcon.applyToItem(spellItem);
}
if (!canCastSpell) {
if (spellItem.getAmount() != 1) {
spellItem.setAmount(1);
}
setAmount = true;
}
} else {
if (spellIcon.isValid() && (spellIcon.getMaterial() != spellItem.getType() || spellIcon.getData() != spellItem.getDurability())) {
spellIcon.applyToItem(spellItem);
}
}
} else if (usingURLIcon && disabledUrlIcon != null && !disabledUrlIcon.isEmpty() && spellItem.getType() == Material.SKULL_ITEM) {
String currentURL = InventoryUtils.getSkullURL(spellItem);
if (!canCast) {
if (!disabledUrlIcon.equals(currentURL)) {
InventoryUtils.setNewSkullURL(spellItem, disabledUrlIcon);
player.getInventory().setItem(i, spellItem);
}
if (!canCastSpell) {
if (spellItem.getAmount() != 1) {
spellItem.setAmount(1);
}
setAmount = true;
}
} else {
if (!urlIcon.equals(currentURL)) {
InventoryUtils.setNewSkullURL(spellItem, urlIcon);
player.getInventory().setItem(i, spellItem);
}
}
}
if (!setAmount && spellItem.getAmount() != targetAmount) {
spellItem.setAmount(targetAmount);
}
}
}
}
}
}
use of com.elmakers.mine.bukkit.api.spell.CastingCost in project MagicPlugin by elBukkit.
the class BaseSpell method checkActiveCosts.
public void checkActiveCosts() {
if (activeCosts == null)
return;
long now = System.currentTimeMillis();
activeCostScale = (float) ((double) (now - lastActiveCost) / 1000);
lastActiveCost = now;
CasterProperties caster = null;
if (currentCast != null) {
caster = currentCast.getWand();
if (caster == null) {
caster = currentCast.getMageClass();
}
}
for (CastingCost cost : activeCosts) {
if (!cost.has(mage, caster, this)) {
deactivate();
break;
}
cost.deduct(mage, caster, this);
}
activeCostScale = 1;
}
use of com.elmakers.mine.bukkit.api.spell.CastingCost in project MagicPlugin by elBukkit.
the class BaseSpell method finalizeCast.
protected boolean finalizeCast(ConfigurationSection parameters) {
SpellResult result = null;
// Global parameters
controller.disablePhysics(parameters.getInt("disable_physics", 0));
if (!mage.isSuperPowered()) {
if (backfireChance > 0 && random.nextDouble() < backfireChance) {
backfire();
} else if (fizzleChance > 0 && random.nextDouble() < fizzleChance) {
result = SpellResult.FIZZLE;
}
}
if (result == null) {
result = onCast(parameters);
}
if (backfired) {
result = SpellResult.BACKFIRE;
}
if (result == SpellResult.CAST) {
LivingEntity sourceEntity = mage.getLivingEntity();
Entity targetEntity = getTargetEntity();
if (sourceEntity == targetEntity) {
result = SpellResult.CAST_SELF;
}
}
processResult(result, parameters);
boolean success = result.isSuccess();
boolean free = result.isFree(castOnNoTarget);
if (!free) {
if (costs != null && !mage.isCostFree()) {
UndoList undoList = currentCast.getUndoList();
for (CastingCost cost : costs) {
if (undoList != null && cost.isItem() && currentCast != null) {
undoList.setConsumed(true);
}
cost.use(this);
}
}
updateCooldown();
}
if (success && toggle != ToggleType.NONE) {
activate();
}
sendCastMessage(result, " (" + success + ")");
return success;
}
Aggregations