Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This file is part of the L2J Mobius project.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package org.l2jmobius.gameserver.network.serverpackets;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import org.l2jmobius.commons.network.PacketWriter;
- import org.l2jmobius.gameserver.instancemanager.CastleManager;
- import org.l2jmobius.gameserver.instancemanager.FortManager;
- import org.l2jmobius.gameserver.model.SiegeClan;
- import org.l2jmobius.gameserver.model.actor.Creature;
- import org.l2jmobius.gameserver.model.clan.Clan;
- import org.l2jmobius.gameserver.model.entity.Castle;
- import org.l2jmobius.gameserver.model.entity.Fort;
- import org.l2jmobius.gameserver.network.OutgoingPackets;
- /**
- * @author UnAfraid, Nos
- */
- public class Die implements IClientOutgoingPacket
- {
- private final int _objectId;
- private boolean _toClanHall;
- private boolean _toCastle;
- private boolean _toOutpost;
- private final boolean _isSweepable;
- private boolean _useFeather;
- private boolean _toFortress;
- @SuppressWarnings("unused")
- private boolean _hideAnimation;
- private List<Integer> _items = null;
- @SuppressWarnings("unused")
- private boolean _itemsEnabled;
- public Die(Creature creature)
- {
- _objectId = creature.getObjectId();
- if (creature.isPlayer())
- {
- final Clan clan = creature.getActingPlayer().getClan();
- boolean isInCastleDefense = false;
- boolean isInFortDefense = false;
- SiegeClan siegeClan = null;
- final Castle castle = CastleManager.getInstance().getCastle(creature);
- final Fort fort = FortManager.getInstance().getFort(creature);
- if ((castle != null) && castle.getSiege().isInProgress())
- {
- siegeClan = castle.getSiege().getAttackerClan(clan);
- isInCastleDefense = (siegeClan == null) && castle.getSiege().checkIsDefender(clan);
- }
- else if ((fort != null) && fort.getSiege().isInProgress())
- {
- siegeClan = fort.getSiege().getAttackerClan(clan);
- isInFortDefense = (siegeClan == null) && fort.getSiege().checkIsDefender(clan);
- }
- _toClanHall = (clan != null) && (clan.getHideoutId() > 0);
- _toCastle = ((clan != null) && (clan.getCastleId() > 0)) || isInCastleDefense;
- _toOutpost = ((siegeClan != null) && !isInCastleDefense && !isInFortDefense && !siegeClan.getFlag().isEmpty());
- _useFeather = creature.getAccessLevel().allowFixedRes() || creature.getInventory().haveItemForSelfResurrection();
- _toFortress = ((clan != null) && (clan.getFortId() > 0)) || isInFortDefense;
- }
- _isSweepable = creature.isAttackable() && creature.isSweepActive();
- }
- public void setHideAnimation(boolean val)
- {
- _hideAnimation = val;
- }
- public void addItem(int itemId)
- {
- if (_items == null)
- {
- _items = new ArrayList<>(8);
- }
- if (_items.size() < 8)
- {
- _items.add(itemId);
- }
- else
- {
- throw new IndexOutOfBoundsException("Die packet doesn't support more then 8 items!");
- }
- }
- public List<Integer> getItems()
- {
- return _items != null ? _items : Collections.emptyList();
- }
- public void setItemsEnabled(boolean val)
- {
- _itemsEnabled = val;
- }
- @Override
- public boolean write(PacketWriter packet)
- {
- OutgoingPackets.DIE.writeId(packet);
- packet.writeD(_objectId);
- // 2: Clan Hall, 4: Castle, 6: Clan Hall & Castle, 8: Fortress, 10: Clan Hall & Fortress,
- // 16: Outpost, 18: Clan Hall & Outpost, 24: Outpost & Fortress, 26: Clan Hall & Outpost & Fortress,
- // 32: Feather, 34: Clan Hall & Feather, 36: Castle & Feather, 38: Clan Hall & Castle & Feather,
- // 40: Fortress & Feather, 42: Clan Hall & Fortress & Feather, 48: Outpost & Feather,
- // 50: Clan Hall & Outpost & Feather, 56: Outpost & Fortress & Feather,
- // 58: Clan Hall & Outpost & Fortress & Feather
- // NOT USED:
- // 12: Castle & Fortress, 14: Clan Hall & Castle & Fortress, 20: Castle & Outpost
- // 22: Clan Hall & Castle & Outpost, 28: Castle & Outpost & Fortress,
- // 30: Clan Hall & Castle & Outpost & Fortress, 44: Castle & Fortress & Feather
- // 46: Clan Hall & Castle & Fortress & Feather, 52: Castle & Outpost & Feather
- // 54: Clan Hall & Castle & Outpost & Feather, 60: Castle & Outpost & Fortress & Feather
- // 62: Clan Hall & Castle & Outpost & Fortress & Feather
- if (_toClanHall && _toCastle && _toOutpost && _toFortress && _useFeather)
- {
- packet.writeC(62);
- }
- else if (_toCastle && _toOutpost && _toFortress && _useFeather)
- {
- packet.writeC(60);
- }
- else if (_toClanHall && _toOutpost && _toFortress && _useFeather)
- {
- packet.writeC(58);
- }
- else if (_toOutpost && _toFortress && _useFeather)
- {
- packet.writeC(56);
- }
- else if (_toClanHall && _toCastle && _toOutpost && _useFeather)
- {
- packet.writeC(54);
- }
- else if (_toCastle && _toOutpost && _useFeather)
- {
- packet.writeC(52);
- }
- else if (_toClanHall && _toOutpost && _useFeather)
- {
- packet.writeC(50);
- }
- else if (_toOutpost && _useFeather)
- {
- packet.writeC(48);
- }
- else if (_toClanHall && _toCastle && _toFortress && _useFeather)
- {
- packet.writeC(46);
- }
- else if (_toCastle && _toFortress && _useFeather)
- {
- packet.writeC(44);
- }
- else if (_toClanHall && _toFortress && _useFeather)
- {
- packet.writeC(42);
- }
- else if (_toFortress && _useFeather)
- {
- packet.writeC(40);
- }
- else if (_toClanHall && _toCastle && _useFeather)
- {
- packet.writeC(38);
- }
- else if (_toCastle && _useFeather)
- {
- packet.writeC(36);
- }
- else if (_toClanHall && _useFeather)
- {
- packet.writeC(34);
- }
- else if (_useFeather)
- {
- packet.writeC(32);
- }
- else if (_toClanHall && _toCastle && _toOutpost && _toFortress)
- {
- packet.writeC(30);
- }
- else if (_toCastle && _toOutpost && _toFortress)
- {
- packet.writeC(28);
- }
- else if (_toClanHall && _toOutpost && _toFortress)
- {
- packet.writeC(26);
- }
- else if (_toOutpost && _toFortress)
- {
- packet.writeC(24);
- }
- else if (_toClanHall && _toCastle && _toOutpost)
- {
- packet.writeC(22);
- }
- else if (_toCastle && _toOutpost)
- {
- packet.writeC(20);
- }
- else if (_toClanHall && _toOutpost)
- {
- packet.writeC(18);
- }
- else if (_toOutpost)
- {
- packet.writeC(16);
- }
- else if (_toClanHall && _toCastle && _toFortress)
- {
- packet.writeC(14);
- }
- else if (_toCastle && _toFortress)
- {
- packet.writeC(12);
- }
- else if (_toClanHall && _toFortress)
- {
- packet.writeC(10);
- }
- else if (_toFortress)
- {
- packet.writeC(8);
- }
- else if (_toClanHall && _toCastle)
- {
- packet.writeC(6);
- }
- else if (_toCastle)
- {
- packet.writeC(4);
- }
- else if (_toClanHall)
- {
- packet.writeC(2);
- }
- else
- {
- packet.writeC(0);
- }
- packet.writeC(0); // unk
- packet.writeC(_isSweepable ? 1 : 0); // sweeper effect
- packet.writeC(0); // 1: Resurrection zone during siege.. wtf
- // OLD
- // packet.writeD(_toVillage ? 0x01 : 0x00);
- // packet.writeD(_toClanHall ? 0x01 : 0x00);
- // packet.writeD(_toCastle ? 0x01 : 0x00);
- // packet.writeD(_toOutpost ? 0x01 : 0x00);
- // packet.writeD(_isSweepable ? 0x01 : 0x00);
- // packet.writeD(_useFeather ? 0x01 : 0x00);
- // packet.writeD(_toFortress ? 0x01 : 0x00);
- // packet.writeD(0x00); // Disables use Feather button for X seconds
- // packet.writeD(0x00); // Adventure's Song
- // packet.writeC(_hideAnimation ? 0x01 : 0x00);
- // packet.writeC(_itemsEnabled ? 0x01 : 0x00);
- // packet.writeD(getItems().size());
- // getItems().forEach(packet::writeD);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement