@Override
  public String onEvent(String event, QuestState st, NpcInstance npc) {
    int _state = st.getState();
    ItemInstance dragonflute = GetDragonflute(st);
    int dragonflute_id = st.getInt("dragonflute");
    int cond = st.getCond();

    if (event.equalsIgnoreCase("30610_05.htm") && _state == CREATED) {
      st.setState(STARTED);
      st.setCond(1);
      st.playSound(SOUND_ACCEPT);
    } else if ((event.equalsIgnoreCase("30747_03.htm") || event.equalsIgnoreCase("30747_04.htm"))
        && _state == STARTED
        && cond == 1) {
      if (dragonflute == null) return "noquest";
      if (dragonflute.getObjectId() != dragonflute_id) {
        if (Rnd.chance(10)) {
          st.takeItems(dragonflute.getItemId(), 1);
          st.playSound(SOUND_FINISH);
          st.exitCurrentQuest(true);
        }
        return "30747_00.htm";
      }
      if (!HatchlingSummoned(st, false))
        return event.equalsIgnoreCase("30747_04.htm") ? "30747_04a.htm" : "30747_02.htm";
      if (event.equalsIgnoreCase("30747_04.htm")) {
        st.setCond(2);
        st.takeItems(Fairy_Leaf, -1);
        st.giveItems(Fairy_Leaf, 4);
        st.playSound(SOUND_MIDDLE);
      }
    }

    return event;
  }
Beispiel #2
0
  public void giveItems(int itemId, long count, Element element, int power) {
    Player player = getPlayer();
    if (player == null) {
      return;
    }

    if (count <= 0) {
      count = 1;
    }

    // Get template of item
    ItemTemplate template = ItemHolder.getInstance().getTemplate(itemId);
    if (template == null) {
      return;
    }

    for (int i = 0; i < count; i++) {
      ItemInstance item = ItemFunctions.createItem(itemId);

      if (element != Element.NONE) {
        item.setAttributeElement(element, power);
      }

      // Add items to player's inventory
      player.getInventory().addItem(item);
    }

    player.sendPacket(SystemMessage2.obtainItems(template.getItemId(), count, 0));
    player.sendChanges();
  }
Beispiel #3
0
  public void dropItem(NpcInstance npc, int itemId, long count) {
    Player player = getPlayer();
    if (player == null) {
      return;
    }

    ItemInstance item = ItemFunctions.createItem(itemId);
    item.setCount(count);
    item.dropToTheGround(player, npc);
  }
 private static boolean HatchlingSummoned(QuestState st, boolean CheckObjID) {
   Summon _pet = st.getPlayer().getSummonList().getPet();
   if (_pet == null) return false;
   if (CheckObjID) {
     int dragonflute_id = st.getInt("dragonflute");
     if (dragonflute_id == 0) return false;
     if (_pet.getControlItemObjId() != dragonflute_id) return false;
   }
   ItemInstance dragonflute = GetDragonflute(st);
   if (dragonflute == null) return false;
   if (PetDataTable.getControlItemId(_pet.getNpcId()) != dragonflute.getItemId()) return false;
   return true;
 }
Beispiel #5
0
 /*
  * Выбирает 1 предмет из группы
  */
 public void getGroupItem(Player activeChar, RewardData[] dropData, Map<Integer, Long> report) {
   ItemInstance item;
   long count = 0;
   for (RewardData d : dropData)
     if (Rnd.get(1, RewardList.MAX_CHANCE)
         <= d.getChance() * Config.EVENT_COFFER_OF_SHADOWS_REWARD_RATE) {
       count = Rnd.get(d.getMinDrop(), d.getMaxDrop());
       item = ItemFunctions.createItem(d.getItemId());
       item.setCount(count);
       activeChar.getInventory().addItem(item);
       Long old = report.get(d.getItemId());
       report.put(d.getItemId(), old != null ? old + count : count);
     }
 }
 private static boolean checkEnchant(ItemInstance item) {
   if (item == null) {
     return false;
   }
   if (!item.canBeEnchanted(true)) {
     return false;
   }
   return true;
 }
  private static ItemInstance GetDragonflute(QuestState st) {
    List<ItemInstance> Dragonflutes = new ArrayList<ItemInstance>();
    for (ItemInstance item : st.getPlayer().getInventory().getItems())
      if (item != null
          && (item.getItemId() == Dragonflute_of_Wind
              || item.getItemId() == Dragonflute_of_Star
              || item.getItemId() == Dragonflute_of_Twilight)) Dragonflutes.add(item);

    if (Dragonflutes.isEmpty()) return null;
    if (Dragonflutes.size() == 1) return Dragonflutes.get(0);
    if (st.getState() == CREATED) return null;

    int dragonflute_id = st.getInt("dragonflute");

    for (ItemInstance item : Dragonflutes) if (item.getObjectId() == dragonflute_id) return item;

    return null;
  }
Beispiel #8
0
  /**
   * Destroy element used by quest when quest is exited
   *
   * @param repeatable
   * @return QuestState
   */
  public QuestState exitCurrentQuest(boolean repeatable) {
    Player player = getPlayer();
    if (player == null) {
      return this;
    }

    removePlayerOnKillListener();
    // Clean drops
    for (int itemId : _quest.getItems()) {
      // Get [item from] / [presence of the item in] the inventory of the player
      ItemInstance item = player.getInventory().getItemByItemId(itemId);
      if ((item == null) || (itemId == 57)) {
        continue;
      }
      long count = item.getCount();
      // If player has the item in inventory, destroy it (if not gold)
      player.getInventory().destroyItemByItemId(itemId, count);
      player.getWarehouse().destroyItemByItemId(itemId, count); // TODO [G1ta0] analyze this
    }

    // If quest is repeatable, delete quest from list of quest of the player and from database
    // (quest CAN be created again => repeatable)
    if (repeatable) {
      player.removeQuestState(_quest.getName());
      Quest.deleteQuestInDb(this);
      _vars.clear();
    } else { // Otherwise, delete variables for quest and update database (quest CANNOT be created
             // again => not repeatable)
      for (String var : _vars.keySet()) {
        if (var != null) {
          unset(var);
        }
      }
      setState(Quest.COMPLETED);
      Quest.updateQuestInDb(this); // FIXME: оно вроде не нужно?
    }
    if (isCompleted()) {
      // WorldStatisticsManager.getInstance().updateStat(player, CategoryType.QUESTS_COMPLETED,0,
      // 1);
    }
    player.sendPacket(new QuestList(player));
    return this;
  }
Beispiel #9
0
  @Override
  public boolean useItem(Playable playable, ItemInstance item, boolean ctrl) {
    if (!playable.isPlayer()) return false;
    Player activeChar = playable.getPlayer();

    if (!activeChar.isQuestContinuationPossible(true)) return false;

    Map<Integer, Long> items = new HashMap<Integer, Long>();
    long count = 0;
    do {
      count++;
      getGroupItem(activeChar, _dropmats, items);
      getGroupItem(activeChar, _dropacc, items);
      getGroupItem(activeChar, _dropevents, items);
      getGroupItem(activeChar, _dropench, items);
    } while (ctrl && item.getCount() > count && activeChar.isQuestContinuationPossible(false));

    activeChar.getInventory().destroyItem(item, count); // FIXME [G1ta0] item-API
    activeChar.sendPacket(SystemMessage2.removeItems(item.getItemId(), count));
    for (Entry<Integer, Long> e : items.entrySet())
      activeChar.sendPacket(SystemMessage2.obtainItems(e.getKey(), e.getValue(), 0));
    return true;
  }
Beispiel #10
0
  /**
   * Удаляет указанные предметы из инвентаря игрока, и обновляет инвентарь
   *
   * @param itemId : id удаляемого предмета
   * @param count : число удаляемых предметов<br>
   *     Если count передать -1, то будут удалены все указанные предметы.
   * @return Количество удаленных предметов
   */
  public long takeItems(int itemId, long count) {
    Player player = getPlayer();
    if (player == null) {
      return 0;
    }

    // Get object item from player's inventory list
    ItemInstance item = player.getInventory().getItemByItemId(itemId);
    if (item == null) {
      return 0;
    }
    // Tests on count value in order not to have negative value
    if ((count < 0) || (count > item.getCount())) {
      count = item.getCount();
    }

    // Destroy the quantity of items wanted
    player.getInventory().destroyItemByItemId(itemId, count);
    // Send message of destruction to client
    player.sendPacket(SystemMessage2.removeItems(itemId, count));

    return count;
  }
Beispiel #11
0
  public void evolve() {
    Player player = getSelf();
    NpcInstance npc = getNpc();
    if (player == null || npc == null) {
      return;
    }
    Summon pl_pet = player.getPet();
    if (player.getInventory().getItemByItemId(BABY_COUGAR_CHIME) == null) {
      show("scripts/services/petevolve/no_item.htm", player, npc);
      return;
    }
    if (pl_pet == null || pl_pet.isDead()) {
      show("scripts/services/petevolve/evolve_no.htm", player, npc);
      return;
    }
    if (pl_pet.getNpcId() != BABY_COUGAR) {
      show("scripts/services/petevolve/no_pet.htm", player, npc);
      return;
    }
    if (pl_pet.getLevel() < 55) {
      show("scripts/services/petevolve/no_level.htm", player, npc);
      return;
    }

    int controlItemId = player.getPet().getControlItemObjId();
    player.getPet().unSummon();

    ItemInstance control = player.getInventory().getItemByObjectId(controlItemId);
    control.setItemId(IN_COUGAR_CHIME);
    control.setEnchantLevel(L2Pet.IMPROVED_BABY_COUGAR.getMinLevel());
    control.setJdbcState(JdbcEntityState.UPDATED);
    control.update();
    player.sendItemList(false);

    show("scripts/services/petevolve/yes_pet.htm", player, npc);
  }
  @Override
  public String onTalk(NpcInstance npc, QuestState st) {
    int _state = st.getState();
    int npcId = npc.getNpcId();
    int cond = st.getCond();
    ItemInstance dragonflute = GetDragonflute(st);
    int dragonflute_id = st.getInt("dragonflute");

    if (_state == CREATED) {
      if (npcId != Cronos) return "noquest";
      if (st.getPlayer().getLevel() < 45) {
        st.exitCurrentQuest(true);
        return "30610_01.htm";
      }
      if (dragonflute == null) {
        st.exitCurrentQuest(true);
        return "30610_02.htm";
      }
      if (dragonflute.getEnchantLevel() < 55) {
        st.exitCurrentQuest(true);
        return "30610_03.htm";
      }
      st.setCond(0);
      st.set("dragonflute", String.valueOf(dragonflute.getObjectId()));
      return "30610_04.htm";
    }

    if (_state != STARTED) return "noquest";

    if (npcId == Cronos) {
      if (dragonflute == null) return "30610_02.htm";
      return dragonflute.getObjectId() == dragonflute_id ? "30610_07.htm" : "30610_06.htm";
    }

    if (npcId == Mimyu) {
      if (st.getQuestItemsCount(Dragon_Bugle_of_Wind)
              + st.getQuestItemsCount(Dragon_Bugle_of_Star)
              + st.getQuestItemsCount(Dragon_Bugle_of_Twilight)
          > 0) return "30747_00b.htm";
      if (dragonflute == null) return "noquest";
      if (cond == 1) return "30747_01.htm";
      if (cond == 2) {
        if (!HatchlingSummoned(st, false)) return "30747_09.htm";
        if (st.getQuestItemsCount(Fairy_Leaf) == 0) {
          st.playSound(SOUND_FINISH);
          st.exitCurrentQuest(true);
          return "30747_11.htm";
        }
        return "30747_10.htm";
      }
      if (cond == 3) {
        if (dragonflute.getObjectId() != dragonflute_id) return "30747_00a.htm";
        if (st.getQuestItemsCount(Fairy_Leaf) > 0) {
          st.playSound(SOUND_FINISH);
          st.exitCurrentQuest(true);
          return "30747_11.htm";
        }
        if (!(CheckTree(st, Fairy_Tree_of_Wind)
            && CheckTree(st, Fairy_Tree_of_Star)
            && CheckTree(st, Fairy_Tree_of_Twilight)
            && CheckTree(st, Fairy_Tree_of_Abyss))) {
          st.playSound(SOUND_FINISH);
          st.exitCurrentQuest(true);
          return "30747_11.htm";
        }
        if (st.getInt("welldone") == 0) {
          if (!HatchlingSummoned(st, false)) return "30747_09.htm";
          st.set("welldone", "1");
          return "30747_12.htm";
        }
        if (HatchlingSummoned(st, false) || st.getPlayer().getSummonList().getPet() != null)
          return "30747_13a.htm";

        dragonflute.setItemId(Dragon_Bugle_of_Wind + dragonflute.getItemId() - Dragonflute_of_Wind);
        dragonflute.setJdbcState(JdbcEntityState.UPDATED);
        dragonflute.update();
        st.getPlayer().sendPacket(new InventoryUpdate().addModifiedItem(dragonflute));

        st.playSound(SOUND_FINISH);
        st.exitCurrentQuest(true);
        return "30747_13.htm";
      }
    }

    return "noquest";
  }