Search in sources :

Example 1 with MinorPower

use of com.magmaguy.elitemobs.powers.meta.MinorPower in project EliteMobs by MagmaGuy.

the class EliteEntity method applyPowers.

public void applyPowers(HashSet<ElitePower> elitePowers, int availablePowerAmount) {
    elitePowers.removeIf(elitePower -> !PowersConfig.getPower(elitePower.getFileName()).isEnabled());
    if (availablePowerAmount < 1)
        return;
    ArrayList<ElitePower> localPowers = new ArrayList<>(elitePowers);
    for (ElitePower mobPower : this.elitePowers) localPowers.remove(mobPower);
    for (int i = 0; i < availablePowerAmount; i++) if (localPowers.size() < 1)
        break;
    else {
        ElitePower selectedPower = localPowers.get(ThreadLocalRandom.current().nextInt(localPowers.size()));
        try {
            this.elitePowers.add(selectedPower.getClass().newInstance());
            selectedPower.applyPowers(this.livingEntity);
            localPowers.remove(selectedPower);
            if (selectedPower instanceof MajorPower)
                this.majorPowerCount++;
            if (selectedPower instanceof MinorPower)
                this.minorPowerCount++;
        } catch (Exception ex) {
            new WarningMessage("Failed to instance new power!");
        }
    }
}
Also used : MinorPower(com.magmaguy.elitemobs.powers.meta.MinorPower) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) MajorPower(com.magmaguy.elitemobs.powers.meta.MajorPower) ElitePower(com.magmaguy.elitemobs.powers.meta.ElitePower)

Aggregations

ElitePower (com.magmaguy.elitemobs.powers.meta.ElitePower)1 MajorPower (com.magmaguy.elitemobs.powers.meta.MajorPower)1 MinorPower (com.magmaguy.elitemobs.powers.meta.MinorPower)1 WarningMessage (com.magmaguy.elitemobs.utils.WarningMessage)1