Ejemplo n.º 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();
 }
Ejemplo n.º 2
0
 public void CompleteQuest(int Index) {
   Quest qstComp = QUEST_LIST.elementAt(Index);
   qstComp.STATUS = 3;
   qstComp.QUEST_GIVER.QUEST_LIST.elementAt(0).STATUS = 3;
   qstComp.QUEST_GIVER.QUEST_LIST.removeElementAt(0);
   STATS.IncreaseXP(qstComp.XP);
   GOLD += qstComp.GOLD;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
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);
  }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
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;
  }
Ejemplo n.º 9
0
 // add a Quest to the hero
 public static void addQuest(Quest q) {
   Quest.getQuests().add(q);
 }
Ejemplo n.º 10
0
  public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException {
    if ((commands.size() == 1) && (((String) commands.firstElement()).startsWith("QUESTW")))
      commands.addElement("WON");
    if ((commands.size() > 1) && (((String) commands.elementAt(1)).equalsIgnoreCase("WON"))) {
      Vector qVec = new Vector();
      for (int q = 0; q < CMLib.quests().numQuests(); q++) {
        Quest Q = CMLib.quests().fetchQuest(q);
        if (Q.wasWinner(mob.Name())) {
          String name = Q.displayName().trim().length() > 0 ? Q.displayName() : Q.name();
          if (!qVec.contains(name)) qVec.addElement(name);
        }
      }
      Collections.sort(qVec);
      StringBuffer msg = new StringBuffer("^HQuests you are listed as having won:^?^N\n\r");
      for (int i = 0; i < qVec.size(); i++) msg.append(((String) qVec.elementAt(i)) + "^N\n\r");
      if (!mob.isMonster()) mob.tell(msg.toString());
    } else if ((commands.size() > 2)
        && (((String) commands.elementAt(1)).equalsIgnoreCase("DROP"))) {
      ScriptingEngine foundS = null;
      for (Enumeration<ScriptingEngine> e = mob.scripts(); e.hasMoreElements(); ) {
        ScriptingEngine SE = e.nextElement();
        if (SE == null) continue;
        if ((SE.defaultQuestName().length() > 0)
            && (CMLib.quests().findQuest(SE.defaultQuestName()) == null)) foundS = SE;
      }
      if (foundS != null) mob.delScript(foundS);
      foundS = null;

      String rest = CMParms.combine(commands, 2);
      Quest Q = CMLib.quests().findQuest(rest);
      if (Q == null) {
        mob.tell("There is no such quest as '" + rest + "'.");
        return false;
      }
      for (Enumeration<ScriptingEngine> e = mob.scripts(); e.hasMoreElements(); ) {
        ScriptingEngine SE = e.nextElement();
        if (SE == null) continue;
        if ((SE.defaultQuestName().length() > 0)
            && (SE.defaultQuestName().equalsIgnoreCase(Q.name()))) foundS = SE;
      }
      if (foundS == null) {
        mob.tell("You have not accepted a quest called '" + rest + "'.  Enter QUESTS for a list.");
        return false;
      }
      if ((!mob.isMonster()
          && (mob.session()
              .confirm("Drop the quest '" + Q.name() + "', are you sure (y/N)?", "N")))) {
        CMLib.coffeeTables().bump(Q, CoffeeTableRow.STAT_QUESTDROPPED);
        mob.delScript(foundS);
        mob.tell("Quest dropped.");
        return false;
      }
    } else if (commands.size() == 1) {
      List<Quest> qQVec = CMLib.quests().getPlayerPersistantQuests(mob);
      Vector<String> qVec = new Vector<String>();
      for (Quest Q : qQVec) {
        String name = Q.displayName().trim().length() > 0 ? Q.displayName() : Q.name();
        if (!qVec.contains(name)) qVec.addElement(name);
      }
      Collections.sort(qVec);
      StringBuffer msg = new StringBuffer("^HQuests you are listed as having accepted:^?^N\n\r");
      for (int i = 0; i < qVec.size(); i++) msg.append(((String) qVec.elementAt(i)) + "^N\n\r");
      if (!mob.isMonster())
        mob.tell(msg.toString() + "\n\r^HEnter QUEST [QUEST NAME] for more information.^N^.");

    } else {
      String rest = CMParms.combine(commands, 1);
      Quest Q = CMLib.quests().findQuest(rest);
      if (Q == null) {
        mob.tell("There is no such quest as '" + rest + "'.");
        return false;
      }
      ScriptingEngine foundS = null;
      for (Enumeration<ScriptingEngine> e = mob.scripts(); e.hasMoreElements(); ) {
        ScriptingEngine SE = e.nextElement();
        if (SE == null) continue;
        if ((SE.defaultQuestName().length() > 0)
            && (SE.defaultQuestName().equalsIgnoreCase(Q.name()))) foundS = SE;
      }
      if (foundS == null) {
        mob.tell("You have not accepted a quest called '" + rest + "'.  Enter QUESTS for a list.");
        return false;
      }
      String name = Q.displayName().trim().length() > 0 ? Q.displayName() : Q.name();
      if (!Q.name().equals(name)) name += " (" + Q.name() + ")";
      mob.tell("^HQuest Information: ^w" + name + "^N");
      String instructions = null;
      if ((instructions == null) || (instructions.length() == 0))
        instructions = foundS.getVar("*", "INSTRUCTIONS");
      if ((instructions == null) || (instructions.length() == 0))
        instructions = Q.isStat("INSTRUCTIONS") ? Q.getStat("INSTRUCTIONS") : null;
      if ((instructions == null) || (instructions.length() == 0))
        instructions = "No further information available.";
      String timeRemaining = foundS.getVar("*", "TIME_REMAINING");
      if ((timeRemaining != null) && (timeRemaining.length() > 0)) {
        String timeRemainingType = foundS.getVar("*", "TIME_REMAINING_TYPE");
        if (((timeRemainingType.equalsIgnoreCase("TICKS") || (timeRemainingType.length() == 0))
            && (CMath.isInteger(timeRemaining)))) {
          long ticks = CMath.s_int(timeRemaining);
          ticks *= CMProps.getTickMillis();
          if (ticks > 60000) timeRemaining = (ticks / 60000) + " minutes";
          else timeRemaining = (ticks / 1000) + " seconds";
        } else if (timeRemainingType.length() > 0) timeRemaining += " " + timeRemainingType;
      }
      String progress = foundS.getVar("*", "PROGRESS");
      mob.tell("^w" + instructions + "^N");
      if ((timeRemaining != null) && (timeRemaining.length() > 0))
        mob.tell("\n\r^yTime Remaining: ^w" + timeRemaining + "^N");
      if ((progress != null) && (progress.length() > 0))
        mob.tell("\n\r^yProgress: ^w" + progress + "^N");
    }
    return false;
  }
Ejemplo n.º 11
0
 public String getStateName() {
   return Quest.getStateName(_state);
 }
Ejemplo n.º 12
0
 public void abortQuest() {
   _quest.onAbort(this);
   exitCurrentQuest(true);
 }