2
0

CombatFlag.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.model;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.datatables.ItemTable;
  18. import net.sf.l2j.gameserver.datatables.SkillTable;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  22. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  23. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  24. public class CombatFlag
  25. {
  26. //private static final Logger _log = Logger.getLogger(CombatFlag.class.getName());
  27. protected L2PcInstance _player = null;
  28. public int playerId = 0;
  29. private L2ItemInstance _item = null;
  30. private Location _location;
  31. public L2ItemInstance itemInstance;
  32. private int _itemId;
  33. @SuppressWarnings("unused")
  34. private int _heading;
  35. @SuppressWarnings("unused")
  36. private int _fortId;
  37. // =========================================================
  38. // Constructor
  39. public CombatFlag(int fort_id, int x, int y, int z, int heading, int item_id)
  40. {
  41. _fortId = fort_id;
  42. _location = new Location(x,y,z,heading);
  43. _heading = heading;
  44. _itemId = item_id;
  45. }
  46. public synchronized void spawnMe()
  47. {
  48. L2ItemInstance i;
  49. // Init the dropped L2ItemInstance and add it in the world as a visible object at the position where mob was last
  50. i = ItemTable.getInstance().createItem("Combat", _itemId, 1, null, null);
  51. i.spawnMe(_location.getX(), _location.getY(), _location.getZ());
  52. itemInstance = i;
  53. }
  54. public synchronized void unSpawnMe()
  55. {
  56. if ( _player != null )
  57. dropIt();
  58. if ( itemInstance != null )
  59. {
  60. itemInstance.decayMe();
  61. }
  62. }
  63. public void activate(L2PcInstance player, L2ItemInstance item)
  64. {
  65. // if the player is mounted, attempt to unmount first. Only allow picking up
  66. // the comabt flag if unmounting is successful.
  67. if (player.isMounted())
  68. {
  69. if (!player.dismount())
  70. {
  71. // TODO: correct this custom message.
  72. player.sendMessage("You may not pick up this item while riding in this territory");
  73. return;
  74. }
  75. }
  76. // Player holding it data
  77. _player = player;
  78. playerId = _player.getObjectId();
  79. itemInstance = null;
  80. // Add skill
  81. giveSkill();
  82. // Equip with the weapon
  83. _item = item;
  84. _player.getInventory().equipItemAndRecord(_item);
  85. SystemMessage sm = new SystemMessage(SystemMessageId.S1_EQUIPPED);
  86. sm.addItemName(_item);
  87. _player.sendPacket(sm);
  88. // Refresh inventory
  89. if (!Config.FORCE_INVENTORY_UPDATE)
  90. {
  91. InventoryUpdate iu = new InventoryUpdate();
  92. iu.addItem(_item);
  93. _player.sendPacket(iu);
  94. }
  95. else _player.sendPacket(new ItemList(_player, false));
  96. // Refresh player stats
  97. _player.broadcastUserInfo();
  98. _player.setCombatFlagEquipped(true);
  99. }
  100. public void dropIt()
  101. {
  102. // Reset player stats
  103. _player.setCombatFlagEquipped(false);
  104. removeSkill();
  105. _player.destroyItem("DieDrop", _item, null, false);
  106. _item = null;
  107. _player.broadcastUserInfo();
  108. _player = null;
  109. playerId = 0;
  110. }
  111. public void giveSkill()
  112. {
  113. _player.addSkill(SkillTable.getInstance().getInfo(3318, 1), false);
  114. _player.addSkill(SkillTable.getInstance().getInfo(3358, 1), false);
  115. _player.sendSkillList();
  116. }
  117. public void removeSkill()
  118. {
  119. _player.removeSkill(SkillTable.getInstance().getInfo(3318, 1), false);
  120. _player.removeSkill(SkillTable.getInstance().getInfo(3358, 1), false);
  121. _player.sendSkillList();
  122. }
  123. }