@Override
  public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon) {
    if (Util.checkIfInRange(1500, killer, npc, true)) {
      for (int i = 0; i < 20; i++) {
        final L2Npc guardian = addSpawn(SOUL_OF_TREE_GUARDIAN, npc);
        startQuestTimer("DESPAWN_GUARDIAN", 300000, guardian, null);

        if (i == 0) {
          npc.setTarget(killer);
          npc.doCast(VICIOUS_POISON.getSkill());
        }

        npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, killer);
      }
    }
    return super.onKill(npc, killer, isSummon);
  }
  @Override
  public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) {
    final QuestState qs = getQuestState(attacker, false);
    if ((qs != null) && qs.isCond(2)) {
      if (isSummon) {
        final NpcData data = NPC_DATA.get(npc.getId());
        if ((qs.getMemoState() % data.memoStateMod) < data.memoStateValue) {
          final L2Summon pet = attacker.getPet();
          if ((pet != null) && (pet.getControlObjectId() == qs.getInt("fluteObjectId"))) {
            final int hits = qs.getInt("hits") + 1;
            qs.set("hits", hits);

            if (hits < data.minHits) {
              if ((npc.getId() == TREE_OF_ABYSS) && (getRandom(100) < 2)) {
                npc.setTarget(attacker);
                npc.doCast(DRYAD_ROOT.getSkill());
              }
            } else if (getRandom(100) < 2) {
              if (hasQuestItems(attacker, FAIRY_LEAF)) {
                npc.broadcastPacket(
                    new NpcSay(npc, ChatType.NPC_GENERAL, NpcStringId.GIVE_ME_A_FAIRY_LEAF));
                takeItems(attacker, FAIRY_LEAF, 1);
                qs.setMemoState(qs.getMemoState() + data.memoStateValue);
                qs.unset("hits");
                playSound(attacker, QuestSound.ITEMSOUND_QUEST_MIDDLE);

                if (qs.getMemoState() == 15) {
                  qs.setCond(3);
                }
              }
            }
          }
        } else {
          switch (getRandom(3)) {
            case 0:
              npc.broadcastPacket(
                  new NpcSay(npc, ChatType.NPC_GENERAL, NpcStringId.WHY_DO_YOU_BOTHER_ME_AGAIN));
              break;
            case 1:
              npc.broadcastPacket(new NpcSay(npc, ChatType.NPC_GENERAL, data.message));
              break;
            case 2:
              npc.broadcastPacket(
                  new NpcSay(
                      npc,
                      ChatType.NPC_GENERAL,
                      NpcStringId.LEAVE_NOW_BEFORE_YOU_INCUR_THE_WRATH_OF_THE_GUARDIAN_GHOST));
              break;
          }
        }
      } else if (getRandom(100) < 30) {
        npc.setTarget(attacker);
        npc.doCast(VICIOUS_POISON.getSkill());
      }
    } else if ((npc.getCurrentHp() < (npc.getMaxHp() * 0.67)) && (getRandom(100) < 30)) {
      npc.setTarget(attacker);
      npc.doCast(VICIOUS_POISON.getSkill());
    }

    return super.onAttack(npc, attacker, damage, isSummon);
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance talker) {
    final QuestState qs = getQuestState(talker, true);
    String htmltext = getNoQuestMsg(talker);

    switch (npc.getId()) {
      case CRONOS:
        {
          switch (qs.getState()) {
            case State.CREATED:
              {
                final long fluteCount =
                    getQuestItemsCount(
                        talker, DRAGONFLUTE_OF_WIND, DRAGONFLUTE_OF_STAR, DRAGONFLUTE_OF_TWILIGHT);
                if (fluteCount == 0) {
                  break; // this quest does not show up if no flute in inventory
                }

                if (talker.getLevel() < MIN_PLAYER_LVL) {
                  htmltext = "30610-01.htm";
                } else if (fluteCount > 1) {
                  htmltext = "30610-02.htm";
                } else if (getFlute(talker).getEnchantLevel() < MIN_HACHLING_LVL) {
                  htmltext = "30610-03.html";
                } else {
                  htmltext = "30610-04.htm";
                }
                break;
              }
            case State.STARTED:
              {
                htmltext = "30610-07.html";
                break;
              }
            case State.COMPLETED:
              {
                htmltext = getAlreadyCompletedMsg(talker);
                break;
              }
          }
          break;
        }
      case MIMYU:
        {
          switch (qs.getMemoState()) {
            case 100:
              {
                qs.setMemoState(200);
                htmltext = "30747-01.html";
                break;
              }
            case 200:
              {
                final L2Summon summon = talker.getPet();

                if (summon == null) {
                  htmltext = "30747-02.html";
                } else if (summon.getControlObjectId() != qs.getInt("fluteObjectId")) {
                  htmltext = "30747-03.html";
                } else {
                  htmltext = "30747-04.html";
                }
                break;
              }
            case 0:
              {
                htmltext = "30747-07.html";
                break;
              }
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
              {
                if (hasQuestItems(talker, FAIRY_LEAF)) {
                  htmltext = "30747-11.html";
                }
                break;
              }
            case 15:
              {
                if (!hasQuestItems(talker, FAIRY_LEAF)) {
                  final L2Summon summon = talker.getPet();

                  if (summon == null) {
                    htmltext = "30747-12.html";
                  } else if (summon.getControlObjectId() == qs.getInt("fluteObjectId")) {
                    qs.setMemoState(16);
                    htmltext = "30747-13.html";
                  } else {
                    htmltext = "30747-14.html";
                  }
                }
                break;
              }
            case 16:
              {
                if (!hasQuestItems(talker, FAIRY_LEAF)) {
                  if (talker.hasSummon()) {
                    htmltext = "30747-15.html";
                  } else {
                    final long fluteCount =
                        getQuestItemsCount(
                            talker,
                            DRAGONFLUTE_OF_WIND,
                            DRAGONFLUTE_OF_STAR,
                            DRAGONFLUTE_OF_TWILIGHT);

                    if (fluteCount > 1) {
                      htmltext = "30747-17.html";
                    } else if (fluteCount == 1) {
                      final L2ItemInstance flute = getFlute(talker);

                      if (flute.getObjectId() == qs.getInt("fluteObjectId")) {
                        // TODO what if the hatchling has items in his inventory?
                        // Should they be transfered to the strider or given to the player?
                        switch (flute.getId()) {
                          case DRAGONFLUTE_OF_WIND:
                            takeItems(talker, DRAGONFLUTE_OF_WIND, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_WIND, 1);
                            break;
                          case DRAGONFLUTE_OF_STAR:
                            takeItems(talker, DRAGONFLUTE_OF_STAR, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_STAR, 1);
                            break;
                          case DRAGONFLUTE_OF_TWILIGHT:
                            takeItems(talker, DRAGONFLUTE_OF_TWILIGHT, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_TWILIGHT, 1);
                            break;
                        }

                        qs.exitQuest(true, true);
                        htmltext = "30747-16.html";
                      } else {
                        npc.setTarget(talker);
                        npc.doCast(CURSE_OF_MIMYU.getSkill());
                        htmltext = "30747-18.html";
                      }
                    }
                  }
                }
                break;
              }
          }
          break;
        }
    }
    return htmltext;
  }