Пример #1
0
 /** Используется для однодневных квестов */
 public void exitCurrentQuest(Quest quest) {
   Player player = getPlayer();
   exitCurrentQuest(true);
   quest.newQuestState(player, Quest.DELAYED);
   QuestState qs = player.getQuestState(quest.getClass());
   qs.setRestartTime();
 }
Пример #2
0
 /**
  * Remove the variable of quest from the list of variables for the quest.<br>
  * <br>
  * <U><I>Concept : </I></U> Remove the variable of quest represented by "var" from the class
  * variable FastMap "vars" and from the database.
  *
  * @param var : String designating the variable for the quest to be deleted
  * @return String pointing out the previous value associated with the variable "var"
  */
 public String unset(String var) {
   if (var == null) {
     return null;
   }
   String old = _vars.remove(var);
   if (old != null) {
     Quest.deleteQuestVarInDb(this, var);
   }
   return old;
 }
Пример #3
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;
  }
Пример #4
0
  /**
   * Constructor<?> of the QuestState : save the quest in the list of quests of the player.<br>
   * <br>
   *
   * <p><U><I>Actions :</U></I><br>
   * <LI>Save informations in the object QuestState created (Quest, Player, Completion, State)
   * <LI>Add the QuestState in the player's list of quests by using setQuestState()
   * <LI>Add drops gotten by the quest <br>
   *
   * @param quest : quest associated with the QuestState
   * @param player : L2Player pointing out the player
   * @param state : state of the quest
   */
  public QuestState(Quest quest, Player player, int state) {
    _quest = quest;
    _player = player;

    // Save the state of the quest for the player in the player's list of quest onwed
    player.setQuestState(this);

    // set the state of the quest
    _state = state;
    quest.notifyCreate(this);
  }
Пример #5
0
  /**
   * <font color=red>Использовать осторожно! Служебная функция!</font><br>
   * <br>
   *
   * <p>Устанавливает переменную и сохраняет в базу, если установлен флаг. Если получен cond
   * обновляет список квестов игрока (только с флагом).
   *
   * @param var : String pointing out the name of the variable for quest
   * @param val : String pointing out the value of the variable for quest
   * @param store : Сохраняет в базу и если var это cond обновляет список квестов игрока.
   * @return String (equal to parameter "val")
   */
  public String set(String var, String val, boolean store) {
    if (val == null) {
      val = StringUtils.EMPTY;
    }

    _vars.put(var, val);

    if (store) {
      Quest.updateQuestVarInDb(this, var, val);
    }

    return val;
  }
Пример #6
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;
  }
Пример #7
0
  public String setCond(int newCond, boolean store) {
    if (newCond == getCond()) {
      return String.valueOf(newCond);
    }

    int oldCond = getInt(VAR_COND);
    _cond = newCond;

    if ((oldCond & 0x80000000) != 0) {
      // уже используется второй формат
      if (newCond > 2) // Если этап меньше 3 то возвращаемся к первому варианту.
      {
        oldCond &= 0x80000001 | ((1 << newCond) - 1);
        newCond = oldCond | (1 << (newCond - 1));
      }
    } else {
      // Второй вариант теперь используется всегда если этап больше 2
      if (newCond > 2) {
        newCond = 0x80000001 | (1 << (newCond - 1)) | ((1 << oldCond) - 1);
      }
    }

    final String sVal = String.valueOf(newCond);
    final String result = set(VAR_COND, sVal, false);
    if (store) {
      Quest.updateQuestVarInDb(this, VAR_COND, sVal);
    }

    final Player player = getPlayer();
    if (player != null) {
      player.sendPacket(new QuestList(player));
      if ((newCond != 0) && getQuest().isVisible(player) && isStarted()) {
        player.sendPacket(new ExShowQuestMark(getQuest().getQuestIntId()));
      }
    }
    return result;
  }
Пример #8
0
 public String getStateName() {
   return Quest.getStateName(_state);
 }
Пример #9
0
 public void abortQuest() {
   _quest.onAbort(this);
   exitCurrentQuest(true);
 }