예제 #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
  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();
  }
예제 #3
0
 /**
  * Add player to get notification of characters death
  *
  * @param player : L2Character of the character to get notification of death
  */
 public void addNotifyOfDeath(Player player, boolean withPet) {
   OnDeathListenerImpl listener = new OnDeathListenerImpl();
   player.addListener(listener);
   if (withPet) {
     for (Summon summon : player.getSummonList()) {
       summon.addListener(listener);
     }
   }
 }
예제 #4
0
 public long getSumQuestItemsCount(int... itemIds) {
   Player player = getPlayer();
   if (player == null) {
     return 0;
   }
   long count = 0;
   for (int itemId : itemIds) {
     count += player.getInventory().getCountOf(itemId);
   }
   return count;
 }
예제 #5
0
    @Override
    public void onDeath(Creature actor, Creature killer) {
      Player player = actor.getPlayer();
      if (player == null) {
        return;
      }

      player.removeListener(this);

      _quest.notifyDeath(killer, actor, QuestState.this);
    }
예제 #6
0
 public void showTutorialHTML(String html, int type) {
   Player player = getPlayer();
   if (player == null) {
     return;
   }
   String text = html;
   if (type == 1) {
     text = HtmCache.getInstance().getNotNull("quests/_255_Tutorial/" + html, player);
   }
   player.sendPacket(new TutorialShowHtml(text, type));
 }
예제 #7
0
 /**
  * Add XP and SP as quest reward <br>
  * <br>
  * Метод учитывает рейты! 3-ий параметр true/false показывает является ли квест на профессию и
  * рейты учитываются в завимисомти от параметра RateQuestsRewardOccupationChange
  */
 public void addExpAndSp(long exp, long sp) {
   Player player = getPlayer();
   if (player == null) {
     return;
   }
   if (exp > 0) {
     player.addExpAndSp((long) (exp * getRateQuestsReward()), 0);
   }
   if (sp > 0) {
     player.addExpAndSp(0, (long) (sp * getRateQuestsReward()));
   }
 }
예제 #8
0
 public boolean checkQuestItemsCount(int... itemIds) {
   Player player = getPlayer();
   if (player == null) {
     return false;
   }
   for (int itemId : itemIds) {
     if (player.getInventory().getCountOf(itemId) <= 0) {
       return false;
     }
   }
   return true;
 }
예제 #9
0
 private boolean checkPartyMember(Player member, int state, int maxrange, GameObject rangefrom) {
   if (member == null) {
     return false;
   }
   if ((rangefrom != null) && (maxrange > 0) && !member.isInRange(rangefrom, maxrange)) {
     return false;
   }
   QuestState qs = member.getQuestState(getQuest().getName());
   if ((qs == null) || (qs.getState() != state)) {
     return false;
   }
   return true;
 }
예제 #10
0
  public Object setStateAndNotSave(int state) {
    Player player = getPlayer();
    if (player == null) {
      return null;
    }

    _state = state;

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

    player.sendPacket(new QuestList(player));
    return state;
  }
예제 #11
0
  public void addPlayerOnKillListener() {
    if (_onKillListener != null) {
      throw new IllegalArgumentException("Cant add twice kill listener to player");
    }

    _onKillListener = new PlayerOnKillListenerImpl();
    _player.addListener(_onKillListener);
  }
예제 #12
0
  /**
   * Добавить предмет игроку
   *
   * @param itemId
   * @param count
   * @param rate - учет квестовых рейтов
   */
  public void giveItems(int itemId, long count, boolean rate) {
    Player player = getPlayer();
    if (player == null) {
      return;
    }

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

    if (rate) {
      count = (long) (count * getRateQuestsReward());
    }

    ItemFunctions.addItem(player, itemId, count, true);
    player.sendChanges();
  }
예제 #13
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);
  }
예제 #14
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;
  }
예제 #15
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;
  }
예제 #16
0
 /**
  * Этот метод рассчитывает количество дропнутых вещей в зависимости от рейтов. <br>
  * <br>
  * Следует учесть, что контроль за верхним пределом вещей в квестах, в которых нужно набить
  * определенное количество предметов не осуществляется. <br>
  * <br>
  * Ни один из передаваемых параметров не должен быть равен 0
  *
  * @param min минимальное количество при рейтах 1х
  * @param max максимальное количество при рейтах 1х
  * @param calcChance шанс при рейтах 1х, в процентах
  * @return количество вещей для дропа, может быть 0
  */
 public int rollDrop(int min, int max, double calcChance) {
   if ((calcChance <= 0) || (min <= 0) || (max <= 0)) {
     return 0;
   }
   int dropmult = 1;
   calcChance *= getRateQuestsDrop();
   if (getQuest().getParty() > Quest.PARTY_NONE) {
     Player player = getPlayer();
     if (player.getParty() != null) {
       calcChance *=
           Config.ALT_PARTY_BONUS[
               player.getParty().getMemberCountInRange(player, Config.ALT_PARTY_DISTRIBUTION_RANGE)
                   - 1];
     }
   }
   if (calcChance > 100) {
     if ((int) Math.ceil(calcChance / 100) <= (calcChance / 100)) {
       calcChance = Math.nextUp(calcChance);
     }
     dropmult = (int) Math.ceil(calcChance / 100);
     calcChance = calcChance / dropmult;
   }
   return Rnd.chance(calcChance) ? Rnd.get(min * dropmult, max * dropmult) : 0;
 }
예제 #17
0
    @Override
    public void onKill(Creature actor, Creature victim) {
      if (!victim.isPlayer()) {
        return;
      }

      Player actorPlayer = (Player) actor;
      List<Player> players = null;
      switch (_quest.getParty()) {
        case Quest.PARTY_NONE:
          players = Collections.singletonList(actorPlayer);
          break;
        case Quest.PARTY_ALL:
          if (actorPlayer.getParty() == null) {
            players = Collections.singletonList(actorPlayer);
          } else {
            players = new ArrayList<Player>(actorPlayer.getParty().getMemberCount());
            for (Player member : actorPlayer.getParty().getPartyMembers()) {
              if (member.isInRange(actorPlayer, Creature.INTERACTION_DISTANCE)) {
                players.add(member);
              }
            }
          }
          break;
        default:
          players = Collections.emptyList();
          break;
      }

      for (Player player : players) {
        QuestState questState = player.getQuestState(_quest.getClass());
        if ((questState != null) && !questState.isCompleted()) {
          _quest.notifyKill((Player) victim, questState);
        }
      }
    }
예제 #18
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;
  }
예제 #19
0
 /**
  * Return the quantity of one sort of item hold by the player
  *
  * @param itemId : ID of the item wanted to be count
  * @return int
  */
 public long getQuestItemsCount(int itemId) {
   Player player = getPlayer();
   return player == null ? 0 : player.getInventory().getCountOf(itemId);
 }
예제 #20
0
 public void showTutorialHTML(String html) {
   Player player = getPlayer();
   if (player == null) return;
   String text = HtmCache.getInstance().getNotNull("quests/_255_Tutorial/" + html, player);
   player.sendPacket(new TutorialShowHtml(TutorialShowHtml.TYPE_HTML, text));
 }
예제 #21
0
 public void showTutorialClientHTML(String html) {
   Player player = getPlayer();
   if (player != null) {
     player.sendPacket(new TutorialShowHtml(html, TutorialShowHtml.TYPE_WINDOW));
   }
 }
예제 #22
0
 public void showQuestionMark(int number) {
   Player player = getPlayer();
   if (player != null) {
     player.sendPacket(new TutorialShowQuestionMark(number));
   }
 }
예제 #23
0
 public void onTutorialClientEvent(int number) {
   Player player = getPlayer();
   if (player != null) {
     player.sendPacket(new TutorialEnableClientEvent(number));
   }
 }
예제 #24
0
 public void playTutorialVoice(String voice) {
   Player player = getPlayer();
   if (player != null) {
     player.sendPacket(new PlaySound(PlaySound.Type.VOICE, voice, 0, 0, player.getLoc()));
   }
 }
예제 #25
0
 /**
  * Send a packet in order to play sound at client terminal
  *
  * @param sound
  */
 public void playSound(String sound) {
   Player player = getPlayer();
   if (player != null) {
     player.sendPacket(new PlaySound(sound));
   }
 }
예제 #26
0
 public void addRadarWithMap(int x, int y, int z) {
   Player player = getPlayer();
   if (player != null) {
     player.addRadarWithMap(x, y, z);
   }
 }
예제 #27
0
 public double getRateQuestsReward() {
   Player player = getPlayer();
   double Bonus = player == null ? 1. : player.getBonus().getQuestRewardRate();
   return Config.RATE_QUESTS_REWARD * Bonus;
 }
예제 #28
0
 public double getRateQuestsDrop() {
   Player player = getPlayer();
   double Bonus = player == null ? 1. : player.getBonus().getQuestDropRate();
   return Config.RATE_QUESTS_DROP * Bonus;
 }
예제 #29
0
 public void removePlayerOnKillListener() {
   if (_onKillListener != null) {
     _player.removeListener(_onKillListener);
   }
 }
예제 #30
0
 public boolean hasQuestItems(int itemId) {
   return _player.getInventory().getItemByItemId(itemId) != null;
 }