use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class Mage method activateIcon.
public void activateIcon(Wand activeWand, ItemStack icon) {
if (System.currentTimeMillis() < ignoreItemActivationUntil) {
return;
}
// Check for spell or material selection
if (icon != null && icon.getType() != Material.AIR) {
com.elmakers.mine.bukkit.api.spell.Spell spell = getSpell(Wand.getSpell(icon));
if (spell != null) {
boolean isQuickCast = spell.isQuickCast() && !activeWand.isQuickCastDisabled();
isQuickCast = isQuickCast || (activeWand.getMode() == WandMode.CHEST && activeWand.isQuickCast());
if (isQuickCast) {
activeWand.cast(spell);
} else {
activeWand.setActiveSpell(spell.getKey());
}
} else if (Wand.isBrush(icon)) {
activeWand.setActiveBrush(icon);
}
} else {
activeWand.setActiveSpell("");
}
DeprecatedUtils.updateInventory(getPlayer());
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class Mage method onDamage.
public void onDamage(EntityDamageEvent event) {
String damageType = currentDamageType;
currentDamageType = null;
LivingEntity entity = getLivingEntity();
if (entity == null) {
return;
}
// Send on to any registered spells
List<Listener> active = new ArrayList<>(damageListeners);
for (Listener listener : active) {
callEvent(listener, event);
if (event.isCancelled())
break;
}
EntityDamageEvent.DamageCause cause = event.getCause();
if (cause == EntityDamageEvent.DamageCause.FALL) {
if (fallProtectionCount > 0 && fallProtection > 0 && fallProtection > System.currentTimeMillis()) {
event.setCancelled(true);
fallProtectionCount--;
if (fallingSpell != null) {
double scale = 1;
LivingEntity li = getLivingEntity();
if (li != null) {
scale = event.getDamage() / li.getMaxHealth();
}
fallingSpell.playEffects("land", (float) scale, getLocation().getBlock().getRelative(BlockFace.DOWN));
}
if (fallProtectionCount <= 0) {
fallProtection = 0;
fallingSpell = null;
}
return;
} else {
fallingSpell = null;
}
}
if (isSuperProtected()) {
event.setCancelled(true);
if (entity.getFireTicks() > 0) {
entity.setFireTicks(0);
}
return;
}
if (event.isCancelled()) {
return;
}
// First check for damage reduction
double reduction = 0;
Double overallProtection = protection.get("overall");
if (overallProtection != null) {
reduction = overallProtection * controller.getMaxDamageReduction("overall");
}
// Apply weaknesses
double multiplier = 1;
Double overallWeakness = weakness.get("overall");
if (overallWeakness != null && overallWeakness > 0) {
double defendMultiplier = controller.getMaxDefendMultiplier("overall");
if (defendMultiplier > 1) {
defendMultiplier = 1 + (defendMultiplier - 1) * overallWeakness;
multiplier *= defendMultiplier;
}
}
if (cause == EntityDamageEvent.DamageCause.FIRE_TICK) {
// Also put out fire if they have maxed out fire protection.
double damageReductionFire = getProtection("fire");
if (damageReductionFire >= 1 && entity.getFireTicks() > 0) {
entity.setFireTicks(0);
}
}
if (damageType == null) {
switch(cause) {
case CONTACT:
case ENTITY_ATTACK:
damageType = "physical";
break;
case FIRE:
case FIRE_TICK:
case LAVA:
damageType = "fire";
break;
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
damageType = "explosion";
break;
default:
damageType = cause.name().toLowerCase();
break;
}
}
lastDamageType = damageType;
double protection = getProtection(damageType);
double maxReduction = controller.getMaxDamageReduction(damageType);
reduction += protection * maxReduction;
if (reduction >= 1) {
event.setCancelled(true);
sendDebugMessage(ChatColor.RED + "Damage nullified by " + ChatColor.BLUE + damageType + " (" + cause + ")", 8);
return;
}
double damage = event.getDamage();
sendDebugMessage(ChatColor.RED + "Damaged by " + ChatColor.BLUE + (damageType == null ? "generic" : damageType) + " (" + cause + ")" + ChatColor.RED + " for " + ChatColor.DARK_RED + damage, 10);
if (reduction > 0) {
damage = (1.0 - reduction) * damage;
sendDebugMessage(ChatColor.DARK_RED + "Damage type " + ChatColor.BLUE + damageType + " reduced by " + ChatColor.AQUA + reduction + ChatColor.DARK_RED + " to " + ChatColor.RED + damage, 9);
event.setDamage(damage);
}
double weakness = getWeakness(damageType);
double maxMultiplier = controller.getMaxDefendMultiplier(damageType);
if (maxMultiplier > 1 && weakness > 0) {
weakness = 1 + (maxMultiplier - 1) * weakness;
multiplier *= weakness;
}
if (multiplier > 1) {
damage = multiplier * damage;
sendDebugMessage(ChatColor.DARK_RED + "Damage type " + ChatColor.BLUE + damageType + " multiplied by " + ChatColor.AQUA + multiplier + ChatColor.DARK_RED + " to " + ChatColor.RED + damage, 9);
event.setDamage(damage);
}
if (damage > 0) {
for (Iterator<Batch> iterator = pendingBatches.iterator(); iterator.hasNext(); ) {
Batch batch = iterator.next();
if (!(batch instanceof SpellBatch))
continue;
SpellBatch spellBatch = (SpellBatch) batch;
Spell spell = spellBatch.getSpell();
double cancelOnDamage = spell.cancelOnDamage();
if (cancelOnDamage > 0 && cancelOnDamage < damage) {
spell.cancel();
batch.finish();
iterator.remove();
}
}
}
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class HeroesSkillSpell method canCast.
@Override
public boolean canCast(Location location) {
if (!isCasting && mage != null && mage.isPlayer() && !heroes.canUseSkill(mage.getPlayer(), skillKey)) {
return false;
}
if (skill instanceof HeroesSpellSkill) {
HeroesSpellSkill spellSkill = (HeroesSpellSkill) skill;
SpellTemplate template = spellSkill.getSpellTemplate();
Spell spell = mage.getSpell(template.getKey());
if (spell != null) {
return spell.canCast(location);
}
}
return super.canCast(location);
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class HeroesSpellSkill method use.
@Override
public SkillResult use(Hero hero, String[] strings) {
Mage mage = controller.getMage(hero.getPlayer());
boolean success = false;
{
String spellKey = spellTemplate.getKey();
int targetLevel = SkillConfigManager.getUseSetting(hero, this, "tier", spellLevel, true);
if (targetLevel != 1) {
SpellKey key = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), targetLevel);
spellKey = key.getKey();
}
Spell spell = mage.getSpell(spellKey);
if (spell == null) {
if (targetLevel > 1) {
controller.getLogger().warning("Invalid tier for spell in skills config: " + spellKey + " (tier " + spellLevel + ")");
} else {
controller.getLogger().warning("Invalid spell in skills config: " + spellKey);
}
return SkillResult.FAIL;
}
Set<String> parameterKeys = parameters.getKeys(false);
ConfigurationSection spellParameters = spellTemplate.getSpellParameters();
ConfigurationSection heroParameters = new MemoryConfiguration();
for (String parameterKey : parameterKeys) {
String value = parameters.getString(parameterKey);
String magicKey = heroesToMagic(parameterKey);
Double doubleValue = null;
try {
doubleValue = Double.parseDouble(value);
} catch (NumberFormatException ignored) {
}
Object magicValue = spellParameters.getString(magicKey);
if (doubleValue != null) {
doubleValue = SkillConfigManager.getUseSetting(hero, this, parameterKey, doubleValue, true);
Double doubleMagicValue = null;
try {
if (magicValue != null) {
doubleMagicValue = Double.parseDouble(magicValue.toString());
}
} catch (NumberFormatException ignored) {
}
if (doubleMagicValue != null && doubleValue.equals(doubleMagicValue))
continue;
} else {
value = SkillConfigManager.getUseSetting(hero, this, parameterKey, value);
if (magicValue != null && value != null && value.equals(magicValue))
continue;
}
if (doubleValue != null) {
heroParameters.set(magicKey, doubleValue);
} else {
heroParameters.set(magicKey, value);
}
}
// Don't let Magic get in the way of using the skill
heroParameters.set("cost_reduction", 2);
heroParameters.set("cooldown_reduction", 2);
success = spell.cast(heroParameters);
}
if (success) {
this.broadcastExecuteText(hero);
}
return success ? SkillResult.NORMAL : SkillResult.FAIL;
}
use of com.elmakers.mine.bukkit.api.spell.Spell in project MagicPlugin by elBukkit.
the class PlaceholderAPIManager method onPlaceholderRequest.
@Override
public String onPlaceholderRequest(Player player, String placeholder) {
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
Wand wand = mage.getActiveWand();
Spell spell = wand == null ? null : wand.getActiveSpell();
if (spell == null) {
ItemStack item = player.getInventory().getItemInMainHand();
String spellKey = controller.getSpell(item);
if (spellKey != null) {
spell = mage.getSpell(spellKey);
}
}
if (spell == null) {
ItemStack item = player.getInventory().getItemInOffHand();
String spellKey = controller.getSpell(item);
if (spellKey != null) {
spell = mage.getSpell(spellKey);
}
}
CasterProperties casterProperties = mage.getActiveProperties();
switch(placeholder) {
case "path":
ProgressionPath path = casterProperties.getPath();
return path == null ? "" : path.getName();
case "class":
return activeClass == null ? "" : activeClass.getName();
case "wand":
return wand == null ? "" : wand.getName();
case "spell":
return spell == null ? "" : spell.getName();
}
return "";
}
Aggregations