Exemple #1
0
  /**
   * Return state of the quest after its initialization.<br>
   * <br>
   * <U><I>Actions :</I></U>
   * <LI>Remove drops from previous state
   * <LI>Set new state of the quest
   * <LI>Add drop for new state
   * <LI>Update information in database
   * <LI>Send packet QuestList to client
   *
   * @param state
   * @return object
   */
  public Object setState(int state) {
    Player player = getPlayer();
    if (player == null) {
      return null;
    }

    _state = state;

    if (getQuest().isVisible(player) && isStarted()) {
      player.sendPacket(new ExShowQuestMark(getQuest().getQuestIntId()));
    }

    Quest.updateQuestInDb(this);
    player.sendPacket(new QuestList(player));
    return state;
  }
Exemple #2
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;
  }