2
0

Die.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 net.sf.l2j.gameserver.serverpackets;
  16. import net.sf.l2j.gameserver.datatables.AccessLevel;
  17. import net.sf.l2j.gameserver.datatables.AccessLevels;
  18. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  19. import net.sf.l2j.gameserver.instancemanager.FortManager;
  20. import net.sf.l2j.gameserver.model.L2Attackable;
  21. import net.sf.l2j.gameserver.model.L2Character;
  22. import net.sf.l2j.gameserver.model.L2SiegeClan;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.model.entity.Castle;
  25. import net.sf.l2j.gameserver.model.entity.Fort;
  26. /**
  27. * sample
  28. * 0b
  29. * 952a1048 objectId
  30. * 00000000 00000000 00000000 00000000 00000000 00000000
  31. * format dddddd rev 377
  32. * format ddddddd rev 417
  33. *
  34. * @version $Revision: 1.3.2.1.2.5 $ $Date: 2005/03/27 18:46:18 $
  35. */
  36. public class Die extends L2GameServerPacket
  37. {
  38. private static final String _S__0B_DIE = "[S] 00 Die";
  39. private int _charObjId;
  40. private boolean _fallDown;
  41. private boolean _sweepable;
  42. private AccessLevel _access = AccessLevels._userAccessLevel;
  43. private net.sf.l2j.gameserver.model.L2Clan _clan;
  44. L2Character _activeChar;
  45. /**
  46. * @param _characters
  47. */
  48. public Die(L2Character cha)
  49. {
  50. _activeChar = cha;
  51. if (cha instanceof L2PcInstance) {
  52. L2PcInstance player = (L2PcInstance)cha;
  53. _access = player.getAccessLevel();
  54. _clan=player.getClan();
  55. }
  56. _charObjId = cha.getObjectId();
  57. _fallDown = cha instanceof L2PcInstance ? ((L2PcInstance)cha).mustFallDownOnDeath() : cha.mustFallDownOnDeath();
  58. if (cha instanceof L2Attackable)
  59. _sweepable = ((L2Attackable)cha).isSweepActive();
  60. }
  61. @Override
  62. protected final void writeImpl()
  63. {
  64. if (!_fallDown)
  65. return;
  66. writeC(0x00);
  67. writeD(_charObjId);
  68. // NOTE:
  69. // 6d 00 00 00 00 - to nearest village
  70. // 6d 01 00 00 00 - to hide away
  71. // 6d 02 00 00 00 - to castle
  72. // 6d 03 00 00 00 - to siege HQ
  73. // sweepable
  74. // 6d 04 00 00 00 - FIXED
  75. writeD(0x01); // 6d 00 00 00 00 - to nearest village
  76. if (_clan != null)
  77. {
  78. Boolean isInCastleDefense = false;
  79. Boolean isInFortDefense = false;
  80. L2SiegeClan siegeClan = null;
  81. Castle castle = CastleManager.getInstance().getCastle(_activeChar);
  82. Fort fort = FortManager.getInstance().getFort(_activeChar);
  83. if (castle != null && castle.getSiege().getIsInProgress())
  84. {
  85. //siege in progress
  86. siegeClan = castle.getSiege().getAttackerClan(_clan);
  87. if (siegeClan == null && castle.getSiege().checkIsDefender(_clan)){
  88. isInCastleDefense = true;
  89. }
  90. }
  91. else if (fort != null && fort.getSiege().getIsInProgress())
  92. {
  93. //siege in progress
  94. siegeClan = fort.getSiege().getAttackerClan(_clan);
  95. if (siegeClan == null && fort.getSiege().checkIsDefender(_clan)){
  96. isInFortDefense = true;
  97. }
  98. }
  99. writeD(_clan.getHasHideout() > 0 ? 0x01 : 0x00); // 6d 01 00 00 00 - to hide away
  100. writeD(_clan.getHasCastle() > 0 ||
  101. isInCastleDefense? 0x01 : 0x00); // 6d 02 00 00 00 - to castle
  102. writeD(siegeClan != null &&
  103. !isInCastleDefense && ! isInFortDefense &&
  104. siegeClan.getFlag().size() > 0 ? 0x01 : 0x00); // 6d 03 00 00 00 - to siege HQ
  105. writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
  106. writeD(_access.allowFixedRes() ? 0x01: 0x00); // 6d 04 00 00 00 - to FIXED
  107. writeD(_clan.getHasFort() > 0 || isInFortDefense? 0x01 : 0x00); // 6d 05 00 00 00 - to fortress
  108. }
  109. else
  110. {
  111. writeD(0x00); // 6d 01 00 00 00 - to hide away
  112. writeD(0x00); // 6d 02 00 00 00 - to castle
  113. writeD(0x00); // 6d 03 00 00 00 - to siege HQ
  114. writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
  115. writeD(_access.allowFixedRes() ? 0x01: 0x00); // 6d 04 00 00 00 - to FIXED
  116. writeD(0x00); // 6d 05 00 00 00 - to fortress
  117. }
  118. }
  119. /* (non-Javadoc)
  120. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  121. */
  122. @Override
  123. public String getType()
  124. {
  125. return _S__0B_DIE;
  126. }
  127. }