Search in sources :

Example 1 with LevelConfig

use of com.jacob_vejvoda.infernal_mobs.config.LevelConfig in project InfernalMobs by NyaaCat.

the class MobManager method getAbilities.

private List<EnumAbilities> getAbilities(int level) {
    List<EnumAbilities> enumAbilities = null;
    if (ConfigReader.isEnhanceEnabled()) {
        LevelConfig levelConfig = ConfigReader.getLevelConfig();
        enumAbilities = Helper.randomNItems(levelConfig.getAbilitiyList(level), level);
    }
    if (enumAbilities == null) {
        enumAbilities = Helper.randomNItems(ConfigReader.getEnabledAbilities(), level);
    }
    return enumAbilities;
}
Also used : LevelConfig(com.jacob_vejvoda.infernal_mobs.config.LevelConfig) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)

Example 2 with LevelConfig

use of com.jacob_vejvoda.infernal_mobs.config.LevelConfig in project InfernalMobs by NyaaCat.

the class EventListener method onEntityAttack.

@EventHandler(priority = EventPriority.HIGH)
public void onEntityAttack(final EntityDamageByEntityEvent event) {
    // todo unexpected fireball damage
    boolean isDirectAttack = true;
    Entity trueVictim = event.getEntity();
    Entity trueAttacker = event.getDamager();
    if (trueAttacker instanceof Projectile) {
        isDirectAttack = false;
        ProjectileSource src = ((Projectile) trueAttacker).getShooter();
        if (src instanceof Entity) {
            trueAttacker = (Entity) src;
        } else {
            return;
        }
    }
    if (!(trueAttacker instanceof LivingEntity))
        return;
    if (!(trueVictim instanceof LivingEntity))
        return;
    if (plugin.mobManager.mobMap.containsKey(trueVictim.getUniqueId())) {
        // something attacked infernal mob
        if (!(trueAttacker instanceof Player))
            return;
        Mob mob = plugin.mobManager.mobMap.get(trueVictim.getUniqueId());
        mob.lastDamageCause = event;
        GameMode gameMode = ((Player) trueAttacker).getGameMode();
        if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR) {
            for (EnumAbilities ab : mob.abilityList) {
                ab.onPlayerAttack((LivingEntity) trueVictim, mob, (Player) trueAttacker, isDirectAttack, event);
            }
        }
        if (ConfigReader.isEnhanceEnabled()) {
            double resistedDamage = ConfigReader.getLevelConfig().calcResistedDamage(event.getDamage(), mob.getMobLevel());
            event.setDamage(resistedDamage);
        }
    }
    if ((plugin.mobManager.mobMap.containsKey(trueAttacker.getUniqueId()))) {
        // infernal mob attacked something
        EntityDamageEvent.DamageCause cause = event.getCause();
        double originDamage = event.getDamage();
        Mob mob = plugin.mobManager.mobMap.get(trueAttacker.getUniqueId());
        if (isValidDamageCause(cause, mob)) {
            if ((trueVictim instanceof Player)) {
                GameMode gameMode = ((Player) trueVictim).getGameMode();
                if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR)
                    return;
                for (EnumAbilities ab : mob.abilityList) {
                    ab.onAttackPlayer((LivingEntity) trueAttacker, mob, (Player) trueVictim, isDirectAttack, event);
                }
            }
            double extraDamage = event.getDamage() - originDamage;
            if (ConfigReader.isEnhanceEnabled()) {
                LevelConfig levelConfig = ConfigReader.getLevelConfig();
                double damage = levelConfig.getDamage(originDamage, mob.getMobLevel());
                damage += extraDamage;
                event.setDamage(damage);
            }
        }
    }
}
Also used : Mob(com.jacob_vejvoda.infernal_mobs.persist.Mob) LevelConfig(com.jacob_vejvoda.infernal_mobs.config.LevelConfig) GameMode(org.bukkit.GameMode) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EnumAbilities(com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities) EventHandler(org.bukkit.event.EventHandler)

Example 3 with LevelConfig

use of com.jacob_vejvoda.infernal_mobs.config.LevelConfig in project InfernalMobs by NyaaCat.

the class ConfigReader method loadLevelConfig.

private static LevelConfig loadLevelConfig() {
    levelConfig = new LevelConfig();
    levelConfig.load();
    return levelConfig;
}
Also used : LevelConfig(com.jacob_vejvoda.infernal_mobs.config.LevelConfig)

Example 4 with LevelConfig

use of com.jacob_vejvoda.infernal_mobs.config.LevelConfig in project InfernalMobs by NyaaCat.

the class MobManager method getInfernalLevelForLocation.

public static int getInfernalLevelForLocation(Location loc) {
    int level;
    Location spawnLocation = loc.getWorld().getSpawnLocation();
    if (ConfigReader.isEnhanceEnabled()) {
        double distance = spawnLocation.distance(loc);
        LevelConfig levelConfig = ConfigReader.getLevelConfig();
        level = levelConfig.getLevel(distance);
        if (level == -1) {
            level = getLevelByDistance(loc, spawnLocation);
        }
    } else if (ConfigReader.isSpawnedLevelByDistance()) {
        level = getLevelByDistance(loc, spawnLocation);
    } else {
        level = Helper.rand(ConfigReader.getMinimalLevel(), ConfigReader.getMaximumLevel());
    }
    if (level <= 0)
        level = 1;
    return level;
}
Also used : LevelConfig(com.jacob_vejvoda.infernal_mobs.config.LevelConfig)

Aggregations

LevelConfig (com.jacob_vejvoda.infernal_mobs.config.LevelConfig)4 EnumAbilities (com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)2 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)1 GameMode (org.bukkit.GameMode)1 EventHandler (org.bukkit.event.EventHandler)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1