Search in sources :

Example 1 with MinorPowers

use of com.magmaguy.elitemobs.minorpowers.MinorPowers in project EliteMobs by MagmaGuy.

the class PowerHandler method powerHandler.

public static void powerHandler(Entity entity) {
    int availableMinorPowers = 0;
    int availableMajorPowers = 0;
    if (entity.hasMetadata(MetadataHandler.ELITE_MOB_MD) && entity.isValid() && ((LivingEntity) entity).getHealth() > 0) {
        if (entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() >= 5) {
            int EliteMobLevel = entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt();
            availableMinorPowers = (EliteMobLevel - 5) / 10 + 1;
            availableMajorPowers = EliteMobLevel / 10;
        }
    }
    if (availableMinorPowers >= 1) {
        int currentMinorPowerAmount = 0;
        if (entity.hasMetadata(MetadataHandler.CUSTOM_POWERS_MD)) {
            return;
        }
        if (minorPowerArray.isEmpty()) {
            minorPowerArrayInitializer();
        }
        if (entity.hasMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD)) {
            currentMinorPowerAmount = entity.getMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD).get(0).asInt();
            //TODO: this is probably not working as intended
            Iterator<MinorPowers> minorPowerIterator = minorPowerArray.iterator();
            while (minorPowerIterator.hasNext()) {
                MinorPowers minorPower = minorPowerIterator.next();
                if (minorPower.existingPowers(entity)) {
                    minorPowerIterator.remove();
                }
            }
        }
        int missingMinorPowerAmount = availableMinorPowers - currentMinorPowerAmount;
        if (missingMinorPowerAmount > 0 && minorPowerArray.size() > 0) {
            for (int i = 0; i < missingMinorPowerAmount; i++) {
                if (minorPowerArray.size() > 0) {
                    int randomizer = random.nextInt(minorPowerArray.size());
                    MinorPowers selectedMinorPower = minorPowerArray.get(randomizer);
                    minorPowerArray.remove(minorPowerArray.get(randomizer));
                    if (entity.hasMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD)) {
                        int oldMinorPowerAmount = entity.getMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD).get(0).asInt();
                        int newMinorPowerAmount = oldMinorPowerAmount + 1;
                        entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, newMinorPowerAmount));
                    } else {
                        entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, 1));
                    }
                    selectedMinorPower.applyPowers(entity);
                }
            }
        }
    }
    if (availableMajorPowers >= 1) {
        int currentMajorPowerAmount = 0;
        if (entity.hasMetadata(MetadataHandler.CUSTOM_POWERS_MD)) {
            return;
        }
        ArrayList<MajorPowers> majorPowersArrayList = new ArrayList();
        if (majorPowersArrayList.isEmpty()) {
            if (entity instanceof Zombie) {
                //These powers can't be intialized like minor powers because the list depends on the mob type
                //TODO: Add a mob type sensitive power list
                majorPowersArrayList.add(zombieFriends);
                majorPowersArrayList.add(zombieNecronomicon);
                majorPowersArrayList.add(zombieTeamRocket);
                majorPowersArrayList.add(zombieParents);
            }
        }
        if (entity.hasMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD)) {
            currentMajorPowerAmount = entity.getMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD).get(0).asInt();
            Iterator<MajorPowers> majorPowerIterator = majorPowersArrayList.iterator();
            while (majorPowerIterator.hasNext()) {
                MajorPowers majorPowers = majorPowerIterator.next();
                if (majorPowers.existingPowers(entity)) {
                    majorPowerIterator.remove();
                }
            }
        }
        //TODO: pretty sure this doesn't check for level 10?
        int missingMajorPowerAmount = availableMajorPowers - currentMajorPowerAmount;
        if (missingMajorPowerAmount > 0 && majorPowersArrayList.size() > 0) {
            for (int i = 0; i < missingMajorPowerAmount; i++) {
                if (majorPowersArrayList.size() > 0) {
                    int randomizer = random.nextInt(majorPowersArrayList.size());
                    MajorPowers selectedMajorPower = majorPowersArrayList.get(randomizer);
                    majorPowersArrayList.remove(majorPowersArrayList.get(randomizer));
                    if (entity.hasMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD)) {
                        int oldMajorPowerAmount = entity.getMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD).get(0).asInt();
                        int newMajorPowerAmount = oldMajorPowerAmount + 1;
                        entity.setMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, newMajorPowerAmount));
                    } else {
                        entity.setMetadata(MetadataHandler.MAJOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, 1));
                    }
                    selectedMajorPower.applyPowers(entity);
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) MinorPowers(com.magmaguy.elitemobs.minorpowers.MinorPowers) Zombie(org.bukkit.entity.Zombie) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue)

Aggregations

MinorPowers (com.magmaguy.elitemobs.minorpowers.MinorPowers)1 ArrayList (java.util.ArrayList)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Zombie (org.bukkit.entity.Zombie)1 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)1