CombatFlag.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.item.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. protected L2PcInstance _player = null;
  28. private int _playerId = 0;
  29. private L2ItemInstance _item = null;
  30. private Location _location;
  31. private 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. // Init the dropped L2ItemInstance and add it in the world as a visible object at the position where mob was last
  49. _itemInstance = ItemTable.getInstance().createItem("Combat", _itemId, 1, null, null);
  50. _itemInstance.dropMe(null, _location.getX(), _location.getY(), _location.getZ());
  51. }
  52. public synchronized void unSpawnMe()
  53. {
  54. if (_player != null)
  55. {
  56. dropIt();
  57. }
  58. if (_itemInstance != null)
  59. {
  60. _itemInstance.decayMe();
  61. }
  62. }
  63. public boolean activate(L2PcInstance player, L2ItemInstance item)
  64. {
  65. if (player.isMounted())
  66. {
  67. player.sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
  68. return false;
  69. }
  70. // Player holding it data
  71. _player = player;
  72. _playerId = _player.getObjectId();
  73. _itemInstance = null;
  74. // Equip with the weapon
  75. _item = item;
  76. _player.getInventory().equipItem(_item);
  77. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_EQUIPPED);
  78. sm.addItemName(_item);
  79. _player.sendPacket(sm);
  80. // Refresh inventory
  81. if (!Config.FORCE_INVENTORY_UPDATE)
  82. {
  83. InventoryUpdate iu = new InventoryUpdate();
  84. iu.addItem(_item);
  85. _player.sendPacket(iu);
  86. }
  87. else _player.sendPacket(new ItemList(_player, false));
  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 getPlayerOnjectId()
  106. {
  107. return _playerId;
  108. }
  109. public L2ItemInstance getCombatFlagInstance()
  110. {
  111. return _itemInstance;
  112. }
  113. }