CombatFlag.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright © 2004-2019 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.datatables.ItemTable;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  26. import com.l2jserver.gameserver.network.serverpackets.ItemList;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. public class CombatFlag
  29. {
  30. // private static final Logger _log = Logger.getLogger(CombatFlag.class.getName());
  31. private L2PcInstance _player = null;
  32. private int _playerId = 0;
  33. private L2ItemInstance _item = null;
  34. private L2ItemInstance _itemInstance;
  35. private final Location _location;
  36. private final int _itemId;
  37. public CombatFlag(int fort_id, int x, int y, int z, int heading, int item_id)
  38. {
  39. _location = new Location(x, y, z, heading);
  40. _itemId = item_id;
  41. }
  42. public synchronized void spawnMe()
  43. {
  44. // Init the dropped L2ItemInstance and add it in the world as a visible object at the position where mob was last
  45. _itemInstance = ItemTable.getInstance().createItem("Combat", _itemId, 1, null, null);
  46. _itemInstance.dropMe(null, _location.getX(), _location.getY(), _location.getZ());
  47. }
  48. public synchronized void unSpawnMe()
  49. {
  50. if (_player != null)
  51. {
  52. dropIt();
  53. }
  54. if (_itemInstance != null)
  55. {
  56. _itemInstance.decayMe();
  57. }
  58. }
  59. public boolean activate(L2PcInstance player, L2ItemInstance item)
  60. {
  61. if (player.isMounted())
  62. {
  63. player.sendPacket(SystemMessageId.CANNOT_EQUIP_ITEM_DUE_TO_BAD_CONDITION);
  64. return false;
  65. }
  66. // Player holding it data
  67. _player = player;
  68. _playerId = _player.getObjectId();
  69. _itemInstance = null;
  70. // Equip with the weapon
  71. _item = item;
  72. _player.getInventory().equipItem(_item);
  73. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_EQUIPPED);
  74. sm.addItemName(_item);
  75. _player.sendPacket(sm);
  76. // Refresh inventory
  77. if (!Config.FORCE_INVENTORY_UPDATE)
  78. {
  79. InventoryUpdate iu = new InventoryUpdate();
  80. iu.addItem(_item);
  81. _player.sendPacket(iu);
  82. }
  83. else
  84. {
  85. _player.sendPacket(new ItemList(_player, false));
  86. }
  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().unEquipItemInBodySlot(slot);
  98. _player.destroyItem("CombatFlag", _item, null, true);
  99. _item = null;
  100. _player.broadcastUserInfo();
  101. _player = null;
  102. _playerId = 0;
  103. }
  104. public int getPlayerObjectId()
  105. {
  106. return _playerId;
  107. }
  108. public L2ItemInstance getCombatFlagInstance()
  109. {
  110. return _itemInstance;
  111. }
  112. }