Advertisement
3Gato

Untitled

Apr 17th, 2018
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.12 KB | None | 0 0
  1. diff --git a/l2j_datapack/dist/game/data/scripts/handlers/MasterHandler.java b/l2j_datapack/dist/game/data/scripts/handlers/MasterHandler.java
  2. index 0b03791..79cad23 100644
  3. --- a/l2j_datapack/dist/game/data/scripts/handlers/MasterHandler.java
  4. +++ b/l2j_datapack/dist/game/data/scripts/handlers/MasterHandler.java
  5. import handlers.voicedcommandhandlers.StatsVCmd;
  6. import handlers.voicedcommandhandlers.UserOptions;
  7. import handlers.voicedcommandhandlers.VotingReward;
  8. +import handlers.voicedcommandhandlers.VisualArmor;
  9. import handlers.voicedcommandhandlers.Epic;
  10. import handlers.voicedcommandhandlers.Wedding;
  11. @@ -379,7 +379,8 @@ public class MasterHandler {
  12. (Config.L2JMOD_CHAT_ADMIN ? ChatAdmin.class : null),
  13. (Config.L2JMOD_MULTILANG_ENABLE && Config.L2JMOD_MULTILANG_VOICED_ALLOW ? Lang.class : null),
  14. (Config.L2JMOD_DEBUG_VOICE_COMMAND ? Debug.class : null),
  15. - (Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null), },
  16. + (Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null),
  17. + VisualArmor.class, },
  18. {
  19. // Target Handlers
  20. Area.class, AreaCorpseMob.class, AreaFriendly.class, AreaSummon.class, Aura.class,
  21. diff --git a/l2j_datapack/dist/game/data/scripts/handlers/voicedcommandhandlers/VisualArmor.java b/l2j_datapack/dist/game/data/scripts/handlers/voicedcommandhandlers/VisualArmor.java
  22. new file mode 100644
  23. index 0000000..e0dc1f1
  24. --- /dev/null
  25. +++ b/l2j_datapack/dist/game/data/scripts/handlers/voicedcommandhandlers/VisualArmor.java
  26. @@ -0,0 +1,71 @@
  27. +/*
  28. + * This program is free software: you can redistribute it and/or modify it under
  29. + * the terms of the GNU General Public License as published by the Free Software
  30. + * Foundation, either version 3 of the License, or (at your option) any later
  31. + * version.
  32. + *
  33. + * This program is distributed in the hope that it will be useful, but WITHOUT
  34. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  35. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  36. + * details.
  37. + *
  38. + * You should have received a copy of the GNU General Public License along with
  39. + * this program. If not, see <http://www.gnu.org/licenses/>.
  40. + */
  41. +package handlers.voicedcommandhandlers;
  42. +
  43. +import com.l2jserver.extensions.VisualArmorController;
  44. +import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  45. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  46. +import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  47. +
  48. +public class VisualArmor implements IVoicedCommandHandler
  49. +{
  50. + private static final String[] VOICED_COMMANDS =
  51. + {
  52. + "dressme",
  53. + "dressMe",
  54. + "DressMe",
  55. + "cloakOn",
  56. + "cloakOff"
  57. + };
  58. +
  59. + @Override
  60. + public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  61. + {
  62. + if (command.contains("cloakOn"))
  63. + {
  64. + activeChar.visualArmor.weaponLRHANDId = 0;
  65. + InventoryUpdate iu = new InventoryUpdate();
  66. + activeChar.sendPacket(iu);
  67. + activeChar.broadcastUserInfo();
  68. + InventoryUpdate iu2 = new InventoryUpdate();
  69. + activeChar.sendPacket(iu2);
  70. + activeChar.broadcastUserInfo();
  71. + activeChar.sendMessage("Cloak enabled.");
  72. + }
  73. + else if (command.contains("cloakOff"))
  74. + {
  75. + activeChar.visualArmor.weaponLRHANDId = 1;
  76. + InventoryUpdate iu = new InventoryUpdate();
  77. + activeChar.sendPacket(iu);
  78. + activeChar.broadcastUserInfo();
  79. + InventoryUpdate iu2 = new InventoryUpdate();
  80. + activeChar.sendPacket(iu2);
  81. + activeChar.broadcastUserInfo();
  82. + activeChar.sendMessage("Cloak disabled.");
  83. + }
  84. + else
  85. + {
  86. + VisualArmorController.dressMe(activeChar);
  87. + }
  88. +
  89. + return true;
  90. + }
  91. +
  92. + @Override
  93. + public String[] getVoicedCommandList()
  94. + {
  95. + return VOICED_COMMANDS;
  96. + }
  97. +}
  98. \ No newline at end of file
  99. diff --git a/l2j_server/src/main/java/com/l2jserver/extensions/VisualArmorController.java b/l2j_server/src/main/java/com/l2jserver/extensions/VisualArmorController.java
  100. new file mode 100644
  101. index 0000000..57ab3f4
  102. --- /dev/null
  103. +++ b/l2j_server/src/main/java/com/l2jserver/extensions/VisualArmorController.java
  104. @@ -0,0 +1,422 @@
  105. +/*
  106. + * This program is free software: you can redistribute it and/or modify it under
  107. + * the terms of the GNU General Public License as published by the Free Software
  108. + * Foundation, either version 3 of the License, or (at your option) any later
  109. + * version.
  110. + *
  111. + * This program is distributed in the hope that it will be useful, but WITHOUT
  112. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  113. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  114. + * details.
  115. + *
  116. + * You should have received a copy of the GNU General Public License along with
  117. + * this program. If not, see <http://www.gnu.org/licenses/>.
  118. + */
  119. +package com.l2jserver.extensions;
  120. +
  121. +import java.sql.Connection;
  122. +import java.sql.PreparedStatement;
  123. +import java.sql.SQLException;
  124. +
  125. +import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  126. +import com.l2jserver.gameserver.datatables.ItemTable;
  127. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  128. +import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  129. +import com.l2jserver.gameserver.model.items.L2Armor;
  130. +import com.l2jserver.gameserver.model.items.L2Item;
  131. +import com.l2jserver.gameserver.model.items.L2Weapon;
  132. +import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  133. +import com.l2jserver.gameserver.model.items.type.ArmorType;
  134. +import com.l2jserver.gameserver.model.items.type.WeaponType;
  135. +import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  136. +
  137. +/**
  138. + * @author giorgakis
  139. + */
  140. +public class VisualArmorController
  141. +{
  142. + // As of freya there are 19 weapon types.
  143. + public static final int totalWeaponTypes = 19;
  144. +
  145. + // As of freya there are 6 armor types.
  146. + public static final int totalArmorTypes = 6;
  147. +
  148. + public static boolean[][] weaponMapping = new boolean[totalWeaponTypes][totalWeaponTypes];
  149. + public static boolean[][] armorMapping = new boolean[totalArmorTypes][totalArmorTypes];
  150. +
  151. + public static void migrate()
  152. + {
  153. + System.out.println("[VisualArmor]:Migrating the database.");
  154. + Connection con = null;
  155. + try
  156. + {
  157. + con = ConnectionFactory.getInstance().getConnection();
  158. + PreparedStatement statement = con.prepareStatement(VisualArmorModel.CREATE);
  159. + statement.execute();
  160. + statement.close();
  161. + }
  162. + catch (SQLException e)
  163. + {
  164. + e.printStackTrace();
  165. + }
  166. + finally
  167. + {
  168. + try
  169. + {
  170. + con.close();
  171. + }
  172. + catch (Exception e)
  173. + {
  174. + }
  175. + }
  176. + }
  177. +
  178. + public static void load()
  179. + {
  180. + migrate();
  181. + generateMappings();
  182. + }
  183. +
  184. + /**
  185. + * All same type armors and same type weapons can get visual. All different types cannot get visual unless it is stated in here.
  186. + */
  187. + public static void generateMappings()
  188. + {
  189. + for (int i = 0; i < weaponMapping.length; i++)
  190. + {
  191. + for (int j = 0; j < weaponMapping.length; j++)
  192. + {
  193. + weaponMapping[i][j] = false;
  194. + }
  195. + }
  196. +
  197. + for (int i = 0; i < armorMapping.length; i++)
  198. + {
  199. + for (int j = 0; j < armorMapping.length; j++)
  200. + {
  201. + armorMapping[i][j] = false;
  202. + }
  203. + }
  204. +
  205. + callRules();
  206. +
  207. + }
  208. +
  209. + public static void callRules()
  210. + {
  211. + // Example: a Virtual sword can mount an Equipped blunt.
  212. + weaponMapping[WeaponType.SWORD.ordinal()][WeaponType.BLUNT.ordinal()] = true;
  213. +
  214. + // Example: a Virtual blunt can mount an Equipped sword.
  215. + weaponMapping[WeaponType.BLUNT.ordinal()][WeaponType.SWORD.ordinal()] = true;
  216. +
  217. + // weaponMapping[WeaponType.BIGSWORD.ordinal()][WeaponType.BIGBLUNT.ordinal()] = true;
  218. + // weaponMapping[WeaponType.BIGBLUNT.ordinal()][WeaponType.BIGSWORD.ordinal()] = true;
  219. +
  220. + armorMapping[ArmorType.SIGIL.ordinal()][ArmorType.SHIELD.ordinal()] = true;
  221. + armorMapping[ArmorType.SHIELD.ordinal()][ArmorType.SIGIL.ordinal()] = true;
  222. +
  223. + // armorMapping[L2ArmorType.HEAVY.ordinal()][L2ArmorType.LIGHT.ordinal()] = true;
  224. + // armorMapping[L2ArmorType.HEAVY.ordinal()][L2ArmorType.MAGIC.ordinal()] = true;
  225. +
  226. + // armorMapping[L2ArmorType.LIGHT.ordinal()][L2ArmorType.HEAVY.ordinal()] = true;
  227. + // armorMapping[L2ArmorType.LIGHT.ordinal()][L2ArmorType.MAGIC.ordinal()] = true;
  228. +
  229. + // armorMapping[L2ArmorType.MAGIC.ordinal()][L2ArmorType.LIGHT.ordinal()] = true;
  230. + // armorMapping[L2ArmorType.MAGIC.ordinal()][L2ArmorType.HEAVY.ordinal()] = true;
  231. + }
  232. +
  233. + /**
  234. + * Checks if the weapon is the same type. If that is true then return the matching virtual id. Else check the mapping tables if any rule states that the two different weapon types should be matched.
  235. + * @param virtual
  236. + * @param equiped
  237. + * @param matchId
  238. + * @param noMatchId
  239. + * @return
  240. + */
  241. + public static int weaponMatching(WeaponType virtual, WeaponType equiped, int matchId, int noMatchId)
  242. + {
  243. + if (virtual == equiped)
  244. + {
  245. + return matchId;
  246. + }
  247. +
  248. + if (weaponMapping[virtual.ordinal()][equiped.ordinal()])
  249. + {
  250. + return matchId;
  251. + }
  252. +
  253. + return noMatchId;
  254. + }
  255. +
  256. + /**
  257. + * Checks if the armor is the same type. If that is true then return the matching virtual id. Else check the mapping tables if any rule states that the two different armor types should be matched.
  258. + * @param virtual
  259. + * @param equiped
  260. + * @param matchId
  261. + * @param noMatchId
  262. + * @return
  263. + */
  264. + public static int armorMatching(ArmorType virtual, ArmorType equiped, int matchId, int noMatchId)
  265. + {
  266. + if (virtual == equiped)
  267. + {
  268. + return matchId;
  269. + }
  270. +
  271. + if (armorMapping[virtual.ordinal()][equiped.ordinal()])
  272. + {
  273. + return matchId;
  274. + }
  275. +
  276. + return noMatchId;
  277. + }
  278. +
  279. + public static void setVirtualRhand(L2PcInstance actor)
  280. + {
  281. + actor.visualArmor.weaponRHANDId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_RHAND);
  282. + }
  283. +
  284. + public static void setVirtualLhand(L2PcInstance actor)
  285. + {
  286. + actor.visualArmor.weaponLHANDId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_LHAND);
  287. + }
  288. +
  289. + public static void setVirtualGloves(L2PcInstance actor)
  290. + {
  291. + actor.visualArmor.glovesTextureId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_GLOVES);
  292. + }
  293. +
  294. + public static void setVirtualBody(L2PcInstance actor)
  295. + {
  296. + actor.visualArmor.armorTextureId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_CHEST);
  297. + }
  298. +
  299. + public static void setVirtualPants(L2PcInstance actor)
  300. + {
  301. + int chestId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_CHEST);
  302. + int pantsId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_LEGS);
  303. +
  304. + if ((chestId != 0) && (pantsId == 0))
  305. + {
  306. + actor.visualArmor.pantsTextureId = chestId;
  307. + }
  308. + else
  309. + {
  310. + actor.visualArmor.pantsTextureId = pantsId;
  311. + }
  312. + }
  313. +
  314. + public static void setVirtualBoots(L2PcInstance actor)
  315. + {
  316. + actor.visualArmor.bootsTextureId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_FEET);
  317. + }
  318. +
  319. + // TODO: Merge the armor getters in one function.
  320. + public static int getVirtualGloves(L2PcInstance actor)
  321. + {
  322. + L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  323. + if (equipedItem == null)
  324. + {
  325. + return 0;
  326. + }
  327. + // ClassCastException wont happen unless some jackass changes the values from the database.
  328. + L2Armor equipedGloves = (L2Armor) actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_GLOVES).getItem();
  329. + int equipedGlovesId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_GLOVES);
  330. +
  331. + int glovesTextureId = actor.visualArmor.glovesTextureId;
  332. + L2Armor virtualGloves = (L2Armor) ItemTable.getInstance().getTemplate(glovesTextureId);
  333. +
  334. + if (glovesTextureId != 0)
  335. + {
  336. + return armorMatching(virtualGloves.getItemType(), equipedGloves.getItemType(), glovesTextureId, equipedGlovesId);
  337. + }
  338. + else
  339. + {
  340. + return equipedGlovesId;
  341. + }
  342. + }
  343. +
  344. + public static int getVirtualBody(L2PcInstance actor)
  345. + {
  346. + L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  347. + if (equipedItem == null)
  348. + {
  349. + return 0;
  350. + }
  351. + // ClassCastException wont happen unless some jackass changes the values from the database.
  352. + L2Armor equipedChest = (L2Armor) actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST).getItem();
  353. + int equipedChestId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_CHEST);
  354. +
  355. + int chestTextureId = actor.visualArmor.armorTextureId;
  356. + L2Armor virtualChest = (L2Armor) ItemTable.getInstance().getTemplate(chestTextureId);
  357. +
  358. + if (chestTextureId != 0)
  359. + {
  360. + return armorMatching(virtualChest.getItemType(), equipedChest.getItemType(), chestTextureId, equipedChestId);
  361. + }
  362. + else
  363. + {
  364. + return equipedChestId;
  365. + }
  366. + }
  367. +
  368. + /**
  369. + * This is a brain fu**er handling the pants since they are also part of a fullbody armor.
  370. + * @param actor
  371. + * @return
  372. + */
  373. + public static int getVirtualPants(L2PcInstance actor)
  374. + {
  375. + L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  376. +
  377. + // Here comes the tricky part. If pants are null, then check for a fullbody armor.
  378. + if (equipedItem == null)
  379. + {
  380. + equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  381. + }
  382. + if (equipedItem == null)
  383. + {
  384. + return 0;
  385. + }
  386. +
  387. + int pantsTextureId = actor.visualArmor.pantsTextureId;
  388. +
  389. + L2Armor equipedPants = (L2Armor) equipedItem.getItem();
  390. +
  391. + if ((equipedPants.getBodyPart() != L2Item.SLOT_FULL_ARMOR) && (equipedPants.getBodyPart() != L2Item.SLOT_LEGS))
  392. + {
  393. + return 0;
  394. + }
  395. + int equipedPantsId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_LEGS);
  396. +
  397. + L2Armor virtualPants = (L2Armor) ItemTable.getInstance().getTemplate(pantsTextureId);
  398. +
  399. + if (pantsTextureId != 0)
  400. + {
  401. + return armorMatching(virtualPants.getItemType(), equipedPants.getItemType(), pantsTextureId, equipedPantsId);
  402. + }
  403. + else
  404. + {
  405. + return equipedPantsId;
  406. + }
  407. + }
  408. +
  409. + public static int getVirtualBoots(L2PcInstance actor)
  410. + {
  411. + L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_FEET);
  412. + if (equipedItem == null)
  413. + {
  414. + return 0;
  415. + }
  416. + // ClassCastException wont happen unless some jackass changes the values from the database.
  417. + L2Armor equipedBoots = (L2Armor) actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_FEET).getItem();
  418. + int equipedBootsId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_FEET);
  419. +
  420. + int bootsTextureId = actor.visualArmor.bootsTextureId;
  421. + L2Armor virtualGloves = (L2Armor) ItemTable.getInstance().getTemplate(bootsTextureId);
  422. +
  423. + if (bootsTextureId != 0)
  424. + {
  425. + return armorMatching(virtualGloves.getItemType(), equipedBoots.getItemType(), bootsTextureId, equipedBootsId);
  426. + }
  427. + else
  428. + {
  429. + return equipedBootsId;
  430. + }
  431. + }
  432. +
  433. + public static int getLHAND(L2PcInstance actor)
  434. + {
  435. + L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  436. + int equipedItemId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_LHAND);
  437. +
  438. + int weaponLHANDId = actor.visualArmor.weaponLHANDId;
  439. + L2Item virtualItem = ItemTable.getInstance().getTemplate(weaponLHANDId);
  440. +
  441. + if ((equipedItem == null) || (weaponLHANDId == 0))
  442. + {
  443. + return equipedItemId;
  444. + }
  445. +
  446. + // Only check same weapon types. Virtual replacement should not happen between armor/weapons.
  447. + if ((equipedItem.getItem() instanceof L2Weapon) && (virtualItem instanceof L2Weapon))
  448. + {
  449. + L2Weapon weapon = (L2Weapon) equipedItem.getItem();
  450. + L2Weapon virtualweapon = (L2Weapon) virtualItem;
  451. +
  452. + return weaponMatching(virtualweapon.getItemType(), weapon.getItemType(), weaponLHANDId, equipedItemId);
  453. + }
  454. + else if ((equipedItem.getItem() instanceof L2Armor) && (virtualItem instanceof L2Armor))
  455. + {
  456. + L2Armor armor = (L2Armor) equipedItem.getItem();
  457. + L2Armor virtualarmor = (L2Armor) virtualItem;
  458. +
  459. + return armorMatching(virtualarmor.getItemType(), armor.getItemType(), weaponLHANDId, equipedItemId);
  460. + }
  461. + return equipedItemId;
  462. + }
  463. +
  464. + public static int getRHAND(L2PcInstance actor)
  465. + {
  466. + int weaponRHANDId = actor.visualArmor.weaponRHANDId;
  467. + L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  468. + int equipedItemId = actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_RHAND);
  469. + L2Item virtualItem = ItemTable.getInstance().getTemplate(weaponRHANDId);
  470. +
  471. + if ((equipedItem == null) || (weaponRHANDId == 0))
  472. + {
  473. + return equipedItemId;
  474. + }
  475. +
  476. + // Only check same weapon types. Virtual replacement should not happen between armor/weapons.
  477. + if ((equipedItem.getItem() instanceof L2Weapon) && (virtualItem instanceof L2Weapon))
  478. + {
  479. + L2Weapon weapon = (L2Weapon) equipedItem.getItem();
  480. + L2Weapon virtualweapon = (L2Weapon) virtualItem;
  481. +
  482. + return weaponMatching(virtualweapon.getItemType(), weapon.getItemType(), weaponRHANDId, equipedItemId);
  483. + }
  484. + else if ((equipedItem.getItem() instanceof L2Armor) && (virtualItem instanceof L2Armor))
  485. + {
  486. + L2Armor armor = (L2Armor) equipedItem.getItem();
  487. + L2Armor virtualarmor = (L2Armor) virtualItem;
  488. +
  489. + return armorMatching(virtualarmor.getItemType(), armor.getItemType(), weaponRHANDId, equipedItemId);
  490. + }
  491. + return equipedItemId;
  492. +
  493. + }
  494. +
  495. + public static int getCloak(L2PcInstance actor)
  496. + {
  497. + if (actor.visualArmor.weaponLRHANDId == 1)
  498. + {
  499. + return 0;
  500. + }
  501. + else
  502. + {
  503. + return actor.getInventory().getPaperdollItemDisplayId(Inventory.PAPERDOLL_CLOAK);
  504. + }
  505. +
  506. + }
  507. +
  508. + public static void dressMe(L2PcInstance activeChar)
  509. + {
  510. + setVirtualBody(activeChar);
  511. + setVirtualGloves(activeChar);
  512. + setVirtualPants(activeChar);
  513. + setVirtualBoots(activeChar);
  514. + setVirtualLhand(activeChar);
  515. + setVirtualRhand(activeChar);
  516. +
  517. + InventoryUpdate iu = new InventoryUpdate();
  518. + activeChar.sendPacket(iu);
  519. + activeChar.broadcastUserInfo();
  520. + InventoryUpdate iu2 = new InventoryUpdate();
  521. + activeChar.sendPacket(iu2);
  522. + activeChar.broadcastUserInfo();
  523. + activeChar.sendMessage("You changed clothes.");
  524. + activeChar.visualArmor.updateVisualArmor();
  525. + }
  526. +}
  527. \ No newline at end of file
  528. diff --git a/l2j_server/src/main/java/com/l2jserver/extensions/VisualArmorModel.java b/l2j_server/src/main/java/com/l2jserver/extensions/VisualArmorModel.java
  529. new file mode 100644
  530. index 0000000..da27023
  531. --- /dev/null
  532. +++ b/l2j_server/src/main/java/com/l2jserver/extensions/VisualArmorModel.java
  533. @@ -0,0 +1,171 @@
  534. +/*
  535. + * This program is free software: you can redistribute it and/or modify it under
  536. + * the terms of the GNU General Public License as published by the Free Software
  537. + * Foundation, either version 3 of the License, or (at your option) any later
  538. + * version.
  539. + *
  540. + * This program is distributed in the hope that it will be useful, but WITHOUT
  541. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  542. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  543. + * details.
  544. + *
  545. + * You should have received a copy of the GNU General Public License along with
  546. + * this program. If not, see <http://www.gnu.org/licenses/>.
  547. + */
  548. +package com.l2jserver.extensions;
  549. +
  550. +import java.sql.Connection;
  551. +import java.sql.PreparedStatement;
  552. +import java.sql.ResultSet;
  553. +import java.sql.SQLException;
  554. +
  555. +import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  556. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  557. +import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  558. +
  559. +/**
  560. + * @author Issle
  561. + *
  562. + */
  563. +public class VisualArmorModel
  564. +{
  565. + private static final String RESTORE_VISUAL_ARMOR = "SELECT GlovesId,ChestId,BootsId,PantsId,LeftHandId,RightHandId,DoubleHandId FROM visual_armor WHERE CharId=?";
  566. + private static final String UPDATE_VISUAL_ARMOR = "UPDATE visual_armor SET GlovesId=?,ChestId=?,BootsId=?,PantsId=?,LeftHandId=?,RightHandId=?,DoubleHandId=? WHERE CharId=?";
  567. + private static final String CREATE_VISUAL_ARMOR = "INSERT INTO visual_armor (CharId,GlovesId,ChestId,BootsId,PantsId,LeftHandId,RightHandId,DoubleHandId) values (?,?,?,?,?,?,?,?)";
  568. +
  569. + public static final String CREATE =
  570. + "CREATE TABLE IF NOT EXISTS `visual_armor` (" +
  571. + "`CharId` int(11) NOT NULL," +
  572. + "`GlovesId` int(11) NOT NULL DEFAULT '0'," +
  573. + "`BootsId` int(11) NOT NULL DEFAULT '0'," +
  574. + "`ChestId` int(11) NOT NULL DEFAULT '0'," +
  575. + "`PantsId` int(11) NOT NULL DEFAULT '0'," +
  576. + "`LeftHandId` int(11) NOT NULL DEFAULT '0'," +
  577. + "`RightHandId` int(11) NOT NULL DEFAULT '0'," +
  578. + "`DoubleHandId` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`CharId`))";
  579. +
  580. + public static final String DROP =
  581. + "DROP TABLE 'visual_armor'";
  582. +
  583. + public int glovesTextureId=0;
  584. + public int armorTextureId=0;
  585. + public int pantsTextureId=0;
  586. + public int bootsTextureId=0;
  587. + public int weaponLHANDId=0;
  588. + public int weaponRHANDId=0;
  589. + public int weaponLRHANDId=0;
  590. + public int ownerId;
  591. +
  592. +
  593. + public void updateVisualArmor()
  594. + {
  595. + Connection con = null;
  596. + try
  597. + {
  598. + con = ConnectionFactory.getInstance().getConnection();
  599. + PreparedStatement statement = con.prepareStatement(UPDATE_VISUAL_ARMOR);
  600. + statement.setInt(1, glovesTextureId);
  601. + statement.setInt(2, armorTextureId);
  602. + statement.setInt(3, bootsTextureId);
  603. + statement.setInt(4, pantsTextureId);
  604. + statement.setInt(5, weaponLHANDId);
  605. + statement.setInt(6, weaponRHANDId);
  606. + statement.setInt(7, weaponLRHANDId);
  607. + statement.setInt(8, ownerId);
  608. + statement.execute();
  609. + statement.close();
  610. +
  611. + }
  612. + catch (SQLException e)
  613. + {
  614. + e.printStackTrace();
  615. + }
  616. + finally
  617. + {
  618. + try { con.close(); } catch (Exception e) {}
  619. + }
  620. + }
  621. +
  622. + public VisualArmorModel(L2PcInstance activeChar)
  623. + {
  624. + ownerId = activeChar.getObjectId();
  625. + Connection con = null;
  626. + try
  627. + {
  628. + con = ConnectionFactory.getInstance().getConnection();
  629. +
  630. + PreparedStatement statement = con.prepareStatement(RESTORE_VISUAL_ARMOR);
  631. + statement.setInt(1, ownerId);
  632. + ResultSet rset = statement.executeQuery();
  633. + boolean got = false;
  634. + while(rset.next())
  635. + {
  636. + glovesTextureId = rset.getInt("GlovesId");
  637. + armorTextureId = rset.getInt("ChestId");
  638. + pantsTextureId = rset.getInt("PantsId");
  639. + bootsTextureId = rset.getInt("BootsId");
  640. + weaponLHANDId = rset.getInt("LeftHandId");
  641. + weaponRHANDId = rset.getInt("RightHandId");
  642. + weaponLRHANDId = rset.getInt("DoubleHandId");
  643. + got = true;
  644. +
  645. + }
  646. +
  647. + rset.close();
  648. + statement.close();
  649. +
  650. + if(got == false)
  651. + {
  652. + createVisualArmor();
  653. + }
  654. +
  655. + InventoryUpdate iu = new InventoryUpdate();
  656. + activeChar.sendPacket(iu);
  657. + activeChar.broadcastUserInfo();
  658. + InventoryUpdate iu2 = new InventoryUpdate();
  659. + activeChar.sendPacket(iu2);
  660. + activeChar.broadcastUserInfo();
  661. + activeChar.sendMessage("You changed clothes.");
  662. + }
  663. + catch (SQLException e)
  664. + {
  665. + e.printStackTrace();
  666. + }
  667. + finally
  668. + {
  669. + try { con.close(); } catch (Exception e) {}
  670. + }
  671. + }
  672. +
  673. + public void createVisualArmor() throws SQLException
  674. + {
  675. + Connection con = null;
  676. +
  677. + try
  678. + {
  679. + con = ConnectionFactory.getInstance().getConnection();
  680. + PreparedStatement statement = con.prepareStatement(CREATE_VISUAL_ARMOR);
  681. +
  682. + statement.setInt(1, ownerId);
  683. + statement.setInt(2, 0);
  684. + statement.setInt(3, 0);
  685. + statement.setInt(4, 0);
  686. + statement.setInt(5, 0);
  687. + statement.setInt(6, 0);
  688. + statement.setInt(7, 0);
  689. + statement.setInt(8, 0);
  690. +
  691. + statement.executeUpdate();
  692. + statement.close();
  693. + }
  694. + catch (Exception e)
  695. + {
  696. + e.printStackTrace();
  697. + }
  698. + finally
  699. + {
  700. + try { con.close(); } catch (Exception e) {}
  701. + }
  702. + }
  703. +
  704. +}
  705. \ No newline at end of file
  706. diff --git a/l2j_server/src/main/java/com/l2jserver/gameserver/GameServer.java b/l2j_server/src/main/java/com/l2jserver/gameserver/GameServer.java
  707. index 83a3b11..ecf383d 100644
  708. --- a/l2j_server/src/main/java/com/l2jserver/gameserver/GameServer.java
  709. +++ b/l2j_server/src/main/java/com/l2jserver/gameserver/GameServer.java
  710. @@ -29,6 +29,7 @@ import java.util.Calendar;
  711. import java.util.concurrent.TimeUnit;
  712. import java.util.logging.LogManager;
  713.  
  714. +import com.l2jserver.extensions.VisualArmorController;
  715. import org.slf4j.Logger;
  716. import org.slf4j.LoggerFactory;
  717.  
  718. @@ -284,6 +285,7 @@ public final class GameServer {
  719. BoatManager.getInstance();
  720. AirShipManager.getInstance();
  721. GraciaSeedsManager.getInstance();
  722. + VisualArmorController.load();
  723.  
  724. try {
  725. _log.info("{}: Loading server scripts:", getClass().getSimpleName());
  726. diff --git a/l2j_server/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java b/l2j_server/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  727. index 0dbb449..4cbd659 100644
  728. --- a/l2j_server/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  729. +++ b/l2j_server/src/main/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  730. @@ -48,6 +48,7 @@ import java.util.concurrent.TimeUnit;
  731. import java.util.concurrent.atomic.AtomicInteger;
  732. import java.util.concurrent.locks.ReentrantLock;
  733.  
  734. +import com.l2jserver.extensions.VisualArmorModel;
  735. import org.slf4j.Logger;
  736. import org.slf4j.LoggerFactory;
  737.  
  738. @@ -340,6 +341,8 @@ import com.l2jserver.util.Rnd;
  739. public final class L2PcInstance extends L2Playable {
  740. private static final Logger LOG = LoggerFactory.getLogger(L2PcInstance.class);
  741.  
  742. + public VisualArmorModel visualArmor;
  743. +
  744. // Character Skill SQL String Definitions:
  745. private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE charId=? AND class_index=?";
  746. private static final String ADD_NEW_SKILL = "INSERT INTO character_skills (charId,skill_id,skill_level,class_index) VALUES (?,?,?,?)";
  747. @@ -886,6 +889,7 @@ public final class L2PcInstance extends L2Playable {
  748. _radar = new L2Radar(this);
  749.  
  750. startVitalityTask();
  751. + visualArmor = new VisualArmorModel(this);
  752. }
  753.  
  754. /**
  755. diff --git a/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java b/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java
  756. index 509da0c..acf3b2f 100644
  757. --- a/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java
  758. +++ b/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java
  759. @@ -19,6 +19,7 @@
  760. package com.l2jserver.gameserver.network.serverpackets;
  761.  
  762. import com.l2jserver.Config;
  763. +import com.l2jserver.extensions.VisualArmorController;
  764. import com.l2jserver.gameserver.data.xml.impl.NpcData;
  765. import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  766. import com.l2jserver.gameserver.model.PcCondOverride;
  767. @@ -214,7 +215,32 @@ public class CharInfo extends L2GameServerPacket
  768.  
  769. for (int slot : getPaperdollOrder())
  770. {
  771. - writeD(_activeChar.getInventory().getPaperdollItemDisplayId(slot));
  772. + switch (slot)
  773. + {
  774. + case 5:
  775. + writeD(VisualArmorController.getRHAND(_activeChar));
  776. + break;
  777. + case 6:
  778. + writeD(VisualArmorController.getVirtualBody(_activeChar));
  779. + break;
  780. + case 7:
  781. + writeD(VisualArmorController.getLHAND(_activeChar));
  782. + break;
  783. + case 10:
  784. + writeD(VisualArmorController.getVirtualGloves(_activeChar));
  785. + break;
  786. + case 11:
  787. + writeD(VisualArmorController.getVirtualPants(_activeChar));
  788. + break;
  789. + case 12:
  790. + writeD(VisualArmorController.getVirtualBoots(_activeChar));
  791. + break;
  792. + case 23:
  793. + writeD(VisualArmorController.getCloak(_activeChar));
  794. + break;
  795. + default:
  796. + writeD(_activeChar.getInventory().getPaperdollItemDisplayId(slot));
  797. + }
  798. }
  799.  
  800. for (int slot : getPaperdollOrder())
  801. diff --git a/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java b/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java
  802. index 136e01a..70ae9fc 100644
  803. --- a/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java
  804. +++ b/l2j_server/src/main/java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java
  805. @@ -19,6 +19,7 @@
  806. package com.l2jserver.gameserver.network.serverpackets;
  807.  
  808. import com.l2jserver.Config;
  809. +import com.l2jserver.extensions.VisualArmorController;
  810. import com.l2jserver.gameserver.data.xml.impl.ExperienceData;
  811. import com.l2jserver.gameserver.data.xml.impl.NpcData;
  812. import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  813. @@ -126,7 +127,32 @@ public final class UserInfo extends L2GameServerPacket
  814.  
  815. for (int slot : getPaperdollOrder())
  816. {
  817. - writeD(_activeChar.getInventory().getPaperdollItemDisplayId(slot));
  818. + switch (slot)
  819. + {
  820. + case 5:
  821. + writeD(VisualArmorController.getRHAND(_activeChar));
  822. + break;
  823. + case 6:
  824. + writeD(VisualArmorController.getVirtualBody(_activeChar));
  825. + break;
  826. + case 7:
  827. + writeD(VisualArmorController.getLHAND(_activeChar));
  828. + break;
  829. + case 10:
  830. + writeD(VisualArmorController.getVirtualGloves(_activeChar));
  831. + break;
  832. + case 11:
  833. + writeD(VisualArmorController.getVirtualPants(_activeChar));
  834. + break;
  835. + case 12:
  836. + writeD(VisualArmorController.getVirtualBoots(_activeChar));
  837. + break;
  838. + case 23:
  839. + writeD(VisualArmorController.getCloak(_activeChar));
  840. + break;
  841. + default:
  842. + writeD(_activeChar.getInventory().getPaperdollItemDisplayId(slot));
  843. + }
  844. }
  845.  
  846. for (int slot : getPaperdollOrder())
  847. --
  848. 2.10.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement