CombatFlag.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 com.l2jserver.gameserver.model;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.ItemTable;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  22. import com.l2jserver.gameserver.network.serverpackets.ItemList;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. @SuppressWarnings("unused")
  25. public class CombatFlag
  26. {
  27. // private static final Logger _log = Logger.getLogger(CombatFlag.class.getName());
  28. private L2PcInstance _player = null;
  29. private int _playerId = 0;
  30. private L2ItemInstance _item = null;
  31. private L2ItemInstance _itemInstance;
  32. private final Location _location;
  33. private final int _itemId;
  34. private final int _heading;
  35. private final int _fortId;
  36. public CombatFlag(int fort_id, int x, int y, int z, int heading, int item_id)
  37. {
  38. _fortId = fort_id;
  39. _location = new Location(x, y, z, heading);
  40. _heading = heading;
  41. _itemId = item_id;
  42. }
  43. public synchronized void spawnMe()
  44. {
  45. // Init the dropped L2ItemInstance and add it in the world as a visible object at the position where mob was last
  46. _itemInstance = ItemTable.getInstance().createItem("Combat", _itemId, 1, null, null);
  47. _itemInstance.dropMe(null, _location.getX(), _location.getY(), _location.getZ());
  48. }
  49. public synchronized void unSpawnMe()
  50. {
  51. if (_player != null)
  52. {
  53. dropIt();
  54. }
  55. if (_itemInstance != null)
  56. {
  57. _itemInstance.decayMe();
  58. }
  59. }
  60. public boolean activate(L2PcInstance player, L2ItemInstance item)
  61. {
  62. if (player.isMounted())
  63. {
  64. player.sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
  65. return false;
  66. }
  67. // Player holding it data
  68. _player = player;
  69. _playerId = _player.getObjectId();
  70. _itemInstance = null;
  71. // Equip with the weapon
  72. _item = item;
  73. _player.getInventory().equipItem(_item);
  74. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_EQUIPPED);
  75. sm.addItemName(_item);
  76. _player.sendPacket(sm);
  77. // Refresh inventory
  78. if (!Config.FORCE_INVENTORY_UPDATE)
  79. {
  80. InventoryUpdate iu = new InventoryUpdate();
  81. iu.addItem(_item);
  82. _player.sendPacket(iu);
  83. }
  84. else
  85. {
  86. _player.sendPacket(new ItemList(_player, false));
  87. }
  88. // Refresh player stats
  89. _player.broadcastUserInfo();
  90. _player.setCombatFlagEquipped(true);
  91. return true;
  92. }
  93. public void dropIt()
  94. {
  95. // Reset player stats
  96. _player.setCombatFlagEquipped(false);
  97. int slot = _player.getInventory().getSlotFromItem(_item);
  98. _player.getInventory().unEquipItemInBodySlot(slot);
  99. _player.destroyItem("CombatFlag", _item, null, true);
  100. _item = null;
  101. _player.broadcastUserInfo();
  102. _player = null;
  103. _playerId = 0;
  104. }
  105. public int getPlayerObjectId()
  106. {
  107. return _playerId;
  108. }
  109. public L2ItemInstance getCombatFlagInstance()
  110. {
  111. return _itemInstance;
  112. }
  113. }