CombatFlag.java 3.6 KB

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