Search in sources :

Example 26 with ISoliniaLivingEntity

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

the class EntityManager method doNPCCheckForEnemies.

@Override
public void doNPCCheckForEnemies() {
    List<Integer> completedNpcsIds = new ArrayList<Integer>();
    for (Player player : Bukkit.getOnlinePlayers()) {
        for (Entity entity : player.getNearbyEntities(50, 50, 50)) {
            if (entity instanceof Player)
                continue;
            if (!(entity instanceof LivingEntity))
                continue;
            LivingEntity le = (LivingEntity) entity;
            if (!Utils.isLivingEntityNPC(le))
                continue;
            try {
                ISoliniaLivingEntity solle = SoliniaLivingEntityAdapter.Adapt(le);
                if (completedNpcsIds.contains(solle.getNpcid()))
                    continue;
                completedNpcsIds.add(solle.getNpcid());
                solle.doCheckForEnemies();
            } catch (CoreStateInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList)

Example 27 with ISoliniaLivingEntity

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

the class SoliniaSpell method getSpellEffectiveness.

@Override
public float getSpellEffectiveness(LivingEntity caster, LivingEntity victim) throws CoreStateInitException {
    // TODO Auto-generated method stub
    int resistmodifier = getResistDiff();
    int casterlevel = 1;
    int targetresist = 0;
    boolean isnpccaster = false;
    if (caster instanceof Player) {
        casterlevel = SoliniaPlayerAdapter.Adapt((Player) caster).getLevel();
    } else {
        if (Utils.isLivingEntityNPC(caster)) {
            ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) caster);
            ISoliniaNPC casternpc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
            casterlevel = casternpc.getLevel();
            isnpccaster = true;
        }
    }
    boolean isnpcvictim = false;
    int victimlevel = 1;
    if (victim instanceof Player) {
        victimlevel = SoliniaPlayerAdapter.Adapt((Player) victim).getLevel();
        targetresist = SoliniaPlayerAdapter.Adapt((Player) victim).getResist(Utils.getSpellResistType(getResisttype()));
    } else {
        if (Utils.isLivingEntityNPC(victim)) {
            ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) victim);
            ISoliniaNPC victimnpc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
            targetresist = solentity.getResists(Utils.getSpellResistType(getResisttype()));
            victimlevel = victimnpc.getLevel();
            isnpcvictim = true;
        }
    }
    int resist_chance = 0;
    int level_mod = 0;
    int temp_level_diff = victimlevel - casterlevel;
    if (isnpcvictim == false && victimlevel >= 21 && temp_level_diff > 15) {
        temp_level_diff = 15;
    }
    if (isnpcvictim == true && temp_level_diff < -9) {
        temp_level_diff = -9;
    }
    level_mod = temp_level_diff * temp_level_diff / 2;
    if (temp_level_diff < 0) {
        level_mod = -level_mod;
    }
    if (isnpcvictim && (casterlevel - victimlevel < -20)) {
        level_mod = 1000;
    }
    // Even more level stuff this time dealing with damage spells
    if (isnpcvictim && isDamageSpell() && victimlevel >= 17) {
        int level_diff;
        level_diff = victimlevel - casterlevel;
        level_mod += (2 * level_diff);
    }
    resist_chance += level_mod;
    resist_chance += resistmodifier;
    resist_chance += targetresist;
    if (resist_chance > 255) {
        resist_chance = 255;
    }
    if (resist_chance < 0) {
        resist_chance = 0;
    }
    int roll = Utils.RandomBetween(0, 200);
    if (roll > resist_chance) {
        return 100;
    } else {
        if (resist_chance < 1) {
            resist_chance = 1;
        }
        int partial_modifier = ((150 * (resist_chance - roll)) / resist_chance);
        if (isnpcvictim == true) {
            if (victimlevel > casterlevel && victimlevel >= 17 && casterlevel <= 50) {
                partial_modifier += 5;
            }
            if (victimlevel >= 30 && casterlevel < 50) {
                partial_modifier += (casterlevel - 25);
            }
            if (victimlevel < 15) {
                partial_modifier -= 5;
            }
        }
        if (isnpccaster) {
            if ((victimlevel - casterlevel) >= 20) {
                partial_modifier += (victimlevel - casterlevel) * 1.5;
            }
        }
        if (partial_modifier <= 0) {
            return 100F;
        } else if (partial_modifier >= 100) {
            return 0;
        }
        return (100.0f - partial_modifier);
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 28 with ISoliniaLivingEntity

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

the class Solinia3CoreEntityListener method onEntityTargetEvent.

// Needs to occur before anything else
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityTargetEvent(EntityTargetEvent event) {
    if (event.isCancelled())
        return;
    if (!(event.getEntity() instanceof Creature))
        return;
    try {
        Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
        if (mzExpiry != null) {
            if (event.getEntity() instanceof Player) {
                event.getEntity().sendMessage("* You are mezzed!");
            }
            Utils.CancelEvent(event);
            ;
            return;
        }
    } catch (CoreStateInitException e) {
    }
    try {
        // Me
        ISoliniaLivingEntity solEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
        if (solEntity.isUndead() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
            if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsUndead2)) {
                ((Creature) event.getEntity()).setTarget(null);
                Utils.CancelEvent(event);
                ;
                return;
            }
        }
        if (!solEntity.isUndead() && !(event.getEntity() instanceof Player) && !solEntity.isAnimal() && event.getTarget() instanceof LivingEntity) {
            if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.Invisibility2)) {
                ((Creature) event.getEntity()).setTarget(null);
                Utils.CancelEvent(event);
                ;
                return;
            }
        }
        if (solEntity.isAnimal() && !(event.getEntity() instanceof Player) && event.getTarget() instanceof LivingEntity) {
            if (StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.InvisVsAnimals) || StateManager.getInstance().getEntityManager().hasEntityEffectType((LivingEntity) event.getTarget(), SpellEffectType.ImprovedInvisAnimals)) {
                ((Creature) event.getEntity()).setTarget(null);
                Utils.CancelEvent(event);
                ;
                return;
            }
        }
        // rogue sneak
        if (event.getTarget() instanceof Player && !(event.getEntity() instanceof Player)) {
            Player targetPlayer = (Player) event.getTarget();
            if (targetPlayer.isSneaking()) {
                ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) event.getTarget());
                if (player.getClassObj() != null) {
                    if (player.getClassObj().isSneakFromCrouch()) {
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                }
            }
        }
        if (event.getEntity() != null && event.getTarget() != null) {
            if (!(event.getEntity() instanceof Player)) {
                if (event.getEntity() instanceof LivingEntity) {
                    ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                }
                // Mez cancel target
                Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getTarget());
                if (mezExpiry != null) {
                    ((Creature) event.getEntity()).setTarget(null);
                    event.getEntity().sendMessage("The target is mezzed, you cannot hit it");
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            }
        }
    } catch (CoreStateInitException e) {
        return;
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Timestamp(java.sql.Timestamp) EventHandler(org.bukkit.event.EventHandler)

Example 29 with ISoliniaLivingEntity

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

the class Solinia3CorePlayerChatListener method OnChat.

@EventHandler
public void OnChat(SoliniaAsyncPlayerChatEvent event) {
    if (event.isCancelled())
        return;
    if (!(event.getRawEvent() instanceof AsyncPlayerChatEvent))
        return;
    // We control all chat!
    AsyncPlayerChatEvent rawEvent = (AsyncPlayerChatEvent) event.getRawEvent();
    Utils.CancelEvent(rawEvent);
    String currentChannel = event.getPlayer().getCurrentChannel();
    // always redirect npc interactions to local
    if (event.getPlayer().getInteraction() != null) {
        currentChannel = "LOCAL";
    }
    // TODO - Support checking channel modes of player
    if (currentChannel.equals("LOCAL")) {
        StateManager.getInstance().getChannelManager().sendToLocalChannelDecorated(event.getPlayer(), event.getMessage());
    } else {
        StateManager.getInstance().getChannelManager().sendToGlobalChannelDecorated(event.getPlayer(), event.getMessage());
    }
    // NPC responses (if applicable)
    if (event.getPlayer().getInteraction() != null) {
        Entity entity = Bukkit.getEntity(event.getPlayer().getInteraction());
        if (entity != null && entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            ISoliniaLivingEntity solentity;
            try {
                solentity = StateManager.getInstance().getEntityManager().getLivingEntity(livingEntity);
                solentity.processInteractionEvent(event.getPlayer().getBukkitPlayer(), InteractionType.CHAT, event.getMessage());
            } catch (CoreStateInitException e) {
            // skip
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaAsyncPlayerChatEvent(com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) EventHandler(org.bukkit.event.EventHandler)

Example 30 with ISoliniaLivingEntity

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

the class SoliniaLivingEntity method avoidDamage.

@Override
public DamageHitInfo avoidDamage(SoliniaLivingEntity attacker, DamageHitInfo hit) {
    ISoliniaLivingEntity defender = this;
    if (getDodgeCheck()) {
        hit.damage_done = 0;
        hit.avoided = true;
        hit.dodged = true;
        return hit;
    }
    if (getRiposteCheck()) {
        hit.damage_done = 0;
        hit.riposted = true;
        hit.avoided = true;
        return hit;
    }
    // TODO Shield Block
    // TODO Two Hand Block
    hit.avoided = false;
    return hit;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity)

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