CombatFlag.java 4.0 KB

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