private final void refreshAiParams(L2Character attacker, L2Npc npc, int damage, int aggro) {
   final int newAggroVal = damage + getRandom(3000);
   final int aggroVal = aggro + 1000;
   final NpcVariables vars = npc.getVariables();
   for (int i = 0; i < 3; i++) {
     if (attacker == vars.getObject("c_quest" + i, L2Character.class)) {
       if (vars.getInt("i_quest" + i) < aggroVal) {
         vars.set("i_quest" + i, newAggroVal);
       }
       return;
     }
   }
   final int index =
       Util.getIndexOfMinValue(
           vars.getInt("i_quest0"), vars.getInt("i_quest1"), vars.getInt("i_quest2"));
   vars.set("i_quest" + index, newAggroVal);
   vars.set("c_quest" + index, attacker);
 }
  private void manageSkills(L2Npc npc) {
    if (npc.isCastingNow() || npc.isCoreAIDisabled() || !npc.isInCombat()) {
      return;
    }

    final NpcVariables vars = npc.getVariables();
    for (int i = 0; i < 3; i++) {
      final L2Character attacker = vars.getObject("c_quest" + i, L2Character.class);
      if ((attacker == null)
          || ((npc.calculateDistance(attacker, true, false) > 9000) || attacker.isDead())) {
        vars.set("i_quest" + i, 0);
      }
    }
    final int index =
        Util.getIndexOfMaxValue(
            vars.getInt("i_quest0"), vars.getInt("i_quest1"), vars.getInt("i_quest2"));
    final L2Character player = vars.getObject("c_quest" + index, L2Character.class);
    final int i2 = vars.getInt("i_quest" + index);
    if ((i2 > 0) && (getRandom(100) < 70)) {
      vars.set("i_quest" + index, 500);
    }

    SkillHolder skillToCast = null;
    if ((player != null) && !player.isDead()) {
      if (npc.getCurrentHp() > (npc.getMaxHp() * 0.75)) {
        if (getRandom(100) < 10) {
          skillToCast = ENERGY_WAVE;
        } else if (getRandom(100) < 10) {
          skillToCast = EARTH_QUAKE;
        } else {
          skillToCast = BAIUM_ATTACK;
        }
      } else if (npc.getCurrentHp() > (npc.getMaxHp() * 0.5)) {
        if (getRandom(100) < 10) {
          skillToCast = GROUP_HOLD;
        } else if (getRandom(100) < 10) {
          skillToCast = ENERGY_WAVE;
        } else if (getRandom(100) < 10) {
          skillToCast = EARTH_QUAKE;
        } else {
          skillToCast = BAIUM_ATTACK;
        }
      } else if (npc.getCurrentHp() > (npc.getMaxHp() * 0.25)) {
        if (getRandom(100) < 10) {
          skillToCast = THUNDERBOLT;
        } else if (getRandom(100) < 10) {
          skillToCast = GROUP_HOLD;
        } else if (getRandom(100) < 10) {
          skillToCast = ENERGY_WAVE;
        } else if (getRandom(100) < 10) {
          skillToCast = EARTH_QUAKE;
        } else {
          skillToCast = BAIUM_ATTACK;
        }
      } else if (getRandom(100) < 10) {
        skillToCast = THUNDERBOLT;
      } else if (getRandom(100) < 10) {
        skillToCast = GROUP_HOLD;
      } else if (getRandom(100) < 10) {
        skillToCast = ENERGY_WAVE;
      } else if (getRandom(100) < 10) {
        skillToCast = EARTH_QUAKE;
      } else {
        skillToCast = BAIUM_ATTACK;
      }
    }

    if ((skillToCast != null) && npc.checkDoCastConditions(skillToCast.getSkill())) {
      npc.setTarget(player);
      npc.doCast(skillToCast.getSkill());
    }
  }