Search in sources :

Example 36 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.

the class SoliniaItem method useItemOnEntity.

@Override
public boolean useItemOnEntity(Plugin plugin, Player player, LivingEntity targetentity, boolean isConsumable) throws CoreStateInitException {
    if (isPetControlRod()) {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player);
        if (pet != null) {
            if (pet instanceof Wolf) {
                // Mez cancel target
                Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed(targetentity);
                if (mezExpiry != null) {
                    ((Creature) pet).setTarget(null);
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(null);
                    player.sendMessage("You cannot send your pet to attack a mezzed player");
                    return false;
                }
                if (!pet.getUniqueId().equals(targetentity.getUniqueId())) {
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(targetentity);
                    player.sendMessage("You send your pet to attack!");
                    return true;
                } else {
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(null);
                    player.sendMessage("You cannot send your pet to attack itself");
                    return false;
                }
            }
        }
    }
    if (isConsumable == true && isExperienceBonus()) {
        SoliniaPlayerAdapter.Adapt(player).grantExperienceBonusFromItem();
        System.out.println("Granted " + player.getName() + " experience bonus from item [" + SoliniaPlayerAdapter.Adapt(player).getExperienceBonusExpires().toString() + "]");
        return true;
    }
    ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(getAbilityid());
    if (spell == null) {
        return false;
    }
    ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) player);
    if (solentity == null)
        return false;
    if (!isConsumable)
        if (spell.getActSpellCost(solentity) > SoliniaPlayerAdapter.Adapt(player).getMana()) {
            player.sendMessage(ChatColor.GRAY + "Insufficient Mana  [E] (Hold crouch or use /trance to meditate)");
            return false;
        }
    try {
        if (StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId()) != null) {
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp nowtimestamp = Timestamp.valueOf(datetime);
            Timestamp expiretimestamp = StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId());
            if (expiretimestamp != null)
                if (!nowtimestamp.after(expiretimestamp)) {
                    player.sendMessage("You do not have enough willpower to cast " + spell.getName() + " (Wait: " + ((expiretimestamp.getTime() - nowtimestamp.getTime()) / 1000) + "s");
                    return false;
                }
        }
    } catch (CoreStateInitException e) {
        // skip
        return false;
    }
    boolean itemUseSuccess = spell.tryApplyOnEntity(plugin, player, targetentity);
    if (itemUseSuccess) {
        if (spell.getRecastTime() > 0) {
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp expiretimestamp = Timestamp.valueOf(datetime.plus(spell.getRecastTime(), ChronoUnit.MILLIS));
            StateManager.getInstance().getEntityManager().addEntitySpellCooldown(player, spell.getId(), expiretimestamp);
        }
        if (!isConsumable)
            SoliniaPlayerAdapter.Adapt(player).reducePlayerMana(spell.getActSpellCost(solentity));
    }
    return itemUseSuccess;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) LocalDateTime(java.time.LocalDateTime) Creature(org.bukkit.entity.Creature) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) Timestamp(java.sql.Timestamp)

Example 37 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.

the class SoliniaEntitySpells method addSpell.

public boolean addSpell(Plugin plugin, SoliniaSpell soliniaSpell, LivingEntity sourceEntity, int duration) {
    // This spell ID is already active
    if (activeSpells.get(soliniaSpell.getId()) != null)
        return false;
    if (this.getLivingEntity() == null)
        return false;
    if (sourceEntity == null)
        return false;
    try {
        if (!SoliniaSpell.isValidEffectForEntity(getLivingEntity(), sourceEntity, soliniaSpell)) {
            // System.out.println("Spell: " + soliniaSpell.getName() + "[" + soliniaSpell.getId() + "] found to have invalid target (" + getLivingEntity().getName() + ")");
            return false;
        }
    } catch (CoreStateInitException e) {
        return false;
    }
    // Resist spells!
    if (soliniaSpell.isResistable() && !soliniaSpell.isBeneficial()) {
        float effectiveness = 100;
        // If state is active, try to use spell effectiveness (resists)
        try {
            effectiveness = soliniaSpell.getSpellEffectiveness(sourceEntity, getLivingEntity());
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (effectiveness < 100) {
            // Check resistances
            if (this.getLivingEntity() instanceof Player) {
                Player player = (Player) this.getLivingEntity();
                player.sendMessage(ChatColor.GRAY + "* You resist " + soliniaSpell.getName());
                return true;
            }
            if (sourceEntity instanceof Player) {
                Player player = (Player) sourceEntity;
                player.sendMessage(ChatColor.GRAY + "* " + soliniaSpell.getName() + " was completely resisted");
                return true;
            }
        }
    }
    SoliniaActiveSpell activeSpell = new SoliniaActiveSpell(getLivingEntityUUID(), soliniaSpell.getId(), isPlayer, sourceEntity.getUniqueId(), true, duration);
    if (duration > 0)
        activeSpells.put(soliniaSpell.getId(), activeSpell);
    if (activeSpell.getSpell().isBardSong()) {
        if (getLivingEntityUUID().equals(sourceEntity.getUniqueId())) {
            try {
                ISoliniaLivingEntity solEntity = SoliniaLivingEntityAdapter.Adapt(sourceEntity);
                solEntity.emote(ChatColor.GRAY + "* " + sourceEntity.getCustomName() + " starts to sing " + soliniaSpell.getName());
                StateManager.getInstance().getEntityManager().setEntitySinging(sourceEntity.getUniqueId(), soliniaSpell.getId());
            } catch (CoreStateInitException e) {
            // ignore
            }
        }
    }
    // Initial run
    activeSpell.apply(plugin);
    Utils.playSpecialEffect(getLivingEntity(), activeSpell);
    getLivingEntity().getWorld().playSound(getLivingEntity().getLocation(), Sound.ITEM_CHORUS_FRUIT_TELEPORT, 1, 0);
    if (duration > 0) {
        if (activeSpells.get(soliniaSpell.getId()) != null)
            activeSpells.get(soliniaSpell.getId()).setFirstRun(false);
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 38 with ISoliniaLivingEntity

use of com.solinia.solinia.Interfaces.ISoliniaLivingEntity in project solinia3-core by mixxit.

the class SoliniaLivingEntity method aiCheckCloseBeneficialSpells.

@Override
public boolean aiCheckCloseBeneficialSpells(Plugin plugin, ISoliniaNPC npc, int iChance, int iRange, int iSpellTypes) throws CoreStateInitException {
    if (((iSpellTypes & SpellType.Detrimental)) == SpellType.Detrimental) {
        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a close beneficial spell as I have a detrimental in my list");
        return false;
    }
    if (this.getClassObj() == null) {
        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a close beneficial spell as I have no class");
        return false;
    }
    if (iChance < 100) {
        if (Utils.RandomBetween(0, 99) >= iChance) {
            Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a close beneficial spell as i rolled less than the chance");
            return false;
        }
    }
    if (npc.getFactionid() == 0) {
        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a close beneficial spell as I have no faction");
        return false;
    }
    // Only iterate through NPCs
    for (Entity nearbyEntity : getBukkitLivingEntity().getNearbyEntities(iRange, iRange, iRange)) {
        if (!(nearbyEntity instanceof LivingEntity))
            continue;
        if (nearbyEntity.isDead())
            continue;
        ISoliniaLivingEntity mob = SoliniaLivingEntityAdapter.Adapt((LivingEntity) nearbyEntity);
        if (!mob.isNPC())
            continue;
        ISoliniaNPC mobNpc = StateManager.getInstance().getConfigurationManager().getNPC(mob.getNpcid());
        if (mobNpc.getFactionid() != npc.getFactionid())
            continue;
        if (((iSpellTypes & SpellType.Buff) == SpellType.Buff)) {
            iSpellTypes = SpellType.Heal;
        }
        if (aiCastSpell(plugin, npc, mob.getBukkitLivingEntity(), 100, iSpellTypes))
            return true;
    }
    return false;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Aggregations

ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)38 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)32 LivingEntity (org.bukkit.entity.LivingEntity)24 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)20 Player (org.bukkit.entity.Player)18 Entity (org.bukkit.entity.Entity)16 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)8 ArrayList (java.util.ArrayList)7 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)7 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)7 Creature (org.bukkit.entity.Creature)7 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)6 SoliniaLivingEntity (com.solinia.solinia.Models.SoliniaLivingEntity)6 Timestamp (java.sql.Timestamp)6 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)5 Wolf (org.bukkit.entity.Wolf)5 EventHandler (org.bukkit.event.EventHandler)5 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)4 LocalDateTime (java.time.LocalDateTime)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)3