JVBarbosa

Die.java

Mar 10th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.74 KB | None | 0 0
  1. /*
  2.  * L2jProject x - www.l2jprojectx.com
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2, or (at your option)
  7.  * any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17.  * 02111-1307, USA.
  18.  *
  19.  * http://www.gnu.org/copyleft/gpl.html
  20.  */
  21. package net.l2jpx.gameserver.network.serverpackets;
  22.  
  23. import net.l2jpx.gameserver.datatables.AccessLevel;
  24. import net.l2jpx.gameserver.datatables.xml.AccessLevels;
  25. import net.l2jpx.gameserver.managers.CastleManager;
  26. import net.l2jpx.gameserver.managers.FortManager;
  27. import net.l2jpx.gameserver.model.L2Attackable;
  28. import net.l2jpx.gameserver.model.L2Character;
  29. import net.l2jpx.gameserver.model.L2SiegeClan;
  30. import net.l2jpx.gameserver.model.actor.instance.L2PcInstance;
  31. import net.l2jpx.gameserver.model.entity.event.CTF;
  32. import net.l2jpx.gameserver.model.entity.event.DM;
  33. import net.l2jpx.gameserver.model.entity.event.TvT;
  34. import net.l2jpx.gameserver.model.entity.siege.Castle;
  35. import net.l2jpx.gameserver.model.entity.siege.Fort;
  36.  
  37. /**
  38.  * sample 0b 952a1048 objectId 00000000 00000000 00000000 00000000 00000000 00000000 format dddddd rev 377 format ddddddd rev 417
  39.  * @version $Revision: 1.3.3 $ $Date: 2009/04/29 00:46:18 $
  40.  */
  41. public class Die extends L2GameServerPacket
  42. {
  43.     private static final String _S__0B_DIE = "[S] 06 Die";
  44.     private final int _charObjId;
  45.     private final boolean _fake;
  46.     private boolean _sweepable;
  47.     private boolean _canTeleport;
  48.     private AccessLevel _access = AccessLevels._userAccessLevel;
  49.     private net.l2jpx.gameserver.model.L2Clan _clan;
  50.     L2Character _activeChar;
  51.    
  52.     /**
  53.      * @param cha
  54.      */
  55.     public Die(final L2Character cha)
  56.     {
  57.         _activeChar = cha;
  58.         if (cha instanceof L2PcInstance)
  59.         {
  60.             final L2PcInstance player = (L2PcInstance) cha;
  61.             _access = player.getAccessLevel();
  62.             _clan = player.getClan();
  63.             _canTeleport = !((TvT.is_started() && player._inEventTvT) || (DM.is_started() && player._inEventDM) || (CTF.is_started() && player._inEventCTF) || player.isInFunEvent() || player.isInArenaEvent() || player.isPendingRevive());
  64.         }
  65.         _charObjId = cha.getObjectId();
  66.         _fake = !cha.isDead();
  67.         if (cha instanceof L2Attackable)
  68.         {
  69.             _sweepable = ((L2Attackable) cha).isSweepActive();
  70.         }
  71.        
  72.     }
  73.    
  74.     @Override
  75.     protected final void writeImpl()
  76.     {
  77.         if (_fake)
  78.             return;
  79.        
  80.         writeC(0x06);
  81.        
  82.         writeD(_charObjId);
  83.         // NOTE:
  84.         // 6d 00 00 00 00 - to nearest village
  85.         // 6d 01 00 00 00 - to hide away
  86.         // 6d 02 00 00 00 - to castle
  87.         // 6d 03 00 00 00 - to siege HQ
  88.         // sweepable
  89.         // 6d 04 00 00 00 - FIXED
  90.        
  91.         writeD(_canTeleport ? 0x01 : 0); // 6d 00 00 00 00 - to nearest village
  92.        
  93.         if (_canTeleport && _clan != null)
  94.         {
  95.             L2SiegeClan siegeClan = null;
  96.             Boolean isInDefense = false;
  97.             final Castle castle = CastleManager.getInstance().getCastle(_activeChar);
  98.             final Fort fort = FortManager.getInstance().getFort(_activeChar);
  99.            
  100.             if (castle != null && castle.getSiege().getIsInProgress())
  101.             {
  102.                 // siege in progress
  103.                 siegeClan = castle.getSiege().getAttackerClan(_clan);
  104.                 if (siegeClan == null && castle.getSiege().checkIsDefender(_clan))
  105.                 {
  106.                     isInDefense = true;
  107.                 }
  108.             }
  109.             else if (fort != null && fort.getSiege().getIsInProgress())
  110.             {
  111.                 // siege in progress
  112.                 siegeClan = fort.getSiege().getAttackerClan(_clan);
  113.                 if (siegeClan == null && fort.getSiege().checkIsDefender(_clan))
  114.                 {
  115.                     isInDefense = true;
  116.                 }
  117.             }
  118.            
  119.             writeD(_clan.getHasHideout() > 0 ? 0x01 : 0x00); // 6d 01 00 00 00 - to hide away
  120.             writeD(_clan.getHasCastle() > 0 || _clan.getHasFort() > 0 || isInDefense ? 0x01 : 0x00); // 6d 02 00 00 00 - to castle
  121.             writeD(siegeClan != null && !isInDefense && siegeClan.getFlag().size() > 0 ? 0x01 : 0x00); // 6d 03 00 00 00 - to siege HQ
  122.         }
  123.         else
  124.         {
  125.             writeD(0x00); // 6d 01 00 00 00 - to hide away
  126.             writeD(0x00); // 6d 02 00 00 00 - to castle
  127.             writeD(0x00); // 6d 03 00 00 00 - to siege HQ
  128.         }
  129.        
  130.         writeD(_sweepable ? 0x01 : 0x00); // sweepable (blue glow)
  131.         writeD(_access.allowFixedRes() ? 0x01 : 0x00); // 6d 04 00 00 00 - to FIXED
  132.     }
  133.    
  134.     /*
  135.      * (non-Javadoc)
  136.      * @see net.l2jpx.gameserver.serverpackets.ServerBasePacket#getType()
  137.      */
  138.     @Override
  139.     public String getType()
  140.     {
  141.         return _S__0B_DIE;
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment