Advertisement
DevWilliams

poly

Nov 25th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 0 0
  1. package org.l2jmobius.gameserver.model.actor;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.util.logging.Level;
  7.  
  8. import org.l2jmobius.commons.database.DatabaseFactory;
  9. import org.l2jmobius.gameserver.model.CharSelectInfoPackage;
  10. import org.l2jmobius.gameserver.model.World;
  11. import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
  12. import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
  13. import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
  14. import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  15. import org.l2jmobius.gameserver.network.serverpackets.NpcInfoPolymorph;
  16.  
  17. public class Monument extends Npc
  18. {
  19. private CharSelectInfoPackage _polymorphInfo;
  20. private int _nameColor = 0xFFFFFF;
  21. private int _titleColor = 0xFFFF77;
  22. private String _visibleTitle = "";
  23.  
  24. public Monument(NpcTemplate template)
  25. {
  26. super(template);
  27. setInvul(true);
  28. }
  29.  
  30. @Override
  31. public boolean hasRandomAnimation()
  32. {
  33. switch (getId())
  34. {
  35. // onDeath
  36. // case 10000:
  37. // onRandomAnimation(13);
  38. // return true;
  39. // Victory
  40. case 10000:
  41. case 10001:
  42. onRandomAnimation(3);
  43. return true;
  44. }
  45. return false;
  46. }
  47.  
  48. public CharSelectInfoPackage getPolymorphInfo()
  49. {
  50. return _polymorphInfo;
  51. }
  52.  
  53. public void setPolymorphInfo(CharSelectInfoPackage polymorphInfo)
  54. {
  55. _polymorphInfo = polymorphInfo;
  56.  
  57. World.getInstance().forEachVisibleObjectInRange(this, Player.class, 100000, player -> sendInfo(player));
  58. }
  59.  
  60. public int getNameColor()
  61. {
  62. return _nameColor;
  63. }
  64.  
  65. public void setNameColor(int nameColor)
  66. {
  67. _nameColor = nameColor;
  68. }
  69.  
  70. public int getTitleColor()
  71. {
  72. return _titleColor;
  73. }
  74.  
  75. public void setTitleColor(int titleColor)
  76. {
  77. _titleColor = titleColor;
  78. }
  79.  
  80. public String getVisibleTitle()
  81. {
  82. return _visibleTitle;
  83. }
  84.  
  85. public void setVisibleTitle(String title)
  86. {
  87. _visibleTitle = title == null ? "" : title;
  88. }
  89.  
  90. @Override
  91. public void sendInfo(Player player)
  92. {
  93. super.sendInfo(player);
  94.  
  95. if (getPolymorphInfo() != null)
  96. {
  97. player.sendPacket(new NpcInfoPolymorph(this));
  98. }
  99. }
  100.  
  101. @Override
  102. public String getHtmlPath(int npcId, int val)
  103. {
  104. String pom = "" + npcId;
  105. if (val != 0)
  106. {
  107. pom += "-" + val;
  108. }
  109. return "data/html/mods/polymorph/" + pom + ".htm";
  110. }
  111.  
  112. @Override
  113. public void showChatWindow(Player player, int val)
  114. {
  115. String filename = getHtmlPath(getId(), val);
  116.  
  117. // Send a Server->Client NpcHtmlMessage containing the text of the L2Npc to the Player
  118. final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  119. html.setFile(player, filename);
  120. html.replace("%objectId%", getObjectId());
  121. html.replace("%ownername%", getPolymorphInfo() != null ? getPolymorphInfo().getName() : "");
  122. player.sendPacket(html);
  123.  
  124. // Send a Server->Client ActionFailed to the Player in order to avoid that the client wait another packet
  125. player.sendPacket(ActionFailed.STATIC_PACKET);
  126. }
  127.  
  128. public static CharSelectInfoPackage loadCharInfo(int objectId)
  129. {
  130. try (Connection con = DatabaseFactory.getConnection();
  131. PreparedStatement ps = con.prepareStatement("SELECT char_name, race, base_class, classid, sex, face, hairStyle, hairColor, clanid FROM characters WHERE charId = ?"))
  132. {
  133. ps.setInt(1, objectId);
  134.  
  135. try (ResultSet rs = ps.executeQuery())
  136. {
  137. if (rs.next())
  138. {
  139. final CharSelectInfoPackage charInfo = new CharSelectInfoPackage(objectId, rs.getString("char_name"));
  140. charInfo.setRace(rs.getInt("race"));
  141. charInfo.setBaseClassId(rs.getInt("base_class"));
  142. charInfo.setClassId(rs.getInt("classid"));
  143. charInfo.setSex(rs.getInt("sex"));
  144. charInfo.setFace(rs.getInt("face"));
  145. charInfo.setHairStyle(rs.getInt("hairStyle"));
  146. charInfo.setHairColor(rs.getInt("hairColor"));
  147. charInfo.setClanId(rs.getInt("clanid"));
  148.  
  149. // Get the augmentation id for equipped weapon
  150. int weaponObjId = charInfo.getPaperdollObjectId(Inventory.PAPERDOLL_RHAND);
  151. if (weaponObjId > 0)
  152. {
  153. try (PreparedStatement psAug = con.prepareStatement("SELECT augAttributes FROM item_attributes WHERE itemId = ?"))
  154. {
  155. psAug.setInt(1, weaponObjId);
  156.  
  157. try (ResultSet rsAugment = psAug.executeQuery())
  158. {
  159. if (rsAugment.next())
  160. {
  161. int augment = rsAugment.getInt("augAttributes");
  162. charInfo.setAugmentationId(augment == -1 ? 0 : augment);
  163. }
  164. }
  165. }
  166. }
  167.  
  168. return charInfo;
  169. }
  170. }
  171. }
  172. catch (Exception e)
  173. {
  174. LOGGER.log(Level.WARNING, "Could not restore char info: " + e.getMessage(), e);
  175. }
  176.  
  177. return null;
  178. }
  179. }
  180. package org.l2jmobius.gameserver.network.serverpackets;
  181.  
  182. import org.l2jmobius.gameserver.data.sql.ClanTable;
  183. import org.l2jmobius.gameserver.data.xml.PlayerTemplateData;
  184. import org.l2jmobius.gameserver.model.CharSelectInfoPackage;
  185. import org.l2jmobius.gameserver.model.actor.Monument;
  186. import org.l2jmobius.gameserver.model.actor.templates.PlayerTemplate;
  187. import org.l2jmobius.gameserver.model.clan.Clan;
  188. import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
  189. import org.l2jmobius.gameserver.network.ServerPackets;
  190.  
  191. public final class NpcInfoPolymorph extends ServerPacket
  192. {
  193. private final Monument _activeChar;
  194. private final int _objId;
  195. private final int _x;
  196. private final int _y;
  197. private final int _z;
  198. private final int _heading;
  199. private final int _mAtkSpd;
  200. private final int _pAtkSpd;
  201. private final int _runSpd;
  202. private final int _walkSpd;
  203. private final int _swimRunSpd;
  204. private final int _swimWalkSpd;
  205. private final int _flyRunSpd;
  206. private final int _flyWalkSpd;
  207. private final double _moveMultiplier;
  208. private final float _attackSpeedMultiplier;
  209. private final int _nameColor;
  210. private final int _titleColor;
  211. private final CharSelectInfoPackage _morph;
  212. private final Clan _clan;
  213. private final PlayerTemplate _template;
  214.  
  215. public NpcInfoPolymorph(Monument cha)
  216. {
  217. super(256);
  218.  
  219. _morph = cha.getPolymorphInfo();
  220. _activeChar = cha;
  221. _objId = cha.getObjectId();
  222. _x = cha.getX();
  223. _y = cha.getY();
  224. _z = cha.getZ();
  225. _heading = cha.getHeading();
  226. _mAtkSpd = cha.getMAtkSpd();
  227. _pAtkSpd = (int) cha.getPAtkSpd();
  228. _attackSpeedMultiplier = cha.getAttackSpeedMultiplier();
  229. _moveMultiplier = cha.getMovementSpeedMultiplier();
  230. _runSpd = (int) Math.round(cha.getRunSpeed() / _moveMultiplier);
  231. _walkSpd = (int) Math.round(cha.getWalkSpeed() / _moveMultiplier);
  232. _swimRunSpd = (int) Math.round(cha.getSwimRunSpeed() / _moveMultiplier);
  233. _swimWalkSpd = (int) Math.round(cha.getSwimWalkSpeed() / _moveMultiplier);
  234. _nameColor = cha.getNameColor();
  235. _titleColor = cha.getTitleColor();
  236. _flyRunSpd = cha.isFlying() ? _runSpd : 0;
  237. _flyWalkSpd = cha.isFlying() ? _walkSpd : 0;
  238. _template = PlayerTemplateData.getInstance().getTemplate(_morph.getBaseClassId());
  239. _clan = ClanTable.getInstance().getClan(_morph.getClanId());
  240. }
  241.  
  242. @Override
  243. public void write()
  244. {
  245. ServerPackets.CHAR_INFO.writeId(this);
  246. writeInt(_x);
  247. writeInt(_y);
  248. writeInt(_z);
  249. writeInt(0); // vehicleId
  250. writeInt(_objId);
  251. writeString(_morph.getName());
  252. writeInt(_morph.getRace());
  253. writeInt(_morph.getSex());
  254. writeInt(_morph.getClassId());
  255. writeInt(0); // Inventory.PAPERDOLL_UNDER
  256. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_HEAD));
  257. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
  258. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_LHAND));
  259. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_GLOVES));
  260. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_CHEST));
  261. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_LEGS));
  262. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_FEET));
  263. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_CLOAK));
  264. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
  265. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_HAIR));
  266. writeInt(_morph.getPaperdollItemId(Inventory.PAPERDOLL_HAIR2));
  267. writeInt(0); // Inventory.PAPERDOLL_RBRACELET
  268. writeInt(0); // Inventory.PAPERDOLL_LBRACELET
  269. writeInt(0); // Inventory.PAPERDOLL_DECO1
  270. writeInt(0); // Inventory.PAPERDOLL_DECO2
  271. writeInt(0); // Inventory.PAPERDOLL_DECO3
  272. writeInt(0); // Inventory.PAPERDOLL_DECO4
  273. writeInt(0); // Inventory.PAPERDOLL_DECO5
  274. writeInt(0); // Inventory.PAPERDOLL_DECO6
  275. writeInt(0); // Inventory.PAPERDOLL_BELT
  276. for (int i = 0; i < 21; i++)
  277. {
  278. writeInt(0);
  279. }
  280. writeInt(0); // getTalismanSlots
  281. writeInt(1); // canEquipCloak
  282. writeInt(0); // getPvpFlag()
  283. writeInt(0);
  284. writeInt(_mAtkSpd);
  285. writeInt(_pAtkSpd);
  286. writeInt(0); // ?
  287. writeInt(_runSpd);
  288. writeInt(_walkSpd);
  289. writeInt(_swimRunSpd);
  290. writeInt(_swimWalkSpd);
  291. writeInt(_flyRunSpd);
  292. writeInt(_flyWalkSpd);
  293. writeInt(_flyRunSpd);
  294. writeInt(_flyWalkSpd);
  295. writeDouble(_moveMultiplier);
  296. writeDouble(_attackSpeedMultiplier);
  297. writeDouble(_template.getCollisionRadius());
  298. writeDouble(_template.getCollisionHeight());
  299. writeInt(_morph.getHairStyle());
  300. writeInt(_morph.getHairColor());
  301. writeInt(_morph.getFace());
  302. writeString(_activeChar.getVisibleTitle());
  303. if (_clan != null)
  304. {
  305. writeInt(_clan.getId());
  306. writeInt(_clan.getCrestId());
  307. writeInt(_clan.getAllyId());
  308. writeInt(_clan.getAllyCrestId());
  309. }
  310. else
  311. {
  312. writeInt(0);
  313. writeInt(0);
  314. writeInt(0);
  315. writeInt(0);
  316. }
  317. writeByte(1); // !isSitting() (at some initial tests it worked)
  318. writeByte(_activeChar.isRunning());
  319. writeByte(_activeChar.isInCombat());
  320. writeByte(_activeChar.isAlikeDead());
  321. writeByte(_activeChar.isInvisible());
  322. writeByte(0); // 1-on Strider, 2-on Wyvern, 3-on Great Wolf, 0-no mount
  323. writeByte(0); // getPrivateStoreType().getId()
  324. writeShort(0); // getCubics().size()
  325. // getCubics().keySet().forEach(packet::writeH);
  326. writeByte(0); // isInPartyMatchRoom
  327. writeInt(_activeChar.getAbnormalVisualEffects());
  328. writeByte(0);
  329. writeShort(0); // Blue value for name (0 = white, 255 = pure blue)
  330. writeInt(0); // getMountNpcId() == 0 ? 0 : getMountNpcId() + 1000000
  331. writeInt(_morph.getClassId());
  332. writeInt(0); // ?
  333. writeByte((_morph.getEnchantEffect() > 127) ? 127 : _morph.getEnchantEffect()); // isMounted() ? 0 : _enchantLevel
  334. writeByte(0);
  335. writeInt(_clan != null ? _clan.getCrestLargeId() : 0);
  336. writeByte(0);
  337. writeByte(0);
  338. writeByte(0);
  339. writeInt(0);
  340. writeInt(0);
  341. writeInt(0);
  342. writeInt(_nameColor);
  343. writeInt(_heading);
  344. writeInt(0);
  345. writeInt(0); // getPledgeType()
  346. writeInt(_titleColor);
  347. writeInt(0); // isCursedWeaponEquipped
  348. writeInt(0); // getClanId() > 0 ? getClan().getReputationScore() : 0
  349. // T1
  350. writeInt(0); // getTransformationDisplayId()
  351. writeInt(0);
  352. // T2
  353. writeInt(1);
  354. // T2.3
  355. writeInt(_activeChar.getAbnormalVisualEffectSpecial());
  356. }
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement