Die.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2004-2015 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.network.serverpackets;
  20. import com.l2jserver.gameserver.data.xml.impl.AdminData;
  21. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  22. import com.l2jserver.gameserver.instancemanager.CastleManager;
  23. import com.l2jserver.gameserver.instancemanager.FortManager;
  24. import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
  25. import com.l2jserver.gameserver.model.L2AccessLevel;
  26. import com.l2jserver.gameserver.model.L2Clan;
  27. import com.l2jserver.gameserver.model.L2SiegeClan;
  28. import com.l2jserver.gameserver.model.actor.L2Character;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.entity.Castle;
  31. import com.l2jserver.gameserver.model.entity.Fort;
  32. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  33. import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
  34. public class Die extends L2GameServerPacket
  35. {
  36. private final int _charObjId;
  37. private final boolean _canTeleport;
  38. private final boolean _sweepable;
  39. private L2AccessLevel _access = AdminData.getInstance().getAccessLevel(0);
  40. private L2Clan _clan;
  41. private final L2Character _activeChar;
  42. private boolean _isJailed;
  43. private boolean _staticRes = false;
  44. public Die(L2Character cha)
  45. {
  46. _charObjId = cha.getObjectId();
  47. _activeChar = cha;
  48. if (cha.isPlayer())
  49. {
  50. final L2PcInstance player = cha.getActingPlayer();
  51. _access = player.getAccessLevel();
  52. _clan = player.getClan();
  53. _isJailed = player.isJailed();
  54. }
  55. _canTeleport = cha.canRevive() && !cha.isPendingRevive();
  56. _sweepable = cha.isAttackable() && cha.isSweepActive();
  57. }
  58. @Override
  59. protected final void writeImpl()
  60. {
  61. writeC(0x00);
  62. writeD(_charObjId);
  63. writeD(_canTeleport ? 0x01 : 0);
  64. if (_activeChar.isPlayer() && !OlympiadManager.getInstance().isRegistered(_activeChar.getActingPlayer()) && !_activeChar.isOnEvent())
  65. {
  66. _staticRes = _activeChar.getInventory().haveItemForSelfResurrection();
  67. }
  68. if (_canTeleport && (_clan != null) && !_isJailed)
  69. {
  70. boolean isInCastleDefense = false;
  71. boolean isInFortDefense = false;
  72. L2SiegeClan siegeClan = null;
  73. Castle castle = CastleManager.getInstance().getCastle(_activeChar);
  74. Fort fort = FortManager.getInstance().getFort(_activeChar);
  75. SiegableHall hall = CHSiegeManager.getInstance().getNearbyClanHall(_activeChar);
  76. if ((castle != null) && castle.getSiege().isInProgress())
  77. {
  78. // siege in progress
  79. siegeClan = castle.getSiege().getAttackerClan(_clan);
  80. if ((siegeClan == null) && castle.getSiege().checkIsDefender(_clan))
  81. {
  82. isInCastleDefense = true;
  83. }
  84. }
  85. else if ((fort != null) && fort.getSiege().isInProgress())
  86. {
  87. // siege in progress
  88. siegeClan = fort.getSiege().getAttackerClan(_clan);
  89. if ((siegeClan == null) && fort.getSiege().checkIsDefender(_clan))
  90. {
  91. isInFortDefense = true;
  92. }
  93. }
  94. if (_access.allowFixedRes())
  95. {
  96. _staticRes = true;
  97. }
  98. writeD(_clan.getHideoutId() > 0 ? 0x01 : 0x00); // 6d 01 00 00 00 - to hide away
  99. writeD((_clan.getCastleId() > 0) || isInCastleDefense ? 0x01 : 0x00); // 6d 02 00 00 00 - to castle
  100. writeD((TerritoryWarManager.getInstance().getHQForClan(_clan) != null) || ((siegeClan != null) && !isInCastleDefense && !isInFortDefense && !siegeClan.getFlag().isEmpty()) || ((hall != null) && hall.getSiege().checkIsAttacker(_clan)) ? 0x01 : 0x00); // 6d 03 00 00 00 - to siege HQ
  101. writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
  102. writeD(_staticRes ? 0x01 : 0x00); // 6d 04 00 00 00 - to FIXED
  103. writeD((_clan.getFortId() > 0) || isInFortDefense ? 0x01 : 0x00); // 6d 05 00 00 00 - to fortress
  104. }
  105. else
  106. {
  107. writeD(0x00); // 6d 01 00 00 00 - to hide away
  108. writeD(0x00); // 6d 02 00 00 00 - to castle
  109. writeD(0x00); // 6d 03 00 00 00 - to siege HQ
  110. writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
  111. writeD(_staticRes ? 0x01 : 0x00); // 6d 04 00 00 00 - to FIXED
  112. writeD(0x00); // 6d 05 00 00 00 - to fortress
  113. }
  114. // TODO: protocol 152
  115. //@formatter:off
  116. /*
  117. * writeC(0); //show die animation
  118. * writeD(0); //agathion ress button
  119. * writeD(0); //additional free space
  120. */
  121. //@formatter:on
  122. }
  123. }