Advertisement
Guest User

DIE packet

a guest
Sep 25th, 2019
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.09 KB | None | 0 0
  1. /*
  2.  * This file is part of the L2J Mobius project.
  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 3 of the License, or
  7.  * (at your option) 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 GNU
  12.  * 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, see <http://www.gnu.org/licenses/>.
  16.  */
  17. package org.l2jmobius.gameserver.network.serverpackets;
  18.  
  19. import java.util.ArrayList;
  20. import java.util.Collections;
  21. import java.util.List;
  22.  
  23. import org.l2jmobius.commons.network.PacketWriter;
  24. import org.l2jmobius.gameserver.instancemanager.CastleManager;
  25. import org.l2jmobius.gameserver.instancemanager.FortManager;
  26. import org.l2jmobius.gameserver.model.SiegeClan;
  27. import org.l2jmobius.gameserver.model.actor.Creature;
  28. import org.l2jmobius.gameserver.model.clan.Clan;
  29. import org.l2jmobius.gameserver.model.entity.Castle;
  30. import org.l2jmobius.gameserver.model.entity.Fort;
  31. import org.l2jmobius.gameserver.network.OutgoingPackets;
  32.  
  33. /**
  34.  * @author UnAfraid, Nos
  35.  */
  36. public class Die implements IClientOutgoingPacket
  37. {
  38.     private final int _objectId;
  39.     private boolean _toClanHall;
  40.     private boolean _toCastle;
  41.     private boolean _toOutpost;
  42.     private final boolean _isSweepable;
  43.     private boolean _useFeather;
  44.     private boolean _toFortress;
  45.     @SuppressWarnings("unused")
  46.     private boolean _hideAnimation;
  47.     private List<Integer> _items = null;
  48.     @SuppressWarnings("unused")
  49.     private boolean _itemsEnabled;
  50.    
  51.     public Die(Creature creature)
  52.     {
  53.         _objectId = creature.getObjectId();
  54.         if (creature.isPlayer())
  55.         {
  56.             final Clan clan = creature.getActingPlayer().getClan();
  57.             boolean isInCastleDefense = false;
  58.             boolean isInFortDefense = false;
  59.            
  60.             SiegeClan siegeClan = null;
  61.             final Castle castle = CastleManager.getInstance().getCastle(creature);
  62.             final Fort fort = FortManager.getInstance().getFort(creature);
  63.             if ((castle != null) && castle.getSiege().isInProgress())
  64.             {
  65.                 siegeClan = castle.getSiege().getAttackerClan(clan);
  66.                 isInCastleDefense = (siegeClan == null) && castle.getSiege().checkIsDefender(clan);
  67.             }
  68.             else if ((fort != null) && fort.getSiege().isInProgress())
  69.             {
  70.                 siegeClan = fort.getSiege().getAttackerClan(clan);
  71.                 isInFortDefense = (siegeClan == null) && fort.getSiege().checkIsDefender(clan);
  72.             }
  73.            
  74.             _toClanHall = (clan != null) && (clan.getHideoutId() > 0);
  75.             _toCastle = ((clan != null) && (clan.getCastleId() > 0)) || isInCastleDefense;
  76.             _toOutpost = ((siegeClan != null) && !isInCastleDefense && !isInFortDefense && !siegeClan.getFlag().isEmpty());
  77.             _useFeather = creature.getAccessLevel().allowFixedRes() || creature.getInventory().haveItemForSelfResurrection();
  78.             _toFortress = ((clan != null) && (clan.getFortId() > 0)) || isInFortDefense;
  79.         }
  80.        
  81.         _isSweepable = creature.isAttackable() && creature.isSweepActive();
  82.     }
  83.    
  84.     public void setHideAnimation(boolean val)
  85.     {
  86.         _hideAnimation = val;
  87.     }
  88.    
  89.     public void addItem(int itemId)
  90.     {
  91.         if (_items == null)
  92.         {
  93.             _items = new ArrayList<>(8);
  94.         }
  95.        
  96.         if (_items.size() < 8)
  97.         {
  98.             _items.add(itemId);
  99.         }
  100.         else
  101.         {
  102.             throw new IndexOutOfBoundsException("Die packet doesn't support more then 8 items!");
  103.         }
  104.     }
  105.    
  106.     public List<Integer> getItems()
  107.     {
  108.         return _items != null ? _items : Collections.emptyList();
  109.     }
  110.    
  111.     public void setItemsEnabled(boolean val)
  112.     {
  113.         _itemsEnabled = val;
  114.     }
  115.    
  116.     @Override
  117.     public boolean write(PacketWriter packet)
  118.     {
  119.         OutgoingPackets.DIE.writeId(packet);
  120.        
  121.         packet.writeD(_objectId);
  122.         // 2: Clan Hall, 4: Castle, 6: Clan Hall & Castle, 8: Fortress, 10: Clan Hall & Fortress,
  123.         // 16: Outpost, 18: Clan Hall & Outpost, 24: Outpost & Fortress, 26: Clan Hall & Outpost & Fortress,
  124.         // 32: Feather, 34: Clan Hall & Feather, 36: Castle & Feather, 38: Clan Hall & Castle & Feather,
  125.         // 40: Fortress & Feather, 42: Clan Hall & Fortress & Feather, 48: Outpost & Feather,
  126.         // 50: Clan Hall & Outpost & Feather, 56: Outpost & Fortress & Feather,
  127.         // 58: Clan Hall & Outpost & Fortress & Feather
  128.         // NOT USED:
  129.         // 12: Castle & Fortress, 14: Clan Hall & Castle & Fortress, 20: Castle & Outpost
  130.         // 22: Clan Hall & Castle & Outpost, 28: Castle & Outpost & Fortress,
  131.         // 30: Clan Hall & Castle & Outpost & Fortress, 44: Castle & Fortress & Feather
  132.         // 46: Clan Hall & Castle & Fortress & Feather, 52: Castle & Outpost & Feather
  133.         // 54: Clan Hall & Castle & Outpost & Feather, 60: Castle & Outpost & Fortress & Feather
  134.         // 62: Clan Hall & Castle & Outpost & Fortress & Feather
  135.         if (_toClanHall && _toCastle && _toOutpost && _toFortress && _useFeather)
  136.         {
  137.             packet.writeC(62);
  138.         }
  139.         else if (_toCastle && _toOutpost && _toFortress && _useFeather)
  140.         {
  141.             packet.writeC(60);
  142.         }
  143.         else if (_toClanHall && _toOutpost && _toFortress && _useFeather)
  144.         {
  145.             packet.writeC(58);
  146.         }
  147.         else if (_toOutpost && _toFortress && _useFeather)
  148.         {
  149.             packet.writeC(56);
  150.         }
  151.         else if (_toClanHall && _toCastle && _toOutpost && _useFeather)
  152.         {
  153.             packet.writeC(54);
  154.         }
  155.         else if (_toCastle && _toOutpost && _useFeather)
  156.         {
  157.             packet.writeC(52);
  158.         }
  159.         else if (_toClanHall && _toOutpost && _useFeather)
  160.         {
  161.             packet.writeC(50);
  162.         }
  163.         else if (_toOutpost && _useFeather)
  164.         {
  165.             packet.writeC(48);
  166.         }
  167.         else if (_toClanHall && _toCastle && _toFortress && _useFeather)
  168.         {
  169.             packet.writeC(46);
  170.         }
  171.         else if (_toCastle && _toFortress && _useFeather)
  172.         {
  173.             packet.writeC(44);
  174.         }
  175.         else if (_toClanHall && _toFortress && _useFeather)
  176.         {
  177.             packet.writeC(42);
  178.         }
  179.         else if (_toFortress && _useFeather)
  180.         {
  181.             packet.writeC(40);
  182.         }
  183.         else if (_toClanHall && _toCastle && _useFeather)
  184.         {
  185.             packet.writeC(38);
  186.         }
  187.         else if (_toCastle && _useFeather)
  188.         {
  189.             packet.writeC(36);
  190.         }
  191.         else if (_toClanHall && _useFeather)
  192.         {
  193.             packet.writeC(34);
  194.         }
  195.         else if (_useFeather)
  196.         {
  197.             packet.writeC(32);
  198.         }
  199.         else if (_toClanHall && _toCastle && _toOutpost && _toFortress)
  200.         {
  201.             packet.writeC(30);
  202.         }
  203.         else if (_toCastle && _toOutpost && _toFortress)
  204.         {
  205.             packet.writeC(28);
  206.         }
  207.         else if (_toClanHall && _toOutpost && _toFortress)
  208.         {
  209.             packet.writeC(26);
  210.         }
  211.         else if (_toOutpost && _toFortress)
  212.         {
  213.             packet.writeC(24);
  214.         }
  215.         else if (_toClanHall && _toCastle && _toOutpost)
  216.         {
  217.             packet.writeC(22);
  218.         }
  219.         else if (_toCastle && _toOutpost)
  220.         {
  221.             packet.writeC(20);
  222.         }
  223.         else if (_toClanHall && _toOutpost)
  224.         {
  225.             packet.writeC(18);
  226.         }
  227.         else if (_toOutpost)
  228.         {
  229.             packet.writeC(16);
  230.         }
  231.         else if (_toClanHall && _toCastle && _toFortress)
  232.         {
  233.             packet.writeC(14);
  234.         }
  235.         else if (_toCastle && _toFortress)
  236.         {
  237.             packet.writeC(12);
  238.         }
  239.         else if (_toClanHall && _toFortress)
  240.         {
  241.             packet.writeC(10);
  242.         }
  243.         else if (_toFortress)
  244.         {
  245.             packet.writeC(8);
  246.         }
  247.         else if (_toClanHall && _toCastle)
  248.         {
  249.             packet.writeC(6);
  250.         }
  251.         else if (_toCastle)
  252.         {
  253.             packet.writeC(4);
  254.         }
  255.         else if (_toClanHall)
  256.         {
  257.             packet.writeC(2);
  258.         }
  259.         else
  260.         {
  261.             packet.writeC(0);
  262.         }
  263.        
  264.         packet.writeC(0); // unk
  265.         packet.writeC(_isSweepable ? 1 : 0); // sweeper effect
  266.         packet.writeC(0); // 1: Resurrection zone during siege.. wtf
  267.        
  268.         // OLD
  269.         // packet.writeD(_toVillage ? 0x01 : 0x00);
  270.         // packet.writeD(_toClanHall ? 0x01 : 0x00);
  271.         // packet.writeD(_toCastle ? 0x01 : 0x00);
  272.         // packet.writeD(_toOutpost ? 0x01 : 0x00);
  273.         // packet.writeD(_isSweepable ? 0x01 : 0x00);
  274.         // packet.writeD(_useFeather ? 0x01 : 0x00);
  275.         // packet.writeD(_toFortress ? 0x01 : 0x00);
  276.         // packet.writeD(0x00); // Disables use Feather button for X seconds
  277.         // packet.writeD(0x00); // Adventure's Song
  278.         // packet.writeC(_hideAnimation ? 0x01 : 0x00);
  279.        
  280.         // packet.writeC(_itemsEnabled ? 0x01 : 0x00);
  281.         // packet.writeD(getItems().size());
  282.         // getItems().forEach(packet::writeD);
  283.         return true;
  284.     }
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement