Search in sources :

Example 6 with ISoliniaLivingEntity

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

the class EntityManager method getNPCMana.

@Override
public Integer getNPCMana(LivingEntity bukkitLivingEntity, ISoliniaNPC npc) {
    if (bukkitLivingEntity instanceof Player)
        return 0;
    if (entityManaLevels.get(bukkitLivingEntity.getUniqueId()) == null) {
        try {
            ISoliniaLivingEntity soliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(bukkitLivingEntity);
            entityManaLevels.put(bukkitLivingEntity.getUniqueId(), soliniaLivingEntity.getMaxMP());
        } catch (CoreStateInitException e) {
            entityManaLevels.put(bukkitLivingEntity.getUniqueId(), 1);
        }
    } else {
    }
    return entityManaLevels.get(bukkitLivingEntity.getUniqueId());
}
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 7 with ISoliniaLivingEntity

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

the class EntityManager method SpawnPet.

@Override
public LivingEntity SpawnPet(Plugin plugin, Player owner, ISoliniaSpell spell) {
    try {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(owner);
        if (pet != null) {
            StateManager.getInstance().getEntityManager().killPet(owner);
        }
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(spell.getTeleportZone());
        if (npc == null)
            return null;
        if (npc.isPet() == false)
            return null;
        Wolf entity = (Wolf) owner.getWorld().spawnEntity(owner.getLocation(), EntityType.WOLF);
        entity.setMetadata("npcid", new FixedMetadataValue(plugin, "NPCID_" + npc.getId()));
        StateManager.getInstance().getEntityManager().setPet(owner, entity);
        entity.setAdult();
        entity.setTamed(true);
        entity.setOwner(owner);
        entity.setBreed(false);
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(owner);
        entity.setCustomName(solplayer.getForename() + "'s Pet");
        entity.setCustomNameVisible(true);
        entity.setCanPickupItems(false);
        ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(entity);
        solentity.configurePetGoals();
        entity.setMaxHealth(solentity.getMaxHP());
        entity.setHealth(solentity.getMaxHP());
        net.minecraft.server.v1_12_R1.EntityInsentient entityhandle = (net.minecraft.server.v1_12_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) entity).getHandle();
        entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue((double) solentity.getMaxDamage());
        owner.sendMessage("New Pet spawned with HP: " + entity.getMaxHealth() + " and " + solentity.getMaxDamage() + " dmg");
        MobDisguise mob = new MobDisguise(DisguiseType.WOLF);
        switch(npc.getMctype().toUpperCase()) {
            case "WOLF":
                mob = new MobDisguise(DisguiseType.WOLF);
                break;
            case "SQUID":
                mob = new MobDisguise(DisguiseType.SQUID);
                break;
            case "PARROT":
                mob = new MobDisguise(DisguiseType.PARROT);
                break;
            case "SKELETON":
                mob = new MobDisguise(DisguiseType.SKELETON);
                break;
            case "BLAZE":
                mob = new MobDisguise(DisguiseType.BLAZE);
                break;
            case "IRON_GOLEM":
                mob = new MobDisguise(DisguiseType.IRON_GOLEM);
                break;
            case "GUARDIAN":
                mob = new MobDisguise(DisguiseType.GUARDIAN);
                break;
            default:
                mob = new MobDisguise(DisguiseType.WOLF);
                break;
        }
        DisguiseAPI.disguiseEntity(entity, mob);
        solentity.configurePetGoals();
        return entity;
    } catch (CoreStateInitException e) {
        return null;
    }
}
Also used : FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MobDisguise(me.libraryaddict.disguise.disguisetypes.MobDisguise) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) Wolf(org.bukkit.entity.Wolf) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 8 with ISoliniaLivingEntity

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

the class EntityManager method doNPCSummon.

/*
	@Override
	public void removeTemporaryMerchantItem(int npcid, int itemid, int amount) throws InsufficientTemporaryMerchantItemException {
		if (temporaryMerchantItems.get(npcid) == null)
			temporaryMerchantItems.put(npcid, new ConcurrentHashMap<Integer, Integer>());
		
		if (temporaryMerchantItems.get(npcid).get(itemid) == null)
			temporaryMerchantItems.get(npcid).put(itemid, 0);
		
		int currentCount = temporaryMerchantItems.get(npcid).get(itemid);
		
		if (currentCount < amount)
			throw new InsufficientTemporaryMerchantItemException("Vendor does not have sufficient items");
		
		int newCount = currentCount - amount;
		if (newCount < 0)
			newCount = 0;
		
		temporaryMerchantItems.get(npcid).put(itemid, newCount);
	}
	*/
@Override
public void doNPCSummon(Plugin plugin) {
    List<Integer> completedNpcsIds = new ArrayList<Integer>();
    for (Player player : Bukkit.getOnlinePlayers()) {
        for (Entity entityThatWillSummon : player.getNearbyEntities(50, 50, 50)) {
            if (entityThatWillSummon instanceof Player)
                continue;
            if (!(entityThatWillSummon instanceof LivingEntity))
                continue;
            LivingEntity livingEntityThatWillSummon = (LivingEntity) entityThatWillSummon;
            if (!(entityThatWillSummon instanceof Creature))
                continue;
            if (entityThatWillSummon.isDead())
                continue;
            Creature creatureThatWillSummon = (Creature) entityThatWillSummon;
            if (creatureThatWillSummon.getTarget() == null)
                continue;
            if (!Utils.isLivingEntityNPC(livingEntityThatWillSummon))
                continue;
            try {
                ISoliniaLivingEntity solLivingEntityThatWillSummon = SoliniaLivingEntityAdapter.Adapt(livingEntityThatWillSummon);
                if (completedNpcsIds.contains(solLivingEntityThatWillSummon.getNpcid()))
                    continue;
                completedNpcsIds.add(solLivingEntityThatWillSummon.getNpcid());
                solLivingEntityThatWillSummon.doSummon(plugin, creatureThatWillSummon.getTarget());
            } 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) Creature(org.bukkit.entity.Creature) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList)

Example 9 with ISoliniaLivingEntity

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

the class SoliniaSpell method isValidEffectForEntity.

public static boolean isValidEffectForEntity(LivingEntity target, LivingEntity source, ISoliniaSpell soliniaSpell) throws CoreStateInitException {
    if (source == null) {
        System.out.println("Source was null for isValidEffectForEntity: " + soliniaSpell.getName() + " on target: " + target.getCustomName());
        return false;
    }
    if (target == null) {
        System.out.println("Target was null for isValidEffectForEntity: " + soliniaSpell.getName() + " from source: " + source.getCustomName());
        return false;
    }
    // Always allow self only spells if the target and source is the self
    if (source.getUniqueId().equals(target.getUniqueId()) && Utils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
        // just be sure to check the item its giving if its an item spell
        for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonHorse)) {
                if (source instanceof Player) {
                    if (source.getUniqueId().equals(target.getUniqueId())) {
                        if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(source.getUniqueId()) != null) {
                            source.sendMessage("You can only summon a mount once per server session. Please wait for the next 4 hourly restart");
                            return false;
                        }
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                int itemId = effect.getBase();
                try {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                    System.out.println("Validating SummonItem for source: " + source.getCustomName());
                    if (item == null) {
                        System.out.println("Validating SummonItem said item was null");
                        return false;
                    }
                    if (!item.isTemporary()) {
                        System.out.println("Validating SummonItem said item was not temporary");
                        return false;
                    }
                    if (!(target instanceof LivingEntity)) {
                        System.out.println("Validating SummonItem said target was not a living entity");
                        return false;
                    }
                } catch (CoreStateInitException e) {
                    return false;
                }
            }
        }
        // System.out.println("Detected a self only spell (" + soliniaSpell.getName() + "), returning as valid, always");
        return true;
    }
    if (!source.getUniqueId().equals(target.getUniqueId()))
        if (!source.hasLineOfSight(target))
            return false;
    // Try not to kill potentially friendly player tameables with hostile spells
    if (target instanceof Tameable && target instanceof Creature && !soliniaSpell.isBeneficial()) {
        Tameable t = (Tameable) target;
        Creature cr = (Creature) target;
        if (t.getOwner() != null) {
            if (cr.getTarget() == null)
                return false;
            if (!cr.getTarget().getUniqueId().equals(source.getUniqueId()))
                return false;
        }
    }
    for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
        // and the spell is a detrimental
        if (source instanceof Player && target instanceof Player && soliniaSpell.isDetrimental()) {
            ISoliniaPlayer solsourceplayer = SoliniaPlayerAdapter.Adapt((Player) source);
            if (solsourceplayer.getGroup() != null) {
                if (solsourceplayer.getGroup().getMembers().contains(target.getUniqueId())) {
                    return false;
                }
            }
        }
        // Return false if the target is in the same faction as the npc and not self
        if (!(source instanceof Player) && !(target instanceof Player) && soliniaSpell.isDetrimental() && !source.getUniqueId().equals(target.getUniqueId())) {
            if (source instanceof LivingEntity && target instanceof LivingEntity) {
                ISoliniaLivingEntity solsourceEntity = SoliniaLivingEntityAdapter.Adapt(source);
                ISoliniaLivingEntity soltargetEntity = SoliniaLivingEntityAdapter.Adapt(target);
                if (solsourceEntity.isNPC() && soltargetEntity.isNPC()) {
                    ISoliniaNPC sourceNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                    ISoliniaNPC targetNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                    if (sourceNpc.getFactionid() > 0 && targetNpc.getFactionid() > 0) {
                        if (sourceNpc.getFactionid() == targetNpc.getFactionid())
                            return false;
                    }
                }
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Revive)) {
            if (!(target instanceof Player)) {
                return false;
            }
            if (!(source instanceof Player))
                return false;
            Player sourcePlayer = (Player) source;
            if (!sourcePlayer.getInventory().getItemInOffHand().getType().equals(Material.NAME_TAG)) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (MC): " + sourcePlayer.getInventory().getItemInOffHand().getType().name());
                return false;
            }
            ItemStack item = sourcePlayer.getInventory().getItemInOffHand();
            if (item.getEnchantmentLevel(Enchantment.DURABILITY) != 1) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (EC)");
                return false;
            }
            if (!item.getItemMeta().getDisplayName().equals("Signaculum")) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (NC)");
                return false;
            }
            if (item.getItemMeta().getLore().size() < 5) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (LC)");
                return false;
            }
            String sigdataholder = item.getItemMeta().getLore().get(3);
            String[] sigdata = sigdataholder.split("\\|");
            if (sigdata.length != 2) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (SD)");
                return false;
            }
            String str_experience = sigdata[0];
            String str_stimetsamp = sigdata[1];
            int experience = Integer.parseInt(str_experience);
            Timestamp timestamp = Timestamp.valueOf(str_stimetsamp);
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp currenttimestamp = Timestamp.valueOf(datetime);
            long maxminutes = 60 * 7;
            if ((currenttimestamp.getTime() - timestamp.getTime()) >= maxminutes * 60 * 1000) {
                sourcePlayer.sendMessage("This Signaculum has lost its binding to the soul");
                return false;
            }
            String playeruuidb64 = item.getItemMeta().getLore().get(4);
            String uuid = Utils.uuidFromBase64(playeruuidb64);
            Player targetplayer = Bukkit.getPlayer(UUID.fromString(uuid));
            if (targetplayer == null || !targetplayer.isOnline()) {
                sourcePlayer.sendMessage("You cannot resurrect that player as they are offline");
                return false;
            }
        }
        // Validate spelleffecttype rules
        if (effect.getSpellEffectType().equals(SpellEffectType.CurrentHP) || effect.getSpellEffectType().equals(SpellEffectType.CurrentHPOnce)) {
            // Ignore this rule if the spell is self
            if (!Utils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
                // If the effect is negative standard nuke and on self, cancel out
                if (effect.getBase() < 0 && target.equals(source))
                    return false;
            }
            // cancel
            if (source instanceof Player) {
                if (!(target instanceof Player)) {
                    ISoliniaLivingEntity soltargetentity = SoliniaLivingEntityAdapter.Adapt(target);
                    if (!soltargetentity.isPet()) {
                        if (effect.getBase() > 0)
                            return false;
                    }
                }
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Illusion) || effect.getSpellEffectType().equals(SpellEffectType.IllusionaryTarget) || effect.getSpellEffectType().equals(SpellEffectType.IllusionCopy) || effect.getSpellEffectType().equals(SpellEffectType.IllusionOther) || effect.getSpellEffectType().equals(SpellEffectType.IllusionPersistence)) {
            // if target has spell effect of above already then we cant apply another
            for (SoliniaActiveSpell activeSpell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(target).getActiveSpells()) {
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Illusion))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionaryTarget))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionCopy))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionOther))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionPersistence))
                    return false;
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
            System.out.println("Validating SummonItem for source: " + source.getCustomName());
            int itemId = effect.getBase();
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                if (item == null) {
                    System.out.println("Validating SummonItem said item was null");
                    return false;
                }
                if (!item.isTemporary()) {
                    System.out.println("Validating SummonItem said item was not temporary");
                    return false;
                }
                if (!(target instanceof LivingEntity)) {
                    System.out.println("Validating SummonItem said target was not a living entity");
                    return false;
                }
            } catch (CoreStateInitException e) {
                return false;
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.ResistAll) || effect.getSpellEffectType().equals(SpellEffectType.ResistCold) || effect.getSpellEffectType().equals(SpellEffectType.ResistFire) || effect.getSpellEffectType().equals(SpellEffectType.ResistMagic) || effect.getSpellEffectType().equals(SpellEffectType.ResistPoison) || effect.getSpellEffectType().equals(SpellEffectType.ResistDisease) || effect.getSpellEffectType().equals(SpellEffectType.ResistCorruption)) {
            // If the effect is negative standard resist debuffer and on self, cancel out
            if (effect.getBase() < 0 && target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Mez)) {
            // If the effect is a mez, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Stun)) {
            // If the effect is a stun, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Root)) {
            // If the effect is a root, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Blind)) {
            // If the effect is a blindness, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.DamageShield) && !(target instanceof Player) && !SoliniaLivingEntityAdapter.Adapt(target).isPet()) {
            // If the effect is a mez, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.NecPet) || effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
            // If the effect is teleport and the target is not a player then fail
            if (!(target instanceof Player))
                return false;
            if (!(source instanceof Player))
                return false;
            // If the effect is a teleport and the target is not in a group or self then fail
            if (effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
                // if target is not the player casting
                if (!target.getUniqueId().equals(source.getUniqueId())) {
                    ISoliniaPlayer solplayertarget = SoliniaPlayerAdapter.Adapt((Player) target);
                    if (solplayertarget == null)
                        return false;
                    if (solplayertarget.getGroup() == null)
                        return false;
                    if (!(solplayertarget.getGroup().getMembers().contains(source.getUniqueId())))
                        return false;
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.NecPet)) {
                try {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(soliniaSpell.getTeleportZone());
                    if (npc == null) {
                        return false;
                    }
                    if (npc.isPet() == false) {
                        System.out.print("NPC " + soliniaSpell.getTeleportZone() + " is not defined as a pet");
                        return false;
                    }
                } catch (CoreStateInitException e) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Tameable(org.bukkit.entity.Tameable) Creature(org.bukkit.entity.Creature) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with ISoliniaLivingEntity

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

the class SoliniaLivingEntity method aiCastSpell.

@Override
public boolean aiCastSpell(Plugin plugin, ISoliniaNPC npc, LivingEntity target, int iChance, int iSpellTypes) throws CoreStateInitException {
    if (this.getClassObj() == null) {
        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a spell as I have no class");
        return false;
    }
    if (this.getClassObj().getNpcspelllist() < 1) {
        return false;
    }
    NPCSpellList npcSpellList = StateManager.getInstance().getConfigurationManager().getNPCSpellList(getClassObj().getNpcspelllist());
    if (iChance < 100) {
        int roll = Utils.RandomBetween(0, 100);
        if (roll >= iChance) {
            Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a spell as i rolled badly roll: " + roll + " vs chance: " + iChance);
            return false;
        }
    }
    float dist2 = 0;
    // TODO escape distance
    boolean checked_los = false;
    double manaR = getManaRatio();
    List<NPCSpellListEntry> spells = new ArrayList<NPCSpellListEntry>();
    for (NPCSpellListEntry entry : npcSpellList.getSpellListEntry()) {
        if (npc.getLevel() >= entry.getMinlevel() && npc.getLevel() <= entry.getMaxlevel()) {
            spells.add(entry);
        }
    }
    Collections.sort(spells, new Comparator<NPCSpellListEntry>() {

        public int compare(NPCSpellListEntry o1, NPCSpellListEntry o2) {
            if (o1.getPriority() == o2.getPriority())
                return 0;
            return o1.getPriority() > o2.getPriority() ? -1 : 1;
        }
    });
    // AI has spells?
    if (spells.size() == 0) {
        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " cannot cast a spell as I have no spells");
        return false;
    }
    for (NPCSpellListEntry spelllistentry : spells) {
        // Does spell types contain spelltype
        if ((iSpellTypes & spelllistentry.getType()) == spelllistentry.getType()) {
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spelllistentry.getSpellid());
            // TODO Check mana
            int mana_cost = spell.getActSpellCost(this);
            if (mana_cost < 0)
                mana_cost = 0;
            ISoliniaLivingEntity soltarget = SoliniaLivingEntityAdapter.Adapt(target);
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp nowtimestamp = Timestamp.valueOf(datetime);
            Timestamp expiretimestamp = Timestamp.valueOf(datetime.plus(spell.getCastTime() + 1000, ChronoUnit.MILLIS));
            switch(spelllistentry.getType()) {
                case SpellType.Heal:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast heal " + spell.getName());
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && (Utils.getSpellTargetType(spell.getTargettype()).equals(SpellTargetType.Target) || target.getUniqueId().equals(getBukkitLivingEntity().getUniqueId())) && (nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Heal))) && !(soltarget.isPet())) {
                        double hpr = soltarget.getHPRatio();
                        // TODO player healing and non engaged healing of less than 50% hp
                        if (hpr <= 35) {
                            aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                            StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Heal, expiretimestamp);
                            return true;
                        }
                    }
                    break;
                case SpellType.Root:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast root " + spell.getName());
                    // TODO - Pick at random
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && !soltarget.isRooted() && Utils.RandomRoll(50) && nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Root))) // TODO buff stacking
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        }
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Root, expiretimestamp);
                        return true;
                    }
                    break;
                case SpellType.InCombatBuff:
                case SpellType.Buff:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast buff " + spell.getName());
                    if (((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && Utils.getSpellTargetType(spell.getTargettype()).equals(SpellTargetType.Target) || target.getUniqueId().equals(getBukkitLivingEntity().getUniqueId())) && nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Buff)) && !spell.isInvisSpell()) // TODO Spell immunities
                    // TODO Spell stacking
                    // TODO NPC Pets
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        } else {
                            Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the target (already)");
                        }
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Buff, expiretimestamp);
                        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " buff appears to be successful");
                        return true;
                    } else {
                        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as either the spell target was wrong, the target was not me or i have already buffed myself recently");
                    }
                    break;
                case SpellType.Escape:
                    // TODO Gate/Escape
                    return false;
                case SpellType.Slow:
                case SpellType.Debuff:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast debuff " + spell.getName());
                    // TODO debuff at random
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && manaR >= 10 && Utils.RandomRoll(70)) // TODO buff stacking
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        }
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        return true;
                    }
                    break;
                case SpellType.Nuke:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast nuke " + spell.getName());
                    boolean nukeRoll = Utils.RandomRoll(70);
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && manaR >= 10 && nukeRoll) // TODO Buff Stacking check
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        } else {
                            Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the target (previously checked)");
                        }
                        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " nuke appears to be successful");
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        return true;
                    } else {
                        Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast nuke as either my mana ratio was too high (" + (manaR >= 10) + ") or i rolled badly roll failure: (" + nukeRoll + ")");
                    }
                    break;
                case SpellType.Dispel:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast dispell " + spell.getName());
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && Utils.RandomRoll(15)) {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        }
                        if (soltarget.countDispellableBuffs() > 0) {
                            aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                            return true;
                        }
                    }
                    break;
                case SpellType.Mez:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast mez " + spell.getName());
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && Utils.RandomRoll(20)) {
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                    }
                    break;
                case SpellType.Charm:
                    // TODO Charms
                    break;
                case SpellType.Pet:
                    // TODO Pets
                    break;
                case SpellType.Lifetap:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast lifetap " + spell.getName());
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && getHPRatio() <= 95 && Utils.RandomRoll(50)) // TODO Buff stacking
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        }
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        return true;
                    }
                    break;
                case SpellType.Snare:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast snare " + spell.getName());
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && !soltarget.isRooted() && Utils.RandomRoll(50) && (nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.Snare)))) // TODO Buff stacking
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        }
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.Snare, expiretimestamp);
                        return true;
                    }
                    break;
                case SpellType.DOT:
                    Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " attempting to cast dot " + spell.getName());
                    if ((SoliniaSpell.isValidEffectForEntity(target, this.getBukkitLivingEntity(), spell)) && !Utils.hasSpellActive(soltarget, spell) && (Utils.RandomRoll(60)) && (nowtimestamp.after(StateManager.getInstance().getEntityManager().getDontSpellTypeMeBefore(target, SpellType.DOT)))) // TODO buff stacking
                    {
                        if (!checked_los) {
                            if (!this.getBukkitLivingEntity().hasLineOfSight(target)) {
                                Utils.DebugMessage("NPC: " + npc.getName() + this.getBukkitLivingEntity().getUniqueId().toString() + " could not cast as i could not see the arget");
                                return false;
                            }
                            checked_los = true;
                        }
                        aiDoSpellCast(plugin, spell, soltarget, mana_cost);
                        StateManager.getInstance().getEntityManager().setDontSpellTypeMeBefore(target, SpellType.DOT, expiretimestamp);
                        return true;
                    }
                    break;
                default:
                    // unknown spell type
                    break;
            }
        }
    }
    return false;
}
Also used : LocalDateTime(java.time.LocalDateTime) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) 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