use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class SuperProtectionAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = verifyNotNull(context.getTargetEntity());
Mage mage = context.getController().getMage(targetEntity);
mage.enableSuperProtection(duration);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class TNTAction method start.
@Override
public SpellResult start(CastContext context) {
Mage mage = context.getMage();
LivingEntity living = mage.getLivingEntity();
MageController controller = context.getController();
int size = (int) (mage.getRadiusMultiplier() * this.size);
Location loc = context.getEyeLocation();
if (loc == null) {
return SpellResult.LOCATION_REQUIRED;
}
if (!context.hasBreakPermission(loc.getBlock())) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
final Random rand = new Random();
for (int i = 0; i < count; i++) {
Location targetLoc = loc.clone();
if (count > 1) {
targetLoc.setX(targetLoc.getX() + rand.nextInt(2 * count) - count);
targetLoc.setZ(targetLoc.getZ() + rand.nextInt(2 * count) - count);
}
TNTPrimed grenade = (TNTPrimed) context.getWorld().spawnEntity(targetLoc, EntityType.PRIMED_TNT);
if (grenade == null) {
return SpellResult.FAIL;
}
if (living != null) {
CompatibilityUtils.setTNTSource(grenade, living);
}
if (velocity > 0) {
Vector aim = context.getDirection();
SafetyUtils.setVelocity(grenade, aim.multiply(velocity));
}
grenade.setYield(size);
grenade.setFuseTicks(fuse);
grenade.setIsIncendiary(useFire);
if (!breakBlocks) {
grenade.setMetadata("cancel_explosion", new FixedMetadataValue(controller.getPlugin(), true));
}
track(context, grenade);
}
return checkTracking(context);
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class WearAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
if (entity == null) {
if (!context.getTargetsCaster())
return SpellResult.NO_TARGET;
entity = context.getEntity();
}
if (entity == null || !(entity instanceof Player)) {
return SpellResult.NO_TARGET;
}
Player player = (Player) entity;
MaterialAndData material = this.material;
MageController controller = context.getController();
Mage mage = controller.getMage(player);
if (useItem) {
Wand activeWand = mage.getActiveWand();
// Not handling this for now.
if (activeWand != context.getWand()) {
return SpellResult.NO_TARGET;
}
if (activeWand != null) {
activeWand.deactivate();
}
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
return SpellResult.FAIL;
}
ItemStack[] armor = player.getInventory().getArmorContents();
ItemStack currentItem = armor[slotNumber];
armor[slotNumber] = itemInHand;
player.getInventory().setArmorContents(armor);
if (!InventoryUtils.isTemporary(currentItem)) {
player.getInventory().setItemInMainHand(currentItem);
} else {
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
}
if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
((com.elmakers.mine.bukkit.magic.Mage) mage).armorUpdated();
}
return SpellResult.CAST;
}
ItemStack wearItem = null;
String materialName = null;
if (item == null) {
if (material == null && (context.getSpell().usesBrush() || context.getSpell().hasBrushOverride())) {
material = context.getBrush();
}
if (material == null) {
Block targetBlock = context.getTargetBlock();
if (targetBlock != null) {
material = new com.elmakers.mine.bukkit.block.MaterialAndData(targetBlock);
// Check for Banners with 1.7 support
// TODO: this is outdated?
Material baseMaterial = material.getMaterial();
if (DeprecatedUtils.getId(baseMaterial) == 176 || DeprecatedUtils.getId(baseMaterial) == 177) {
((com.elmakers.mine.bukkit.block.MaterialAndData) material).setMaterialId(425);
}
}
}
if (material == null || material.getMaterial() == Material.AIR) {
return SpellResult.NO_TARGET;
}
wearItem = material.getItemStack(1);
materialName = material.getName();
} else {
wearItem = InventoryUtils.getCopy(item);
materialName = context.getController().describeItem(wearItem);
}
ItemMeta meta = wearItem.getItemMeta();
// Legacy support
String displayName = context.getMessage("hat_name", "");
displayName = context.getMessage("wear_name", displayName);
if (materialName == null || materialName.isEmpty()) {
materialName = "?";
}
if (displayName != null && !displayName.isEmpty()) {
meta.setDisplayName(displayName.replace("$hat", materialName).replace("$item", materialName));
}
List<String> lore = new ArrayList<>();
String loreLine = context.getMessage("hat_lore");
loreLine = context.getMessage("wear_lore", loreLine);
lore.add(loreLine);
meta.setLore(lore);
wearItem.setItemMeta(meta);
wearItem = InventoryUtils.makeReal(wearItem);
NMSUtils.makeTemporary(wearItem, context.getMessage("removed").replace("$hat", materialName).replace("$item", materialName));
if (enchantments != null) {
wearItem.addUnsafeEnchantments(enchantments);
}
if (unbreakable) {
CompatibilityUtils.makeUnbreakable(wearItem);
}
ItemStack[] armor = player.getInventory().getArmorContents();
ItemStack itemStack = armor[slotNumber];
if (itemStack != null && itemStack.getType() != Material.AIR) {
if (NMSUtils.isTemporary(itemStack)) {
ItemStack replacement = NMSUtils.getReplacement(itemStack);
if (replacement != null) {
itemStack = replacement;
}
}
NMSUtils.setReplacement(wearItem, itemStack);
}
armor[slotNumber] = wearItem;
player.getInventory().setArmorContents(armor);
// Sanity check to make sure the block was allowed to be created
armor = player.getInventory().getArmorContents();
ItemStack helmetItem = armor[slotNumber];
if (!NMSUtils.isTemporary(helmetItem)) {
armor[slotNumber] = itemStack;
player.getInventory().setArmorContents(armor);
return SpellResult.NO_TARGET;
}
targetMage = mage;
context.registerForUndo(new WearUndoAction());
if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
((com.elmakers.mine.bukkit.magic.Mage) mage).armorUpdated();
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class SimulateBatch method target.
public void target(TargetMode mode) {
TargetType targetType = this.targetType;
if (mode == TargetMode.DIRECTED) {
targetType = TargetType.PLAYER;
}
switch(mode) {
case FLEE:
case HUNT:
case DIRECTED:
Target bestTarget = null;
reverseTargetDistanceScore = true;
if (targetType == TargetType.ANY || targetType == TargetType.MOB) {
List<Entity> entities = CompatibilityUtils.getNearbyEntities(center, huntMaxRange, huntMaxRange, huntMaxRange);
for (Entity entity : entities) {
// We'll get the players from the Mages list
if (entity instanceof Player || !(entity instanceof LivingEntity) || entity.isDead())
continue;
if (!entity.getLocation().getWorld().equals(center.getWorld()))
continue;
LivingEntity li = (LivingEntity) entity;
if (li.hasPotionEffect(PotionEffectType.INVISIBILITY))
continue;
Target newScore = new Target(center, entity, huntMinRange, huntMaxRange, huntFov, 1000, false);
int score = newScore.getScore();
if (bestTarget == null || score > bestTarget.getScore()) {
bestTarget = newScore;
}
}
}
if (targetType == TargetType.MAGE || targetType == TargetType.AUTOMATON || targetType == TargetType.ANY || targetType == TargetType.PLAYER) {
Collection<Mage> mages = controller.getMages();
for (Mage mage : mages) {
if (mage == this.mage)
continue;
if (targetType == TargetType.AUTOMATON && !mage.isAutomaton())
continue;
if (targetType == TargetType.PLAYER && mage.getPlayer() == null)
continue;
if (mage.isAutomaton() && mage.hasTag(spell.getKey()))
continue;
if (mage.isDead() || !mage.isOnline() || !mage.hasLocation() || mage.isSuperProtected())
continue;
if (!mage.getLocation().getWorld().equals(center.getWorld()))
continue;
LivingEntity li = mage.getLivingEntity();
if (li != null && li.hasPotionEffect(PotionEffectType.INVISIBILITY))
continue;
Target newScore = new Target(center, mage, huntMinRange, huntMaxRange, huntFov, 1000, false);
int score = newScore.getScore();
if (bestTarget == null || score > bestTarget.getScore()) {
bestTarget = newScore;
}
}
}
if (bestTarget != null) {
String targetDescription = bestTarget.getEntity() == null ? "NONE" : ((bestTarget instanceof Player) ? ((Player) bestTarget.getEntity()).getName() : bestTarget.getEntity().getType().name());
if (DEBUG) {
controller.getLogger().info(" Tracking " + targetDescription + " score: " + bestTarget.getScore() + " location: " + center + " -> " + bestTarget.getLocation() + " move " + commandMoveRangeSquared);
}
Vector direction = null;
if (mode == TargetMode.DIRECTED) {
direction = bestTarget.getLocation().getDirection();
if (DEBUG) {
controller.getLogger().info(" *Directed: " + direction);
}
} else {
Location targetLocation = bestTarget.getLocation();
direction = targetLocation.toVector().subtract(center.toVector());
}
if (direction != null) {
center.setDirection(direction);
}
/*
Block block = spell.getInteractBlock();
if (block.getType() != Material.AIR && block.getType() != POWER_MATERIAL && !!birthMaterial.is(block)) {
// TODO: Use location.setDirection in 1.7+
center = CompatibilityUtils.setDirection(center, new Vector(0, 1, 0));
}
*/
if (mode == TargetMode.HUNT && level != null && center.distanceSquared(bestTarget.getLocation()) < castRange * castRange) {
level.onTick(mage, birthMaterial);
}
// After ticking, re-position for movement. This way spells still fire towards the target.
if (mode == TargetMode.FLEE) {
direction = direction.multiply(-1);
// Don't Flee upward
if (direction.getY() > 0) {
direction.setY(-direction.getY());
}
}
} else {
if (backupTargetMode != mode) {
if (DEBUG) {
controller.getLogger().info("Falling back to target mode: " + backupTargetMode);
}
target(backupTargetMode);
} else {
// Make sure we don't fly off into the sunset
center.setPitch(-10);
mage.setLocation(center);
}
}
break;
case GLIDE:
reverseTargetDistanceScore = true;
break;
default:
reverseTargetDistanceScore = false;
}
if (!hasDirection) {
hasDirection = true;
center.setYaw(RandomUtils.getRandom().nextInt(360));
}
mage.setLocation(center);
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class TeleportAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
Mage mage = context.getMage();
ledgeSearchDistance = parameters.getInt("ledge_range", 2);
autoPassthrough = parameters.getBoolean("allow_passthrough", true);
useTargetLocation = parameters.getBoolean("use_target_location", false);
passthroughRange = (int) Math.floor(mage.getRangeMultiplier() * parameters.getInt("passthrough_range", DEFAULT_PASSTHROUGH_RANGE));
}
Aggregations