Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.61 KB | None | 0 0
  1. /*
  2.  * This program is free software; you can redistribute it and/or modify
  3.  * it under the terms of the GNU General Public License as published by
  4.  * the Free Software Foundation; either version 2, or (at your option)
  5.  * any later version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful,
  8.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  * GNU General Public License for more details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License
  13.  * along with this program; if not, write to the Free Software
  14.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15.  * 02111-1307, USA.
  16.  *
  17.  * http://www.gnu.org/copyleft/gpl.html
  18.  */
  19. package net.sf.l2j.gameserver.model.quest;
  20.  
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.logging.Logger;
  25.  
  26. import javolution.util.FastList;
  27. import javolution.util.FastMap;
  28. import net.sf.l2j.Config;
  29. import net.sf.l2j.gameserver.GameTimeController;
  30. import net.sf.l2j.gameserver.cache.HtmCache;
  31. import net.sf.l2j.gameserver.instancemanager.QuestManager;
  32. import net.sf.l2j.gameserver.lib.Rnd;
  33. import net.sf.l2j.gameserver.model.L2Character;
  34. import net.sf.l2j.gameserver.model.L2DropData;
  35. import net.sf.l2j.gameserver.model.L2ItemInstance;
  36. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  37. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  38. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  39. import net.sf.l2j.gameserver.serverpackets.ExShowQuestMark;
  40. import net.sf.l2j.gameserver.serverpackets.ItemList;
  41. import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  42. import net.sf.l2j.gameserver.serverpackets.PlaySound;
  43. import net.sf.l2j.gameserver.serverpackets.QuestList;
  44. import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
  45. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  46. import net.sf.l2j.gameserver.serverpackets.TutorialCloseHtml;
  47. import net.sf.l2j.gameserver.serverpackets.TutorialEnableClientEvent;
  48. import net.sf.l2j.gameserver.serverpackets.TutorialShowHtml;
  49. import net.sf.l2j.gameserver.serverpackets.TutorialShowQuestionMark;
  50. import net.sf.l2j.gameserver.skills.Stats;
  51.  
  52. /**
  53.  * @author Luis Arias
  54.  */
  55. public final class QuestState
  56. {
  57.     protected static Logger _log = Logger.getLogger(Quest.class.getName());
  58.  
  59.     /** Quest associated to the QuestState */
  60.     private final String _questName;
  61.  
  62.     /** Player who engaged the quest */
  63.     private final L2PcInstance _player;
  64.  
  65.     /** State of the quest */
  66.     private State _state;
  67.  
  68.     /** Boolean representing the completion of the quest */
  69.     private boolean _isCompleted;
  70.  
  71.  
  72.     /** List of couples (variable for quest,value of the variable for quest) */
  73.     private Map<String, String> _vars;
  74.  
  75.     /** List of drops needed for quest according to the mob */
  76.     private Map<Integer, List<L2DropData>> _drops;
  77.  
  78.     /** Boolean flag letting QuestStateManager know to exit quest when cleaning up */
  79.     private boolean _isExitQuestOnCleanUp = false;
  80.  
  81.     /**
  82.      * Constructor of the QuestState : save the quest in the list of quests of the player.<BR/><BR/>
  83.      *
  84.      * <U><I>Actions :</U></I><BR/>
  85.      * <LI>Save informations in the object QuestState created (Quest, Player, Completion, State)</LI>
  86.      * <LI>Add the QuestState in the player's list of quests by using setQuestState()</LI>
  87.      * <LI>Add drops gotten by the quest</LI>
  88.      * <BR/>
  89.      * @param quest : quest associated with the QuestState
  90.      * @param player : L2PcInstance pointing out the player  
  91.      * @param state : state of the quest
  92.      * @param completed : boolean for completion of the quest
  93.      */
  94.     public QuestState(Quest quest, L2PcInstance player, State state, boolean completed)
  95.     {
  96.         _questName = quest.getName();
  97.         _player = player;
  98.  
  99.         // Save the state of the quest for the player in the player's list of quest onwed
  100.         getPlayer().setQuestState(this);
  101.  
  102.         _isCompleted = completed;
  103.         // set the state of the quest
  104.         _state = state;
  105.  
  106.         // add drops from state of the quest
  107.         if (state != null && !isCompleted())
  108.         {
  109.             Map<Integer, List<L2DropData>> new_drops = state.getDrops();
  110.  
  111.  
  112.             if (new_drops != null)
  113.             {
  114.                 _drops = new FastMap<>();
  115.                 _drops.putAll(new_drops);
  116.             }
  117.         }
  118.     }
  119.  
  120.     public String getQuestName()
  121.     {
  122.         return _questName;
  123.     }
  124.  
  125.     /**
  126.      * Return the quest
  127.      * @return Quest
  128.      */
  129.     public Quest getQuest()
  130.     {
  131.         return QuestManager.getInstance().getQuest(_questName);
  132.     }
  133.  
  134.     /**
  135.      * Return the L2PcInstance
  136.      * @return L2PcInstance
  137.      */
  138.     public L2PcInstance getPlayer()
  139.     {
  140.         return _player;
  141.     }
  142.  
  143.     /**
  144.      * Return the state of the quest
  145.      * @return State
  146.      */
  147.     public State getState()
  148.     {
  149.         return _state;
  150.     }
  151.  
  152.     /**
  153.      * Return list of drops needed for the quest in concordance with mobs
  154.      * @return FastMap
  155.      */
  156.     public Map<Integer, List<L2DropData>> getDrops()
  157.     {
  158.         return _drops;
  159.     }
  160.  
  161.     /**
  162.      * Return true if quest completed, false otherwise
  163.      * @return boolean
  164.      */
  165.     public boolean isCompleted()
  166.     {
  167.         return _isCompleted;
  168.     }
  169.  
  170.     /**
  171.      * Return true if quest started, false otherwise
  172.      * @return boolean
  173.      */
  174.     public boolean isStarted()
  175.     {
  176.         if (getStateId().equals("Start") || getStateId().equals("Completed"))
  177.             return false;
  178.  
  179.         return true;
  180.     }
  181.  
  182.     /**
  183.      * Return state of the quest after its initialization.<BR><BR>
  184.      * <U><I>Actions :</I></U>
  185.      * <LI>Remove drops from previous state</LI>
  186.      * <LI>Set new state of the quest</LI>
  187.      * <LI>Add drop for new state</LI>
  188.      * <LI>Update information in database</LI>
  189.      * <LI>Send packet QuestList to client</LI>
  190.      * @param state
  191.      * @return object
  192.      */
  193.     public Object setState(State state)
  194.     {
  195.         // remove drops from previous state
  196.         if (getDrops() != null)
  197.         {
  198.             for (Iterator<List<L2DropData>> i = getDrops().values().iterator(); i.hasNext();)
  199.             {
  200.                 List<L2DropData> lst = i.next();
  201.  
  202.                 for (Iterator<L2DropData> ds = lst.iterator(); ds.hasNext();)
  203.                 {
  204.                     L2DropData d = ds.next();
  205.                     String[] states = d.getStateIDs();
  206.  
  207.  
  208.                     for (int k=0; k < states.length; k++)
  209.                     {
  210.                         if (getState().getName().equals(states[k]))
  211.                         {
  212.                             ds.remove();
  213.                             break;
  214.                         }
  215.                     }
  216.                 }
  217.  
  218.  
  219.                 if (lst == null || lst.size() == 0)
  220.                     i.remove();
  221.             }
  222.         }
  223.  
  224.         // set new state
  225.         _state = state;
  226.  
  227.  
  228.  
  229.         if (state == null)
  230.             return null;
  231.  
  232.  
  233.         if (getStateId().equals("Completed"))
  234.             _isCompleted = true;
  235.  
  236.         else
  237.             _isCompleted = false;
  238.  
  239.         // add drops from new state
  240.         if (!isCompleted())
  241.         {
  242.             Map<Integer, List<L2DropData>> newDrops = state.getDrops();
  243.             if (newDrops != null)
  244.             {
  245.                 if (getDrops() == null)
  246.                     _drops = new FastMap<>();
  247.  
  248.  
  249.                 _drops.putAll(newDrops);
  250.             }
  251.         }
  252.  
  253.  
  254.  
  255.         Quest.updateQuestInDb(this);
  256.         QuestList ql = new QuestList();
  257.  
  258.  
  259.  
  260.         getPlayer().sendPacket(ql);
  261.         return state;
  262.     }
  263.  
  264.     /**
  265.      * Return ID of the state of the quest
  266.      * @return String
  267.      */
  268.     public String getStateId()
  269.     {
  270.         return getState().getName();
  271.     }
  272.  
  273.     /**
  274.      * Add parameter used in quests.
  275.      * @param var : String pointing out the name of the variable for quest
  276.      * @param val : String pointing out the value of the variable for quest
  277.      * @return String (equal to parameter "val")
  278.      */
  279.     public String setInternal(String var, String val)
  280.     {
  281.         if (_vars == null)
  282.             _vars = new FastMap<>();
  283.  
  284.  
  285.         if (val == null)
  286.             val = "";
  287.  
  288.  
  289.         _vars.put(var, val);
  290.         return val;
  291.     }
  292.  
  293.     /**
  294.      * Return value of parameter "val" after adding the couple (var,val) in class variable "vars".<BR><BR>
  295.      * <U><I>Actions :</I></U><BR>
  296.      * <LI>Initialize class variable "vars" if is null</LI>
  297.      * <LI>Initialize parameter "val" if is null</LI>
  298.      * <LI>Add/Update couple (var,val) in class variable FastMap "vars"</LI>
  299.      * <LI>If the key represented by "var" exists in FastMap "vars", the couple (var,val) is updated in the database. The key is known as
  300.      * existing if the preceding value of the key (given as result of function put()) is not null.<BR>
  301.      * If the key doesn't exist, the couple is added/created in the database</LI>
  302.      * @param var : String indicating the name of the variable for quest
  303.      * @param val : String indicating the value of the variable for quest
  304.      * @return String (equal to parameter "val")
  305.      */
  306.     public String set(String var, String val)
  307.  
  308.     {
  309.         if (_vars == null)
  310.             _vars = new FastMap<>();
  311.  
  312.  
  313.         if (val == null)
  314.             val = "";
  315.  
  316.  
  317.         // FastMap.put() returns previous value associated with specified key, or null if there was no mapping for key.
  318.         String old = _vars.put(var, val);
  319.  
  320.  
  321.         if (old != null)
  322.             Quest.updateQuestVarInDb(this, var, val);
  323.         else
  324.             Quest.createQuestVarInDb(this, var, val);
  325.  
  326.  
  327.         if (var.equals("cond"))
  328.  
  329.         {
  330.  
  331.             QuestList ql = new QuestList();
  332.  
  333.             getPlayer().sendPacket(ql);
  334.  
  335.             int questId = getQuest().getQuestIntId();
  336.             if (questId > 0 && questId < 999 && !val.equals("0"))
  337.                 getPlayer().sendPacket(new ExShowQuestMark(questId));
  338.         }
  339.  
  340.         return val;
  341.     }
  342.  
  343.     /**
  344.      * Remove the variable of quest from the list of variables for the quest.<BR><BR>
  345.      * <U><I>Concept : </I></U>
  346.      * Remove the variable of quest represented by "var" from the class variable FastMap "vars" and from the database.
  347.      * @param var : String designating the variable for the quest to be deleted
  348.      * @return String pointing out the previous value associated with the variable "var"
  349.      */
  350.     public String unset(String var)
  351.     {
  352.         if (_vars == null)
  353.             return null;
  354.        
  355.         String old = _vars.remove(var);
  356.        
  357.         if (old != null)
  358.             Quest.deleteQuestVarInDb(this, var);
  359.        
  360.         return old;
  361.     }
  362.  
  363.     /**
  364.      * Return the value of the variable of quest represented by "var"
  365.      * @param var : name of the variable of quest
  366.      * @return String
  367.      */
  368.     public String get(String var)
  369.         {
  370.                 if (_vars != null && _vars.get(var) != null)
  371.                 return _vars.get(var);
  372.                 return null;
  373.     }
  374.  
  375.     /**
  376.      * Return the value of the variable of quest represented by "var"
  377.      * @param var : String designating the variable for the quest
  378.      * @return int
  379.      */
  380.     public int getInt(String var)
  381.     {
  382.         int varint = 0;
  383.        
  384.         try
  385.         {
  386.             varint = Integer.parseInt(_vars.get(var));
  387.         }
  388.         catch (Exception e)
  389.         {
  390.             _log.finer(getPlayer().getName()+": variable "+var+" isn't an integer: " + varint + e);
  391. //      if (Config.AUTODELETE_INVALID_QUEST_DATA)
  392. //      exitQuest(true);
  393.         }
  394.        
  395.         return varint;
  396.     }
  397.  
  398.     /**
  399.      * Add player to get notification of characters death
  400.      * @param character : L2Character of the character to get notification of death
  401.      */
  402.     public void addNotifyOfDeath(L2Character character)
  403.     {
  404.         if (character == null)
  405.             return;
  406.        
  407.         character.addNotifyQuestOfDeath(this);
  408.     }
  409.    
  410.     /**
  411.      * Add drop to the list of drops for the quest
  412.      * @param npcId : int pointing out the NPC given the drop
  413.      * @param itemId : int pointing out the ID of the item dropped
  414.      * @param chance : int pointing out the chance to get the drop
  415.      */
  416.     public void addQuestDrop(int npcId, int itemId, int chance)
  417.     {
  418.         if (getDrops() == null)
  419.             _drops = new FastMap<>();
  420.        
  421.         L2DropData d = new L2DropData();
  422.         d.setItemId(itemId);
  423.         d.setChance(chance);
  424.         d.setQuestID(getQuestName());
  425.         d.addStates(new String[]{getState().getName()});
  426.         List<L2DropData> lst = getDrops().get(npcId);
  427.        
  428.         if (lst != null)
  429.         {
  430.             lst.add(d);
  431.         }
  432.         else
  433.         {
  434.             lst = new FastList<>();
  435.             lst.add(d);
  436.             _drops.put(npcId, lst);
  437.         }
  438.     }
  439.  
  440.     /**
  441.      * Clear all drops from the class variable "drops"
  442.      */
  443.     public void clearQuestDrops()
  444.     {
  445.         _drops = null;
  446.     }
  447.  
  448.     /**
  449.      * Add quest drops to the parameter "drops"
  450.      * @param npc : L2Attackable killed
  451.      * @param drops : List of drops of the L2Attackable
  452.      */
  453.     public void fillQuestDrops(L2NpcInstance npc, List<L2DropData> drops)
  454.     {
  455.         if (getDrops() == null)
  456.             return;
  457.        
  458.         // Get drops of the NPC recorded in class variable "drops"
  459.         List<L2DropData> lst = getDrops().get(npc.getTemplate().npcId);
  460.         // If drops of the NPC in class variable "drops" exist, add them to parameter "drops"
  461.         if (lst != null)
  462.             drops.addAll(lst);
  463.         // Get drops for all NPC recorded in class variable "drops"
  464.         lst = getDrops().get(0); // all mobs
  465.         // If drops for all NPC in class variable "drops" exist, add them to parameter "drops"
  466.         if (lst != null)
  467.             drops.addAll(lst);
  468.     }
  469.  
  470.     public int getQuestItemsCount(int itemId)
  471.     {
  472.         return getQuestItemsCount(getPlayer(), itemId);
  473.     }
  474.  
  475.     /**
  476.      * Return the quantity of one sort of item hold by the player
  477.      * @param itemId : ID of the item wanted to be count
  478.      * @return int
  479.      */
  480.     public int getQuestItemsCount(L2PcInstance player, int itemId)
  481.     {
  482.         int count = 0;
  483.        
  484.         for (L2ItemInstance item : player.getInventory().getItems())
  485.             if (item.getItemId() == itemId)
  486.                 count += item.getCount();
  487.  
  488.         return count;
  489.     }
  490.  
  491.     /**
  492.      * Return the level of enchantment on the weapon of the player(Done specifically for weapon SA's)
  493.      * @param itemId : ID of the item to check enchantment
  494.      * @return int
  495.      */
  496.     public int getEnchantLevel(int itemId)
  497.     {
  498.         L2ItemInstance enchanteditem = getPlayer().getInventory().getItemByItemId(itemId);
  499.        
  500.         if (enchanteditem == null)
  501.             return 0;
  502.        
  503.         return enchanteditem.getEnchantLevel();
  504.     }
  505.    
  506.     /**
  507.      * Give item/reward to the player
  508.      * @param itemId
  509.      * @param count
  510.      */
  511.     public void giveItems(int itemId, int count)
  512.     {
  513.         giveItems(itemId, count, 0);
  514.     }
  515.  
  516.     public void giveItems(int itemId, int count, int enchantlevel)
  517.     {
  518.         giveItems(getPlayer(), itemId, count, 0);
  519.     }
  520.  
  521.     public void giveItems(L2PcInstance player, int itemId, int count, int enchantlevel)
  522.     {
  523.         if (count <= 0)
  524.             return;
  525.  
  526.         // If item for reward is gold (ID=57), modify count with rate for quest reward
  527.         if (itemId == 57
  528.             && !(getQuest().getQuestIntId()>=217 && getQuest().getQuestIntId()<=233)
  529.             && !(getQuest().getQuestIntId()>=401 && getQuest().getQuestIntId()<=418))
  530.             count = (int)(count*Config.RATE_QUESTS_REWARD);
  531.  
  532.         // Set quantity of item
  533.         // Add items to player's inventory
  534.         L2ItemInstance item = player.getInventory().addItem("Quest", itemId, count, player, player.getTarget());
  535.  
  536.  
  537.         if (item == null)
  538.  
  539.             return;
  540.  
  541.         if (enchantlevel > 0)
  542.             item.setEnchantLevel(enchantlevel);
  543.  
  544.         // If item for reward is gold, send message of gold reward to client
  545.         if (itemId == 57)
  546.         {
  547.             SystemMessage smsg = new SystemMessage(SystemMessage.EARNED_ADENA);
  548.             smsg.addNumber(count);
  549.             player.sendPacket(smsg);
  550.         }
  551.         // Otherwise, send message of object reward to client
  552.         else
  553.         {
  554.             if (count > 1)
  555.             {
  556.                 SystemMessage smsg = new SystemMessage(SystemMessage.EARNED_S2_S1_s);
  557.                 smsg.addItemName(item.getItemId());
  558.                 smsg.addNumber(count);
  559.                 player.sendPacket(smsg);
  560.             }
  561.             else
  562.             {
  563.                 SystemMessage smsg = new SystemMessage(SystemMessage.EARNED_ITEM);
  564.                 smsg.addItemName(item.getItemId());
  565.                 player.sendPacket(smsg);
  566.             }
  567.         }
  568.         player.sendPacket(new ItemList(player, false));
  569.  
  570.         StatusUpdate su = new StatusUpdate(player.getObjectId());
  571.         su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
  572.         player.sendPacket(su);
  573.     }
  574.  
  575.     /**
  576.      * Drop Quest item using Config.RATE_DROP_QUEST
  577.      * @param itemId : int Item Identifier of the item to be dropped
  578.      * @param count(minCount, maxCount) : int Quantity of items to be dropped
  579.      * @param neededCount : Quantity of items needed for quest
  580.      * @param dropChance : int Base chance of drop, same as in droplist
  581.      * @param sound : boolean indicating whether to play sound
  582.      * @return boolean indicating whether player has requested number of items
  583.      */
  584.     public boolean dropQuestItems(int itemId, int count, int neededCount, int dropChance, boolean sound)
  585.     {
  586.         return dropQuestItems(itemId, count, count, neededCount, dropChance, sound);
  587.     }
  588.    
  589.     public boolean dropQuestItems(int itemId, int minCount, int maxCount, int neededCount, int dropChance, boolean sound)
  590.     {
  591.         dropChance *= Config.RATE_DROP_QUEST / ((getPlayer().getParty() != null) ? getPlayer().getParty().getMemberCount() : 1);
  592.         int currentCount = getQuestItemsCount(itemId);
  593.  
  594.         if (neededCount > 0 && currentCount >= neededCount)
  595.             return true;
  596.        
  597.         if (currentCount >= neededCount)
  598.             return true;
  599.        
  600.         int itemCount = 0;
  601.         int random = Rnd.get(L2DropData.MAX_CHANCE);
  602.        
  603.         while (random < dropChance)
  604.         {
  605.             // Get the item quantity dropped
  606.             if (minCount < maxCount)
  607.                 itemCount += Rnd.get(minCount, maxCount);
  608.             else if (minCount == maxCount)
  609.                 itemCount += minCount;
  610.             else
  611.                 itemCount++;
  612.  
  613.             // Prepare for next iteration if dropChance > L2DropData.MAX_CHANCE
  614.             dropChance -= L2DropData.MAX_CHANCE;
  615.         }
  616.  
  617.         if (itemCount > 0)
  618.         {
  619.             // if over neededCount, just fill the gap
  620.             if (neededCount > 0 && currentCount + itemCount > neededCount)
  621.                 itemCount = neededCount - currentCount;
  622.    
  623.             // Inventory slot check
  624.             if (!getPlayer().getInventory().validateCapacityByItemId(itemId))
  625.                 return false;
  626.            
  627.             // Give the item to Player
  628.             getPlayer().addItem("Quest", itemId, itemCount, getPlayer().getTarget(), true);
  629.            
  630.             if (sound)
  631.                 playSound((currentCount + itemCount < neededCount) ? "Itemsound.quest_itemget" : "Itemsound.quest_middle");
  632.         }
  633.        
  634.         return (neededCount > 0 && currentCount + itemCount >= neededCount);
  635.     }
  636.  
  637.     //TODO: More radar functions need to be added when the radar class is complete.
  638.     // BEGIN STUFF THAT WILL PROBABLY BE CHANGED
  639.     public void addRadar(int x, int y, int z)
  640.     {
  641.         getPlayer().getRadar().addMarker(x, y, z);
  642.     }
  643.  
  644.     public void removeRadar(int x, int y, int z)
  645.     {
  646.         getPlayer().getRadar().removeMarker(x, y, z);
  647.     }
  648.  
  649.     public void clearRadar()
  650.     {
  651.         getPlayer().getRadar().removeAllMarkers();
  652.     }
  653.     // END STUFF THAT WILL PROBABLY BE CHANGED
  654.  
  655.     /**
  656.      * Remove items from player's inventory when talking to NPC in order to have rewards.<BR><BR>
  657.      * <U><I>Actions :</I></U>
  658.      * <LI>Destroy quantity of items wanted</LI>
  659.      * <LI>Send new inventory list to player</LI>
  660.      * @param itemId : Identifier of the item
  661.      * @param count : Quantity of items to destroy
  662.      */
  663.     public void takeItems(int itemId, int count)
  664.     {
  665.         takeItems(getPlayer(), itemId, count);
  666.     }
  667.  
  668.     public void takeItems(L2PcInstance player, int itemId, int count)
  669.     {
  670.         // Get object item from player's inventory list
  671.         L2ItemInstance item = player.getInventory().getItemByItemId(itemId);
  672.  
  673.  
  674.         if (item == null)
  675.             return;
  676.  
  677.         // Tests on count value in order not to have negative value
  678.         if (count < 0 || count > item.getCount())
  679.             count = item.getCount();
  680.  
  681.         // Destroy the quantity of items wanted
  682.         if (itemId == 57)
  683.             player.reduceAdena("Quest", count, player, true);
  684.         else
  685.         {
  686.             if (item.isEquipped())
  687.                 player.getInventory().unEquipItemInBodySlotAndRecord(item.getItem().getBodyPart());
  688.  
  689.             player.destroyItemByItemId("Quest", itemId, count, player, true);
  690.         }
  691.  
  692.     }
  693.  
  694.     /**
  695.      * Send a packet in order to play sound at client terminal
  696.      * @param sound
  697.      */
  698.     public void playSound(String sound)
  699.     {
  700.         playSound(getPlayer(), sound);
  701.     }
  702.  
  703.     public void playSound(L2PcInstance player, String sound)
  704.  
  705.     {
  706.         player.sendPacket(new PlaySound(sound));
  707.  
  708.     }
  709.  
  710.     /**
  711.      * Return random value
  712.      * @param max : max value for randomization
  713.      * @return int
  714.      */
  715.     public int getRandom(int max)
  716.     {
  717.         return getQuest().getRandom(max);
  718.     }
  719.  
  720.     /**
  721.      * Add XP and SP as quest reward
  722.      * @param exp
  723.      * @param sp
  724.      */
  725.     public void addExpAndSp(long exp, int sp)
  726.     {
  727.         getPlayer().addExpAndSp((long)getPlayer().calcStat(Stats.EXPSP_RATE, exp * Config.RATE_QUESTS_REWARD, null, null),
  728. (int)getPlayer().calcStat(Stats.EXPSP_RATE, sp * Config.RATE_QUESTS_REWARD, null, null));
  729.     }
  730.  
  731.     /**
  732.      * Return number of ticks from GameTimeController
  733.      * @return int
  734.      */
  735.     public int getItemEquipped(int loc)
  736.     {
  737.         return getPlayer().getInventory().getPaperdollItemId(loc);
  738.     }
  739.  
  740.     /**
  741.      * Return the number of ticks from the GameTimeController
  742.      * @return int
  743.      */
  744.     public int getGameTicks()
  745.     {
  746.         return GameTimeController.getGameTicks();
  747.     }
  748.  
  749.     /**
  750.      * Return true if quest is to exited on clean up by QuestStateManager
  751.      * @return boolean
  752.      */
  753.     public final boolean isExitQuestOnCleanUp()
  754.     {
  755.         return _isExitQuestOnCleanUp;
  756.     }
  757.  
  758.  
  759.     /**
  760.      * Return the QuestTimer object with the specified name
  761.      * @return QuestTimer<BR> Return null if name does not exist
  762.      */
  763.     public void setIsExitQuestOnCleanUp(boolean isExitQuestOnCleanUp)
  764.     {
  765.         _isExitQuestOnCleanUp = isExitQuestOnCleanUp;
  766.     }
  767.  
  768.  
  769.     public void startQuestTimer(String name, long time)
  770.     {
  771.         getQuest().startQuestTimer(name, time, null, getPlayer(), false);
  772.     }
  773.  
  774.     public void startQuestTimer(String name, long time, L2NpcInstance npc)
  775.     {
  776.         getQuest().startQuestTimer(name, time, npc, getPlayer(), false);
  777.     }
  778.  
  779.     public void startRepeatingQuestTimer(String name, long time)
  780.     {
  781.         getQuest().startQuestTimer(name, time, null, getPlayer(), true);
  782.     }
  783.  
  784.     public void startRepeatingQuestTimer(String name, long time, L2NpcInstance npc)
  785.     {
  786.         getQuest().startQuestTimer(name, time, npc, getPlayer(), true);
  787.     }
  788.  
  789.     public final QuestTimer getQuestTimer(String name)
  790.     {
  791.         return getQuest().getQuestTimer(name, null, getPlayer());
  792.     }
  793.  
  794.     /**
  795.      * Add spawn for player instance
  796.      * Return object id of newly spawned npc
  797.      */
  798.     public L2NpcInstance addSpawn(int npcId)
  799.     {
  800.         return addSpawn(npcId, getPlayer().getX(), getPlayer().getY(), getPlayer().getZ(), 0, false, 0);
  801.     }
  802.  
  803.     public L2NpcInstance addSpawn(int npcId, int despawnDelay)
  804.     {
  805.         return addSpawn(npcId, getPlayer().getX(), getPlayer().getY(), getPlayer().getZ(), 0, false, despawnDelay);
  806.     }
  807.  
  808.     public L2NpcInstance addSpawn(int npcId, int x, int y, int z)
  809.     {
  810.         return addSpawn(npcId, x, y, z, 0, false, 0);
  811.     }
  812.  
  813.     /**
  814.      * Add spawn for player instance
  815.      * Will despawn after the spawn length expires
  816.      * Uses player's coords and heading.
  817.      * Adds a little randomization in the x y coords
  818.      * Return object id of newly spawned npc
  819.      */
  820.     public L2NpcInstance addSpawn(int npcId, L2Character cha)
  821.     {
  822.         return addSpawn(npcId, cha, true, 0);
  823.     }
  824.  
  825.     public L2NpcInstance addSpawn(int npcId, L2Character cha, int despawnDelay)
  826.     {
  827.         return addSpawn(npcId, cha.getX(), cha.getY(), cha.getZ(), cha.getHeading(), true, despawnDelay);
  828.     }
  829.  
  830.     /**
  831.      * Add spawn for player instance
  832.      * Will despawn after the spawn length expires
  833.      * Return object id of newly spawned npc
  834.      */
  835.     public L2NpcInstance addSpawn(int npcId, int x, int y, int z, int despawnDelay)
  836.     {
  837.         return addSpawn(npcId, x, y, z, 0, false, despawnDelay);
  838.     }
  839.  
  840.     /**
  841.      * Add spawn for player instance
  842.      * Inherits coords and heading from specified L2Character instance.
  843.      * It could be either the player, or any killed/attacked mob
  844.      * Return object id of newly spawned npc
  845.      */
  846.     public L2NpcInstance addSpawn(int npcId, L2Character cha, boolean randomOffset, int despawnDelay)
  847.     {
  848.         return addSpawn(npcId, cha.getX(), cha.getY(), cha.getZ(), cha.getHeading(), randomOffset, despawnDelay);
  849.     }
  850.  
  851.     /**
  852.      * Add spawn for player instance
  853.      * Return object id of newly spawned npc
  854.      */
  855.     public L2NpcInstance addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, int despawnDelay)
  856.     {
  857.         return getQuest().addSpawn(npcId, x, y, z, heading, randomOffset, despawnDelay);
  858.     }
  859.  
  860.     /**
  861.      * Show HTML file to client
  862.      * @param fileName
  863.      * @return String : message sent to client
  864.      */
  865.     public String showHtmlFile(String fileName)
  866.     {
  867.         return getQuest().showHtmlFile(getPlayer(), fileName);
  868.     }
  869.  
  870.     /**
  871.      * Destroy element used by quest when quest is exited
  872.      * @param repeatable
  873.      * @return QuestState
  874.      */
  875.     public QuestState exitQuest(boolean repeatable)
  876.     {
  877.         if (isCompleted())
  878.             return this;
  879.  
  880.  
  881.         // Say quest is completed
  882.         _isCompleted = true;
  883.         // Clean drops
  884.         if (getDrops() != null)
  885.         {
  886.             // Go through values of class variable "drops" pointing out mobs that drop for quest
  887.             for (Iterator<List<L2DropData>> i = getDrops().values().iterator(); i.hasNext();)
  888.             {
  889.                 List<L2DropData> lst = i.next();
  890.  
  891.  
  892.                 // Go through values of mobs that drop for quest pointing out drops of the mob
  893.                 for (Iterator<L2DropData> ds = lst.iterator(); ds.hasNext();)
  894.                 {
  895.                     L2DropData d = ds.next();
  896.                     int itemId = d.getItemId();
  897.  
  898.  
  899.                     // Get [item from] / [presence of the item in] the inventory of the player
  900.                     L2ItemInstance item = getPlayer().getInventory().getItemByItemId(itemId);
  901.  
  902.  
  903.                     if (item == null || itemId == 57)
  904.                         continue;
  905.  
  906.  
  907.                     int count = item.getCount();
  908.  
  909.                     // If player has the item in inventory, destroy it (if not gold)
  910.  
  911.  
  912.                     getPlayer().destroyItemByItemId("Quest", itemId, count, getPlayer(), true);
  913.  
  914.  
  915.                 }
  916.             }
  917.  
  918.             _drops = null;
  919.         }
  920.  
  921.         // If quest is repeatable, delete quest from list of quest of the player and from database (quest CAN be created again => repeatable)
  922.         if (repeatable)
  923.         {
  924.             getPlayer().delQuestState(getQuestName());
  925.             Quest.deleteQuestInDb(this);
  926.  
  927.             _vars = null;
  928.         }
  929.         else
  930.         {
  931.             // Otherwise, delete variables for quest and update database (quest CANNOT be created again => not repeatable)
  932.             if (_vars != null)
  933.             {
  934.                 for (String var : _vars.keySet())
  935.                     unset(var);
  936.  
  937.             }
  938.             Quest.updateQuestInDb(this);
  939.         }
  940.  
  941.  
  942.         return this;
  943.     }
  944.  
  945.     public void showQuestionMark(int number)
  946.     {
  947.         getPlayer().sendPacket(new TutorialShowQuestionMark(number));
  948.     }
  949.  
  950.     public void playTutorialVoice(String voice)
  951.     {
  952.         getPlayer().sendPacket(new PlaySound(2, voice, 0, 0, getPlayer().getX(), getPlayer().getY(), getPlayer().getZ()));
  953.     }
  954.  
  955.     public void showTutorialHTML(String html)
  956.     {
  957.         String text = HtmCache.getInstance().getHtm("data/scripts/quests/255_Tutorial/"+ html);
  958.         if (text == null)
  959.         {
  960.             _log.warning("missing html page data/scripts/quests/255_Tutorial/"+html);
  961.             text = "<html><body>File data/scripts/quests/255_Tutorial/" + html + " not found or file is empty.</body></html>";
  962.         }
  963.         getPlayer().sendPacket(new TutorialShowHtml(text));
  964.     }
  965.  
  966.     public void closeTutorialHtml()
  967.     {
  968.         getPlayer().sendPacket(new TutorialCloseHtml());
  969.     }
  970.  
  971.     public void onTutorialClientEvent(int number)
  972.     {
  973.         getPlayer().sendPacket(new TutorialEnableClientEvent(number));
  974.     }
  975.  
  976.     public void dropItem(L2MonsterInstance npc, L2PcInstance player, int itemId, int count)
  977.     {
  978.         npc.dropItem(player, itemId, count);
  979.     }
  980. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement