Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.l2jmobius.gameserver.model.actor;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.logging.Level;
- import org.l2jmobius.commons.database.DatabaseFactory;
- import org.l2jmobius.gameserver.model.CharSelectInfoPackage;
- import org.l2jmobius.gameserver.model.World;
- import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
- import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
- import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
- import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
- import org.l2jmobius.gameserver.network.serverpackets.NpcInfoPolymorph;
- public class Monument extends Npc
- {
- private CharSelectInfoPackage _polymorphInfo;
- private int _nameColor = 0xFFFFFF;
- private int _titleColor = 0xFFFF77;
- private String _visibleTitle = "";
- public Monument(NpcTemplate template)
- {
- super(template);
- setInvul(true);
- }
- @Override
- public boolean hasRandomAnimation()
- {
- switch (getId())
- {
- // onDeath
- // case 10000:
- // onRandomAnimation(13);
- // return true;
- // Victory
- case 10000:
- case 10001:
- onRandomAnimation(3);
- return true;
- }
- return false;
- }
- public CharSelectInfoPackage getPolymorphInfo()
- {
- return _polymorphInfo;
- }
- public void setPolymorphInfo(CharSelectInfoPackage polymorphInfo)
- {
- _polymorphInfo = polymorphInfo;
- World.getInstance().forEachVisibleObjectInRange(this, Player.class, 100000, player -> sendInfo(player));
- }
- public int getNameColor()
- {
- return _nameColor;
- }
- public void setNameColor(int nameColor)
- {
- _nameColor = nameColor;
- }
- public int getTitleColor()
- {
- return _titleColor;
- }
- public void setTitleColor(int titleColor)
- {
- _titleColor = titleColor;
- }
- public String getVisibleTitle()
- {
- return _visibleTitle;
- }
- public void setVisibleTitle(String title)
- {
- _visibleTitle = title == null ? "" : title;
- }
- @Override
- public void sendInfo(Player player)
- {
- super.sendInfo(player);
- if (getPolymorphInfo() != null)
- {
- player.sendPacket(new NpcInfoPolymorph(this));
- }
- }
- @Override
- public String getHtmlPath(int npcId, int val)
- {
- String pom = "" + npcId;
- if (val != 0)
- {
- pom += "-" + val;
- }
- return "data/html/mods/polymorph/" + pom + ".htm";
- }
- @Override
- public void showChatWindow(Player player, int val)
- {
- String filename = getHtmlPath(getId(), val);
- // Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the Player
- final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
- html.setFile(player, filename);
- html.replace("%objectId%", getObjectId());
- html.replace("%ownername%", getPolymorphInfo() != null ? getPolymorphInfo().getName() : "");
- player.sendPacket(html);
- // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- public static CharSelectInfoPackage loadCharInfo(int objectId)
- {
- try (Connection con = DatabaseFactory.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT char_name, race, base_class, classid, sex, face, hairStyle, hairColor, clanid FROM characters WHERE charId = ?"))
- {
- ps.setInt(1, objectId);
- try (ResultSet rs = ps.executeQuery())
- {
- if (rs.next())
- {
- final CharSelectInfoPackage charInfo = new CharSelectInfoPackage(objectId, rs.getString("char_name"));
- charInfo.setRace(rs.getInt("race"));
- charInfo.setBaseClassId(rs.getInt("base_class"));
- charInfo.setClassId(rs.getInt("classid"));
- charInfo.setSex(rs.getInt("sex"));
- charInfo.setFace(rs.getInt("face"));
- charInfo.setHairStyle(rs.getInt("hairStyle"));
- charInfo.setHairColor(rs.getInt("hairColor"));
- charInfo.setClanId(rs.getInt("clanid"));
- // Get the augmentation id for equipped weapon
- int weaponObjId = charInfo.getPaperdollObjectId(Inventory.PAPERDOLL_RHAND);
- if (weaponObjId > 0)
- {
- try (PreparedStatement psAug = con.prepareStatement("SELECT augAttributes FROM item_attributes WHERE itemId = ?"))
- {
- psAug.setInt(1, weaponObjId);
- try (ResultSet rsAugment = psAug.executeQuery())
- {
- if (rsAugment.next())
- {
- int augment = rsAugment.getInt("augAttributes");
- charInfo.setAugmentationId(augment == -1 ? 0 : augment);
- }
- }
- }
- }
- return charInfo;
- }
- }
- }
- catch (Exception e)
- {
- LOGGER.log(Level.WARNING, "Could not restore char info: " + e.getMessage(), e);
- }
- return null;
- }
- }
- package org.l2jmobius.gameserver.network.serverpackets;
- import org.l2jmobius.gameserver.data.sql.ClanTable;
- import org.l2jmobius.gameserver.data.xml.PlayerTemplateData;
- import org.l2jmobius.gameserver.model.CharSelectInfoPackage;
- import org.l2jmobius.gameserver.model.actor.Monument;
- import org.l2jmobius.gameserver.model.actor.templates.PlayerTemplate;
- import org.l2jmobius.gameserver.model.clan.Clan;
- import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
- import org.l2jmobius.gameserver.network.ServerPackets;
- public final class NpcInfoPolymorph extends ServerPacket
- {
- private final Monument _activeChar;
- private final int _objId;
- private final int _x;
- private final int _y;
- private final int _z;
- private final int _heading;
- private final int _mAtkSpd;
- private final int _pAtkSpd;
- private final int _runSpd;
- private final int _walkSpd;
- private final int _swimRunSpd;
- private final int _swimWalkSpd;
- private final int _flyRunSpd;
- private final int _flyWalkSpd;
- private final double _moveMultiplier;
- private final float _attackSpeedMultiplier;
- private final int _nameColor;
- private final int _titleColor;
- private final CharSelectInfoPackage _morph;
- private final Clan _clan;
- private final PlayerTemplate _template;
- public NpcInfoPolymorph(Monument cha)
- {
- super(256);
- _morph = cha.getPolymorphInfo();
- _activeChar = cha;
- _objId = cha.getObjectId();
- _x = cha.getX();
- _y = cha.getY();
- _z = cha.getZ();
- _heading = cha.getHeading();
- _mAtkSpd = cha.getMAtkSpd();
- _pAtkSpd = (int) cha.getPAtkSpd();
- _attackSpeedMultiplier = cha.getAttackSpeedMultiplier();
- _moveMultiplier = cha.getMovementSpeedMultiplier();
- _runSpd = (int) Math.round(cha.getRunSpeed() / _moveMultiplier);
- _walkSpd = (int) Math.round(cha.getWalkSpeed() / _moveMultiplier);
- _swimRunSpd = (int) Math.round(cha.getSwimRunSpeed() / _moveMultiplier);
- _swimWalkSpd = (int) Math.round(cha.getSwimWalkSpeed() / _moveMultiplier);
- _nameColor = cha.getNameColor();
- _titleColor = cha.getTitleColor();
- _flyRunSpd = cha.isFlying() ? _runSpd : 0;
- _flyWalkSpd = cha.isFlying() ? _walkSpd : 0;
- _template = PlayerTemplateData.getInstance().getTemplate(_morph.getBaseClassId());
- _clan = ClanTable.getInstance().getClan(_morph.getClanId());
- }
- @Override
- public void write()
- {
- ServerPackets.CHAR_INFO.writeId(this);
- writeInt(_x);
- writeInt(_y);
- writeInt(_z);
- writeInt(0); // vehicleId
- writeInt(_objId);
- writeString(_morph.getName());
- writeInt(_morph.getRace());
- writeInt(_morph.getSex());
- writeInt(_morph.getClassId());
- writeInt(0); // Inventory.PAPERDOLL_UNDER
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_HEAD));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_LHAND));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_GLOVES));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_CHEST));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_LEGS));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_FEET));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_CLOAK));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_HAIR));
- writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_HAIR2));
- writeInt(0); // Inventory.PAPERDOLL_RBRACELET
- writeInt(0); // Inventory.PAPERDOLL_LBRACELET
- writeInt(0); // Inventory.PAPERDOLL_DECO1
- writeInt(0); // Inventory.PAPERDOLL_DECO2
- writeInt(0); // Inventory.PAPERDOLL_DECO3
- writeInt(0); // Inventory.PAPERDOLL_DECO4
- writeInt(0); // Inventory.PAPERDOLL_DECO5
- writeInt(0); // Inventory.PAPERDOLL_DECO6
- writeInt(0); // Inventory.PAPERDOLL_BELT
- for (int i = 0; i < 21; i++)
- {
- writeInt(0);
- }
- writeInt(0); // getTalismanSlots
- writeInt(1); // canEquipCloak
- writeInt(0); // getPvpFlag()
- writeInt(0);
- writeInt(_mAtkSpd);
- writeInt(_pAtkSpd);
- writeInt(0); // ?
- writeInt(_runSpd);
- writeInt(_walkSpd);
- writeInt(_swimRunSpd);
- writeInt(_swimWalkSpd);
- writeInt(_flyRunSpd);
- writeInt(_flyWalkSpd);
- writeInt(_flyRunSpd);
- writeInt(_flyWalkSpd);
- writeDouble(_moveMultiplier);
- writeDouble(_attackSpeedMultiplier);
- writeDouble(_template.getCollisionRadius());
- writeDouble(_template.getCollisionHeight());
- writeInt(_morph.getHairStyle());
- writeInt(_morph.getHairColor());
- writeInt(_morph.getFace());
- writeString(_activeChar.getVisibleTitle());
- if (_clan != null)
- {
- writeInt(_clan.getId());
- writeInt(_clan.getCrestId());
- writeInt(_clan.getAllyId());
- writeInt(_clan.getAllyCrestId());
- }
- else
- {
- writeInt(0);
- writeInt(0);
- writeInt(0);
- writeInt(0);
- }
- writeByte(1); // !isSitting() (at some initial tests it worked)
- writeByte(_activeChar.isRunning());
- writeByte(_activeChar.isInCombat());
- writeByte(_activeChar.isAlikeDead());
- writeByte(_activeChar.isInvisible());
- writeByte(0); // 1-on Strider, 2-on Wyvern, 3-on Great Wolf, 0-no mount
- writeByte(0); // getPrivateStoreType().getId()
- writeShort(0); // getCubics().size()
- // getCubics().keySet().forEach(packet::writeH);
- writeByte(0); // isInPartyMatchRoom
- writeInt(_activeChar.getAbnormalVisualEffects());
- writeByte(0);
- writeShort(0); // Blue value for name (0 = white, 255 = pure blue)
- writeInt(0); // getMountNpcId() == 0 ? 0 : getMountNpcId() + 1000000
- writeInt(_morph.getClassId());
- writeInt(0); // ?
- writeByte((_morph.getEnchantEffect() > 127) ? 127 : _morph.getEnchantEffect()); // isMounted() ? 0 : _enchantLevel
- writeByte(0);
- writeInt(_clan != null ? _clan.getCrestLargeId() : 0);
- writeByte(0);
- writeByte(0);
- writeByte(0);
- writeInt(0);
- writeInt(0);
- writeInt(0);
- writeInt(_nameColor);
- writeInt(_heading);
- writeInt(0);
- writeInt(0); // getPledgeType()
- writeInt(_titleColor);
- writeInt(0); // isCursedWeaponEquipped
- writeInt(0); // getClanId() > 0 ? getClan().getReputationScore() : 0
- // T1
- writeInt(0); // getTransformationDisplayId()
- writeInt(0);
- // T2
- writeInt(1);
- // T2.3
- writeInt(_activeChar.getAbnormalVisualEffectSpecial());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement