/** Используется для однодневных квестов */ public void exitCurrentQuest(Quest quest) { Player player = getPlayer(); exitCurrentQuest(true); quest.newQuestState(player, Quest.DELAYED); QuestState qs = player.getQuestState(quest.getClass()); qs.setRestartTime(); }
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(); }
/** * 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); } } }
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; }
@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); }
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)); }
/** * 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())); } }
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; }
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; }
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; }
public void addPlayerOnKillListener() { if (_onKillListener != null) { throw new IllegalArgumentException("Cant add twice kill listener to player"); } _onKillListener = new PlayerOnKillListenerImpl(); _player.addListener(_onKillListener); }
/** * Добавить предмет игроку * * @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(); }
/** * 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); }
/** * Удаляет указанные предметы из инвентаря игрока, и обновляет инвентарь * * @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; }
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; }
/** * Этот метод рассчитывает количество дропнутых вещей в зависимости от рейтов. <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; }
@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); } } }
/** * 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; }
/** * 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); }
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)); }
public void showTutorialClientHTML(String html) { Player player = getPlayer(); if (player != null) { player.sendPacket(new TutorialShowHtml(html, TutorialShowHtml.TYPE_WINDOW)); } }
public void showQuestionMark(int number) { Player player = getPlayer(); if (player != null) { player.sendPacket(new TutorialShowQuestionMark(number)); } }
public void onTutorialClientEvent(int number) { Player player = getPlayer(); if (player != null) { player.sendPacket(new TutorialEnableClientEvent(number)); } }
public void playTutorialVoice(String voice) { Player player = getPlayer(); if (player != null) { player.sendPacket(new PlaySound(PlaySound.Type.VOICE, voice, 0, 0, player.getLoc())); } }
/** * 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)); } }
public void addRadarWithMap(int x, int y, int z) { Player player = getPlayer(); if (player != null) { player.addRadarWithMap(x, y, z); } }
public double getRateQuestsReward() { Player player = getPlayer(); double Bonus = player == null ? 1. : player.getBonus().getQuestRewardRate(); return Config.RATE_QUESTS_REWARD * Bonus; }
public double getRateQuestsDrop() { Player player = getPlayer(); double Bonus = player == null ? 1. : player.getBonus().getQuestDropRate(); return Config.RATE_QUESTS_DROP * Bonus; }
public void removePlayerOnKillListener() { if (_onKillListener != null) { _player.removeListener(_onKillListener); } }
public boolean hasQuestItems(int itemId) { return _player.getInventory().getItemByItemId(itemId) != null; }