Guest User

L2NPC.java

a guest
Dec 28th, 2010
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 101.57 KB | None | 0 0
  1. /*
  2.  
  3. * This program is free software: you can redistribute it and/or modify it under
  4.  
  5. * the terms of the GNU General Public License as published by the Free Software
  6.  
  7. * Foundation, either version 3 of the License, or (at your option) any later
  8.  
  9. * version.
  10.  
  11. *
  12.  
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14.  
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16.  
  17. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  18.  
  19. * details.
  20.  
  21. *
  22.  
  23. * You should have received a copy of the GNU General Public License along with
  24.  
  25. * this program. If not, see <http://www.gnu.org/licenses/>.
  26.  
  27. */
  28.  
  29. package com.l2jfree.gameserver.model.actor;
  30.  
  31.  
  32.  
  33. import static com.l2jfree.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
  34.  
  35.  
  36.  
  37. import java.text.DateFormat;
  38.  
  39. import java.util.StringTokenizer;
  40.  
  41.  
  42.  
  43. import javolution.util.FastList;
  44.  
  45.  
  46.  
  47. import com.l2jfree.Config;
  48.  
  49. import com.l2jfree.gameserver.SevenSigns;
  50.  
  51. import com.l2jfree.gameserver.SevenSignsFestival;
  52.  
  53. import com.l2jfree.gameserver.Shutdown;
  54.  
  55. import com.l2jfree.gameserver.ThreadPoolManager;
  56.  
  57. import com.l2jfree.gameserver.Shutdown.DisableType;
  58.  
  59. import com.l2jfree.gameserver.ai.CtrlIntention;
  60.  
  61. import com.l2jfree.gameserver.cache.HtmCache;
  62.  
  63. import com.l2jfree.gameserver.datatables.BuffTemplateTable;
  64.  
  65. import com.l2jfree.gameserver.datatables.ClanTable;
  66.  
  67. import com.l2jfree.gameserver.datatables.DoorTable;
  68.  
  69. import com.l2jfree.gameserver.datatables.ItemTable;
  70.  
  71. import com.l2jfree.gameserver.datatables.NpcTable;
  72.  
  73. import com.l2jfree.gameserver.datatables.PetDataTable;
  74.  
  75. import com.l2jfree.gameserver.datatables.SkillTable;
  76.  
  77. import com.l2jfree.gameserver.datatables.SpawnTable;
  78.  
  79. import com.l2jfree.gameserver.idfactory.IdFactory;
  80.  
  81. import com.l2jfree.gameserver.instancemanager.CastleManager;
  82.  
  83. import com.l2jfree.gameserver.instancemanager.DimensionalRiftManager;
  84.  
  85. import com.l2jfree.gameserver.instancemanager.FortManager;
  86.  
  87. import com.l2jfree.gameserver.instancemanager.QuestManager;
  88.  
  89. import com.l2jfree.gameserver.instancemanager.TownManager;
  90.  
  91. import com.l2jfree.gameserver.instancemanager.games.Lottery;
  92.  
  93. import com.l2jfree.gameserver.instancemanager.grandbosses.BaiumManager;
  94.  
  95. import com.l2jfree.gameserver.instancemanager.leaderboards.ArenaManager;
  96.  
  97. import com.l2jfree.gameserver.instancemanager.leaderboards.FishermanManager;
  98.  
  99. import com.l2jfree.gameserver.model.L2Clan;
  100.  
  101. import com.l2jfree.gameserver.model.L2DropCategory;
  102.  
  103. import com.l2jfree.gameserver.model.L2DropData;
  104.  
  105. import com.l2jfree.gameserver.model.L2ItemInstance;
  106.  
  107. import com.l2jfree.gameserver.model.L2Multisell;
  108.  
  109. import com.l2jfree.gameserver.model.L2Skill;
  110.  
  111. import com.l2jfree.gameserver.model.L2Spawn;
  112.  
  113. import com.l2jfree.gameserver.model.L2WorldRegion;
  114.  
  115. import com.l2jfree.gameserver.model.MobGroupTable;
  116.  
  117. import com.l2jfree.gameserver.model.actor.instance.L2AuctioneerInstance;
  118.  
  119. import com.l2jfree.gameserver.model.actor.instance.L2CCHBossInstance;
  120.  
  121. import com.l2jfree.gameserver.model.actor.instance.L2ChestInstance;
  122.  
  123. import com.l2jfree.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  124.  
  125. import com.l2jfree.gameserver.model.actor.instance.L2ControllableMobInstance;
  126.  
  127. import com.l2jfree.gameserver.model.actor.instance.L2DoormenInstance;
  128.  
  129. import com.l2jfree.gameserver.model.actor.instance.L2FestivalGuideInstance;
  130.  
  131. import com.l2jfree.gameserver.model.actor.instance.L2FishermanInstance;
  132.  
  133. import com.l2jfree.gameserver.model.actor.instance.L2MerchantInstance;
  134.  
  135. import com.l2jfree.gameserver.model.actor.instance.L2MonsterInstance;
  136.  
  137. import com.l2jfree.gameserver.model.actor.instance.L2PcInstance;
  138.  
  139. import com.l2jfree.gameserver.model.actor.instance.L2PetInstance;
  140.  
  141. import com.l2jfree.gameserver.model.actor.instance.L2TeleporterInstance;
  142.  
  143. import com.l2jfree.gameserver.model.actor.instance.L2WarehouseInstance;
  144.  
  145. import com.l2jfree.gameserver.model.actor.knownlist.CharKnownList;
  146.  
  147. import com.l2jfree.gameserver.model.actor.knownlist.NpcKnownList;
  148.  
  149. import com.l2jfree.gameserver.model.actor.shot.CharShots;
  150.  
  151. import com.l2jfree.gameserver.model.actor.shot.NpcShots;
  152.  
  153. import com.l2jfree.gameserver.model.actor.stat.CharStat;
  154.  
  155. import com.l2jfree.gameserver.model.actor.stat.NpcStat;
  156.  
  157. import com.l2jfree.gameserver.model.actor.status.CharStatus;
  158.  
  159. import com.l2jfree.gameserver.model.actor.status.NpcStatus;
  160.  
  161. import com.l2jfree.gameserver.model.actor.view.CharLikeView;
  162.  
  163. import com.l2jfree.gameserver.model.actor.view.NpcView;
  164.  
  165. import com.l2jfree.gameserver.model.entity.Castle;
  166.  
  167. import com.l2jfree.gameserver.model.entity.Fort;
  168.  
  169. import com.l2jfree.gameserver.model.entity.Town;
  170.  
  171. import com.l2jfree.gameserver.model.itemcontainer.NpcInventory;
  172.  
  173. import com.l2jfree.gameserver.model.itemcontainer.PcInventory;
  174.  
  175. import com.l2jfree.gameserver.model.olympiad.Olympiad;
  176.  
  177. import com.l2jfree.gameserver.model.quest.Quest;
  178.  
  179. import com.l2jfree.gameserver.model.quest.QuestState;
  180.  
  181. import com.l2jfree.gameserver.model.quest.State;
  182.  
  183. import com.l2jfree.gameserver.model.restriction.global.GlobalRestrictions;
  184.  
  185. import com.l2jfree.gameserver.network.SystemMessageId;
  186.  
  187. import com.l2jfree.gameserver.network.serverpackets.AbstractNpcInfo;
  188.  
  189. import com.l2jfree.gameserver.network.serverpackets.ActionFailed;
  190.  
  191. import com.l2jfree.gameserver.network.serverpackets.ExShowBaseAttributeCancelWindow;
  192.  
  193. import com.l2jfree.gameserver.network.serverpackets.ExShowQuestInfo;
  194.  
  195. import com.l2jfree.gameserver.network.serverpackets.ExShowVariationCancelWindow;
  196.  
  197. import com.l2jfree.gameserver.network.serverpackets.ExShowVariationMakeWindow;
  198.  
  199. import com.l2jfree.gameserver.network.serverpackets.InventoryUpdate;
  200.  
  201. import com.l2jfree.gameserver.network.serverpackets.ItemList;
  202.  
  203. import com.l2jfree.gameserver.network.serverpackets.MagicSkillUse;
  204.  
  205. import com.l2jfree.gameserver.network.serverpackets.NpcHtmlMessage;
  206.  
  207. import com.l2jfree.gameserver.network.serverpackets.RadarControl;
  208.  
  209. import com.l2jfree.gameserver.network.serverpackets.ServerObjectInfo;
  210.  
  211. import com.l2jfree.gameserver.network.serverpackets.SocialAction;
  212.  
  213. import com.l2jfree.gameserver.network.serverpackets.StatusUpdate;
  214.  
  215. import com.l2jfree.gameserver.network.serverpackets.SystemMessage;
  216.  
  217. import com.l2jfree.gameserver.skills.Stats;
  218.  
  219. import com.l2jfree.gameserver.taskmanager.AbstractIterativePeriodicTaskManager;
  220.  
  221. import com.l2jfree.gameserver.taskmanager.DecayTaskManager;
  222.  
  223. import com.l2jfree.gameserver.templates.chars.L2NpcTemplate;
  224.  
  225. import com.l2jfree.gameserver.templates.chars.L2NpcTemplate.AIType;
  226.  
  227. import com.l2jfree.gameserver.templates.item.L2Item;
  228.  
  229. import com.l2jfree.gameserver.templates.item.L2Weapon;
  230.  
  231. import com.l2jfree.gameserver.templates.skills.L2BuffTemplate;
  232.  
  233. import com.l2jfree.gameserver.templates.skills.L2SkillType;
  234.  
  235. import com.l2jfree.gameserver.util.StringUtil;
  236.  
  237. import com.l2jfree.lang.L2Math;
  238.  
  239. import com.l2jfree.lang.L2TextBuilder;
  240.  
  241. import com.l2jfree.tools.random.Rnd;
  242.  
  243.  
  244.  
  245. /**
  246.  
  247. * This class represents a Non-Player-Character in the world. It can be a monster or a friendly character.
  248.  
  249. * It also uses a template to fetch some static values. The templates are hardcoded in the client, so we can rely on them.<BR><BR>
  250.  
  251. *
  252.  
  253. * L2Character :<BR><BR>
  254.  
  255. * <li>L2Attackable</li>
  256.  
  257. * <li>L2NpcInstance</li>
  258.  
  259. *
  260.  
  261. * @version $Revision: 1.32.2.7.2.24 $ $Date: 2005/04/11 10:06:09 $
  262.  
  263. */
  264.  
  265. public class L2Npc extends L2Character
  266.  
  267. {
  268.  
  269. private static final class RandomAnimationTaskManager extends AbstractIterativePeriodicTaskManager<L2Npc>
  270.  
  271. {
  272.  
  273. private static final int MIN_SOCIAL_INTERVAL = 6000;
  274.  
  275. private static final RandomAnimationTaskManager _instance = new RandomAnimationTaskManager();
  276.  
  277.  
  278.  
  279. private static RandomAnimationTaskManager getInstance()
  280.  
  281. {
  282.  
  283. return _instance;
  284.  
  285. }
  286.  
  287.  
  288.  
  289. private RandomAnimationTaskManager()
  290.  
  291. {
  292.  
  293. super(1000);
  294.  
  295. //super(MIN_SOCIAL_INTERVAL);
  296.  
  297. }
  298.  
  299.  
  300.  
  301. @Override
  302.  
  303. protected void callTask(L2Npc npc)
  304.  
  305. {
  306.  
  307. if (!npc.tryBroadcastRandomAnimation(false, false))
  308.  
  309. stopTask(npc);
  310.  
  311. }
  312.  
  313.  
  314.  
  315. @Override
  316.  
  317. protected String getCalledMethodName()
  318.  
  319. {
  320.  
  321. return "broadcastRandomAnimation()";
  322.  
  323. }
  324.  
  325. }
  326.  
  327.  
  328.  
  329. /** The interaction distance of the L2Npc(is used as offset in MovetoLocation method) */
  330.  
  331. public static final int INTERACTION_DISTANCE = 150;
  332.  
  333.  
  334.  
  335. /** The L2Spawn object that manage this L2Npc */
  336.  
  337. private L2Spawn _spawn;
  338.  
  339.  
  340.  
  341. private NpcInventory _inventory = null;
  342.  
  343.  
  344.  
  345. /** The flag to specify if this L2Npc is busy */
  346.  
  347. private boolean _isBusy = false;
  348.  
  349.  
  350.  
  351. /** The busy message for this L2Npc */
  352.  
  353. private String _busyMessage = "";
  354.  
  355.  
  356.  
  357. /** True if endDecayTask has already been called */
  358.  
  359. volatile boolean _isDecayed = false;
  360.  
  361.  
  362.  
  363. /** True if a Dwarf has used Spoil on this L2Npc */
  364.  
  365. private boolean _isSpoil = false;
  366.  
  367.  
  368.  
  369. /** The castle index in the array of L2Castle this L2Npc belongs to */
  370.  
  371. private int _castleIndex = -2;
  372.  
  373.  
  374.  
  375. /** The fortress index in the array of L2Fort this L2Npc belongs to */
  376.  
  377. private int _fortIndex = -2;
  378.  
  379.  
  380.  
  381. public String _CTF_FlagTeamName;
  382.  
  383. public boolean _isEventMobTvT = false, _isEventMobDM = false, _isEventMobCTF = false,
  384.  
  385. _isCTF_throneSpawn = false, _isCTF_Flag = false, _isEventVIPNPC = false, _isEventVIPNPCEnd = false;
  386.  
  387. public boolean _isEventMobTvTi = false;
  388.  
  389. public boolean _isEventMobSH = false;
  390.  
  391.  
  392.  
  393. private boolean _isInTown = false;
  394.  
  395. private int _isSpoiledBy = 0;
  396.  
  397.  
  398.  
  399. private long _lastRandomAnimation;
  400.  
  401. private int _randomAnimationDelay;
  402.  
  403. private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
  404.  
  405. private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
  406.  
  407.  
  408.  
  409. private double _currentCollisionHeight; // used for npc grow effect skills
  410.  
  411. private double _currentCollisionRadius; // used for npc grow effect skills
  412.  
  413.  
  414.  
  415. private boolean _isKillable = true;
  416.  
  417. private boolean _questDropable = true;
  418.  
  419.  
  420.  
  421. // In case quests are going to use non-L2Attackables in the future
  422.  
  423. private int _questAttackStatus;
  424.  
  425. private L2PcInstance _questFirstAttacker;
  426.  
  427.  
  428.  
  429. // doesn't affect damage at all (retail)
  430.  
  431. private int _weaponEnchant = 0;
  432.  
  433.  
  434.  
  435. public final void broadcastRandomAnimation(boolean force)
  436.  
  437. {
  438.  
  439. tryBroadcastRandomAnimation(force, true);
  440.  
  441. }
  442.  
  443.  
  444.  
  445. public final boolean tryBroadcastRandomAnimation(boolean force, boolean init)
  446.  
  447. {
  448.  
  449. if (!isInActiveRegion() || !hasRandomAnimation())
  450.  
  451. return false;
  452.  
  453.  
  454.  
  455. if (isMob() && getAI().getIntention() != AI_INTENTION_ACTIVE)
  456.  
  457. return false;
  458.  
  459.  
  460.  
  461. if (_lastRandomAnimation + RandomAnimationTaskManager.MIN_SOCIAL_INTERVAL < System.currentTimeMillis()
  462.  
  463. && !getKnownList().getKnownPlayers().isEmpty())
  464.  
  465. {
  466.  
  467. if (force || _lastRandomAnimation + _randomAnimationDelay < System.currentTimeMillis())
  468.  
  469. {
  470.  
  471. if (!isDead() && !isStunned() && !isSleeping() && !isParalyzed())
  472.  
  473. {
  474.  
  475. SocialAction sa;
  476.  
  477. if (force) // on talk/interact
  478.  
  479. sa = new SocialAction(getObjectId(), Rnd.get(8));
  480.  
  481. else // periodic
  482.  
  483. sa = new SocialAction(getObjectId(), Rnd.get(2, 3));
  484.  
  485. broadcastPacket(sa);
  486.  
  487.  
  488.  
  489. int minWait = isMob() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
  490.  
  491. int maxWait = isMob() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
  492.  
  493.  
  494.  
  495. _lastRandomAnimation = System.currentTimeMillis();
  496.  
  497. _randomAnimationDelay = Rnd.get(minWait, maxWait) * 1000;
  498.  
  499. }
  500.  
  501. }
  502.  
  503. }
  504.  
  505.  
  506.  
  507. if (init)
  508.  
  509. RandomAnimationTaskManager.getInstance().startTask(this);
  510.  
  511. return true;
  512.  
  513. }
  514.  
  515.  
  516.  
  517. public final void stopRandomAnimation()
  518.  
  519. {
  520.  
  521. RandomAnimationTaskManager.getInstance().stopTask(this);
  522.  
  523. }
  524.  
  525.  
  526.  
  527. /**
  528.  
  529. * Check if the server allows Random Animation.<BR><BR>
  530.  
  531. */
  532.  
  533. public boolean hasRandomAnimation()
  534.  
  535. {
  536.  
  537. return (Config.MAX_NPC_ANIMATION > 0 && getTemplate().getAI() != AIType.CORPSE);
  538.  
  539. }
  540.  
  541.  
  542.  
  543. public class DestroyTemporalNPC implements Runnable
  544.  
  545. {
  546.  
  547. private final L2Spawn _oldSpawn;
  548.  
  549.  
  550.  
  551. public DestroyTemporalNPC(L2Spawn spawn)
  552.  
  553. {
  554.  
  555. _oldSpawn = spawn;
  556.  
  557. }
  558.  
  559.  
  560.  
  561. public void run()
  562.  
  563. {
  564.  
  565. try
  566.  
  567. {
  568.  
  569. _oldSpawn.getLastSpawn().deleteMe();
  570.  
  571. _oldSpawn.stopRespawn();
  572.  
  573. SpawnTable.getInstance().deleteSpawn(_oldSpawn, false);
  574.  
  575. }
  576.  
  577. catch (Exception e)
  578.  
  579. {
  580.  
  581. _log.error(e.getMessage(), e);
  582.  
  583. }
  584.  
  585. }
  586.  
  587. }
  588.  
  589.  
  590.  
  591. public class DestroyTemporalSummon implements Runnable
  592.  
  593. {
  594.  
  595. L2Summon _summon;
  596.  
  597. L2PcInstance _player;
  598.  
  599.  
  600.  
  601. public DestroyTemporalSummon(L2Summon summon, L2PcInstance player)
  602.  
  603. {
  604.  
  605. _summon = summon;
  606.  
  607. _player = player;
  608.  
  609. }
  610.  
  611.  
  612.  
  613. public void run()
  614.  
  615. {
  616.  
  617. _summon.unSummon(_player);
  618.  
  619. }
  620.  
  621. }
  622.  
  623.  
  624.  
  625. /**
  626.  
  627. * Constructor of L2Npc (use L2Character constructor).<BR><BR>
  628.  
  629. *
  630.  
  631. * <B><U> Actions</U> :</B><BR><BR>
  632.  
  633. * <li>Call the L2Character constructor to set the _template of the L2Character (copy skills from template to object and link _calculators to NPC_STD_CALCULATOR) </li>
  634.  
  635. * <li>Set the name of the L2Character</li>
  636.  
  637. * <li>Create a RandomAnimation Task that will be launched after the calculated delay if the server allow it </li><BR><BR>
  638.  
  639. *
  640.  
  641. * @param objectId Identifier of the object to initialized
  642.  
  643. * @param template The L2NpcTemplate to apply to the NPC
  644.  
  645. *
  646.  
  647. */
  648.  
  649. public L2Npc(int objectId, L2NpcTemplate template)
  650.  
  651. {
  652.  
  653. // Call the L2Character constructor to set the _template of the L2Character, copy skills from template to object
  654.  
  655. // and link _calculators to NPC_STD_CALCULATOR
  656.  
  657. super(objectId, template);
  658.  
  659. getKnownList(); // init knownlist
  660.  
  661. getStat(); // init stats
  662.  
  663. getStatus(); // init status
  664.  
  665. super.initCharStatusUpdateValues(); // init status upadte values
  666.  
  667.  
  668.  
  669. // Initialize the "current" equipment
  670.  
  671. _currentLHandId = getTemplate().getLhand();
  672.  
  673. _currentRHandId = getTemplate().getRhand();
  674.  
  675. // initialize the "current" collisions
  676.  
  677. _currentCollisionHeight = getTemplate().getCollisionHeight();
  678.  
  679. _currentCollisionRadius = getTemplate().getCollisionRadius();
  680.  
  681.  
  682.  
  683. if (template == null)
  684.  
  685. {
  686.  
  687. _log.fatal("No template for Npc. Please check your datapack is setup correctly.");
  688.  
  689. return;
  690.  
  691. }
  692.  
  693.  
  694.  
  695. // Set the name and the title of the L2Character
  696.  
  697. setName(template.getName());
  698.  
  699. setTitle(template.getTitle());
  700.  
  701.  
  702.  
  703. if ((template.getSS() > 0 || template.getBSS() > 0) && template.getSSRate() > 0)
  704.  
  705. _inventory = new NpcInventory(this);
  706.  
  707. }
  708.  
  709.  
  710.  
  711. @Override
  712.  
  713. protected CharKnownList initKnownList()
  714.  
  715. {
  716.  
  717. return new NpcKnownList(this);
  718.  
  719. }
  720.  
  721.  
  722.  
  723. @Override
  724.  
  725. public NpcKnownList getKnownList()
  726.  
  727. {
  728.  
  729. return (NpcKnownList)_knownList;
  730.  
  731. }
  732.  
  733.  
  734.  
  735. @Override
  736.  
  737. protected CharLikeView initView()
  738.  
  739. {
  740.  
  741. return new NpcView(this);
  742.  
  743. }
  744.  
  745.  
  746.  
  747. @Override
  748.  
  749. public NpcView getView()
  750.  
  751. {
  752.  
  753. return (NpcView)_view;
  754.  
  755. }
  756.  
  757.  
  758.  
  759. @Override
  760.  
  761. protected CharStat initStat()
  762.  
  763. {
  764.  
  765. return new NpcStat(this);
  766.  
  767. }
  768.  
  769.  
  770.  
  771. @Override
  772.  
  773. public NpcStat getStat()
  774.  
  775. {
  776.  
  777. return (NpcStat)_stat;
  778.  
  779. }
  780.  
  781.  
  782.  
  783. @Override
  784.  
  785. protected CharStatus initStatus()
  786.  
  787. {
  788.  
  789. return new NpcStatus(this);
  790.  
  791. }
  792.  
  793.  
  794.  
  795. @Override
  796.  
  797. public NpcStatus getStatus()
  798.  
  799. {
  800.  
  801. return (NpcStatus)_status;
  802.  
  803. }
  804.  
  805.  
  806.  
  807. /** Return the L2NpcTemplate of the L2Npc. */
  808.  
  809. @Override
  810.  
  811. public final L2NpcTemplate getTemplate()
  812.  
  813. {
  814.  
  815. return (L2NpcTemplate) super.getTemplate();
  816.  
  817. }
  818.  
  819.  
  820.  
  821. /**
  822.  
  823. * Return the generic Identifier of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  824.  
  825. */
  826.  
  827. public int getNpcId()
  828.  
  829. {
  830.  
  831. return getTemplate().getNpcId();
  832.  
  833. }
  834.  
  835.  
  836.  
  837. @Override
  838.  
  839. public boolean isAttackable()
  840.  
  841. {
  842.  
  843. return Config.ALT_ATTACKABLE_NPCS;
  844.  
  845. }
  846.  
  847.  
  848.  
  849. /**
  850.  
  851. * Return the faction Identifier of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  852.  
  853. *
  854.  
  855. * <B><U> Concept</U> :</B><BR><BR>
  856.  
  857. * If a NPC belows to a Faction, other NPC of the faction inside the Faction range will help it if it's attacked<BR><BR>
  858.  
  859. *
  860.  
  861. */
  862.  
  863. public final String getFactionId()
  864.  
  865. {
  866.  
  867. return getTemplate().getFactionId();
  868.  
  869. }
  870.  
  871.  
  872.  
  873. /**
  874.  
  875. * Return the Level of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  876.  
  877. */
  878.  
  879. @Override
  880.  
  881. public final int getLevel()
  882.  
  883. {
  884.  
  885. return getTemplate().getLevel();
  886.  
  887. }
  888.  
  889.  
  890.  
  891. /**
  892.  
  893. * Return True if the L2Npc is agressive (ex : L2MonsterInstance in function of aggroRange).<BR><BR>
  894.  
  895. */
  896.  
  897. public boolean isAggressive()
  898.  
  899. {
  900.  
  901. return false;
  902.  
  903. }
  904.  
  905.  
  906.  
  907. /**
  908.  
  909. * Return the Aggro Range of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  910.  
  911. */
  912.  
  913. public int getAggroRange()
  914.  
  915. {
  916.  
  917. return getTemplate().getAggroRange();
  918.  
  919. }
  920.  
  921.  
  922.  
  923. /**
  924.  
  925. * Return the Faction Range of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  926.  
  927. */
  928.  
  929. public int getFactionRange()
  930.  
  931. {
  932.  
  933. return getTemplate().getFactionRange();
  934.  
  935. }
  936.  
  937.  
  938.  
  939. /**
  940.  
  941. * Return True if this L2Npc is undead in function of the L2NpcTemplate.<BR><BR>
  942.  
  943. */
  944.  
  945. @Override
  946.  
  947. public boolean isUndead()
  948.  
  949. {
  950.  
  951. return getTemplate().isUndead();
  952.  
  953. }
  954.  
  955.  
  956.  
  957. /**
  958.  
  959. * Return the Identifier of the item in the left hand of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  960.  
  961. */
  962.  
  963. public int getLeftHandItem()
  964.  
  965. {
  966.  
  967. return _currentLHandId;
  968.  
  969. }
  970.  
  971.  
  972.  
  973. /**
  974.  
  975. * Return the Identifier of the item in the right hand of this L2Npc contained in the L2NpcTemplate.<BR><BR>
  976.  
  977. */
  978.  
  979. public int getRightHandItem()
  980.  
  981. {
  982.  
  983. return _currentRHandId;
  984.  
  985. }
  986.  
  987.  
  988.  
  989. /**
  990.  
  991. * Return True if this L2Npc has drops that can be sweeped.<BR><BR>
  992.  
  993. */
  994.  
  995. public boolean isSpoil()
  996.  
  997. {
  998.  
  999. return _isSpoil;
  1000.  
  1001. }
  1002.  
  1003.  
  1004.  
  1005. /**
  1006.  
  1007. * Set the spoil state of this L2Npc.<BR><BR>
  1008.  
  1009. */
  1010.  
  1011. public void setSpoil(boolean isSpoil)
  1012.  
  1013. {
  1014.  
  1015. _isSpoil = isSpoil;
  1016.  
  1017. }
  1018.  
  1019.  
  1020.  
  1021. public final int getIsSpoiledBy()
  1022.  
  1023. {
  1024.  
  1025. return _isSpoiledBy;
  1026.  
  1027. }
  1028.  
  1029.  
  1030.  
  1031. public final void setIsSpoiledBy(int value)
  1032.  
  1033. {
  1034.  
  1035. _isSpoiledBy = value;
  1036.  
  1037. }
  1038.  
  1039.  
  1040.  
  1041. /**
  1042.  
  1043. * Return the busy status of this L2Npc.<BR><BR>
  1044.  
  1045. */
  1046.  
  1047. public final boolean isBusy()
  1048.  
  1049. {
  1050.  
  1051. return _isBusy;
  1052.  
  1053. }
  1054.  
  1055.  
  1056.  
  1057. /**
  1058.  
  1059. * Set the busy status of this L2Npc.<BR><BR>
  1060.  
  1061. */
  1062.  
  1063. public void setBusy(boolean isBusy)
  1064.  
  1065. {
  1066.  
  1067. _isBusy = isBusy;
  1068.  
  1069. }
  1070.  
  1071.  
  1072.  
  1073. /**
  1074.  
  1075. * Return the busy message of this L2Npc.<BR><BR>
  1076.  
  1077. */
  1078.  
  1079. public final String getBusyMessage()
  1080.  
  1081. {
  1082.  
  1083. return _busyMessage;
  1084.  
  1085. }
  1086.  
  1087.  
  1088.  
  1089. /**
  1090.  
  1091. * Set the busy message of this L2Npc.<BR><BR>
  1092.  
  1093. */
  1094.  
  1095. public void setBusyMessage(String message)
  1096.  
  1097. {
  1098.  
  1099. _busyMessage = message;
  1100.  
  1101. }
  1102.  
  1103.  
  1104.  
  1105. /**
  1106.  
  1107. * Return true if this L2Npc instance can be warehouse manager.<BR><BR>
  1108.  
  1109. */
  1110.  
  1111. public boolean isWarehouse()
  1112.  
  1113. {
  1114.  
  1115. return false;
  1116.  
  1117. }
  1118.  
  1119.  
  1120.  
  1121. protected boolean canTarget(L2PcInstance player)
  1122.  
  1123. {
  1124.  
  1125. if (player.isOutOfControl())
  1126.  
  1127. {
  1128.  
  1129. player.sendPacket(ActionFailed.STATIC_PACKET);
  1130.  
  1131. return false;
  1132.  
  1133. }
  1134.  
  1135.  
  1136.  
  1137. if (!player.canChangeLockedTarget(this))
  1138.  
  1139. return false;
  1140.  
  1141.  
  1142.  
  1143. // Restrict interactions during restart/shutdown
  1144.  
  1145. if (Shutdown.isActionDisabled(DisableType.NPC_ITERACTION))
  1146.  
  1147. {
  1148.  
  1149. player.sendMessage("NPC interaction disabled during restart/shutdown.");
  1150.  
  1151. player.sendPacket(ActionFailed.STATIC_PACKET);
  1152.  
  1153. return false;
  1154.  
  1155. }
  1156.  
  1157. return true;
  1158.  
  1159. }
  1160.  
  1161.  
  1162.  
  1163. public boolean canInteract(L2PcInstance player)
  1164.  
  1165. {
  1166.  
  1167. // TODO: NPC busy check etc...
  1168.  
  1169.  
  1170.  
  1171. if (player.isCastingNow() || player.isCastingSimultaneouslyNow())
  1172.  
  1173. return false;
  1174.  
  1175. if (player.isDead() || player.isFakeDeath())
  1176.  
  1177. return false;
  1178.  
  1179. if (player.isSitting())
  1180.  
  1181. return false;
  1182.  
  1183. if (!isSameInstance(player))
  1184.  
  1185. return false;
  1186.  
  1187.  
  1188.  
  1189. if (player.getPrivateStoreType() != 0)
  1190.  
  1191. return false;
  1192.  
  1193.  
  1194.  
  1195. return isInsideRadius(player, INTERACTION_DISTANCE, true, false);
  1196.  
  1197. }
  1198.  
  1199.  
  1200.  
  1201. /**
  1202.  
  1203. * Manage actions when a player click on the L2Npc.<BR><BR>
  1204.  
  1205. *
  1206.  
  1207. * <B><U> Actions on first click on the L2Npc (Select it)</U> :</B><BR><BR>
  1208.  
  1209. * <li>Set the L2Npc as target of the L2PcInstance player (if necessary)</li>
  1210.  
  1211. * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
  1212.  
  1213. * <li>If L2Npc is autoAttackable, send a Server->Client packet StatusUpdate to the L2PcInstance in order to update L2Npc HP bar </li>
  1214.  
  1215. * <li>Send a Server->Client packet ValidateLocation to correct the L2Npc position and heading on the client </li><BR><BR>
  1216.  
  1217. *
  1218.  
  1219. * <B><U> Actions on second click on the L2Npc (Attack it/Intercat with it)</U> :</B><BR><BR>
  1220.  
  1221. * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
  1222.  
  1223. * <li>If L2Npc is autoAttackable, notify the L2PcInstance AI with AI_INTENTION_ATTACK (after a height verification)</li>
  1224.  
  1225. * <li>If L2Npc is NOT autoAttackable, notify the L2PcInstance AI with AI_INTENTION_INTERACT (after a distance verification) and show message</li><BR><BR>
  1226.  
  1227. *
  1228.  
  1229. * <FONT COLOR=#FF0000><B> <U>Caution</U> : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid
  1230.  
  1231. * that client wait an other packet</B></FONT><BR><BR>
  1232.  
  1233. *
  1234.  
  1235. * <B><U> Example of use </U> :</B><BR><BR>
  1236.  
  1237. * <li> Client packet : Action, AttackRequest</li><BR><BR>
  1238.  
  1239. *
  1240.  
  1241. * <B><U> Overridden in </U> :</B><BR><BR>
  1242.  
  1243. * <li> L2ArtefactInstance : Manage only fisrt click to select Artefact</li><BR><BR>
  1244.  
  1245. * <li> L2GuardInstance : </li><BR><BR>
  1246.  
  1247. *
  1248.  
  1249. * @param player The L2PcInstance that start an action on the L2Npc
  1250.  
  1251. *
  1252.  
  1253. */
  1254.  
  1255. @Override
  1256.  
  1257. public void onAction(L2PcInstance player)
  1258.  
  1259. {
  1260.  
  1261. if (!canTarget(player))
  1262.  
  1263. return;
  1264.  
  1265.  
  1266.  
  1267. player.setLastFolkNPC(this);
  1268.  
  1269.  
  1270.  
  1271. try
  1272.  
  1273. {
  1274.  
  1275. // Check if the L2PcInstance already target the L2Npc
  1276.  
  1277. if (this != player.getTarget())
  1278.  
  1279. {
  1280.  
  1281. if (_log.isDebugEnabled())
  1282.  
  1283. _log.debug("new target selected:" + getObjectId());
  1284.  
  1285.  
  1286.  
  1287. // Set the target of the L2PcInstance player
  1288.  
  1289. player.setTarget(this);
  1290.  
  1291.  
  1292.  
  1293. // Check if the player is attackable (without a forced attack)
  1294.  
  1295. if (isAutoAttackable(player))
  1296.  
  1297. {
  1298.  
  1299. // Send a Server->Client packet StatusUpdate of the L2Npc to the L2PcInstance to update its HP bar
  1300.  
  1301. StatusUpdate su = new StatusUpdate(getObjectId());
  1302.  
  1303. su.addAttribute(StatusUpdate.CUR_HP, (int) getStatus().getCurrentHp());
  1304.  
  1305. su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  1306.  
  1307. player.sendPacket(su);
  1308.  
  1309. }
  1310.  
  1311. }
  1312.  
  1313. else
  1314.  
  1315. {
  1316.  
  1317. // Check if the player is attackable (without a forced attack) and isn't dead
  1318.  
  1319. if (isAutoAttackable(player) && !isAlikeDead())
  1320.  
  1321. {
  1322.  
  1323. // Check the height difference
  1324.  
  1325. if (Math.abs(player.getZ() - getZ()) < 400) // this max heigth difference might need some tweaking
  1326.  
  1327. {
  1328.  
  1329. // Set the L2PcInstance Intention to AI_INTENTION_ATTACK
  1330.  
  1331. player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
  1332.  
  1333. // player.startAttack(this);
  1334.  
  1335. }
  1336.  
  1337. else
  1338.  
  1339. {
  1340.  
  1341. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  1342.  
  1343. player.sendPacket(ActionFailed.STATIC_PACKET);
  1344.  
  1345. }
  1346.  
  1347. }
  1348.  
  1349. else if (!isAutoAttackable(player))
  1350.  
  1351. {
  1352.  
  1353. // Calculate the distance between the L2PcInstance and the L2Npc
  1354.  
  1355. if (!canInteract(player))
  1356.  
  1357. {
  1358.  
  1359. // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  1360.  
  1361. player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  1362.  
  1363. }
  1364.  
  1365. else
  1366.  
  1367. {
  1368.  
  1369. // Send a Server->Client packet SocialAction to the all L2PcInstance on the _knownPlayer of the L2Npc
  1370.  
  1371. // to display a social action of the L2Npc on their client
  1372.  
  1373. broadcastRandomAnimation(true);
  1374.  
  1375.  
  1376.  
  1377. // Open a chat window on client with the text of the L2Npc
  1378.  
  1379. if (GlobalRestrictions.onAction(this, player))
  1380.  
  1381. {
  1382.  
  1383. }
  1384.  
  1385. else
  1386.  
  1387. {
  1388.  
  1389. Quest[] qlsa = getTemplate().getEventQuests(Quest.QuestEventType.QUEST_START);
  1390.  
  1391. if (qlsa != null && qlsa.length > 0)
  1392.  
  1393. player.setLastQuestNpcObject(getObjectId());
  1394.  
  1395. Quest[] qlst = getTemplate().getEventQuests(Quest.QuestEventType.ON_FIRST_TALK);
  1396.  
  1397. if ((qlst != null) && qlst.length == 1)
  1398.  
  1399. qlst[0].notifyFirstTalk(this, player);
  1400.  
  1401. else
  1402.  
  1403. showChatWindow(player, 0);
  1404.  
  1405. }
  1406.  
  1407. player.sendPacket(ActionFailed.STATIC_PACKET);
  1408.  
  1409. }
  1410.  
  1411. }
  1412.  
  1413. else
  1414.  
  1415. player.sendPacket(ActionFailed.STATIC_PACKET);
  1416.  
  1417. }
  1418.  
  1419. }
  1420.  
  1421. catch (Exception e)
  1422.  
  1423. {
  1424.  
  1425. _log.error("", e);
  1426.  
  1427. player.sendPacket(ActionFailed.STATIC_PACKET);
  1428.  
  1429. }
  1430.  
  1431. }
  1432.  
  1433.  
  1434.  
  1435. @Override
  1436.  
  1437. public int getMyTargetSelectedColor(L2PcInstance player)
  1438.  
  1439. {
  1440.  
  1441. if (isAutoAttackable(player))
  1442.  
  1443. return player.getLevel() - getLevel();
  1444.  
  1445. else
  1446.  
  1447. return 0;
  1448.  
  1449. }
  1450.  
  1451.  
  1452.  
  1453. /**
  1454.  
  1455. * Manage and Display the GM console to modify the L2Npc (GM only).<BR><BR>
  1456.  
  1457. *
  1458.  
  1459. * <B><U> Actions (If the L2PcInstance is a GM only)</U> :</B><BR><BR>
  1460.  
  1461. * <li>Set the L2Npc as target of the L2PcInstance player (if necessary)</li>
  1462.  
  1463. * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
  1464.  
  1465. * <li>If L2Npc is autoAttackable, send a Server->Client packet StatusUpdate to the L2PcInstance in order to update L2Npc HP bar </li>
  1466.  
  1467. * <li>Send a Server->Client NpcHtmlMessage() containing the GM console about this L2Npc </li><BR><BR>
  1468.  
  1469. *
  1470.  
  1471. * <FONT COLOR=#FF0000><B> <U>Caution</U> : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid
  1472.  
  1473. * that client wait an other packet</B></FONT><BR><BR>
  1474.  
  1475. *
  1476.  
  1477. * <B><U> Example of use </U> :</B><BR><BR>
  1478.  
  1479. * <li> Client packet : Action</li><BR><BR>
  1480.  
  1481. *
  1482.  
  1483. * @param player The thread that manage the player that pessed Shift and click on the L2Npc
  1484.  
  1485. *
  1486.  
  1487. */
  1488.  
  1489. @Override
  1490.  
  1491. public void onActionShift(L2PcInstance player)
  1492.  
  1493. {
  1494.  
  1495. // Check if the L2PcInstance is a GM
  1496.  
  1497. if (player.getAccessLevel() >= Config.GM_ACCESSLEVEL)
  1498.  
  1499. {
  1500.  
  1501. // Set the target of the L2PcInstance player
  1502.  
  1503. player.setTarget(this);
  1504.  
  1505.  
  1506.  
  1507. // Check if the player is attackable (without a forced attack)
  1508.  
  1509. if (isAutoAttackable(player))
  1510.  
  1511. {
  1512.  
  1513. // Send a Server->Client packet StatusUpdate of the L2Npc to the L2PcInstance to update its HP bar
  1514.  
  1515. StatusUpdate su = new StatusUpdate(getObjectId());
  1516.  
  1517. su.addAttribute(StatusUpdate.CUR_HP, (int) getStatus().getCurrentHp());
  1518.  
  1519. su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  1520.  
  1521. player.sendPacket(su);
  1522.  
  1523. }
  1524.  
  1525.  
  1526.  
  1527. // Send a Server->Client NpcHtmlMessage() containing the GM console about this L2Npc
  1528.  
  1529. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  1530.  
  1531. String className = getClass().getSimpleName();
  1532.  
  1533.  
  1534.  
  1535. final StringBuilder html1 = StringUtil.startAppend(500,
  1536.  
  1537. "<html><body><center><font color=\"LEVEL\">NPC Information</font></center>" +
  1538.  
  1539. "<br>" +
  1540.  
  1541. "Instance Type: ",
  1542.  
  1543. className,
  1544.  
  1545. "<br1>Faction: ",
  1546.  
  1547. getFactionId() != null ? getFactionId() : "null",
  1548.  
  1549. "<br1>"
  1550.  
  1551. );
  1552.  
  1553. StringUtil.append(html1,
  1554.  
  1555. "Coords ",
  1556.  
  1557. String.valueOf(getX()),
  1558.  
  1559. ",",
  1560.  
  1561. String.valueOf(getY()),
  1562.  
  1563. ",",
  1564.  
  1565. String.valueOf(getZ()),
  1566.  
  1567. "<br1>"
  1568.  
  1569. );
  1570.  
  1571. if (getSpawn() != null)
  1572.  
  1573. StringUtil.append(html1,
  1574.  
  1575. "Spawn ",
  1576.  
  1577. String.valueOf(getSpawn().getLocx()),
  1578.  
  1579. ",",
  1580.  
  1581. String.valueOf(getSpawn().getLocy()),
  1582.  
  1583. ",",
  1584.  
  1585. String.valueOf(getSpawn().getLocz()),
  1586.  
  1587. " Loc ID: ",
  1588.  
  1589. String.valueOf(getSpawn().getLocation()),
  1590.  
  1591. "<br1>",
  1592.  
  1593. "Distance from spawn 2D ",
  1594.  
  1595. String.valueOf((int)Math.sqrt(getPlanDistanceSq(getSpawn().getLocx(), getSpawn().getLocy()))),
  1596.  
  1597. " 3D ",
  1598.  
  1599. String.valueOf((int)Math.sqrt(getDistanceSq(getSpawn().getLocx(), getSpawn().getLocy(), getSpawn().getLocz()))),
  1600.  
  1601. "<br1>"
  1602.  
  1603. );
  1604.  
  1605.  
  1606.  
  1607. if (this instanceof L2ControllableMobInstance)
  1608.  
  1609. html1.append("Mob Group: " + MobGroupTable.getInstance().getGroupForMob((L2ControllableMobInstance) this).getGroupId() + "<br>");
  1610.  
  1611. else
  1612.  
  1613. html1.append("Respawn Time: " + (getSpawn() != null ? (getSpawn().getRespawnDelay() / 1000) + " Seconds<br>" : "? Seconds<br>"));
  1614.  
  1615.  
  1616.  
  1617. html1.append("<table border=\"0\" width=\"100%\">");
  1618.  
  1619. html1.append("<tr><td>Object ID</td><td>" + getObjectId() + "</td><td>NPC ID</td><td>" + getTemplate().getNpcId() + "</td></tr>");
  1620.  
  1621. html1.append("<tr><td>Castle</td><td>" + getCastle().getCastleId() + "</td><td>AI </td><td>"
  1622.  
  1623. + (hasAI() ? getAI().getIntention() : "NULL") + "</td></tr>");
  1624.  
  1625. html1.append("<tr><td>Level</td><td>" + getLevel() + "</td><td>Aggro</td><td>"
  1626.  
  1627. + ((this instanceof L2Attackable) ? getAggroRange() : 0) + "</td></tr>");
  1628.  
  1629. html1.append("</table><br>");
  1630.  
  1631.  
  1632.  
  1633. html1.append("<font color=\"LEVEL\">Combat</font>");
  1634.  
  1635. html1.append("<table border=\"0\" width=\"100%\">");
  1636.  
  1637. html1.append("<tr><td>Current HP</td><td>" + getStatus().getCurrentHp() + "</td><td>Current MP</td><td>" + getStatus().getCurrentMp()
  1638.  
  1639. + "</td></tr>");
  1640.  
  1641. html1.append("<tr><td>Max.HP</td><td>" + (int) (getMaxHp() / getStat().calcStat(Stats.MAX_HP, 1, this, null)) + "*"
  1642.  
  1643. + getStat().calcStat(Stats.MAX_HP, 1, this, null) + "</td><td>Max.MP</td><td>" + getMaxMp() + "</td></tr>");
  1644.  
  1645. html1.append("<tr><td>P.Atk.</td><td>" + getPAtk(null) + "</td><td>M.Atk.</td><td>" + getMAtk(null, null) + "</td></tr>");
  1646.  
  1647. html1.append("<tr><td>P.Def.</td><td>" + getPDef(null) + "</td><td>M.Def.</td><td>" + getMDef(null, null) + "</td></tr>");
  1648.  
  1649. html1.append("<tr><td>Accuracy</td><td>" + getAccuracy() + "</td><td>Evasion</td><td>" + getEvasionRate() + "</td></tr>");
  1650.  
  1651. html1.append("<tr><td>Critical</td><td>" + getCriticalHit() + "</td><td>Speed</td><td>" + getRunSpeed() + "</td></tr>");
  1652.  
  1653. html1.append("<tr><td>Atk.Speed</td><td>" + getPAtkSpd() + "</td><td>Cast.Speed</td><td>" + getMAtkSpd() + "</td></tr>");
  1654.  
  1655. html1.append("<tr><td>Race</td><td>" + getTemplate().getRace() + "</td><td></td><td></td></tr>");
  1656.  
  1657. html1.append("</table><br>");
  1658.  
  1659.  
  1660.  
  1661. html1.append("<font color=\"LEVEL\">Basic Stats</font>");
  1662.  
  1663. html1.append("<table border=\"0\" width=\"100%\">");
  1664.  
  1665. html1.append("<tr><td>STR</td><td>" + getStat().getSTR() + "</td><td>DEX</td><td>" + getStat().getDEX() + "</td><td>CON</td><td>"
  1666.  
  1667. + getStat().getCON() + "</td></tr>");
  1668.  
  1669. html1.append("<tr><td>INT</td><td>" + getINT() + "</td><td>WIT</td><td>" + getStat().getWIT() + "</td><td>MEN</td><td>" + getStat().getMEN()
  1670.  
  1671. + "</td></tr>");
  1672.  
  1673. html1.append("</table>");
  1674.  
  1675.  
  1676.  
  1677. html1.append("<font color=\"LEVEL\">Quest Info</font>");
  1678.  
  1679. html1.append("<table border=\"0\" width=\"100%\">");
  1680.  
  1681. html1.append("<tr><td>Quest attack status:</td><td>" + getQuestAttackStatus() + "</td></tr>");
  1682.  
  1683. html1.append("<tr><td>Quest attacker:</td><td>" + getQuestFirstAttacker() + "</td></tr>");
  1684.  
  1685. html1.append("</table>");
  1686.  
  1687.  
  1688.  
  1689. html1.append("<br><center><table><tr><td><button value=\"Edit NPC\" action=\"bypass -h admin_edit_npc " + getTemplate().getNpcId()
  1690.  
  1691. + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1></td>");
  1692.  
  1693. html1
  1694.  
  1695. .append("<td><button value=\"Kill\" action=\"bypass -h admin_kill\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><br1></tr>");
  1696.  
  1697. html1.append("<tr><td><button value=\"Show DropList\" action=\"bypass -h admin_show_droplist " + getTemplate().getNpcId()
  1698.  
  1699. + "\" width=100 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  1700.  
  1701. html1
  1702.  
  1703. .append("<td><button value=\"Delete\" action=\"bypass -h admin_delete\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  1704.  
  1705. // [L2J_JP ADD START]
  1706.  
  1707. html1.append("<tr><td><button value=\"Show Skillist\" action=\"bypass -h admin_show_skilllist_npc " + getTemplate().getNpcId()
  1708.  
  1709. + "\" width=100 height=20 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td></td></tr>");
  1710.  
  1711. // [L2J_JP ADD END]
  1712.  
  1713. html1.append("</table></center><br>");
  1714.  
  1715. html1.append("</body></html>");
  1716.  
  1717.  
  1718.  
  1719. html.setHtml(html1.toString());
  1720.  
  1721. player.sendPacket(html);
  1722.  
  1723. }
  1724.  
  1725. // Allow to see the stats of npc if option is activated and if not a box
  1726.  
  1727. else if (Config.ALT_GAME_VIEWNPC && !(this instanceof L2ChestInstance))
  1728.  
  1729. {
  1730.  
  1731. // Set the target of the L2PcInstance player
  1732.  
  1733. player.setTarget(this);
  1734.  
  1735.  
  1736.  
  1737. // Check if the player is attackable (without a forced attack)
  1738.  
  1739. if (isAutoAttackable(player))
  1740.  
  1741. {
  1742.  
  1743. // Send a Server->Client packet StatusUpdate of the L2Npc to the L2PcInstance to update its HP bar
  1744.  
  1745. StatusUpdate su = new StatusUpdate(getObjectId());
  1746.  
  1747. su.addAttribute(StatusUpdate.CUR_HP, (int) getStatus().getCurrentHp());
  1748.  
  1749. su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
  1750.  
  1751. player.sendPacket(su);
  1752.  
  1753. }
  1754.  
  1755.  
  1756.  
  1757. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  1758.  
  1759. L2TextBuilder html1 = L2TextBuilder.newInstance("<html><body>");
  1760.  
  1761.  
  1762.  
  1763. html1.append("<br><center><font color=\"LEVEL\">[Combat Stats]</font></center>");
  1764.  
  1765. html1.append("<table border=0 width=\"100%\">");
  1766.  
  1767. html1.append("<tr><td>Max.HP</td><td>" + (int) (getMaxHp() / getStat().calcStat(Stats.MAX_HP, 1, this, null)) + "*"
  1768.  
  1769. + (int) getStat().calcStat(Stats.MAX_HP, 1, this, null) + "</td><td>Max.MP</td><td>" + getMaxMp() + "</td></tr>");
  1770.  
  1771. html1.append("<tr><td>P.Atk.</td><td>" + getPAtk(null) + "</td><td>M.Atk.</td><td>" + getMAtk(null, null) + "</td></tr>");
  1772.  
  1773. html1.append("<tr><td>P.Def.</td><td>" + getPDef(null) + "</td><td>M.Def.</td><td>" + getMDef(null, null) + "</td></tr>");
  1774.  
  1775. html1.append("<tr><td>Accuracy</td><td>" + getAccuracy() + "</td><td>Evasion</td><td>" + getEvasionRate() + "</td></tr>");
  1776.  
  1777. html1.append("<tr><td>Critical</td><td>" + getCriticalHit() + "</td><td>Speed</td><td>" + getRunSpeed() + "</td></tr>");
  1778.  
  1779. html1.append("<tr><td>Atk.Speed</td><td>" + getPAtkSpd() + "</td><td>Cast.Speed</td><td>" + getMAtkSpd() + "</td></tr>");
  1780.  
  1781. html1.append("<tr><td>Race</td><td>" + getTemplate().getRace() + "</td><td></td><td></td></tr>");
  1782.  
  1783. html1.append("</table>");
  1784.  
  1785.  
  1786.  
  1787. html1.append("<br><center><font color=\"LEVEL\">[Basic Stats]</font></center>");
  1788.  
  1789. html1.append("<table border=0 width=\"100%\">");
  1790.  
  1791. html1.append("<tr><td>STR</td><td>" + getStat().getSTR() + "</td><td>DEX</td><td>" + getStat().getDEX() + "</td><td>CON</td><td>"
  1792.  
  1793. + getStat().getCON() + "</td></tr>");
  1794.  
  1795. html1.append("<tr><td>INT</td><td>" + getINT() + "</td><td>WIT</td><td>" + getStat().getWIT() + "</td><td>MEN</td><td>" + getStat().getMEN()
  1796.  
  1797. + "</td></tr>");
  1798.  
  1799. html1.append("</table>");
  1800.  
  1801.  
  1802.  
  1803. html1.append("<br><center><font color=\"LEVEL\">[Drop Info]</font></center>");
  1804.  
  1805. html1.append("<br>Rates legend: <font color=\"ff0000\">50%+</font> <font color=\"00ff00\">30%+</font> <font color=\"0000ff\">less than 30%</font>");
  1806.  
  1807. html1.append("<table border=0 width=\"100%\">");
  1808.  
  1809.  
  1810.  
  1811. if (getTemplate().getDropData() != null)
  1812.  
  1813. {
  1814.  
  1815. for (L2DropCategory cat : getTemplate().getDropData())
  1816.  
  1817. {
  1818.  
  1819. for (L2DropData drop : cat.getAllDrops())
  1820.  
  1821. {
  1822.  
  1823. final L2Item item = ItemTable.getInstance().getTemplate(drop.getItemId());
  1824.  
  1825. if (item == null)
  1826.  
  1827. continue;
  1828.  
  1829.  
  1830.  
  1831. String name = item.getName();
  1832.  
  1833.  
  1834.  
  1835. if (drop.getChance() >= 500000)
  1836.  
  1837. html1.append("<tr><td><font color=\"ff0000\">" + name + "</font></td><td>"
  1838.  
  1839. + (drop.isQuestDrop() ? "Quest" : (cat.isSweep() ? "Sweep" : "Drop")) + "</td></tr>");
  1840.  
  1841. else if (drop.getChance() >= 300000)
  1842.  
  1843. html1.append("<tr><td><font color=\"00ff00\">" + name + "</font></td><td>"
  1844.  
  1845. + (drop.isQuestDrop() ? "Quest" : (cat.isSweep() ? "Sweep" : "Drop")) + "</td></tr>");
  1846.  
  1847. else
  1848.  
  1849. html1.append("<tr><td><font color=\"0000ff\">" + name + "</font></td><td>"
  1850.  
  1851. + (drop.isQuestDrop() ? "Quest" : (cat.isSweep() ? "Sweep" : "Drop")) + "</td></tr>");
  1852.  
  1853. }
  1854.  
  1855. }
  1856.  
  1857. }
  1858.  
  1859.  
  1860.  
  1861. html1.append("</table>");
  1862.  
  1863. html1.append("</body></html>");
  1864.  
  1865.  
  1866.  
  1867. html.setHtml(html1.moveToString());
  1868.  
  1869. player.sendPacket(html);
  1870.  
  1871. }
  1872.  
  1873.  
  1874.  
  1875. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  1876.  
  1877. player.sendPacket(ActionFailed.STATIC_PACKET);
  1878.  
  1879. }
  1880.  
  1881.  
  1882.  
  1883. /** Return the L2Castle this L2Npc belongs to. */
  1884.  
  1885. public final Castle getCastle()
  1886.  
  1887. {
  1888.  
  1889. // Get castle this NPC belongs to (excluding L2Attackable)
  1890.  
  1891. if (_castleIndex < 0)
  1892.  
  1893. {
  1894.  
  1895. Town town = TownManager.getInstance().getTown(this);
  1896.  
  1897. // Npc was spawned in town
  1898.  
  1899. _isInTown = (town != null);
  1900.  
  1901.  
  1902.  
  1903. if (!_isInTown)
  1904.  
  1905. _castleIndex = CastleManager.getInstance().getClosestCastle(this).getCastleId();
  1906.  
  1907. else if (town != null && town.getCastle() != null)
  1908.  
  1909. _castleIndex = town.getCastle().getCastleId();
  1910.  
  1911. else
  1912.  
  1913. _castleIndex = CastleManager.getInstance().getClosestCastle(this).getCastleId();
  1914.  
  1915. }
  1916.  
  1917.  
  1918.  
  1919. return CastleManager.getInstance().getCastleById(_castleIndex);
  1920.  
  1921. }
  1922.  
  1923.  
  1924.  
  1925. /** Return the L2Fort this L2Npc belongs to. */
  1926.  
  1927. public final Fort getFort()
  1928.  
  1929. {
  1930.  
  1931. // Get Fort this NPC belongs to (excluding L2Attackable)
  1932.  
  1933. if (_fortIndex < 0)
  1934.  
  1935. {
  1936.  
  1937. Fort fort = FortManager.getInstance().getFort(getX(), getY(), getZ());
  1938.  
  1939. if (fort != null)
  1940.  
  1941. {
  1942.  
  1943. _fortIndex = FortManager.getInstance().getFortIndex(fort.getFortId());
  1944.  
  1945. }
  1946.  
  1947. if (_fortIndex < 0)
  1948.  
  1949. {
  1950.  
  1951. _fortIndex = FortManager.getInstance().findNearestFortIndex(this);
  1952.  
  1953. }
  1954.  
  1955. }
  1956.  
  1957. if (_fortIndex < 0)
  1958.  
  1959. {
  1960.  
  1961. return null;
  1962.  
  1963. }
  1964.  
  1965. return FortManager.getInstance().getForts().get(_fortIndex);
  1966.  
  1967. }
  1968.  
  1969.  
  1970.  
  1971. public final boolean getIsInTown()
  1972.  
  1973. {
  1974.  
  1975. if (_castleIndex < 0)
  1976.  
  1977. getCastle();
  1978.  
  1979. return _isInTown;
  1980.  
  1981. }
  1982.  
  1983.  
  1984.  
  1985. /**
  1986.  
  1987. * Open a quest or chat window on client with the text of the L2Npc in function of the command.<BR><BR>
  1988.  
  1989. *
  1990.  
  1991. * <B><U> Example of use </U> :</B><BR><BR>
  1992.  
  1993. * <li> Client packet : RequestBypassToServer</li><BR><BR>
  1994.  
  1995. *
  1996.  
  1997. * @param command The command string received from client
  1998.  
  1999. *
  2000.  
  2001. */
  2002.  
  2003. public void onBypassFeedback(L2PcInstance player, String command)
  2004.  
  2005. {
  2006.  
  2007. //if (canInteract(player))
  2008.  
  2009. {
  2010.  
  2011. if (isBusy() && getBusyMessage().length() > 0)
  2012.  
  2013. {
  2014.  
  2015. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2016.  
  2017. html.setFile("data/html/npcbusy.htm");
  2018.  
  2019. html.replace("%busymessage%", getBusyMessage());
  2020.  
  2021. html.replace("%npcname%", getName());
  2022.  
  2023. html.replace("%playername%", player.getName());
  2024.  
  2025. player.sendPacket(html);
  2026.  
  2027. }
  2028.  
  2029. else if (Config.ALLOW_WYVERN_UPGRADER && command.startsWith("upgrade") && player.getClan() != null && player.getClan().getHasCastle() != 0)
  2030.  
  2031. {
  2032.  
  2033. String type = command.substring(8);
  2034.  
  2035.  
  2036.  
  2037. if (type.equalsIgnoreCase("wyvern"))
  2038.  
  2039. {
  2040.  
  2041. L2NpcTemplate wind = NpcTable.getInstance().getTemplate(PetDataTable.STRIDER_WIND_ID);
  2042.  
  2043. L2NpcTemplate star = NpcTable.getInstance().getTemplate(PetDataTable.STRIDER_STAR_ID);
  2044.  
  2045. L2NpcTemplate twilight = NpcTable.getInstance().getTemplate(PetDataTable.STRIDER_TWILIGHT_ID);
  2046.  
  2047.  
  2048.  
  2049. L2Summon summon = player.getPet();
  2050.  
  2051. L2NpcTemplate myPet = summon.getTemplate();
  2052.  
  2053.  
  2054.  
  2055. if ((myPet.equals(wind) || myPet.equals(star) || myPet.equals(twilight)) && player.getAdena() >= 20000000
  2056.  
  2057. && (player.getInventory().getItemByObjectId(summon.getControlItemId()) != null))
  2058.  
  2059. {
  2060.  
  2061. int exchangeItem = PetDataTable.WYVERN_ID;
  2062.  
  2063. if (!player.reduceAdena("PetUpdate", 20000000, this, true))
  2064.  
  2065. return;
  2066.  
  2067. player.getInventory().destroyItem("PetUpdate", summon.getControlItemId(), 1, player, this);
  2068.  
  2069.  
  2070.  
  2071. L2NpcTemplate template1 = NpcTable.getInstance().getTemplate(20629);
  2072.  
  2073. try
  2074.  
  2075. {
  2076.  
  2077. L2Spawn spawn = new L2Spawn(template1);
  2078.  
  2079.  
  2080.  
  2081. spawn.setLocx(getX() + 20);
  2082.  
  2083. spawn.setLocy(getY() + 20);
  2084.  
  2085. spawn.setLocz(getZ());
  2086.  
  2087. spawn.setAmount(1);
  2088.  
  2089. spawn.setHeading(player.getHeading());
  2090.  
  2091. spawn.setRespawnDelay(1);
  2092.  
  2093.  
  2094.  
  2095. SpawnTable.getInstance().addNewSpawn(spawn, false);
  2096.  
  2097.  
  2098.  
  2099. spawn.init();
  2100.  
  2101. spawn.getLastSpawn().getStatus().setCurrentHp(getMaxHp());
  2102.  
  2103. spawn.getLastSpawn().setName("baal");
  2104.  
  2105. spawn.getLastSpawn().setTitle("hell's god");
  2106.  
  2107. //spawn.getLastSpawn().isEventMob = true;
  2108.  
  2109. spawn.getLastSpawn().isAggressive();
  2110.  
  2111. spawn.getLastSpawn().decayMe();
  2112.  
  2113. spawn.getLastSpawn().spawnMe(spawn.getLastSpawn().getX(), spawn.getLastSpawn().getY(), spawn.getLastSpawn().getZ());
  2114.  
  2115.  
  2116.  
  2117. int level = summon.getLevel();
  2118.  
  2119. int chance = (level - 54) * 10;
  2120.  
  2121. spawn.getLastSpawn().broadcastPacket(new MagicSkillUse(spawn.getLastSpawn(), spawn.getLastSpawn(), 1034, 1, 1, 1));
  2122.  
  2123. spawn.getLastSpawn().broadcastPacket(new MagicSkillUse(spawn.getLastSpawn(), summon, 1034, 1, 1, 1));
  2124.  
  2125.  
  2126.  
  2127. if (Rnd.nextInt(100) < chance)
  2128.  
  2129. {
  2130.  
  2131. ThreadPoolManager.getInstance().scheduleGeneral(new DestroyTemporalSummon(summon, player), 6000);
  2132.  
  2133. player.addItem("PetUpdate", exchangeItem, 1, player, true, true);
  2134.  
  2135.  
  2136.  
  2137. NpcHtmlMessage adminReply = new NpcHtmlMessage(getObjectId());
  2138.  
  2139. L2TextBuilder replyMSG = L2TextBuilder.newInstance("<html><body>");
  2140.  
  2141. replyMSG.append("Congratulations, the evolution suceeded.");
  2142.  
  2143. replyMSG.append("</body></html>");
  2144.  
  2145. adminReply.setHtml(replyMSG.moveToString());
  2146.  
  2147. player.sendPacket(adminReply);
  2148.  
  2149. }
  2150.  
  2151. else
  2152.  
  2153. {
  2154.  
  2155. summon.reduceCurrentHp(summon.getStatus().getCurrentHp(), player);
  2156.  
  2157. }
  2158.  
  2159. ThreadPoolManager.getInstance().scheduleGeneral(new DestroyTemporalNPC(spawn), 15000);
  2160.  
  2161.  
  2162.  
  2163. ItemList il = new ItemList(player, true);
  2164.  
  2165. player.sendPacket(il);
  2166.  
  2167. }
  2168.  
  2169. catch (Exception e)
  2170.  
  2171. {
  2172.  
  2173. _log.error(e.getMessage(), e);
  2174.  
  2175. }
  2176.  
  2177. }
  2178.  
  2179. else
  2180.  
  2181. {
  2182.  
  2183. NpcHtmlMessage adminReply = new NpcHtmlMessage(getObjectId());
  2184.  
  2185. L2TextBuilder replyMSG = L2TextBuilder.newInstance("<html><body>");
  2186.  
  2187.  
  2188.  
  2189. replyMSG.append("You will need 20.000.000 and have the pet summoned for the ceremony ...");
  2190.  
  2191. replyMSG.append("</body></html>");
  2192.  
  2193.  
  2194.  
  2195. adminReply.setHtml(replyMSG.moveToString());
  2196.  
  2197. player.sendPacket(adminReply);
  2198.  
  2199. }
  2200.  
  2201. }
  2202.  
  2203. else if (Config.ALT_CLASS_MASTER_STRIDER_UPDATE && type.equalsIgnoreCase("strider"))
  2204.  
  2205. {
  2206.  
  2207. L2NpcTemplate wind = NpcTable.getInstance().getTemplate(PetDataTable.HATCHLING_WIND_ID);
  2208.  
  2209. L2NpcTemplate star = NpcTable.getInstance().getTemplate(PetDataTable.HATCHLING_STAR_ID);
  2210.  
  2211. L2NpcTemplate twilight = NpcTable.getInstance().getTemplate(PetDataTable.HATCHLING_TWILIGHT_ID);
  2212.  
  2213.  
  2214.  
  2215. L2Summon summon = player.getPet();
  2216.  
  2217. L2NpcTemplate myPet = summon.getTemplate();
  2218.  
  2219.  
  2220.  
  2221. if ((myPet.equals(wind) || myPet.equals(star) || myPet.equals(twilight)) && player.getAdena() >= 6000000
  2222.  
  2223. && (player.getInventory().getItemByObjectId(summon.getControlItemId()) != null))
  2224.  
  2225. {
  2226.  
  2227. int exchangeItem = PetDataTable.STRIDER_TWILIGHT_ID;
  2228.  
  2229. if (myPet.equals(wind))
  2230.  
  2231. exchangeItem = PetDataTable.STRIDER_WIND_ID;
  2232.  
  2233. else if (myPet.equals(star))
  2234.  
  2235. exchangeItem = PetDataTable.STRIDER_STAR_ID;
  2236.  
  2237.  
  2238.  
  2239. if (!player.reduceAdena("PetUpdate", 6000000, this, true))
  2240.  
  2241. return;
  2242.  
  2243. player.getInventory().destroyItem("PetUpdate", summon.getControlItemId(), 1, player, this);
  2244.  
  2245.  
  2246.  
  2247. L2NpcTemplate template1 = NpcTable.getInstance().getTemplate(689);
  2248.  
  2249. try
  2250.  
  2251. {
  2252.  
  2253. L2Spawn spawn = new L2Spawn(template1);
  2254.  
  2255.  
  2256.  
  2257. spawn.setLocx(getX() + 20);
  2258.  
  2259. spawn.setLocy(getY() + 20);
  2260.  
  2261. spawn.setLocz(getZ());
  2262.  
  2263. spawn.setAmount(1);
  2264.  
  2265. spawn.setHeading(player.getHeading());
  2266.  
  2267. spawn.setRespawnDelay(1);
  2268.  
  2269.  
  2270.  
  2271. SpawnTable.getInstance().addNewSpawn(spawn, false);
  2272.  
  2273.  
  2274.  
  2275. spawn.init();
  2276.  
  2277. spawn.getLastSpawn().getStatus().setCurrentHp(getMaxHp());
  2278.  
  2279. spawn.getLastSpawn().setName("mercebu");
  2280.  
  2281. spawn.getLastSpawn().setTitle("baal's son");
  2282.  
  2283.  
  2284.  
  2285. spawn.getLastSpawn().isAggressive();
  2286.  
  2287. spawn.getLastSpawn().decayMe();
  2288.  
  2289. spawn.getLastSpawn().spawnMe(spawn.getLastSpawn().getX(), spawn.getLastSpawn().getY(), spawn.getLastSpawn().getZ());
  2290.  
  2291.  
  2292.  
  2293. spawn.getLastSpawn().broadcastPacket(new MagicSkillUse(spawn.getLastSpawn(), summon, 297, 1, 1, 1));
  2294.  
  2295.  
  2296.  
  2297. int level = summon.getLevel();
  2298.  
  2299. int chance = (level - 34) * 10;
  2300.  
  2301. spawn.getLastSpawn().broadcastPacket(new MagicSkillUse(spawn.getLastSpawn(), spawn.getLastSpawn(), 1034, 1, 1, 1));
  2302.  
  2303. spawn.getLastSpawn().broadcastPacket(new MagicSkillUse(spawn.getLastSpawn(), summon, 1034, 1, 1, 1));
  2304.  
  2305.  
  2306.  
  2307. if (Rnd.nextInt(100) < chance)
  2308.  
  2309. {
  2310.  
  2311. ThreadPoolManager.getInstance().scheduleGeneral(new DestroyTemporalSummon(summon, player), 6000);
  2312.  
  2313. player.addItem("PetUpdate", exchangeItem, 1, player, true, true);
  2314.  
  2315. NpcHtmlMessage adminReply = new NpcHtmlMessage(getObjectId());
  2316.  
  2317. L2TextBuilder replyMSG = L2TextBuilder.newInstance("<html><body>");
  2318.  
  2319.  
  2320.  
  2321. replyMSG.append("Congratulations, the evolution suceeded.");
  2322.  
  2323. replyMSG.append("</body></html>");
  2324.  
  2325.  
  2326.  
  2327. adminReply.setHtml(replyMSG.moveToString());
  2328.  
  2329. player.sendPacket(adminReply);
  2330.  
  2331. }
  2332.  
  2333. else
  2334.  
  2335. {
  2336.  
  2337. summon.reduceCurrentHp(summon.getStatus().getCurrentHp(), player);
  2338.  
  2339. }
  2340.  
  2341.  
  2342.  
  2343. ThreadPoolManager.getInstance().scheduleGeneral(new DestroyTemporalNPC(spawn), 15000);
  2344.  
  2345. ItemList il = new ItemList(player, true);
  2346.  
  2347. player.sendPacket(il);
  2348.  
  2349. }
  2350.  
  2351. catch (Exception e)
  2352.  
  2353. {
  2354.  
  2355. _log.error(e.getMessage(), e);
  2356.  
  2357. }
  2358.  
  2359. }
  2360.  
  2361. else
  2362.  
  2363. {
  2364.  
  2365. NpcHtmlMessage adminReply = new NpcHtmlMessage(getObjectId());
  2366.  
  2367. L2TextBuilder replyMSG = L2TextBuilder.newInstance("<html><body>");
  2368.  
  2369.  
  2370.  
  2371. replyMSG.append("You will need 6.000.000 and have the pet summoned for the ceremony ...");
  2372.  
  2373. replyMSG.append("</body></html>");
  2374.  
  2375.  
  2376.  
  2377. adminReply.setHtml(replyMSG.moveToString());
  2378.  
  2379. player.sendPacket(adminReply);
  2380.  
  2381. }
  2382.  
  2383. }
  2384.  
  2385. }
  2386.  
  2387. else if (command.equalsIgnoreCase("TerritoryStatus"))
  2388.  
  2389. {
  2390.  
  2391. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2392.  
  2393. {
  2394.  
  2395. if (getCastle().getOwnerId() > 0)
  2396.  
  2397. {
  2398.  
  2399. html.setFile("data/html/territorystatus.htm");
  2400.  
  2401. L2Clan clan = ClanTable.getInstance().getClan(getCastle().getOwnerId());
  2402.  
  2403. html.replace("%clanname%", clan.getName());
  2404.  
  2405. html.replace("%clanleadername%", clan.getLeaderName());
  2406.  
  2407. }
  2408.  
  2409. else
  2410.  
  2411. {
  2412.  
  2413. html.setFile("data/html/territorynoclan.htm");
  2414.  
  2415. }
  2416.  
  2417. }
  2418.  
  2419. html.replace("%castlename%", getCastle().getName());
  2420.  
  2421. html.replace("%taxpercent%", "" + getCastle().getTaxPercent());
  2422.  
  2423. html.replace("%objectId%", String.valueOf(getObjectId()));
  2424.  
  2425. {
  2426.  
  2427. if (getCastle().getCastleId() > 6)
  2428.  
  2429. {
  2430.  
  2431. html.replace("%territory%", "The Kingdom of Elmore");
  2432.  
  2433. }
  2434.  
  2435. else
  2436.  
  2437. {
  2438.  
  2439. html.replace("%territory%", "The Kingdom of Aden");
  2440.  
  2441. }
  2442.  
  2443. }
  2444.  
  2445. player.sendPacket(html);
  2446.  
  2447. }
  2448.  
  2449. else if (command.startsWith("Quest"))
  2450.  
  2451. {
  2452.  
  2453. String quest = "";
  2454.  
  2455. try
  2456.  
  2457. {
  2458.  
  2459. quest = command.substring(5).trim();
  2460.  
  2461. }
  2462.  
  2463. catch (IndexOutOfBoundsException ioobe)
  2464.  
  2465. {
  2466.  
  2467. }
  2468.  
  2469.  
  2470.  
  2471. if (quest.length() == 0)
  2472.  
  2473. showQuestWindow(player);
  2474.  
  2475. else
  2476.  
  2477. showQuestWindow(player, quest);
  2478.  
  2479. }
  2480.  
  2481. else if (command.startsWith("Chat"))
  2482.  
  2483. {
  2484.  
  2485. int val = 0;
  2486.  
  2487. try
  2488.  
  2489. {
  2490.  
  2491. val = Integer.parseInt(command.substring(5));
  2492.  
  2493. }
  2494.  
  2495. catch (IndexOutOfBoundsException ioobe)
  2496.  
  2497. {
  2498.  
  2499. }
  2500.  
  2501. catch (NumberFormatException nfe)
  2502.  
  2503. {
  2504.  
  2505. }
  2506.  
  2507. showChatWindow(player, val);
  2508.  
  2509. }
  2510.  
  2511. else if (command.startsWith("Link"))
  2512.  
  2513. {
  2514.  
  2515. String path = command.substring(5).trim();
  2516.  
  2517. if (path.indexOf("..") != -1)
  2518.  
  2519. return;
  2520.  
  2521. String filename = "data/html/" + path;
  2522.  
  2523. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2524.  
  2525. html.setFile(filename);
  2526.  
  2527. html.replace("%objectId%", String.valueOf(getObjectId()));
  2528.  
  2529. player.sendPacket(html);
  2530.  
  2531. }
  2532.  
  2533. else if (command.startsWith("NobleTeleport"))
  2534.  
  2535. {
  2536.  
  2537. if (!player.isNoble())
  2538.  
  2539. {
  2540.  
  2541. String filename = "data/html/teleporter/nobleteleporter-no.htm";
  2542.  
  2543. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2544.  
  2545. html.setFile(filename);
  2546.  
  2547. html.replace("%objectId%", String.valueOf(getObjectId()));
  2548.  
  2549. html.replace("%npcname%", getName());
  2550.  
  2551. player.sendPacket(html);
  2552.  
  2553. return;
  2554.  
  2555. }
  2556.  
  2557. int val = 0;
  2558.  
  2559. try
  2560.  
  2561. {
  2562.  
  2563. val = Integer.parseInt(command.substring(5));
  2564.  
  2565. }
  2566.  
  2567. catch (IndexOutOfBoundsException ioobe)
  2568.  
  2569. {
  2570.  
  2571. }
  2572.  
  2573. catch (NumberFormatException nfe)
  2574.  
  2575. {
  2576.  
  2577. }
  2578.  
  2579. showChatWindow(player, val);
  2580.  
  2581. }
  2582.  
  2583. else if (command.startsWith("Loto"))
  2584.  
  2585. {
  2586.  
  2587. int val = 0;
  2588.  
  2589. try
  2590.  
  2591. {
  2592.  
  2593. val = Integer.parseInt(command.substring(5));
  2594.  
  2595. }
  2596.  
  2597. catch (IndexOutOfBoundsException ioobe)
  2598.  
  2599. {
  2600.  
  2601. }
  2602.  
  2603. catch (NumberFormatException nfe)
  2604.  
  2605. {
  2606.  
  2607. }
  2608.  
  2609. if (val == 0)
  2610.  
  2611. {
  2612.  
  2613. // new loto ticket
  2614.  
  2615. for (int i = 0; i < 5; i++)
  2616.  
  2617. player.setLoto(i, 0);
  2618.  
  2619. }
  2620.  
  2621. showLotoWindow(player, val);
  2622.  
  2623. }
  2624.  
  2625. else if (command.startsWith("CPRecovery"))
  2626.  
  2627. {
  2628.  
  2629. makeCPRecovery(player);
  2630.  
  2631. }
  2632.  
  2633. else if (command.startsWith("SupportMagic"))
  2634.  
  2635. {
  2636.  
  2637. makeSupportMagic(player, command);
  2638.  
  2639. }
  2640.  
  2641. else if (command.startsWith("GiveBlessing"))
  2642.  
  2643. {
  2644.  
  2645. giveBlessingSupport(player);
  2646.  
  2647. }
  2648.  
  2649. else if (command.startsWith("multisell"))
  2650.  
  2651. {
  2652.  
  2653. int listId = Integer.parseInt(command.substring(9).trim());
  2654.  
  2655. L2Multisell.getInstance().separateAndSend(listId, player, getNpcId(), false, getCastle().getTaxRate());
  2656.  
  2657. }
  2658.  
  2659. else if (command.startsWith("exc_multisell"))
  2660.  
  2661. {
  2662.  
  2663. int listId = Integer.parseInt(command.substring(13).trim());
  2664.  
  2665. L2Multisell.getInstance().separateAndSend(listId, player, getNpcId(), true, getCastle().getTaxRate());
  2666.  
  2667. }
  2668.  
  2669. else if (command.startsWith("Augment"))
  2670.  
  2671. {
  2672.  
  2673. int cmdChoice = Integer.parseInt(command.substring(8, 9).trim());
  2674.  
  2675. switch (cmdChoice)
  2676.  
  2677. {
  2678.  
  2679. case 1:
  2680.  
  2681. player.sendPacket(SystemMessageId.SELECT_THE_ITEM_TO_BE_AUGMENTED);
  2682.  
  2683. player.sendPacket(new ExShowVariationMakeWindow());
  2684.  
  2685. break;
  2686.  
  2687. case 2:
  2688.  
  2689. player.sendPacket(SystemMessageId.SELECT_THE_ITEM_FROM_WHICH_YOU_WISH_TO_REMOVE_AUGMENTATION);
  2690.  
  2691. player.sendPacket(new ExShowVariationCancelWindow());
  2692.  
  2693. break;
  2694.  
  2695. }
  2696.  
  2697. }
  2698.  
  2699. else if (command.startsWith("npcfind_byid"))
  2700.  
  2701. {
  2702.  
  2703. try
  2704.  
  2705. {
  2706.  
  2707. L2Spawn spawn = SpawnTable.getInstance().getTemplate(Integer.parseInt(command.substring(12).trim()));
  2708.  
  2709. if (spawn != null)
  2710.  
  2711. {
  2712.  
  2713. player.sendPacket(new RadarControl(2, 2, spawn.getLocx(), spawn.getLocy(), spawn.getLocz()));
  2714.  
  2715. player.sendPacket(new RadarControl(0, 1, spawn.getLocx(), spawn.getLocy(), spawn.getLocz()));
  2716.  
  2717. }
  2718.  
  2719. else
  2720.  
  2721. {
  2722.  
  2723. player.sendMessage("Boss not implemented yet");
  2724.  
  2725. }
  2726.  
  2727. }
  2728.  
  2729. catch (NumberFormatException nfe)
  2730.  
  2731. {
  2732.  
  2733. player.sendMessage("Wrong command parameters");
  2734.  
  2735. }
  2736.  
  2737. }
  2738.  
  2739. else if (command.startsWith("EnterRift"))
  2740.  
  2741. {
  2742.  
  2743. try
  2744.  
  2745. {
  2746.  
  2747. Byte b1 = Byte.parseByte(command.substring(10)); // Selected Area: Recruit, Soldier etc
  2748.  
  2749. DimensionalRiftManager.getInstance().start(player, b1, this);
  2750.  
  2751. }
  2752.  
  2753. catch (Exception e)
  2754.  
  2755. {
  2756.  
  2757. _log.warn("", e);
  2758.  
  2759. }
  2760.  
  2761. }
  2762.  
  2763. else if (command.startsWith("ChangeRiftRoom"))
  2764.  
  2765. {
  2766.  
  2767. if (player.isInParty() && player.getParty().isInDimensionalRift())
  2768.  
  2769. {
  2770.  
  2771. player.getParty().getDimensionalRift().manualTeleport(player, this);
  2772.  
  2773. }
  2774.  
  2775. else
  2776.  
  2777. {
  2778.  
  2779. DimensionalRiftManager.getInstance().handleCheat(player, this);
  2780.  
  2781. }
  2782.  
  2783. }
  2784.  
  2785. else if (command.startsWith("ExitRift"))
  2786.  
  2787. {
  2788.  
  2789. if (player.isInParty() && player.getParty().isInDimensionalRift())
  2790.  
  2791. {
  2792.  
  2793. player.getParty().getDimensionalRift().manualExitRift(player, this);
  2794.  
  2795. }
  2796.  
  2797. else
  2798.  
  2799. {
  2800.  
  2801. DimensionalRiftManager.getInstance().handleCheat(player, this);
  2802.  
  2803. }
  2804.  
  2805. }
  2806.  
  2807. else if (command.equals("questlist"))
  2808.  
  2809. {
  2810.  
  2811. player.sendPacket(ExShowQuestInfo.PACKET);
  2812.  
  2813. }
  2814.  
  2815. else if (command.startsWith("MakeBuffs"))
  2816.  
  2817. {
  2818.  
  2819. makeBuffs(player, command.substring(9).trim());
  2820.  
  2821. }
  2822.  
  2823. else if (command.equalsIgnoreCase("exchange"))
  2824.  
  2825. {
  2826.  
  2827. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2828.  
  2829. html.setFile("data/html/merchant/exchange.htm");
  2830.  
  2831. html.replace("%objectId%", String.valueOf(getObjectId()));
  2832.  
  2833. player.sendPacket(html);
  2834.  
  2835. }
  2836.  
  2837. else if (command.equals("ReleaseAttribute"))
  2838.  
  2839. {
  2840.  
  2841. player.sendPacket(new ExShowBaseAttributeCancelWindow(player));
  2842.  
  2843. }
  2844.  
  2845. // [L2J_JP ADD START]
  2846.  
  2847. else if (command.startsWith("open_gate"))
  2848.  
  2849. {
  2850.  
  2851. final DoorTable _doorTable = DoorTable.getInstance();
  2852.  
  2853. int doorId;
  2854.  
  2855.  
  2856.  
  2857. StringTokenizer st = new StringTokenizer(command.substring(10), ", ");
  2858.  
  2859.  
  2860.  
  2861. while (st.hasMoreTokens())
  2862.  
  2863. {
  2864.  
  2865. doorId = Integer.parseInt(st.nextToken());
  2866.  
  2867.  
  2868.  
  2869. if (_doorTable.getDoor(doorId) != null) {
  2870.  
  2871. _doorTable.getDoor(doorId).openMe();
  2872.  
  2873. _doorTable.getDoor(doorId).onOpen();
  2874.  
  2875. } else {
  2876.  
  2877. _log.warn("Door Id does not exist.(" + doorId + ")");
  2878.  
  2879. }
  2880.  
  2881. }
  2882.  
  2883. return;
  2884.  
  2885. }
  2886.  
  2887. else if (command.equalsIgnoreCase("wake_baium"))
  2888.  
  2889. {
  2890.  
  2891. setTarget(player);
  2892.  
  2893. BaiumManager.getInstance().spawnBaium(this);
  2894.  
  2895. }
  2896.  
  2897. // [L2J_JP ADD END]
  2898.  
  2899. else if (command.startsWith("remove_dp"))
  2900.  
  2901. {
  2902.  
  2903. int cmdChoice = Integer.parseInt(command.substring(10, 11).trim());
  2904.  
  2905. int[] pen_clear_price = { 3600, 8640, 25200, 50400, 86400, 144000, 144000, 144000 };
  2906.  
  2907. int price = pen_clear_price[player.getExpertiseIndex()] * (int)Config.RATE_DROP_ADENA;
  2908.  
  2909. switch (cmdChoice)
  2910.  
  2911. {
  2912.  
  2913. case 1:
  2914.  
  2915. String filename = "data/html/default/30981-1.htm";
  2916.  
  2917. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2918.  
  2919. html.setFile(filename);
  2920.  
  2921. html.replace("%objectId%", String.valueOf(getObjectId()));
  2922.  
  2923. html.replace("%dp_price%", String.valueOf(price));
  2924.  
  2925. player.sendPacket(html);
  2926.  
  2927. break;
  2928.  
  2929. case 2:
  2930.  
  2931. NpcHtmlMessage Reply = new NpcHtmlMessage(getObjectId());
  2932.  
  2933. L2TextBuilder replyMSG = L2TextBuilder.newInstance("<html><body>Black Judge:<br>");
  2934.  
  2935.  
  2936.  
  2937. if (player.getDeathPenaltyBuffLevel() > 0)
  2938.  
  2939. {
  2940.  
  2941. if (player.getAdena() >= price)
  2942.  
  2943. {
  2944.  
  2945. if (!player.reduceAdena("DeathPenality", price, this, true))
  2946.  
  2947. return;
  2948.  
  2949. player.setDeathPenaltyBuffLevel(player.getDeathPenaltyBuffLevel() - 1);
  2950.  
  2951. player.sendPacket(SystemMessageId.DEATH_PENALTY_LIFTED);
  2952.  
  2953. player.sendEtcStatusUpdate();
  2954.  
  2955. return;
  2956.  
  2957. }
  2958.  
  2959.  
  2960.  
  2961. replyMSG.append("The wound you have received from death's touch is too deep to be healed for the money you have to give me. Find more money if you wish death's mark to be fully removed from you.");
  2962.  
  2963. }
  2964.  
  2965. else
  2966.  
  2967. {
  2968.  
  2969. replyMSG.append("You have no more death wounds that require healing.<br>");
  2970.  
  2971. replyMSG.append("Go forth and fight, both for this world and your own glory.");
  2972.  
  2973. }
  2974.  
  2975.  
  2976.  
  2977. replyMSG.append("</body></html>");
  2978.  
  2979. Reply.setHtml(replyMSG.moveToString());
  2980.  
  2981. player.sendPacket(Reply);
  2982.  
  2983. break;
  2984.  
  2985. }
  2986.  
  2987. }
  2988.  
  2989. else if (command.startsWith("arena_info"))
  2990.  
  2991. {
  2992.  
  2993. NpcHtmlMessage htm = new NpcHtmlMessage(getObjectId());
  2994.  
  2995. htm.setHtml(ArenaManager.getInstance().showHtm(player.getObjectId()));
  2996.  
  2997. player.sendPacket(htm);
  2998.  
  2999. }
  3000.  
  3001. else if (command.startsWith("fisherman_info"))
  3002.  
  3003. {
  3004.  
  3005. NpcHtmlMessage htm = new NpcHtmlMessage(getObjectId());
  3006.  
  3007. htm.setHtml(FishermanManager.getInstance().showHtm(player.getObjectId()));
  3008.  
  3009. player.sendPacket(htm);
  3010.  
  3011. }
  3012.  
  3013.  
  3014.  
  3015. }
  3016.  
  3017. player.sendPacket(ActionFailed.STATIC_PACKET);
  3018.  
  3019. }
  3020.  
  3021.  
  3022.  
  3023. /**
  3024.  
  3025. * Cast buffs on player, this function ignore target type
  3026.  
  3027. * only buff effects are aplied to player
  3028.  
  3029. *
  3030.  
  3031. * @param player Target player
  3032.  
  3033. * @param buffTemplate Name of buff template
  3034.  
  3035. */
  3036.  
  3037. public void makeBuffs(L2PcInstance player, String buffTemplate)
  3038.  
  3039. {
  3040.  
  3041. int _templateId = 0;
  3042.  
  3043.  
  3044.  
  3045. try
  3046.  
  3047. {
  3048.  
  3049. _templateId = Integer.parseInt(buffTemplate);
  3050.  
  3051. }
  3052.  
  3053. catch (NumberFormatException e)
  3054.  
  3055. {
  3056.  
  3057. _templateId = BuffTemplateTable.getInstance().getTemplateIdByName(buffTemplate);
  3058.  
  3059. }
  3060.  
  3061.  
  3062.  
  3063. if (_templateId > 0)
  3064.  
  3065. makeBuffs(player, _templateId, false);
  3066.  
  3067. }
  3068.  
  3069.  
  3070.  
  3071. /**
  3072.  
  3073. * Cast buffs on player/servitor, this function ignore target type
  3074.  
  3075. * only buff effects are aplied to player/servitor
  3076.  
  3077. *
  3078.  
  3079. * @param player Target player/servitor owner
  3080.  
  3081. * @param _templateId Id of buff template
  3082.  
  3083. */
  3084.  
  3085. public void makeBuffs(L2PcInstance player, int _templateId, boolean servitor)
  3086.  
  3087. {
  3088.  
  3089. if (player == null)
  3090.  
  3091. return;
  3092.  
  3093.  
  3094.  
  3095. FastList<L2BuffTemplate> _templateBuffs = BuffTemplateTable.getInstance().getBuffTemplate(_templateId);
  3096.  
  3097.  
  3098.  
  3099. if (_templateBuffs == null || _templateBuffs.size() == 0)
  3100.  
  3101. return;
  3102.  
  3103.  
  3104.  
  3105. L2Playable receiver = (servitor ? player.getPet() : player);
  3106.  
  3107. setTarget(receiver);
  3108.  
  3109.  
  3110.  
  3111. int _priceTotal = 0;
  3112.  
  3113. //TODO: add faction points support (evil33t, im waiting for you ^^ )
  3114.  
  3115. //TODO: add more options for player condition, like: pk, ssq winner/looser...etc
  3116.  
  3117. //TODO: add ancient adena price
  3118.  
  3119. //TODO: add autobuff tasks for npc (with options range,ignorePrice,showCast)
  3120.  
  3121. //TODO: add buff template striction to specified npc ids, merchants like
  3122.  
  3123. for (L2BuffTemplate _buff : _templateBuffs)
  3124.  
  3125. {
  3126.  
  3127. if (_buff.checkPlayer(player) && _buff.checkPrice(player))
  3128.  
  3129. {
  3130.  
  3131. if (player.getInventory().getAdena() >= (_priceTotal + _buff.getAdenaPrice()))
  3132.  
  3133. {
  3134.  
  3135. _priceTotal += _buff.getAdenaPrice();
  3136.  
  3137.  
  3138.  
  3139. if (_buff.forceCast() || receiver.getFirstEffect(_buff.getSkill()) == null)
  3140.  
  3141. {
  3142.  
  3143. // regeneration ^^
  3144.  
  3145. getStatus().setCurrentHpMp(getMaxHp(), getMaxMp());
  3146.  
  3147.  
  3148.  
  3149. // yes, its not for all skills right, but atleast player will know
  3150.  
  3151. // for what he paid =)
  3152.  
  3153. if (_templateId != 1 && !servitor)
  3154.  
  3155. {
  3156.  
  3157. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  3158.  
  3159. sm.addSkillName(_buff.getSkill().getId());
  3160.  
  3161. player.sendPacket(sm);
  3162.  
  3163. }
  3164.  
  3165.  
  3166.  
  3167. // hack for newbie summons
  3168.  
  3169. if (_buff.getSkill().getSkillType() == L2SkillType.SUMMON)
  3170.  
  3171. {
  3172.  
  3173. player.doSimultaneousCast(_buff.getSkill());
  3174.  
  3175. }
  3176.  
  3177. else
  3178.  
  3179. { // Ignore skill cast time, using 100ms for NPC buffer's animation
  3180.  
  3181. MagicSkillUse msu = new MagicSkillUse(this, receiver, _buff.getSkill().getId(), _buff.getSkill().getLevel(), 100, 0);
  3182.  
  3183. broadcastPacket(msu);
  3184.  
  3185. _buff.getSkill().getEffects(this, receiver);
  3186.  
  3187. }
  3188.  
  3189. }
  3190.  
  3191. }
  3192.  
  3193. }
  3194.  
  3195. }
  3196.  
  3197. player.reduceAdena("NpcBuffer", _priceTotal, player.getLastFolkNPC(), true);
  3198.  
  3199. }
  3200.  
  3201.  
  3202.  
  3203. /**
  3204.  
  3205. * Return null (regular NPCs don't have weapons instancies).<BR><BR>
  3206.  
  3207. */
  3208.  
  3209. @Override
  3210.  
  3211. public L2ItemInstance getActiveWeaponInstance()
  3212.  
  3213. {
  3214.  
  3215. // Regular NPCs dont have weapons instancies
  3216.  
  3217. return null;
  3218.  
  3219. }
  3220.  
  3221.  
  3222.  
  3223. /**
  3224.  
  3225. * Return the weapon item equiped in the right hand of the L2Npc or null.<BR><BR>
  3226.  
  3227. */
  3228.  
  3229. @Override
  3230.  
  3231. public L2Weapon getActiveWeaponItem()
  3232.  
  3233. {
  3234.  
  3235. // Get the weapon identifier equiped in the right hand of the L2Npc
  3236.  
  3237. int weaponId = getTemplate().getRhand();
  3238.  
  3239.  
  3240.  
  3241. if (weaponId < 1)
  3242.  
  3243. return null;
  3244.  
  3245.  
  3246.  
  3247. // Get the weapon item equiped in the right hand of the L2Npc
  3248.  
  3249. L2Item item = ItemTable.getInstance().getTemplate(getTemplate().getRhand());
  3250.  
  3251.  
  3252.  
  3253. if (!(item instanceof L2Weapon))
  3254.  
  3255. return null;
  3256.  
  3257.  
  3258.  
  3259. return (L2Weapon) item;
  3260.  
  3261. }
  3262.  
  3263.  
  3264.  
  3265. /**
  3266.  
  3267. * Return null (regular NPCs don't have weapons instancies).<BR><BR>
  3268.  
  3269. */
  3270.  
  3271. @Override
  3272.  
  3273. public L2ItemInstance getSecondaryWeaponInstance()
  3274.  
  3275. {
  3276.  
  3277. // Regular NPCs dont have weapons instancies
  3278.  
  3279. return null;
  3280.  
  3281. }
  3282.  
  3283.  
  3284.  
  3285. /**
  3286.  
  3287. * Return the weapon item equiped in the left hand of the L2Npc or null.<BR><BR>
  3288.  
  3289. */
  3290.  
  3291. @Override
  3292.  
  3293. public L2Weapon getSecondaryWeaponItem()
  3294.  
  3295. {
  3296.  
  3297. // Get the weapon identifier equiped in the right hand of the L2Npc
  3298.  
  3299. int weaponId = getTemplate().getLhand();
  3300.  
  3301.  
  3302.  
  3303. if (weaponId < 1)
  3304.  
  3305. return null;
  3306.  
  3307.  
  3308.  
  3309. // Get the weapon item equiped in the right hand of the L2Npc
  3310.  
  3311. L2Item item = ItemTable.getInstance().getTemplate(getTemplate().getLhand());
  3312.  
  3313.  
  3314.  
  3315. if (!(item instanceof L2Weapon))
  3316.  
  3317. return null;
  3318.  
  3319.  
  3320.  
  3321. return (L2Weapon) item;
  3322.  
  3323. }
  3324.  
  3325.  
  3326.  
  3327. /**
  3328.  
  3329. * Send a Server->Client packet NpcHtmlMessage to the L2PcInstance in order to display the message of the L2Npc.<BR><BR>
  3330.  
  3331. *
  3332.  
  3333. * @param player The L2PcInstance who talks with the L2Npc
  3334.  
  3335. * @param content The text of the L2NpcMessage
  3336.  
  3337. *
  3338.  
  3339. */
  3340.  
  3341. public void insertObjectIdAndShowChatWindow(L2PcInstance player, String content)
  3342.  
  3343. {
  3344.  
  3345. // Send a Server->Client packet NpcHtmlMessage to the L2PcInstance in order to display the message of the L2Npc
  3346.  
  3347. content = content.replaceAll("%objectId%", String.valueOf(getObjectId()));
  3348.  
  3349. NpcHtmlMessage npcReply = new NpcHtmlMessage(getObjectId());
  3350.  
  3351. npcReply.setHtml(content);
  3352.  
  3353. player.sendPacket(npcReply);
  3354.  
  3355. }
  3356.  
  3357.  
  3358.  
  3359. /**
  3360.  
  3361. * Return the pathfile of the selected HTML file in function of the npcId and of the page number.<BR><BR>
  3362.  
  3363. *
  3364.  
  3365. * <B><U> Format of the pathfile </U> :</B><BR><BR>
  3366.  
  3367. * <li> if the file exists on the server (page number = 0) : <B>data/html/default/12006.htm</B> (npcId-page number)</li>
  3368.  
  3369. * <li> if the file exists on the server (page number > 0) : <B>data/html/default/12006-1.htm</B> (npcId-page number)</li>
  3370.  
  3371. * <li> if the file doesn't exist on the server : <B>data/html/npcdefault.htm</B> (message : "I have nothing to say to you")</li><BR><BR>
  3372.  
  3373. *
  3374.  
  3375. * <B><U> Overridden in </U> :</B><BR><BR>
  3376.  
  3377. * <li> L2GuardInstance : Set the pathfile to data/html/guard/12006-1.htm (npcId-page number)</li><BR><BR>
  3378.  
  3379. *
  3380.  
  3381. * @param npcId The Identifier of the L2Npc whose text must be display
  3382.  
  3383. * @param val The number of the page to display
  3384.  
  3385. *
  3386.  
  3387. */
  3388.  
  3389. public String getHtmlPath(int npcId, int val)
  3390.  
  3391. {
  3392.  
  3393. String pom = String.valueOf(npcId);
  3394.  
  3395.  
  3396.  
  3397. if (val != 0)
  3398.  
  3399. pom += "-" + val;
  3400.  
  3401.  
  3402.  
  3403. String temp = "data/html/default/" + pom + ".htm";
  3404.  
  3405.  
  3406.  
  3407. if (HtmCache.getInstance().pathExists(temp))
  3408.  
  3409. return temp;
  3410.  
  3411.  
  3412.  
  3413. // If the file is not found, the standard message "I have nothing to say to you" is returned
  3414.  
  3415. return "data/html/npcdefault.htm";
  3416.  
  3417. }
  3418.  
  3419.  
  3420.  
  3421. /**
  3422.  
  3423. * Open a choose quest window on client with all quests available of the L2Npc.<BR><BR>
  3424.  
  3425. *
  3426.  
  3427. * <B><U> Actions</U> :</B><BR><BR>
  3428.  
  3429. * <li>Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance </li><BR><BR>
  3430.  
  3431. *
  3432.  
  3433. * @param player The L2PcInstance that talk with the L2Npc
  3434.  
  3435. * @param quests The table containing quests of the L2Npc
  3436.  
  3437. *
  3438.  
  3439. */
  3440.  
  3441. public void showQuestChooseWindow(L2PcInstance player, Quest[] quests)
  3442.  
  3443. {
  3444.  
  3445. L2TextBuilder sb = L2TextBuilder.newInstance();
  3446.  
  3447. sb.append("<html><body>");
  3448.  
  3449. for (Quest q : quests)
  3450.  
  3451. {
  3452.  
  3453. sb.append("<a action=\"bypass -h npc_").append(getObjectId()).append("_Quest ").append(q.getName()).append("\"> [").append(q.getDescr());
  3454.  
  3455.  
  3456.  
  3457. QuestState qs = player.getQuestState(q.getScriptName());
  3458.  
  3459. if (qs != null)
  3460.  
  3461. {
  3462.  
  3463. if (qs.getState() == State.STARTED && qs.getInt("cond") > 0)
  3464.  
  3465. sb.append(" (In Progress)");
  3466.  
  3467. else if (qs.getState() == State.COMPLETED)
  3468.  
  3469. sb.append(" (Done)");
  3470.  
  3471. }
  3472.  
  3473. sb.append("]</a><br>");
  3474.  
  3475. }
  3476.  
  3477.  
  3478.  
  3479. sb.append("</body></html>");
  3480.  
  3481.  
  3482.  
  3483. // Send a Server->Client packet NpcHtmlMessage to the L2PcInstance in order to display the message of the L2Npc
  3484.  
  3485. insertObjectIdAndShowChatWindow(player, sb.moveToString());
  3486.  
  3487. }
  3488.  
  3489.  
  3490.  
  3491. /**
  3492.  
  3493. * Open a quest window on client with the text of the L2Npc.<BR><BR>
  3494.  
  3495. *
  3496.  
  3497. * <B><U> Actions</U> :</B><BR><BR>
  3498.  
  3499. * <li>Get the text of the quest state in the folder data/scripts/quests/questId/stateId.htm </li>
  3500.  
  3501. * <li>Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance </li>
  3502.  
  3503. * <li>Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet </li><BR><BR>
  3504.  
  3505. *
  3506.  
  3507. * @param player The L2PcInstance that talk with the L2Npc
  3508.  
  3509. * @param questId The Identifier of the quest to display the message
  3510.  
  3511. *
  3512.  
  3513. */
  3514.  
  3515. public void showQuestWindow(L2PcInstance player, String questId)
  3516.  
  3517. {
  3518.  
  3519. String content = null;
  3520.  
  3521.  
  3522.  
  3523. Quest q = QuestManager.getInstance().getQuest(questId);
  3524.  
  3525.  
  3526.  
  3527. // Get the state of the selected quest
  3528.  
  3529. QuestState qs = player.getQuestState(questId);
  3530.  
  3531.  
  3532.  
  3533. if (q == null)
  3534.  
  3535. {
  3536.  
  3537. // No quests found
  3538.  
  3539. content = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>";
  3540.  
  3541. }
  3542.  
  3543. else
  3544.  
  3545. {
  3546.  
  3547. if ((q.getQuestIntId() >= 1 && q.getQuestIntId() < 20000)
  3548.  
  3549. && (player.getWeightPenalty() >= 3 || player.getInventoryLimit() * 0.8 <= player.getInventory().getSize()))
  3550.  
  3551. {
  3552.  
  3553. player.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
  3554.  
  3555. return;
  3556.  
  3557. }
  3558.  
  3559.  
  3560.  
  3561. if (qs == null)
  3562.  
  3563. {
  3564.  
  3565. if (q.getQuestIntId() >= 1 && q.getQuestIntId() < 20000)
  3566.  
  3567. {
  3568.  
  3569. Quest[] questList = player.getAllActiveQuests();
  3570.  
  3571. if (questList.length >= 25) // if too many ongoing quests, don't show window and send message
  3572.  
  3573. {
  3574.  
  3575. player.sendPacket(SystemMessageId.TOO_MANY_QUESTS);
  3576.  
  3577. return;
  3578.  
  3579. }
  3580.  
  3581. }
  3582.  
  3583. // Check for start point
  3584.  
  3585. Quest[] qlst = getTemplate().getEventQuests(Quest.QuestEventType.QUEST_START);
  3586.  
  3587.  
  3588.  
  3589. if (qlst != null && qlst.length > 0)
  3590.  
  3591. {
  3592.  
  3593. for (Quest temp: qlst)
  3594.  
  3595. {
  3596.  
  3597. if (temp == q)
  3598.  
  3599. {
  3600.  
  3601. qs = q.newQuestState(player);
  3602.  
  3603. break;
  3604.  
  3605. }
  3606.  
  3607. }
  3608.  
  3609. }
  3610.  
  3611. }
  3612.  
  3613. }
  3614.  
  3615.  
  3616.  
  3617. if (qs != null)
  3618.  
  3619. {
  3620.  
  3621. // If the quest is alreday started, no need to show a window
  3622.  
  3623. if (!qs.getQuest().notifyTalk(this, qs))
  3624.  
  3625. return;
  3626.  
  3627.  
  3628.  
  3629. questId = qs.getQuest().getName();
  3630.  
  3631. String stateId = State.getStateName(qs.getState());
  3632.  
  3633. String path = "data/scripts/quests/" + questId + "/" + stateId + ".htm";
  3634.  
  3635. content = HtmCache.getInstance().getHtm(path);
  3636.  
  3637.  
  3638.  
  3639. if (_log.isDebugEnabled())
  3640.  
  3641. {
  3642.  
  3643. if (content != null)
  3644.  
  3645. {
  3646.  
  3647. _log.debug("Showing quest window for quest " + questId + " html path: " + path);
  3648.  
  3649. }
  3650.  
  3651. else
  3652.  
  3653. {
  3654.  
  3655. _log.debug("File not exists for quest " + questId + " html path: " + path);
  3656.  
  3657. }
  3658.  
  3659. }
  3660.  
  3661. }
  3662.  
  3663.  
  3664.  
  3665. // Send a Server->Client packet NpcHtmlMessage to the L2PcInstance in order to display the message of the L2Npc
  3666.  
  3667. if (content != null)
  3668.  
  3669. insertObjectIdAndShowChatWindow(player, content);
  3670.  
  3671.  
  3672.  
  3673. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  3674.  
  3675. player.sendPacket(ActionFailed.STATIC_PACKET);
  3676.  
  3677. }
  3678.  
  3679.  
  3680.  
  3681. /**
  3682.  
  3683. * Collect awaiting quests/start points and display a QuestChooseWindow (if several available) or QuestWindow.<BR><BR>
  3684.  
  3685. *
  3686.  
  3687. * @param player The L2PcInstance that talk with the L2Npc
  3688.  
  3689. *
  3690.  
  3691. */
  3692.  
  3693. public void showQuestWindow(L2PcInstance player)
  3694.  
  3695. {
  3696.  
  3697. // Collect awaiting quests and start points
  3698.  
  3699. FastList<Quest> options = new FastList<Quest>();
  3700.  
  3701.  
  3702.  
  3703. QuestState[] awaits = player.getQuestsForTalk(getTemplate().getNpcId());
  3704.  
  3705. Quest[] starts = getTemplate().getEventQuests(Quest.QuestEventType.QUEST_START);
  3706.  
  3707.  
  3708.  
  3709. // Quests are limited between 1 and 999 because those are the quests that are supported by the client.
  3710.  
  3711. // By limitting them there, we are allowed to create custom quests at higher IDs without interfering
  3712.  
  3713. if (awaits != null)
  3714.  
  3715. {
  3716.  
  3717. for (QuestState x : awaits)
  3718.  
  3719. {
  3720.  
  3721. if (!options.contains(x.getQuest()))
  3722.  
  3723. if ((x.getQuest().getQuestIntId() > 0) && (x.getQuest().getQuestIntId() < 20000))
  3724.  
  3725. options.add(x.getQuest());
  3726.  
  3727. }
  3728.  
  3729. }
  3730.  
  3731.  
  3732.  
  3733. if (starts != null)
  3734.  
  3735. {
  3736.  
  3737. for (Quest x : starts)
  3738.  
  3739. {
  3740.  
  3741. if (!options.contains(x))
  3742.  
  3743. if ((x.getQuestIntId() > 0) && (x.getQuestIntId() < 20000))
  3744.  
  3745. options.add(x);
  3746.  
  3747. }
  3748.  
  3749. }
  3750.  
  3751.  
  3752.  
  3753. // Display a QuestChooseWindow (if several quests are available) or QuestWindow
  3754.  
  3755. if (options.size() > 1)
  3756.  
  3757. {
  3758.  
  3759. showQuestChooseWindow(player, options.toArray(new Quest[options.size()]));
  3760.  
  3761. }
  3762.  
  3763. else if (options.size() == 1)
  3764.  
  3765. {
  3766.  
  3767. showQuestWindow(player, options.get(0).getName());
  3768.  
  3769. }
  3770.  
  3771. else
  3772.  
  3773. {
  3774.  
  3775. showQuestWindow(player, "");
  3776.  
  3777. }
  3778.  
  3779. }
  3780.  
  3781.  
  3782.  
  3783. /**
  3784.  
  3785. * Open a Loto window on client with the text of the L2Npc.<BR><BR>
  3786.  
  3787. *
  3788.  
  3789. * <B><U> Actions</U> :</B><BR><BR>
  3790.  
  3791. * <li>Get the text of the selected HTML file in function of the npcId and of the page number </li>
  3792.  
  3793. * <li>Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance </li>
  3794.  
  3795. * <li>Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet </li><BR>
  3796.  
  3797. *
  3798.  
  3799. * @param player The L2PcInstance that talk with the L2Npc
  3800.  
  3801. * @param val The number of the page of the L2Npc to display
  3802.  
  3803. *
  3804.  
  3805. */
  3806.  
  3807. /**
  3808.  
  3809. * Open a Loto window on client with the text of the L2Npc.<BR><BR>
  3810.  
  3811. *
  3812.  
  3813. * <B><U> Actions</U> :</B><BR><BR>
  3814.  
  3815. * <li>Get the text of the selected HTML file in function of the npcId and of the page number </li>
  3816.  
  3817. * <li>Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance </li>
  3818.  
  3819. * <li>Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet </li><BR>
  3820.  
  3821. *
  3822.  
  3823. * @param player The L2PcInstance that talk with the L2Npc
  3824.  
  3825. * @param val The number of the page of the L2Npc to display
  3826.  
  3827. *
  3828.  
  3829. */
  3830.  
  3831. // -1 - lottery instructions
  3832.  
  3833. // 0 - first buy lottery ticket window
  3834.  
  3835. // 1-20 - buttons
  3836.  
  3837. // 21 - second buy lottery ticket window
  3838.  
  3839. // 22 - selected ticket with 5 numbers
  3840.  
  3841. // 23 - current lottery jackpot
  3842.  
  3843. // 24 - Previous winning numbers/Prize claim
  3844.  
  3845. // >24 - check lottery ticket by item object id
  3846.  
  3847. public void showLotoWindow(L2PcInstance player, int val)
  3848.  
  3849. {
  3850.  
  3851. int npcId = getTemplate().getNpcId();
  3852.  
  3853. String filename;
  3854.  
  3855. SystemMessage sm;
  3856.  
  3857. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  3858.  
  3859.  
  3860.  
  3861. if (val == 0) // 0 - first buy lottery ticket window
  3862.  
  3863. {
  3864.  
  3865. filename = (getHtmlPath(npcId, 1));
  3866.  
  3867. html.setFile(filename);
  3868.  
  3869. }
  3870.  
  3871. else if (val >= 1 && val <= 21) // 1-20 - buttons, 21 - second buy lottery ticket window
  3872.  
  3873. {
  3874.  
  3875. if (!Lottery.getInstance().isStarted())
  3876.  
  3877. {
  3878.  
  3879. //tickets can't be sold
  3880.  
  3881. player.sendPacket(SystemMessageId.NO_LOTTERY_TICKETS_CURRENT_SOLD);
  3882.  
  3883. return;
  3884.  
  3885. }
  3886.  
  3887. if (!Lottery.getInstance().isSellableTickets())
  3888.  
  3889. {
  3890.  
  3891. //tickets can't be sold
  3892.  
  3893. player.sendPacket(SystemMessageId.NO_LOTTERY_TICKETS_AVAILABLE);
  3894.  
  3895. return;
  3896.  
  3897. }
  3898.  
  3899.  
  3900.  
  3901. filename = (getHtmlPath(npcId, 5));
  3902.  
  3903. html.setFile(filename);
  3904.  
  3905.  
  3906.  
  3907. int count = 0;
  3908.  
  3909. int found = 0;
  3910.  
  3911. // Counting buttons and unsetting button if found
  3912.  
  3913. for (int i = 0; i < 5; i++)
  3914.  
  3915. {
  3916.  
  3917. if (player.getLoto(i) == val)
  3918.  
  3919. {
  3920.  
  3921. //unsetting button
  3922.  
  3923. player.setLoto(i, 0);
  3924.  
  3925. found = 1;
  3926.  
  3927. }
  3928.  
  3929. else if (player.getLoto(i) > 0)
  3930.  
  3931. {
  3932.  
  3933. count++;
  3934.  
  3935. }
  3936.  
  3937. }
  3938.  
  3939.  
  3940.  
  3941. // If not rearched limit 5 and not unseted value
  3942.  
  3943. if (count < 5 && found == 0 && val <= 20)
  3944.  
  3945. for (int i = 0; i < 5; i++)
  3946.  
  3947. if (player.getLoto(i) == 0)
  3948.  
  3949. {
  3950.  
  3951. player.setLoto(i, val);
  3952.  
  3953. break;
  3954.  
  3955. }
  3956.  
  3957.  
  3958.  
  3959. // Setting pusshed buttons
  3960.  
  3961. count = 0;
  3962.  
  3963. for (int i = 0; i < 5; i++)
  3964.  
  3965. if (player.getLoto(i) > 0)
  3966.  
  3967. {
  3968.  
  3969. count++;
  3970.  
  3971. String button = String.valueOf(player.getLoto(i));
  3972.  
  3973. if (player.getLoto(i) < 10)
  3974.  
  3975. button = "0" + button;
  3976.  
  3977. String search = "fore=\"L2UI.lottoNum" + button + "\" back=\"L2UI.lottoNum" + button + "a_check\"";
  3978.  
  3979. String replace = "fore=\"L2UI.lottoNum" + button + "a_check\" back=\"L2UI.lottoNum" + button + "\"";
  3980.  
  3981. html.replace(search, replace);
  3982.  
  3983. }
  3984.  
  3985.  
  3986.  
  3987. if (count == 5)
  3988.  
  3989. {
  3990.  
  3991. String search = "0\">Return";
  3992.  
  3993. String replace = "22\">The winner selected the numbers above.";
  3994.  
  3995. html.replace(search, replace);
  3996.  
  3997. }
  3998.  
  3999. }
  4000.  
  4001. else if (val == 22) //22 - Selected ticket with 5 numbers
  4002.  
  4003. {
  4004.  
  4005. if (!Lottery.getInstance().isStarted())
  4006.  
  4007. {
  4008.  
  4009. // Tickets can't be sold
  4010.  
  4011. player.sendPacket(SystemMessageId.NO_LOTTERY_TICKETS_CURRENT_SOLD);
  4012.  
  4013. return;
  4014.  
  4015. }
  4016.  
  4017. if (!Lottery.getInstance().isSellableTickets())
  4018.  
  4019. {
  4020.  
  4021. // Tickets can't be sold
  4022.  
  4023. player.sendPacket(SystemMessageId.NO_LOTTERY_TICKETS_AVAILABLE);
  4024.  
  4025. return;
  4026.  
  4027. }
  4028.  
  4029.  
  4030.  
  4031. long price = Config.ALT_LOTTERY_TICKET_PRICE;
  4032.  
  4033. int lotonumber = Lottery.getInstance().getId();
  4034.  
  4035. int enchant = 0;
  4036.  
  4037. int type2 = 0;
  4038.  
  4039.  
  4040.  
  4041. for (int i = 0; i < 5; i++)
  4042.  
  4043. {
  4044.  
  4045. if (player.getLoto(i) == 0)
  4046.  
  4047. return;
  4048.  
  4049.  
  4050.  
  4051. if (player.getLoto(i) < 17)
  4052.  
  4053. enchant += L2Math.pow(2, player.getLoto(i) - 1);
  4054.  
  4055. else
  4056.  
  4057. type2 += L2Math.pow(2, player.getLoto(i) - 17);
  4058.  
  4059. }
  4060.  
  4061. if (player.getAdena() < price)
  4062.  
  4063. {
  4064.  
  4065. player.sendPacket(SystemMessageId.YOU_NOT_ENOUGH_ADENA);
  4066.  
  4067. return;
  4068.  
  4069. }
  4070.  
  4071. if (!player.reduceAdena("Loto", price, this, true))
  4072.  
  4073. return;
  4074.  
  4075. Lottery.getInstance().increasePrize(price);
  4076.  
  4077.  
  4078.  
  4079. sm = new SystemMessage(SystemMessageId.ACQUIRED_S1_S2);
  4080.  
  4081. sm.addItemNumber(lotonumber);
  4082.  
  4083. sm.addItemName(4442);
  4084.  
  4085. player.sendPacket(sm);
  4086.  
  4087.  
  4088.  
  4089. L2ItemInstance item = new L2ItemInstance(IdFactory.getInstance().getNextId(), 4442);
  4090.  
  4091. item.setCount(1);
  4092.  
  4093. item.setCustomType1(lotonumber);
  4094.  
  4095. item.setEnchantLevel(enchant);
  4096.  
  4097. item.setCustomType2(type2);
  4098.  
  4099. player.getInventory().addItem("Loto", item, player, this);
  4100.  
  4101.  
  4102.  
  4103. InventoryUpdate iu = new InventoryUpdate();
  4104.  
  4105. iu.addItem(item);
  4106.  
  4107. L2ItemInstance adenaupdate = player.getInventory().getItemByItemId(PcInventory.ADENA_ID);
  4108.  
  4109. iu.addModifiedItem(adenaupdate);
  4110.  
  4111. player.sendPacket(iu);
  4112.  
  4113.  
  4114.  
  4115. filename = (getHtmlPath(npcId, 3));
  4116.  
  4117. html.setFile(filename);
  4118.  
  4119. }
  4120.  
  4121. else if (val == 23) //23 - Current lottery jackpot
  4122.  
  4123. {
  4124.  
  4125. filename = (getHtmlPath(npcId, 3));
  4126.  
  4127. html.setFile(filename);
  4128.  
  4129. }
  4130.  
  4131. else if (val == 24) // 24 - Previous winning numbers/Prize claim
  4132.  
  4133. {
  4134.  
  4135. filename = (getHtmlPath(npcId, 4));
  4136.  
  4137. html.setFile(filename);
  4138.  
  4139.  
  4140.  
  4141. int lotonumber = Lottery.getInstance().getId();
  4142.  
  4143. String message = "";
  4144.  
  4145. for (L2ItemInstance item : player.getInventory().getItems())
  4146.  
  4147. {
  4148.  
  4149. if (item == null)
  4150.  
  4151. continue;
  4152.  
  4153. if (item.getItemId() == 4442 && item.getCustomType1() < lotonumber)
  4154.  
  4155. {
  4156.  
  4157. message = message + "<a action=\"bypass -h npc_%objectId%_Loto " + item.getObjectId() + "\">" + item.getCustomType1() + " Event Number ";
  4158.  
  4159. int[] numbers = Lottery.getInstance().decodeNumbers(item.getEnchantLevel(), item.getCustomType2());
  4160.  
  4161. for (int i = 0; i < 5; i++)
  4162.  
  4163. {
  4164.  
  4165. message += numbers[i] + " ";
  4166.  
  4167. }
  4168.  
  4169. long[] check = Lottery.getInstance().checkTicket(item);
  4170.  
  4171. if (check[0] > 0)
  4172.  
  4173. {
  4174.  
  4175. switch ((int) check[0])
  4176.  
  4177. {
  4178.  
  4179. case 1:
  4180.  
  4181. message += "- 1st Prize";
  4182.  
  4183. break;
  4184.  
  4185. case 2:
  4186.  
  4187. message += "- 2nd Prize";
  4188.  
  4189. break;
  4190.  
  4191. case 3:
  4192.  
  4193. message += "- 3th Prize";
  4194.  
  4195. break;
  4196.  
  4197. case 4:
  4198.  
  4199. message += "- 4th Prize";
  4200.  
  4201. break;
  4202.  
  4203. }
  4204.  
  4205. message += " " + check[1] + "a.";
  4206.  
  4207. }
  4208.  
  4209. message += "</a><br>";
  4210.  
  4211. }
  4212.  
  4213. }
  4214.  
  4215. if (message.isEmpty())
  4216.  
  4217. {
  4218.  
  4219. message += "There is no winning lottery ticket...<br>";
  4220.  
  4221. }
  4222.  
  4223. html.replace("%result%", message);
  4224.  
  4225. }
  4226.  
  4227. else if (val > 24) // >24 - Check lottery ticket by item object id
  4228.  
  4229. {
  4230.  
  4231. int lotonumber = Lottery.getInstance().getId();
  4232.  
  4233. L2ItemInstance item = player.getInventory().getItemByObjectId(val);
  4234.  
  4235. if (item == null || item.getItemId() != 4442 || item.getCustomType1() >= lotonumber)
  4236.  
  4237. return;
  4238.  
  4239. long[] check = Lottery.getInstance().checkTicket(item);
  4240.  
  4241.  
  4242.  
  4243. sm = new SystemMessage(SystemMessageId.S1_DISAPPEARED);
  4244.  
  4245. sm.addItemName(4442);
  4246.  
  4247. player.sendPacket(sm);
  4248.  
  4249.  
  4250.  
  4251. long adena = check[1];
  4252.  
  4253. if (adena > 0)
  4254.  
  4255. player.addAdena("Loto", adena, this, true);
  4256.  
  4257. player.destroyItem("Loto", item, this, false);
  4258.  
  4259. return;
  4260.  
  4261. }
  4262.  
  4263. else if (val == -1) // -1 - Lottery Instrucions
  4264.  
  4265. {
  4266.  
  4267. filename = (getHtmlPath(npcId, 2));
  4268.  
  4269. html.setFile(filename);
  4270.  
  4271. }
  4272.  
  4273. html.replace("%objectId%", String.valueOf(getObjectId()));
  4274.  
  4275. html.replace("%race%", "" + Lottery.getInstance().getId());
  4276.  
  4277. html.replace("%adena%", "" + Lottery.getInstance().getPrize());
  4278.  
  4279. html.replace("%ticket_price%", "" + Config.ALT_LOTTERY_TICKET_PRICE);
  4280.  
  4281. html.replace("%prize5%", "" + (Config.ALT_LOTTERY_5_NUMBER_RATE * 100));
  4282.  
  4283. html.replace("%prize4%", "" + (Config.ALT_LOTTERY_4_NUMBER_RATE * 100));
  4284.  
  4285. html.replace("%prize3%", "" + (Config.ALT_LOTTERY_3_NUMBER_RATE * 100));
  4286.  
  4287. html.replace("%prize2%", "" + Config.ALT_LOTTERY_2_AND_1_NUMBER_PRIZE);
  4288.  
  4289. html.replace("%enddate%", "" + DateFormat.getDateInstance().format(Lottery.getInstance().getEndDate()));
  4290.  
  4291. player.sendPacket(html);
  4292.  
  4293.  
  4294.  
  4295. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  4296.  
  4297. player.sendPacket(ActionFailed.STATIC_PACKET);
  4298.  
  4299. }
  4300.  
  4301.  
  4302.  
  4303. public void makeCPRecovery(L2PcInstance player)
  4304.  
  4305. {
  4306.  
  4307. if (getNpcId() != 31225 && getNpcId() != 31226)
  4308.  
  4309. return;
  4310.  
  4311.  
  4312.  
  4313. if (!cwCheck(player))
  4314.  
  4315. {
  4316.  
  4317. player.sendMessage("Go away, you're not welcome here.");
  4318.  
  4319. player.sendPacket(ActionFailed.STATIC_PACKET);
  4320.  
  4321. return;
  4322.  
  4323. }
  4324.  
  4325.  
  4326.  
  4327. int neededmoney = 100;
  4328.  
  4329. if (!player.reduceAdena("RestoreCP", neededmoney, player.getLastFolkNPC(), true))
  4330.  
  4331. return;
  4332.  
  4333.  
  4334.  
  4335. L2Skill skill = SkillTable.getInstance().getInfo(4380, 1);
  4336.  
  4337. if (skill != null)
  4338.  
  4339. {
  4340.  
  4341. setTarget(player);
  4342.  
  4343. doCast(skill);
  4344.  
  4345. }
  4346.  
  4347. player.sendPacket(ActionFailed.STATIC_PACKET);
  4348.  
  4349. }
  4350.  
  4351.  
  4352.  
  4353. /**
  4354.  
  4355. * Add Newbie helper buffs to L2Player according to its level.<BR><BR>
  4356.  
  4357. *
  4358.  
  4359. * <B><U> Actions</U> :</B><BR><BR>
  4360.  
  4361. * <li>Get the range level in wich player must be to obtain buff </li>
  4362.  
  4363. * <li>If player level is out of range, display a message and return </li>
  4364.  
  4365. * <li>According to player level cast buff </li><BR><BR>
  4366.  
  4367. *
  4368.  
  4369. * <FONT COLOR=#FF0000><B> Newbie Helper Buff list is define in buff templates sql table as "SupportMagic"</B></FONT><BR><BR>
  4370.  
  4371. *
  4372.  
  4373. * @param player The L2PcInstance that talk with the L2Npc
  4374.  
  4375. *
  4376.  
  4377. */
  4378.  
  4379. public void makeSupportMagic(L2PcInstance player, String cmd)
  4380.  
  4381. {
  4382.  
  4383. // Prevent a cursed weapon weilder of being buffed
  4384.  
  4385. if (!cwCheck(player))
  4386.  
  4387. return;
  4388.  
  4389.  
  4390.  
  4391. int _newbieBuffsId = BuffTemplateTable.getInstance().getTemplateIdByName(cmd);
  4392.  
  4393.  
  4394.  
  4395. if (_newbieBuffsId == 0)
  4396.  
  4397. return;
  4398.  
  4399.  
  4400.  
  4401. int _lowestLevel = BuffTemplateTable.getInstance().getLowestLevel(_newbieBuffsId);
  4402.  
  4403. int _highestLevel = BuffTemplateTable.getInstance().getHighestLevel(_newbieBuffsId);
  4404.  
  4405.  
  4406.  
  4407. // If the player is too high level, display a message and return
  4408.  
  4409. if (player.getLevel() > _highestLevel)
  4410.  
  4411. {
  4412.  
  4413. String content = "<html><body>Newbie Guide:<br>Only a <font color=\"LEVEL\">novice character of level "
  4414.  
  4415. + _highestLevel
  4416.  
  4417. + " or less</font> can receive my support magic.<br>Your novice character is the first one that you created and raised in this world.</body></html>";
  4418.  
  4419. insertObjectIdAndShowChatWindow(player, content);
  4420.  
  4421. return;
  4422.  
  4423. }
  4424.  
  4425.  
  4426.  
  4427. // If the player is too low level, display a message and return
  4428.  
  4429. if (player.getLevel() < _lowestLevel)
  4430.  
  4431. {
  4432.  
  4433. String content = "<html><body>Come back here when you have reached level " + _lowestLevel + ". I will give you support magic then.</body></html>";
  4434.  
  4435. insertObjectIdAndShowChatWindow(player, content);
  4436.  
  4437. return;
  4438.  
  4439. }
  4440.  
  4441.  
  4442.  
  4443. // If buffs are for servitor, check it's presence
  4444.  
  4445. boolean servitor = cmd.endsWith("vitor");
  4446.  
  4447. if (servitor)
  4448.  
  4449. {
  4450.  
  4451. L2Summon pet = player.getPet();
  4452.  
  4453. if (pet == null || pet instanceof L2PetInstance)
  4454.  
  4455. {
  4456.  
  4457. String content = "<html><body>Only servitors can receive this Support Magic. If you do not have a servitor, you cannot access these spells.</body></html>";
  4458.  
  4459. insertObjectIdAndShowChatWindow(player, content);
  4460.  
  4461. return;
  4462.  
  4463. }
  4464.  
  4465. }
  4466.  
  4467.  
  4468.  
  4469. makeBuffs(player, _newbieBuffsId, servitor);
  4470.  
  4471. }
  4472.  
  4473.  
  4474.  
  4475. public void giveBlessingSupport(L2PcInstance player)
  4476.  
  4477. {
  4478.  
  4479. if (player == null)
  4480.  
  4481. return;
  4482.  
  4483.  
  4484.  
  4485. // Blessing of protection - author kerberos_20. Used codes from Rayan - L2Emu project.
  4486.  
  4487. // Prevent a cursed weapon weilder of being buffed - I think no need of that becouse karma check > 0
  4488.  
  4489. // if (player.isCursedWeaponEquiped())
  4490.  
  4491. // return;
  4492.  
  4493.  
  4494.  
  4495. int player_level = player.getLevel();
  4496.  
  4497. // Select the player
  4498.  
  4499. setTarget(player);
  4500.  
  4501. // If the player is too high level, display a message and return
  4502.  
  4503. if (player_level > 39 || player.getClassId().level() >= 2)
  4504.  
  4505. {
  4506.  
  4507. String content = "<html><body>Newbie Guide:<br>I'm sorry, but you are not eligible to receive the protection blessing.<br1>It can only be bestowed on <font color=\"LEVEL\">characters below level 39 who have not made a seccond transfer.</font></body></html>";
  4508.  
  4509. insertObjectIdAndShowChatWindow(player, content);
  4510.  
  4511. return;
  4512.  
  4513. }
  4514.  
  4515. L2Skill skill = SkillTable.getInstance().getInfo(5182,1);
  4516.  
  4517. if (skill != null)
  4518.  
  4519. doCast(skill);
  4520.  
  4521. }
  4522.  
  4523.  
  4524.  
  4525. public void showChatWindow(L2PcInstance player)
  4526.  
  4527. {
  4528.  
  4529. showChatWindow(player, 0);
  4530.  
  4531. }
  4532.  
  4533.  
  4534.  
  4535. /**
  4536.  
  4537. * Returns true if html exists
  4538.  
  4539. * @param player
  4540.  
  4541. * @param type
  4542.  
  4543. * @return boolean
  4544.  
  4545. */
  4546.  
  4547. private boolean showPkDenyChatWindow(L2PcInstance player, String type)
  4548.  
  4549. {
  4550.  
  4551. String html = HtmCache.getInstance().getHtm("data/html/" + type + "/" + getNpcId() + "-pk.htm");
  4552.  
  4553.  
  4554.  
  4555. if (html != null)
  4556.  
  4557. {
  4558.  
  4559. NpcHtmlMessage pkDenyMsg = new NpcHtmlMessage(getObjectId());
  4560.  
  4561. pkDenyMsg.setHtml(html);
  4562.  
  4563. player.sendPacket(pkDenyMsg);
  4564.  
  4565. player.sendPacket(ActionFailed.STATIC_PACKET);
  4566.  
  4567. return true;
  4568.  
  4569. }
  4570.  
  4571.  
  4572.  
  4573. return false;
  4574.  
  4575. }
  4576.  
  4577.  
  4578.  
  4579. /**
  4580.  
  4581. * Open a chat window on client with the text of the L2Npc.<BR><BR>
  4582.  
  4583. *
  4584.  
  4585. * <B><U> Actions</U> :</B><BR><BR>
  4586.  
  4587. * <li>Get the text of the selected HTML file in function of the npcId and of the page number </li>
  4588.  
  4589. * <li>Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance </li>
  4590.  
  4591. * <li>Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet </li><BR>
  4592.  
  4593. *
  4594.  
  4595. * @param player The L2PcInstance that talk with the L2Npc
  4596.  
  4597. * @param val The number of the page of the L2Npc to display
  4598.  
  4599. *
  4600.  
  4601. */
  4602.  
  4603. public void showChatWindow(L2PcInstance player, int val)
  4604.  
  4605. {
  4606.  
  4607. if (!cwCheck(player) && !(player.getTarget() instanceof L2ClanHallManagerInstance || player.getTarget() instanceof L2DoormenInstance))
  4608.  
  4609. {
  4610.  
  4611. player.setTarget(player);
  4612.  
  4613. return;
  4614.  
  4615. }
  4616.  
  4617. if (player.getKarma() > 0)
  4618.  
  4619. {
  4620.  
  4621. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && this instanceof L2MerchantInstance)
  4622.  
  4623. {
  4624.  
  4625. if (showPkDenyChatWindow(player, "merchant"))
  4626.  
  4627. return;
  4628.  
  4629. }
  4630.  
  4631. else if (!Config.ALT_GAME_KARMA_PLAYER_CAN_USE_GK && this instanceof L2TeleporterInstance)
  4632.  
  4633. {
  4634.  
  4635. if (showPkDenyChatWindow(player, "teleporter"))
  4636.  
  4637. return;
  4638.  
  4639. }
  4640.  
  4641. else if (!Config.ALT_GAME_KARMA_PLAYER_CAN_USE_WAREHOUSE && this instanceof L2WarehouseInstance)
  4642.  
  4643. {
  4644.  
  4645. if (showPkDenyChatWindow(player, "warehouse"))
  4646.  
  4647. return;
  4648.  
  4649. }
  4650.  
  4651. else if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && this instanceof L2FishermanInstance)
  4652.  
  4653. {
  4654.  
  4655. if (showPkDenyChatWindow(player, "fisherman"))
  4656.  
  4657. return;
  4658.  
  4659. }
  4660.  
  4661. }
  4662.  
  4663.  
  4664.  
  4665. if (this instanceof L2AuctioneerInstance && val == 0)
  4666.  
  4667. return;
  4668.  
  4669.  
  4670.  
  4671. int npcId = getTemplate().getNpcId();
  4672.  
  4673.  
  4674.  
  4675. /* For use with Seven Signs implementation */
  4676.  
  4677. String filename = SevenSigns.SEVEN_SIGNS_HTML_PATH;
  4678.  
  4679. int sealAvariceOwner = SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_AVARICE);
  4680.  
  4681. int sealGnosisOwner = SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_GNOSIS);
  4682.  
  4683. int playerCabal = SevenSigns.getInstance().getPlayerCabal(player);
  4684.  
  4685. boolean isSealValidationPeriod = SevenSigns.getInstance().isSealValidationPeriod();
  4686.  
  4687. int compWinner = SevenSigns.getInstance().getCabalHighestScore();
  4688.  
  4689.  
  4690.  
  4691. switch (npcId)
  4692.  
  4693. {
  4694.  
  4695. case 31078:
  4696.  
  4697. case 31079:
  4698.  
  4699. case 31080:
  4700.  
  4701. case 31081:
  4702.  
  4703. case 31082: // Dawn Priests
  4704.  
  4705. case 31083:
  4706.  
  4707. case 31084:
  4708.  
  4709. case 31168:
  4710.  
  4711. case 31692:
  4712.  
  4713. case 31694:
  4714.  
  4715. case 31997:
  4716.  
  4717. switch (playerCabal)
  4718.  
  4719. {
  4720.  
  4721. case SevenSigns.CABAL_DAWN:
  4722.  
  4723. if (isSealValidationPeriod)
  4724.  
  4725. if (compWinner == SevenSigns.CABAL_DAWN)
  4726.  
  4727. if (compWinner != sealGnosisOwner)
  4728.  
  4729. filename += "dawn_priest_2c.htm";
  4730.  
  4731. else
  4732.  
  4733. filename += "dawn_priest_2a.htm";
  4734.  
  4735. else
  4736.  
  4737. filename += "dawn_priest_2b.htm";
  4738.  
  4739. else
  4740.  
  4741. filename += "dawn_priest_1b.htm";
  4742.  
  4743. break;
  4744.  
  4745. case SevenSigns.CABAL_DUSK:
  4746.  
  4747. if (isSealValidationPeriod)
  4748.  
  4749. filename += "dawn_priest_3b.htm";
  4750.  
  4751. else
  4752.  
  4753. filename += "dawn_priest_3a.htm";
  4754.  
  4755. break;
  4756.  
  4757. default:
  4758.  
  4759. if (isSealValidationPeriod)
  4760.  
  4761. if (compWinner == SevenSigns.CABAL_DAWN)
  4762.  
  4763. filename += "dawn_priest_4.htm";
  4764.  
  4765. else
  4766.  
  4767. filename += "dawn_priest_2b.htm";
  4768.  
  4769. else
  4770.  
  4771. filename += "dawn_priest_1a.htm";
  4772.  
  4773. break;
  4774.  
  4775. }
  4776.  
  4777. break;
  4778.  
  4779. case 31085:
  4780.  
  4781. case 31086:
  4782.  
  4783. case 31087:
  4784.  
  4785. case 31088: // Dusk Priest
  4786.  
  4787. case 31089:
  4788.  
  4789. case 31090:
  4790.  
  4791. case 31091:
  4792.  
  4793. case 31169:
  4794.  
  4795. case 31693:
  4796.  
  4797. case 31695:
  4798.  
  4799. case 31998:
  4800.  
  4801. switch (playerCabal)
  4802.  
  4803. {
  4804.  
  4805. case SevenSigns.CABAL_DUSK:
  4806.  
  4807. if (isSealValidationPeriod)
  4808.  
  4809. if (compWinner == SevenSigns.CABAL_DUSK)
  4810.  
  4811. if (compWinner != sealGnosisOwner)
  4812.  
  4813. filename += "dusk_priest_2c.htm";
  4814.  
  4815. else
  4816.  
  4817. filename += "dusk_priest_2a.htm";
  4818.  
  4819. else
  4820.  
  4821. filename += "dusk_priest_2b.htm";
  4822.  
  4823. else
  4824.  
  4825. filename += "dusk_priest_1b.htm";
  4826.  
  4827. break;
  4828.  
  4829. case SevenSigns.CABAL_DAWN:
  4830.  
  4831. if (isSealValidationPeriod)
  4832.  
  4833. filename += "dusk_priest_3b.htm";
  4834.  
  4835. else
  4836.  
  4837. filename += "dusk_priest_3a.htm";
  4838.  
  4839. break;
  4840.  
  4841. default:
  4842.  
  4843. if (isSealValidationPeriod)
  4844.  
  4845. if (compWinner == SevenSigns.CABAL_DUSK)
  4846.  
  4847. filename += "dusk_priest_4.htm";
  4848.  
  4849. else
  4850.  
  4851. filename += "dusk_priest_2b.htm";
  4852.  
  4853. else
  4854.  
  4855. filename += "dusk_priest_1a.htm";
  4856.  
  4857. break;
  4858.  
  4859. }
  4860.  
  4861. break;
  4862.  
  4863. case 31127: //
  4864.  
  4865. case 31128: //
  4866.  
  4867. case 31129: // Dawn Festival Guides
  4868.  
  4869. case 31130: //
  4870.  
  4871. case 31131: //
  4872.  
  4873. filename += "festival/dawn_guide.htm";
  4874.  
  4875. break;
  4876.  
  4877. case 31137: //
  4878.  
  4879. case 31138: //
  4880.  
  4881. case 31139: // Dusk Festival Guides
  4882.  
  4883. case 31140: //
  4884.  
  4885. case 31141: //
  4886.  
  4887. filename += "festival/dusk_guide.htm";
  4888.  
  4889. break;
  4890.  
  4891. case 31092: // Black Marketeer of Mammon
  4892.  
  4893. filename += "blkmrkt_1.htm";
  4894.  
  4895. break;
  4896.  
  4897. case 31113: // Merchant of Mammon
  4898.  
  4899. if (Config.ALT_STRICT_SEVENSIGNS)
  4900.  
  4901. {
  4902.  
  4903. switch (compWinner)
  4904.  
  4905. {
  4906.  
  4907. case SevenSigns.CABAL_DAWN:
  4908.  
  4909. if (playerCabal != compWinner || playerCabal != sealAvariceOwner)
  4910.  
  4911. {
  4912.  
  4913. player.sendPacket(SystemMessageId.CAN_BE_USED_BY_DAWN);
  4914.  
  4915. player.sendPacket(ActionFailed.STATIC_PACKET);
  4916.  
  4917. return;
  4918.  
  4919. }
  4920.  
  4921. break;
  4922.  
  4923. case SevenSigns.CABAL_DUSK:
  4924.  
  4925. if (playerCabal != compWinner || playerCabal != sealAvariceOwner)
  4926.  
  4927. {
  4928.  
  4929. player.sendPacket(SystemMessageId.CAN_BE_USED_BY_DUSK);
  4930.  
  4931. player.sendPacket(ActionFailed.STATIC_PACKET);
  4932.  
  4933. return;
  4934.  
  4935. }
  4936.  
  4937. break;
  4938.  
  4939. }
  4940.  
  4941. }
  4942.  
  4943. filename += "mammmerch_1.htm";
  4944.  
  4945. break;
  4946.  
  4947. case 31126: // Blacksmith of Mammon
  4948.  
  4949. if (Config.ALT_STRICT_SEVENSIGNS)
  4950.  
  4951. {
  4952.  
  4953. switch (compWinner)
  4954.  
  4955. {
  4956.  
  4957. case SevenSigns.CABAL_DAWN:
  4958.  
  4959. if (playerCabal != compWinner || playerCabal != sealGnosisOwner)
  4960.  
  4961. {
  4962.  
  4963. player.sendPacket(SystemMessageId.CAN_BE_USED_BY_DAWN);
  4964.  
  4965. player.sendPacket(ActionFailed.STATIC_PACKET);
  4966.  
  4967. return;
  4968.  
  4969. }
  4970.  
  4971. break;
  4972.  
  4973. case SevenSigns.CABAL_DUSK:
  4974.  
  4975. if (playerCabal != compWinner || playerCabal != sealGnosisOwner)
  4976.  
  4977. {
  4978.  
  4979. player.sendPacket(SystemMessageId.CAN_BE_USED_BY_DUSK);
  4980.  
  4981. player.sendPacket(ActionFailed.STATIC_PACKET);
  4982.  
  4983. return;
  4984.  
  4985. }
  4986.  
  4987. break;
  4988.  
  4989. }
  4990.  
  4991. }
  4992.  
  4993. filename += "mammblack_1.htm";
  4994.  
  4995. break;
  4996.  
  4997. case 31132:
  4998.  
  4999. case 31133:
  5000.  
  5001. case 31134:
  5002.  
  5003. case 31135:
  5004.  
  5005. case 31136: // Festival Witches
  5006.  
  5007. case 31142:
  5008.  
  5009. case 31143:
  5010.  
  5011. case 31144:
  5012.  
  5013. case 31145:
  5014.  
  5015. case 31146:
  5016.  
  5017. filename += "festival/festival_witch.htm";
  5018.  
  5019. break;
  5020.  
  5021. case 31688:
  5022.  
  5023. if (player.isNoble())
  5024.  
  5025. filename = Olympiad.OLYMPIAD_HTML_PATH + "noble_main.htm";
  5026.  
  5027. else
  5028.  
  5029. filename = (getHtmlPath(npcId, val));
  5030.  
  5031. break;
  5032.  
  5033. case 31690:
  5034.  
  5035. case 31769:
  5036.  
  5037. case 31770:
  5038.  
  5039. case 31771:
  5040.  
  5041. case 31772:
  5042.  
  5043. if (player.isHero())
  5044.  
  5045. filename = Olympiad.OLYMPIAD_HTML_PATH + "hero_main.htm";
  5046.  
  5047. else
  5048.  
  5049. filename = (getHtmlPath(npcId, val));
  5050.  
  5051. break;
  5052.  
  5053. case 36402:
  5054.  
  5055. if (player.olyBuff > 0)
  5056.  
  5057. filename = Olympiad.OLYMPIAD_HTML_PATH + (player.olyBuff == 5 ? "olympiad_buffs.htm" : "olympiad_5buffs.htm");
  5058.  
  5059. else
  5060.  
  5061. filename = Olympiad.OLYMPIAD_HTML_PATH + "olympiad_nobuffs.htm";
  5062.  
  5063. break;
  5064.  
  5065. default:
  5066.  
  5067. if (npcId >= 31865 && npcId <= 31918)
  5068.  
  5069. {
  5070.  
  5071. if (val == 0)
  5072.  
  5073. filename += "rift/GuardianOfBorder.htm";
  5074.  
  5075. else
  5076.  
  5077. filename += "rift/GuardianOfBorder-" + val + ".htm";
  5078.  
  5079. break;
  5080.  
  5081. }
  5082.  
  5083. if ((npcId >= 31093 && npcId <= 31094) || (npcId >= 31172 && npcId <= 31201) || (npcId >= 31239 && npcId <= 31254))
  5084.  
  5085. return;
  5086.  
  5087. // Get the text of the selected HTML file in function of the npcId and of the page number
  5088.  
  5089. if (this instanceof L2TeleporterInstance && val == 1 && player.getLevel() < 40) // Players below level 40 have free teleport
  5090.  
  5091. {
  5092.  
  5093. filename = "data/html/teleporter/free/" + npcId + ".htm";
  5094.  
  5095. if (!HtmCache.getInstance().pathExists(filename))
  5096.  
  5097. filename = getHtmlPath(npcId, val);
  5098.  
  5099. }
  5100.  
  5101. else
  5102.  
  5103. filename = (getHtmlPath(npcId, val));
  5104.  
  5105. break;
  5106.  
  5107. }
  5108.  
  5109.  
  5110.  
  5111. // Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance
  5112.  
  5113. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  5114.  
  5115. html.setFile(filename);
  5116.  
  5117.  
  5118.  
  5119. //String word = "npc-"+npcId+(val>0 ? "-"+val : "" )+"-dialog-append";
  5120.  
  5121.  
  5122.  
  5123. if (this instanceof L2MerchantInstance)
  5124.  
  5125. if (Config.LIST_PET_RENT_NPC.contains(npcId))
  5126.  
  5127. html.replace("_Quest", "_RentPet\">Rent Pet</a><br><a action=\"bypass -h npc_%objectId%_Quest");
  5128.  
  5129.  
  5130.  
  5131. html.replace("%objectId%", String.valueOf(getObjectId()));
  5132.  
  5133. if (this instanceof L2FestivalGuideInstance)
  5134.  
  5135. {
  5136.  
  5137. html.replace("%festivalMins%", SevenSignsFestival.getInstance().getTimeToNextFestivalStr());
  5138.  
  5139. }
  5140.  
  5141. player.sendPacket(html);
  5142.  
  5143.  
  5144.  
  5145. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  5146.  
  5147. player.sendPacket(ActionFailed.STATIC_PACKET);
  5148.  
  5149. }
  5150.  
  5151.  
  5152.  
  5153. /**
  5154.  
  5155. * Open a chat window on client with the text specified by the given file name and path,<BR>
  5156.  
  5157. * relative to the datapack root.
  5158.  
  5159. * <BR><BR>
  5160.  
  5161. * Added by Tempy
  5162.  
  5163. * @param player The L2PcInstance that talk with the L2Npc
  5164.  
  5165. * @param filename The filename that contains the text to send
  5166.  
  5167. *
  5168.  
  5169. */
  5170.  
  5171. public void showChatWindow(L2PcInstance player, String filename)
  5172.  
  5173. {
  5174.  
  5175. // Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the L2PcInstance
  5176.  
  5177. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  5178.  
  5179. html.setFile(filename);
  5180.  
  5181. html.replace("%objectId%", String.valueOf(getObjectId()));
  5182.  
  5183. player.sendPacket(html);
  5184.  
  5185.  
  5186.  
  5187. // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  5188.  
  5189. player.sendPacket(ActionFailed.STATIC_PACKET);
  5190.  
  5191. }
  5192.  
  5193.  
  5194.  
  5195. /**
  5196.  
  5197. * Return the Exp Reward of this L2Npc contained in the L2NpcTemplate (modified by RATE_XP).<BR><BR>
  5198.  
  5199. */
  5200.  
  5201. public int getExpReward()
  5202.  
  5203. {
  5204.  
  5205. double rateXp = getStat().calcStat(Stats.MAX_HP, 1, this, null);
  5206.  
  5207. return (int) (getTemplate().getRewardExp() * rateXp * Config.RATE_XP);
  5208.  
  5209. }
  5210.  
  5211.  
  5212.  
  5213. /**
  5214.  
  5215. * Return the SP Reward of this L2Npc contained in the L2NpcTemplate (modified by RATE_SP).<BR><BR>
  5216.  
  5217. */
  5218.  
  5219. public int getSpReward()
  5220.  
  5221. {
  5222.  
  5223. double rateSp = getStat().calcStat(Stats.MAX_HP, 1, this, null);
  5224.  
  5225. return (int) (getTemplate().getRewardSp() * rateSp * Config.RATE_SP);
  5226.  
  5227. }
  5228.  
  5229.  
  5230.  
  5231. /**
  5232.  
  5233. * Kill the L2Npc (the corpse disappeared after 7 seconds).<BR><BR>
  5234.  
  5235. *
  5236.  
  5237. * <B><U> Actions</U> :</B><BR><BR>
  5238.  
  5239. * <li>Create a DecayTask to remove the corpse of the L2Npc after 7 seconds </li>
  5240.  
  5241. * <li>Set target to null and cancel Attack or Cast </li>
  5242.  
  5243. * <li>Stop movement </li>
  5244.  
  5245. * <li>Stop HP/MP/CP Regeneration task </li>
  5246.  
  5247. * <li>Stop all active skills effects in progress on the L2Character </li>
  5248.  
  5249. * <li>Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform </li>
  5250.  
  5251. * <li>Notify L2Character AI </li><BR><BR>
  5252.  
  5253. *
  5254.  
  5255. * <B><U> Overridden in </U> :</B><BR><BR>
  5256.  
  5257. * <li> L2Attackable </li><BR><BR>
  5258.  
  5259. *
  5260.  
  5261. * @param killer The L2Character who killed it
  5262.  
  5263. *
  5264.  
  5265. */
  5266.  
  5267. @Override
  5268.  
  5269. public boolean doDie(L2Character killer)
  5270.  
  5271. {
  5272.  
  5273. if (!super.doDie(killer))
  5274.  
  5275. return false;
  5276.  
  5277.  
  5278.  
  5279. // Normally this wouldn't really be needed, but for those few exceptions,
  5280.  
  5281. // We do need to reset the weapons back to the initial templated weapon.
  5282.  
  5283. _currentLHandId = getTemplate().getLhand();
  5284.  
  5285. _currentRHandId = getTemplate().getRhand();
  5286.  
  5287. _currentCollisionHeight = getTemplate().getCollisionHeight();
  5288.  
  5289. _currentCollisionRadius = getTemplate().getCollisionRadius();
  5290.  
  5291. DecayTaskManager.getInstance().addDecayTask(this);
  5292.  
  5293. return true;
  5294.  
  5295. }
  5296.  
  5297.  
  5298.  
  5299. /**
  5300.  
  5301. * Set the spawn of the L2Npc.<BR><BR>
  5302.  
  5303. *
  5304.  
  5305. * @param spawn The L2Spawn that manage the L2Npc
  5306.  
  5307. *
  5308.  
  5309. */
  5310.  
  5311. public void setSpawn(L2Spawn spawn)
  5312.  
  5313. {
  5314.  
  5315. _spawn = spawn;
  5316.  
  5317. }
  5318.  
  5319.  
  5320.  
  5321. @Override
  5322.  
  5323. public void onSpawn()
  5324.  
  5325. {
  5326.  
  5327. if (_inventory != null)
  5328.  
  5329. _inventory.reset();
  5330.  
  5331.  
  5332.  
  5333. super.onSpawn();
  5334.  
  5335.  
  5336.  
  5337. setQuestFirstAttacker(null);
  5338.  
  5339. setQuestAttackStatus(Quest.ATTACK_NOONE);
  5340.  
  5341. if (getTemplate().getEventQuests(Quest.QuestEventType.ON_SPAWN) != null)
  5342.  
  5343. for (Quest quest : getTemplate().getEventQuests(Quest.QuestEventType.ON_SPAWN))
  5344.  
  5345. quest.notifySpawn(this);
  5346.  
  5347. }
  5348.  
  5349.  
  5350.  
  5351. /**
  5352.  
  5353. * Remove the L2Npc from the world and update its spawn object (for a complete removal use the deleteMe method).<BR><BR>
  5354.  
  5355. *
  5356.  
  5357. * <B><U> Actions</U> :</B><BR><BR>
  5358.  
  5359. * <li>Remove the L2Npc from the world when the decay task is launched </li>
  5360.  
  5361. * <li>Decrease its spawn counter </li>
  5362.  
  5363. * <li>Manage Siege task (killFlag, killCT) </li><BR><BR>
  5364.  
  5365. *
  5366.  
  5367. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  5368.  
  5369. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR><BR>
  5370.  
  5371. *
  5372.  
  5373. * @see com.l2jfree.gameserver.model.L2Object#decayMe()
  5374.  
  5375. */
  5376.  
  5377. @Override
  5378.  
  5379. public void onDecay()
  5380.  
  5381. {
  5382.  
  5383. if (isDecayed())
  5384.  
  5385. return;
  5386.  
  5387. setDecayed(true);
  5388.  
  5389.  
  5390.  
  5391. // Reset champion status if the thing is a mob
  5392.  
  5393. setChampion(false);
  5394.  
  5395.  
  5396.  
  5397. // Remove the L2Npc from the world when the decay task is launched
  5398.  
  5399. super.onDecay();
  5400.  
  5401.  
  5402.  
  5403. // Decrease its spawn counter
  5404.  
  5405. if (_spawn != null)
  5406.  
  5407. _spawn.decreaseCount(this);
  5408.  
  5409. }
  5410.  
  5411.  
  5412.  
  5413. private boolean _champion;
  5414.  
  5415.  
  5416.  
  5417. public final void setChampion(boolean champion)
  5418.  
  5419. {
  5420.  
  5421. _champion = champion;
  5422.  
  5423. }
  5424.  
  5425.  
  5426.  
  5427. @Override
  5428.  
  5429. public final boolean isChampion()
  5430.  
  5431. {
  5432.  
  5433. return _champion;
  5434.  
  5435. }
  5436.  
  5437.  
  5438.  
  5439. /**
  5440.  
  5441. * Remove PROPERLY the L2Npc from the world.<BR><BR>
  5442.  
  5443. *
  5444.  
  5445. * <B><U> Actions</U> :</B><BR><BR>
  5446.  
  5447. * <li>Remove the L2Npc from the world and update its spawn object </li>
  5448.  
  5449. * <li>Remove all L2Object from _knownObjects and _knownPlayer of the L2Npc then cancel Attack or Cast and notify AI </li>
  5450.  
  5451. * <li>Remove L2Object object from _allObjects of L2World </li><BR><BR>
  5452.  
  5453. *
  5454.  
  5455. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR><BR>
  5456.  
  5457. *
  5458.  
  5459. */
  5460.  
  5461. public void deleteMe()
  5462.  
  5463. {
  5464.  
  5465. abortCast();
  5466.  
  5467. abortAttack();
  5468.  
  5469. getStatus().stopHpMpRegeneration();
  5470.  
  5471. getEffects().stopAllEffects(true);
  5472.  
  5473.  
  5474.  
  5475. L2WorldRegion region = getWorldRegion();
  5476.  
  5477.  
  5478.  
  5479. try
  5480.  
  5481. {
  5482.  
  5483. decayMe();
  5484.  
  5485. }
  5486.  
  5487. catch (Exception e)
  5488.  
  5489. {
  5490.  
  5491. _log.fatal("Failed decayMe().", e);
  5492.  
  5493. }
  5494.  
  5495.  
  5496.  
  5497. try
  5498.  
  5499. {
  5500.  
  5501. if (_fusionSkill != null)
  5502.  
  5503. abortCast();
  5504.  
  5505.  
  5506.  
  5507. for (L2Character character : getKnownList().getKnownCharacters())
  5508.  
  5509. if (character.getFusionSkill() != null && character.getFusionSkill().getTarget() == this)
  5510.  
  5511. character.abortCast();
  5512.  
  5513. }
  5514.  
  5515. catch (Exception e)
  5516.  
  5517. {
  5518.  
  5519. _log.fatal("Failed deleteMe().", e);
  5520.  
  5521. }
  5522.  
  5523.  
  5524.  
  5525. if (region != null)
  5526.  
  5527. region.removeFromZones(this);
  5528.  
  5529.  
  5530.  
  5531. // Remove all L2Object from _knownObjects and _knownPlayer of the L2Character then cancel Attack or Cast and notify AI
  5532.  
  5533. try
  5534.  
  5535. {
  5536.  
  5537. getKnownList().removeAllKnownObjects();
  5538.  
  5539. }
  5540.  
  5541. catch (Exception e)
  5542.  
  5543. {
  5544.  
  5545. _log.fatal("Failed removing cleaning knownlist.", e);
  5546.  
  5547. }
  5548.  
  5549. }
  5550.  
  5551.  
  5552.  
  5553. /**
  5554.  
  5555. * Return the L2Spawn object that manage this L2Npc.<BR><BR>
  5556.  
  5557. */
  5558.  
  5559. public L2Spawn getSpawn()
  5560.  
  5561. {
  5562.  
  5563. return _spawn;
  5564.  
  5565. }
  5566.  
  5567.  
  5568.  
  5569. @Override
  5570.  
  5571. public String toString()
  5572.  
  5573. {
  5574.  
  5575. return getTemplate().getName();
  5576.  
  5577. }
  5578.  
  5579.  
  5580.  
  5581. public boolean isDecayed()
  5582.  
  5583. {
  5584.  
  5585. return _isDecayed;
  5586.  
  5587. }
  5588.  
  5589.  
  5590.  
  5591. public void setDecayed(boolean decayed)
  5592.  
  5593. {
  5594.  
  5595. _isDecayed = decayed;
  5596.  
  5597. }
  5598.  
  5599.  
  5600.  
  5601. public void endDecayTask()
  5602.  
  5603. {
  5604.  
  5605. if (!isDecayed())
  5606.  
  5607. {
  5608.  
  5609. DecayTaskManager.getInstance().cancelDecayTask(this);
  5610.  
  5611. onDecay();
  5612.  
  5613. }
  5614.  
  5615. }
  5616.  
  5617.  
  5618.  
  5619. public boolean isMob() // Rather delete this check
  5620.  
  5621. {
  5622.  
  5623. return false; // This means we use MAX_NPC_ANIMATION instead of MAX_MONSTER_ANIMATION
  5624.  
  5625. }
  5626.  
  5627.  
  5628.  
  5629. // Two functions to change the appearance of the equipped weapons on the NPC
  5630.  
  5631. // This is only useful for a few NPCs and is most likely going to be called from AI
  5632.  
  5633. public void setLHandId(int newWeaponId)
  5634.  
  5635. {
  5636.  
  5637. _currentLHandId = newWeaponId;
  5638.  
  5639. updateAbnormalEffect();
  5640.  
  5641. }
  5642.  
  5643.  
  5644.  
  5645. public void setRHandId(int newWeaponId)
  5646.  
  5647. {
  5648.  
  5649. _currentRHandId = newWeaponId;
  5650.  
  5651. updateAbnormalEffect();
  5652.  
  5653. }
  5654.  
  5655.  
  5656.  
  5657. public void setLRHandId(int newLWeaponId, int newRWeaponId)
  5658.  
  5659. {
  5660.  
  5661. _currentRHandId = newRWeaponId;
  5662.  
  5663. _currentLHandId = newLWeaponId;
  5664.  
  5665. updateAbnormalEffect();
  5666.  
  5667. }
  5668.  
  5669.  
  5670.  
  5671. public void setCollisionHeight(double height)
  5672.  
  5673. {
  5674.  
  5675. _currentCollisionHeight = height;
  5676.  
  5677. }
  5678.  
  5679.  
  5680.  
  5681. public void setCollisionRadius(double radius)
  5682.  
  5683. {
  5684.  
  5685. _currentCollisionRadius = radius;
  5686.  
  5687. }
  5688.  
  5689.  
  5690.  
  5691. public double getCollisionHeight()
  5692.  
  5693. {
  5694.  
  5695. return _currentCollisionHeight;
  5696.  
  5697. }
  5698.  
  5699.  
  5700.  
  5701. public double getCollisionRadius()
  5702.  
  5703. {
  5704.  
  5705. return _currentCollisionRadius;
  5706.  
  5707. }
  5708.  
  5709.  
  5710.  
  5711. @Override
  5712.  
  5713. protected final CharShots initShots()
  5714.  
  5715. {
  5716.  
  5717. return new NpcShots(this);
  5718.  
  5719. }
  5720.  
  5721.  
  5722.  
  5723. @Override
  5724.  
  5725. public final NpcShots getShots()
  5726.  
  5727. {
  5728.  
  5729. return (NpcShots)_shots;
  5730.  
  5731. }
  5732.  
  5733.  
  5734.  
  5735. @Override
  5736.  
  5737. public NpcInventory getInventory()
  5738.  
  5739. {
  5740.  
  5741. return _inventory;
  5742.  
  5743. }
  5744.  
  5745.  
  5746.  
  5747. private boolean cwCheck(L2PcInstance player)
  5748.  
  5749. {
  5750.  
  5751. return Config.CURSED_WEAPON_NPC_INTERACT || !player.isCursedWeaponEquipped();
  5752.  
  5753. }
  5754.  
  5755.  
  5756.  
  5757. @Override
  5758.  
  5759. public void sendInfo(L2PcInstance activeChar)
  5760.  
  5761. {
  5762.  
  5763. if (Config.TEST_KNOWNLIST && activeChar.isGM())
  5764.  
  5765. activeChar.sendMessage("Knownlist, added NPC: " + getName());
  5766.  
  5767.  
  5768.  
  5769. activeChar.sendPacket(getRunSpeed() == 0 ? new ServerObjectInfo(this) : new AbstractNpcInfo.NpcInfo(this));
  5770.  
  5771. }
  5772.  
  5773.  
  5774.  
  5775. @Override
  5776.  
  5777. public void broadcastFullInfoImpl()
  5778.  
  5779. {
  5780.  
  5781. broadcastPacket(getRunSpeed() == 0 ? new ServerObjectInfo(this) : new AbstractNpcInfo.NpcInfo(this));
  5782.  
  5783. }
  5784.  
  5785.  
  5786.  
  5787. public void setKillable(boolean b)
  5788.  
  5789. {
  5790.  
  5791. _isKillable = b;
  5792.  
  5793. }
  5794.  
  5795.  
  5796.  
  5797. public boolean isKillable()
  5798.  
  5799. {
  5800.  
  5801. return _isKillable;
  5802.  
  5803. }
  5804.  
  5805.  
  5806.  
  5807. public void setQuestDropable(boolean b)
  5808.  
  5809. {
  5810.  
  5811. _questDropable = b;
  5812.  
  5813. }
  5814.  
  5815.  
  5816.  
  5817. public boolean getQuestDropable()
  5818.  
  5819. {
  5820.  
  5821. return _questDropable;
  5822.  
  5823. }
  5824.  
  5825.  
  5826.  
  5827. public boolean canBeChampion()
  5828.  
  5829. {
  5830.  
  5831. switch (getNpcId())
  5832.  
  5833. {
  5834.  
  5835. // Devastated Castle
  5836.  
  5837. case 35411: case 35412: case 35413: case 35414: case 35415: case 35416:
  5838.  
  5839. // Fortress of the Dead
  5840.  
  5841. case 35629: case 35630: case 35631: case 35632: case 35633: case 35634: case 35635:
  5842.  
  5843. case 35636: case 35637:
  5844.  
  5845. return false;
  5846.  
  5847. }
  5848.  
  5849. if (this instanceof L2CCHBossInstance)
  5850.  
  5851. return false;
  5852.  
  5853. return ((this instanceof L2MonsterInstance && !(this instanceof L2Boss)) || (this instanceof L2Boss && Config.CHAMPION_BOSS))
  5854.  
  5855. && Config.CHAMPION_FREQUENCY > 0 && !getTemplate().isQuestMonster() && getLevel() >= Config.CHAMPION_MIN_LEVEL
  5856.  
  5857. && getLevel() <= Config.CHAMPION_MAX_LEVEL;
  5858.  
  5859. }
  5860.  
  5861.  
  5862.  
  5863. public int getQuestAttackStatus()
  5864.  
  5865. {
  5866.  
  5867. return _questAttackStatus;
  5868.  
  5869. }
  5870.  
  5871.  
  5872.  
  5873. public void setQuestAttackStatus(int status)
  5874.  
  5875. {
  5876.  
  5877. _questAttackStatus = status;
  5878.  
  5879. }
  5880.  
  5881.  
  5882.  
  5883. public L2PcInstance getQuestFirstAttacker()
  5884.  
  5885. {
  5886.  
  5887. return _questFirstAttacker;
  5888.  
  5889. }
  5890.  
  5891.  
  5892.  
  5893. public void setQuestFirstAttacker(L2PcInstance attacker)
  5894.  
  5895. {
  5896.  
  5897. _questFirstAttacker = attacker;
  5898.  
  5899. }
  5900.  
  5901.  
  5902.  
  5903. public int getWeaponEnchantLevel()
  5904.  
  5905. {
  5906.  
  5907. return _weaponEnchant;
  5908.  
  5909. }
  5910.  
  5911.  
  5912.  
  5913. public void setWeaponEnchantLevel(int level)
  5914.  
  5915. {
  5916.  
  5917. _weaponEnchant = level;
  5918.  
  5919. }
  5920.  
  5921. }
Add Comment
Please, Sign In to add comment