Guest User

dressme freya

a guest
Oct 9th, 2012
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.11 KB | None | 0 0
  1. Index: java/com/l2jserver/extensions/VisualArmorController.java
  2. ===================================================================
  3. --- java/com/l2jserver/extensions/VisualArmorController.java    (revision 0)
  4. +++ java/com/l2jserver/extensions/VisualArmorController.java    (revision 0)
  5. @@ -0,0 +1,373 @@
  6. +/*
  7. + * This program is free software: you can redistribute it and/or modify it under
  8. + * the terms of the GNU General Public License as published by the Free Software
  9. + * Foundation, either version 3 of the License, or (at your option) any later
  10. + * version.
  11. + *
  12. + * This program is distributed in the hope that it will be useful, but WITHOUT
  13. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  15. + * details.
  16. + *
  17. + * You should have received a copy of the GNU General Public License along with
  18. + * this program. If not, see <http://www.gnu.org/licenses/>.
  19. + */
  20. +package com.l2jserver.extensions;
  21. +
  22. +import java.sql.Connection;
  23. +import java.sql.PreparedStatement;
  24. +import java.sql.SQLException;
  25. +import com.l2jserver.L2DatabaseFactory;
  26. +import com.l2jserver.gameserver.datatables.ItemTable;
  27. +import com.l2jserver.gameserver.model.L2ItemInstance;
  28. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. +import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  30. +import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  31. +import com.l2jserver.gameserver.templates.item.L2Armor;
  32. +import com.l2jserver.gameserver.templates.item.L2ArmorType;
  33. +import com.l2jserver.gameserver.templates.item.L2Item;
  34. +import com.l2jserver.gameserver.templates.item.L2Weapon;
  35. +import com.l2jserver.gameserver.templates.item.L2WeaponType;
  36. +
  37. +/**
  38. + * @author giorgakis
  39. + *
  40. + */
  41. +public class VisualArmorController
  42. +{
  43. +  //As of freya there are 19 weapon types.
  44. +  public static final int totalWeaponTypes = 19;
  45. +  
  46. +  //As of freya there are 6 armor types.
  47. +  public static final int totalArmorTypes = 6;
  48. +  
  49. +  public static boolean[][] weaponMapping = new boolean[totalWeaponTypes][totalWeaponTypes];
  50. +  public static boolean[][] armorMapping = new boolean[totalArmorTypes][totalArmorTypes];
  51. +  
  52. +  public static void migrate()
  53. +  {
  54. +      System.out.println("[VisualArmor]:Migrating the database.");
  55. +      Connection con = null;
  56. +      try
  57. +      {
  58. +          con = L2DatabaseFactory.getInstance().getConnection();
  59. +          PreparedStatement statement = con.prepareStatement(VisualArmorModel.CREATE);
  60. +          statement.execute();
  61. +          statement.close();
  62. +      }
  63. +      catch (SQLException e)
  64. +      {
  65. +          e.printStackTrace();
  66. +      }
  67. +      finally
  68. +      {
  69. +          try { con.close(); } catch (Exception e) {}
  70. +      }
  71. +  }
  72. +  
  73. +  public static void load()
  74. +  {
  75. +      migrate();
  76. +      generateMappings();
  77. +  }
  78. +  
  79. +  /**
  80. +    * All same type armors and same type weapons can get visual. All different types
  81. +    * cannot get visual unless it is stated in here.
  82. +    */
  83. +  public static void generateMappings()
  84. +  {
  85. +      for(int i =0; i< weaponMapping.length; i++)
  86. +          for(int j = 0; j< weaponMapping.length; j++)
  87. +              weaponMapping[i][j]=false;
  88. +      
  89. +      for(int i =0; i< armorMapping.length; i++)
  90. +          for(int j = 0; j< armorMapping.length; j++)
  91. +              armorMapping[i][j]=false;
  92. +      
  93. +      callRules();
  94. +      
  95. +  }
  96. +  
  97. +  public static void callRules()
  98. +  {
  99. +      //Example: a Virtual sword can mount an Equipped blunt.
  100. +      weaponMapping[L2WeaponType.SWORD.ordinal()][L2WeaponType.BLUNT.ordinal()] = true;
  101. +      
  102. +      //Example: a Virtual blunt can mount an Equipped sword.
  103. +      weaponMapping[L2WeaponType.BLUNT.ordinal()][L2WeaponType.SWORD.ordinal()] = true;
  104. +      
  105. +      weaponMapping[L2WeaponType.BIGSWORD.ordinal()][L2WeaponType.BIGBLUNT.ordinal()] = true;
  106. +      weaponMapping[L2WeaponType.BIGBLUNT.ordinal()][L2WeaponType.BIGSWORD.ordinal()] = true;
  107. +      
  108. +      armorMapping[L2ArmorType.SIGIL.ordinal()][L2ArmorType.SHIELD.ordinal()] = true;
  109. +      armorMapping[L2ArmorType.SHIELD.ordinal()][L2ArmorType.SIGIL.ordinal()] = true;
  110. +      
  111. +      //armorMapping[L2ArmorType.HEAVY.ordinal()][L2ArmorType.LIGHT.ordinal()] = true;
  112. +      //armorMapping[L2ArmorType.HEAVY.ordinal()][L2ArmorType.MAGIC.ordinal()] = true;
  113. +      
  114. +      //armorMapping[L2ArmorType.LIGHT.ordinal()][L2ArmorType.HEAVY.ordinal()] = true;
  115. +      //armorMapping[L2ArmorType.LIGHT.ordinal()][L2ArmorType.MAGIC.ordinal()] = true;
  116. +      
  117. +      //armorMapping[L2ArmorType.MAGIC.ordinal()][L2ArmorType.LIGHT.ordinal()] = true;
  118. +      //armorMapping[L2ArmorType.MAGIC.ordinal()][L2ArmorType.HEAVY.ordinal()] = true;
  119. +  }
  120. +  
  121. +  /**
  122. +    * Checks if the weapon is the same type. If that is true then return
  123. +    * the matching virtual id. Else check the mapping tables if any
  124. +    * rule states that the two different weapon types should be matched.
  125. +    * @param virtual
  126. +    * @param equiped
  127. +    * @param matchId
  128. +    * @param noMatchId
  129. +    * @return
  130. +    */
  131. +  public static int weaponMatching(L2WeaponType virtual, L2WeaponType equiped, int matchId, int noMatchId)
  132. +  {
  133. +      if(virtual == equiped)
  134. +          return matchId;
  135. +
  136. +      if(weaponMapping[virtual.ordinal()][equiped.ordinal()] == true)
  137. +      {
  138. +          return matchId;
  139. +      }
  140. +      
  141. +      return noMatchId;
  142. +  }
  143. +  
  144. +  /**
  145. +    * Checks if the armor is the same type. If that is true then return
  146. +    * the matching virtual id. Else check the mapping tables if any
  147. +    * rule states that the two different armor types should be matched.
  148. +    * @param virtual
  149. +    * @param equiped
  150. +    * @param matchId
  151. +    * @param noMatchId
  152. +    * @return
  153. +    */
  154. +  public static int armorMatching(L2ArmorType virtual, L2ArmorType equiped, int matchId , int noMatchId)
  155. +  {
  156. +      if(virtual == equiped)
  157. +          return matchId;
  158. +      
  159. +      if(armorMapping[virtual.ordinal()][equiped.ordinal()] == true)
  160. +          return matchId;
  161. +      
  162. +      return noMatchId;
  163. +  }
  164. +  
  165. +  
  166. +  
  167. +  public static void setVirtualRhand(L2PcInstance actor)
  168. +  {
  169. +      actor.visualArmor.weaponRHANDId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_RHAND);
  170. +  }
  171. +  
  172. +  public static void setVirtualLhand(L2PcInstance actor)
  173. +  {
  174. +      actor.visualArmor.weaponLHANDId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_LHAND);
  175. +  }
  176. +  
  177. +  public static void setVirtualGloves(L2PcInstance actor)
  178. +  {
  179. +      actor.visualArmor.glovesTextureId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_GLOVES);
  180. +  }
  181. +  
  182. +  public static void setVirtualBody(L2PcInstance actor)
  183. +  {  
  184. +      actor.visualArmor.armorTextureId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_CHEST);
  185. +  }  
  186. +  
  187. +  public static void setVirtualPants(L2PcInstance actor)
  188. +  {
  189. +      int chestId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_CHEST);
  190. +      int pantsId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_LEGS);
  191. +      
  192. +      if(chestId != 0 && pantsId==0)
  193. +          actor.visualArmor.pantsTextureId = chestId;
  194. +      else
  195. +          actor.visualArmor.pantsTextureId = pantsId;
  196. +  }
  197. +  
  198. +  public static void setVirtualBoots(L2PcInstance actor)
  199. +  {  
  200. +      actor.visualArmor.bootsTextureId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_FEET);
  201. +  }
  202. +  
  203. +  //TODO: Merge the armor getters in one function.
  204. +  public static int getVirtualGloves(L2PcInstance actor)
  205. +  {
  206. +      L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  207. +      if(equipedItem == null)
  208. +          return 0;
  209. +      //ClassCastException wont happen unless some jackass changes the values from the database.
  210. +      L2Armor equipedGloves = (L2Armor)actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_GLOVES).getItem();
  211. +      int equipedGlovesId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_GLOVES);
  212. +      
  213. +      int glovesTextureId = actor.visualArmor.glovesTextureId;
  214. +      L2Armor virtualGloves = (L2Armor)ItemTable.getInstance().getTemplate(glovesTextureId);
  215. +      
  216. +      if(glovesTextureId != 0)
  217. +          return armorMatching(virtualGloves.getItemType(), equipedGloves.getItemType(),glovesTextureId, equipedGlovesId);
  218. +      else
  219. +          return equipedGlovesId;
  220. +  }
  221. +  
  222. +  public static int getVirtualBody(L2PcInstance actor)
  223. +  {
  224. +      L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  225. +      if(equipedItem == null)
  226. +          return 0;
  227. +      //ClassCastException wont happen unless some jackass changes the values from the database.
  228. +      L2Armor equipedChest = (L2Armor)actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST).getItem();
  229. +      int equipedChestId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_CHEST);
  230. +      
  231. +      int chestTextureId = actor.visualArmor.armorTextureId;
  232. +      L2Armor virtualChest = (L2Armor)ItemTable.getInstance().getTemplate(chestTextureId);
  233. +      
  234. +      if(chestTextureId != 0)
  235. +          return armorMatching(virtualChest.getItemType(), equipedChest.getItemType(),chestTextureId, equipedChestId);
  236. +      else
  237. +          return equipedChestId;
  238. +  }
  239. +  
  240. +  /**
  241. +    * This is a brain fu**er handling the pants since they are
  242. +    * also part of a fullbody armor.
  243. +    * @param actor
  244. +    * @return
  245. +    */
  246. +  public static int getVirtualPants(L2PcInstance actor)
  247. +  {
  248. +      L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  249. +      
  250. +      //Here comes the tricky part. If pants are null, then check for a fullbody armor.
  251. +      if(equipedItem == null)
  252. +          equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  253. +      if(equipedItem == null)
  254. +          return 0;
  255. +          
  256. +      int pantsTextureId = actor.visualArmor.pantsTextureId;
  257. +      
  258. +      L2Armor equipedPants = (L2Armor) equipedItem.getItem();
  259. +      
  260. +      if(equipedPants.getBodyPart() != L2Item.SLOT_FULL_ARMOR && equipedPants.getBodyPart() != L2Item.SLOT_LEGS)
  261. +          return 0;
  262. +      int equipedPantsId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_LEGS);
  263. +      
  264. +      
  265. +      L2Armor virtualPants = (L2Armor)ItemTable.getInstance().getTemplate(pantsTextureId);
  266. +      
  267. +      if(pantsTextureId != 0)
  268. +          return armorMatching(virtualPants.getItemType(), equipedPants.getItemType(),pantsTextureId, equipedPantsId);
  269. +      else
  270. +          return equipedPantsId;
  271. +  }
  272. +  
  273. +  public static int getVirtualBoots(L2PcInstance actor)
  274. +  {
  275. +      L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_FEET);
  276. +      if(equipedItem == null)
  277. +          return 0;
  278. +      //ClassCastException wont happen unless some jackass changes the values from the database.
  279. +      L2Armor equipedBoots = (L2Armor)actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_FEET).getItem();
  280. +      int equipedBootsId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_FEET);
  281. +      
  282. +      int bootsTextureId = actor.visualArmor.bootsTextureId;
  283. +      L2Armor virtualGloves = (L2Armor)ItemTable.getInstance().getTemplate(bootsTextureId);
  284. +      
  285. +      if(bootsTextureId != 0)
  286. +          return armorMatching(virtualGloves.getItemType(), equipedBoots.getItemType(),bootsTextureId, equipedBootsId);
  287. +      else
  288. +          return equipedBootsId;
  289. +  }
  290. +  
  291. +  public static int getLHAND(L2PcInstance actor)
  292. +  {
  293. +      L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  294. +      int equipedItemId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_LHAND);
  295. +      
  296. +      int weaponLHANDId = actor.visualArmor.weaponLHANDId;
  297. +      L2Item virtualItem = ItemTable.getInstance().getTemplate(weaponLHANDId);
  298. +      
  299. +      if(equipedItem == null || weaponLHANDId == 0)
  300. +          return equipedItemId;
  301. +      
  302. +      //Only check same weapon types. Virtual replacement should not happen between armor/weapons.
  303. +      if(equipedItem.getItem() instanceof L2Weapon && virtualItem instanceof L2Weapon)
  304. +      {
  305. +          L2Weapon weapon = (L2Weapon) equipedItem.getItem();
  306. +          L2Weapon virtualweapon = (L2Weapon)virtualItem;
  307. +          
  308. +          return weaponMatching(virtualweapon.getItemType(), weapon.getItemType(), weaponLHANDId, equipedItemId);
  309. +      }
  310. +      else if(equipedItem.getItem() instanceof L2Armor && virtualItem instanceof L2Armor)
  311. +      {
  312. +          L2Armor armor = (L2Armor) equipedItem.getItem();
  313. +          L2Armor virtualarmor = (L2Armor)virtualItem;
  314. +          
  315. +          return armorMatching(virtualarmor.getItemType(), armor.getItemType(), weaponLHANDId, equipedItemId);
  316. +      }
  317. +      return equipedItemId;
  318. +  }
  319. +  
  320. +  public static int getRHAND(L2PcInstance actor)
  321. +  {
  322. +      int weaponRHANDId = actor.visualArmor.weaponRHANDId;
  323. +      L2ItemInstance equipedItem = actor.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  324. +      int equipedItemId = actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_RHAND);
  325. +      L2Item virtualItem = ItemTable.getInstance().getTemplate(weaponRHANDId);
  326. +      
  327. +      if(equipedItem == null || weaponRHANDId == 0)
  328. +          return equipedItemId;
  329. +      
  330. +      //Only check same weapon types. Virtual replacement should not happen between armor/weapons.
  331. +      if(equipedItem.getItem() instanceof L2Weapon && virtualItem instanceof L2Weapon)
  332. +      {
  333. +          L2Weapon weapon = (L2Weapon) equipedItem.getItem();
  334. +          L2Weapon virtualweapon = (L2Weapon)virtualItem;
  335. +          
  336. +          return weaponMatching(virtualweapon.getItemType(), weapon.getItemType(), weaponRHANDId, equipedItemId);
  337. +      }
  338. +      else if(equipedItem.getItem() instanceof L2Armor && virtualItem instanceof L2Armor)
  339. +      {
  340. +          L2Armor armor = (L2Armor) equipedItem.getItem();
  341. +          L2Armor virtualarmor = (L2Armor)virtualItem;
  342. +          
  343. +          return armorMatching(virtualarmor.getItemType(), armor.getItemType(), weaponRHANDId, equipedItemId);
  344. +      }
  345. +      return equipedItemId;
  346. +      
  347. +  }
  348. +  
  349. +  
  350. +  
  351. +  public static int getCloak(L2PcInstance actor)
  352. +  {
  353. +      if(actor.visualArmor.weaponLRHANDId == 1)
  354. +          return 0;
  355. +      else
  356. +          return actor.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_CLOAK);
  357. +          
  358. +  }
  359. +  
  360. +  public static void dressMe(L2PcInstance activeChar)
  361. +  {
  362. +      setVirtualBody(activeChar);
  363. +      setVirtualGloves(activeChar);
  364. +      setVirtualPants(activeChar);
  365. +      setVirtualBoots(activeChar);
  366. +      setVirtualLhand(activeChar);
  367. +      setVirtualRhand(activeChar);
  368. +      
  369. +      InventoryUpdate iu = new InventoryUpdate();
  370. +        activeChar.sendPacket(iu);
  371. +      activeChar.broadcastUserInfo();
  372. +      InventoryUpdate iu2 = new InventoryUpdate();
  373. +        activeChar.sendPacket(iu2);
  374. +      activeChar.broadcastUserInfo();
  375. +      activeChar.sendMessage("You changed clothes.");
  376. +      activeChar.visualArmor.updateVisualArmor();
  377. +  }
  378. +}
  379. Index: java/com/l2jserver/extensions/VisualArmorModel.java
  380. ===================================================================
  381. --- java/com/l2jserver/extensions/VisualArmorModel.java (revision 0)
  382. +++ java/com/l2jserver/extensions/VisualArmorModel.java (revision 0)
  383. @@ -0,0 +1,171 @@
  384. +/*
  385. + * This program is free software: you can redistribute it and/or modify it under
  386. + * the terms of the GNU General Public License as published by the Free Software
  387. + * Foundation, either version 3 of the License, or (at your option) any later
  388. + * version.
  389. + *
  390. + * This program is distributed in the hope that it will be useful, but WITHOUT
  391. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  392. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  393. + * details.
  394. + *
  395. + * You should have received a copy of the GNU General Public License along with
  396. + * this program. If not, see <http://www.gnu.org/licenses/>.
  397. + */
  398. +package com.l2jserver.extensions;
  399. +
  400. +import java.sql.Connection;
  401. +import java.sql.PreparedStatement;
  402. +import java.sql.ResultSet;
  403. +import java.sql.SQLException;
  404. +import com.l2jserver.L2DatabaseFactory;
  405. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  406. +import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  407. +
  408. +/**
  409. + * @author Issle
  410. + *
  411. + */
  412. +public class VisualArmorModel
  413. +{
  414. +  private static final String RESTORE_VISUAL_ARMOR = "SELECT GlovesId,ChestId,BootsId,PantsId,LeftHandId,RightHandId,DoubleHandId FROM visual_armor WHERE CharId=?";
  415. +  private static final String UPDATE_VISUAL_ARMOR = "UPDATE visual_armor SET GlovesId=?,ChestId=?,BootsId=?,PantsId=?,LeftHandId=?,RightHandId=?,DoubleHandId=? WHERE CharId=?";
  416. +  private static final String CREATE_VISUAL_ARMOR = "INSERT INTO visual_armor (CharId,GlovesId,ChestId,BootsId,PantsId,LeftHandId,RightHandId,DoubleHandId) values (?,?,?,?,?,?,?,?)";
  417. +  
  418. +  public static final String CREATE =
  419. +      "CREATE TABLE IF NOT EXISTS `visual_armor` (" +
  420. +      "`CharId` int(11) NOT NULL," +
  421. +      "`GlovesId` int(11) NOT NULL DEFAULT '0'," +
  422. +      "`BootsId` int(11) NOT NULL DEFAULT '0'," +
  423. +      "`ChestId` int(11) NOT NULL DEFAULT '0'," +
  424. +      "`PantsId` int(11) NOT NULL DEFAULT '0'," +
  425. +      "`LeftHandId` int(11) NOT NULL DEFAULT '0'," +
  426. +      "`RightHandId` int(11) NOT NULL DEFAULT '0'," +
  427. +      "`DoubleHandId` int(11) NOT NULL DEFAULT '0',PRIMARY KEY (`CharId`))";
  428. +  
  429. +  public static final String DROP =
  430. +      "DROP TABLE 'visual_armor'";
  431. +  
  432. +  public int glovesTextureId=0;
  433. +  public int armorTextureId=0;
  434. +  public int pantsTextureId=0;
  435. +  public int bootsTextureId=0;
  436. +  public int weaponLHANDId=0;
  437. +  public int weaponRHANDId=0;
  438. +  public int weaponLRHANDId=0;
  439. +  public int ownerId;
  440. +  
  441. +  
  442. +  public void updateVisualArmor()
  443. +  {
  444. +      Connection con = null;
  445. +      try
  446. +      {
  447. +          con = L2DatabaseFactory.getInstance().getConnection();
  448. +          PreparedStatement statement = con.prepareStatement(UPDATE_VISUAL_ARMOR);
  449. +          statement.setInt(1, glovesTextureId);
  450. +          statement.setInt(2, armorTextureId);
  451. +          statement.setInt(3, bootsTextureId);
  452. +          statement.setInt(4, pantsTextureId);
  453. +          statement.setInt(5, weaponLHANDId);
  454. +          statement.setInt(6, weaponRHANDId);
  455. +          statement.setInt(7, weaponLRHANDId);
  456. +          statement.setInt(8, ownerId);
  457. +          statement.execute();
  458. +          statement.close();
  459. +
  460. +      }
  461. +      catch (SQLException e)
  462. +      {
  463. +          e.printStackTrace();
  464. +      }
  465. +      finally
  466. +      {
  467. +          try { con.close(); } catch (Exception e) {}
  468. +      }
  469. +  }
  470. +  
  471. +  public VisualArmorModel(L2PcInstance activeChar)
  472. +  {
  473. +      ownerId = activeChar.getObjectId();
  474. +      Connection con = null;
  475. +      try
  476. +      {
  477. +          con = L2DatabaseFactory.getInstance().getConnection();
  478. +          
  479. +          PreparedStatement statement = con.prepareStatement(RESTORE_VISUAL_ARMOR);
  480. +          statement.setInt(1, ownerId);
  481. +          ResultSet rset = statement.executeQuery();
  482. +          boolean got = false;
  483. +          while(rset.next())
  484. +          {
  485. +              glovesTextureId = rset.getInt("GlovesId");
  486. +              armorTextureId = rset.getInt("ChestId");
  487. +              pantsTextureId = rset.getInt("PantsId");
  488. +              bootsTextureId = rset.getInt("BootsId");
  489. +              weaponLHANDId = rset.getInt("LeftHandId");
  490. +              weaponRHANDId = rset.getInt("RightHandId");
  491. +              weaponLRHANDId = rset.getInt("DoubleHandId");
  492. +              got = true;
  493. +      
  494. +          }
  495. +          
  496. +          rset.close();
  497. +          statement.close();
  498. +          
  499. +          if(got == false)
  500. +          {
  501. +              createVisualArmor();
  502. +          }
  503. +          
  504. +          InventoryUpdate iu = new InventoryUpdate();
  505. +          activeChar.sendPacket(iu);
  506. +          activeChar.broadcastUserInfo();
  507. +          InventoryUpdate iu2 = new InventoryUpdate();
  508. +          activeChar.sendPacket(iu2);
  509. +          activeChar.broadcastUserInfo();
  510. +          activeChar.sendMessage("You changed clothes.");
  511. +      }
  512. +      catch (SQLException e)
  513. +      {
  514. +          e.printStackTrace();
  515. +      }
  516. +      finally
  517. +      {
  518. +          try { con.close(); } catch (Exception e) {}
  519. +      }
  520. +  }
  521. +  
  522. +  public void createVisualArmor() throws SQLException
  523. +  {
  524. +      Connection con = null;
  525. +      
  526. +      try
  527. +      {
  528. +          con = L2DatabaseFactory.getInstance().getConnection();
  529. +          PreparedStatement statement = con.prepareStatement(CREATE_VISUAL_ARMOR);
  530. +          
  531. +          statement.setInt(1, ownerId);
  532. +          statement.setInt(2, 0);
  533. +          statement.setInt(3, 0);
  534. +          statement.setInt(4, 0);
  535. +          statement.setInt(5, 0);
  536. +          statement.setInt(6, 0);
  537. +          statement.setInt(7, 0);
  538. +          statement.setInt(8, 0);
  539. +          
  540. +          statement.executeUpdate();
  541. +          statement.close();
  542. +      }
  543. +      catch (Exception e)
  544. +      {
  545. +          e.printStackTrace();
  546. +      }
  547. +      finally
  548. +      {
  549. +          try { con.close(); } catch (Exception e) {}
  550. +      }
  551. +  }
  552. +  
  553. +}
  554. +
  555. Index: java/com/l2jserver/gameserver/GameServer.java
  556. ===================================================================
  557. --- java/com/l2jserver/gameserver/GameServer.java  (revision 4469)
  558. +++ java/com/l2jserver/gameserver/GameServer.java  (working copy)
  559. @@ -32,6 +32,7 @@
  560.  import com.l2jserver.Config;
  561.  import com.l2jserver.L2DatabaseFactory;
  562.  import com.l2jserver.Server;
  563. +import com.l2jserver.extensions.VisualArmorController;
  564.  import com.l2jserver.gameserver.cache.CrestCache;
  565.  import com.l2jserver.gameserver.cache.HtmCache;
  566.  import com.l2jserver.gameserver.datatables.AccessLevels;
  567. @@ -315,6 +316,7 @@
  568.         BoatManager.getInstance();
  569.         AirShipManager.getInstance();
  570.         GraciaSeedsManager.getInstance();
  571. +      VisualArmorController.load();
  572.      
  573.         try
  574.         {
  575. Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  576. ===================================================================
  577. --- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (revision 4469)
  578. +++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (working copy)
  579. @@ -38,6 +38,7 @@
  580.  
  581.  import com.l2jserver.Config;
  582.  import com.l2jserver.L2DatabaseFactory;
  583. +import com.l2jserver.extensions.VisualArmorModel;
  584.  import com.l2jserver.gameserver.Announcements;
  585.  import com.l2jserver.gameserver.GameTimeController;
  586.  import com.l2jserver.gameserver.GeoData;
  587. @@ -274,6 +275,7 @@
  588.   */
  589.  public final class L2PcInstance extends L2Playable
  590.  {
  591. +  public VisualArmorModel visualArmor;
  592.     // Character Skill SQL String Definitions:
  593.     private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE charId=? AND class_index=?";
  594.     private static final String ADD_NEW_SKILL = "INSERT INTO character_skills (charId,skill_id,skill_level,class_index) VALUES (?,?,?,?)";
  595. @@ -324,6 +326,8 @@
  596.     public static final int STORE_PRIVATE_MANUFACTURE = 5;
  597.     public static final int STORE_PRIVATE_PACKAGE_SELL = 8;
  598.    
  599. +  
  600. +  
  601.     /** The table containing all minimum level needed for each Expertise (None, D, C, B, A, S, S80, S84)*/
  602.     private static final int[] EXPERTISE_LEVELS =
  603.     {
  604. @@ -1254,6 +1258,7 @@
  605.         if (!Config.WAREHOUSE_CACHE)
  606.             getWarehouse();
  607.         startVitalityTask();
  608. +      visualArmor = new VisualArmorModel(this);
  609.     }
  610.    
  611.     private L2PcInstance(int objectId)
  612. Index: java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java
  613. ===================================================================
  614. --- java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java  (revision 4469)
  615. +++ java/com/l2jserver/gameserver/network/serverpackets/CharInfo.java  (working copy)
  616. @@ -17,6 +17,7 @@
  617.  import java.util.logging.Logger;
  618.  
  619.  import com.l2jserver.Config;
  620. +import com.l2jserver.extensions.VisualArmorController;
  621.  import com.l2jserver.gameserver.datatables.NpcTable;
  622.  import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  623.  import com.l2jserver.gameserver.model.actor.L2Decoy;
  624. @@ -249,20 +250,20 @@
  625.             writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_HEAD));
  626.             if (_airShipHelm == 0)
  627.             {
  628. -              writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
  629. -              writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_LHAND));
  630. +              writeD(VisualArmorController.getRHAND(_activeChar));
  631. +              writeD(VisualArmorController.getLHAND(_activeChar));
  632.             }
  633.             else
  634.             {
  635.                 writeD(_airShipHelm);
  636.                 writeD(0);
  637.             }
  638. -          writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_GLOVES));
  639. -          writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_CHEST));
  640. -          writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_LEGS));
  641. -          writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_FEET));
  642. -          writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_CLOAK));
  643. -          writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
  644. +          writeD(VisualArmorController.getVirtualGloves(_activeChar));
  645. +          writeD(VisualArmorController.getVirtualBody(_activeChar));
  646. +          writeD(VisualArmorController.getVirtualPants(_activeChar));
  647. +          writeD(VisualArmorController.getVirtualBoots(_activeChar));
  648. +          writeD(VisualArmorController.getCloak(_activeChar));
  649. +          writeD(VisualArmorController.getRHAND(_activeChar));
  650.             writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_HAIR));
  651.             writeD(_inv.getPaperdollItemId(Inventory.PAPERDOLL_HAIR2));
  652.             // T1 new d's
  653. Index: java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java
  654. ===================================================================
  655. --- java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java  (revision 4469)
  656. +++ java/com/l2jserver/gameserver/network/serverpackets/UserInfo.java  (working copy)
  657. @@ -15,6 +15,7 @@
  658.  package com.l2jserver.gameserver.network.serverpackets;
  659.  
  660.  import com.l2jserver.Config;
  661. +import com.l2jserver.extensions.VisualArmorController;
  662.  import com.l2jserver.gameserver.datatables.NpcTable;
  663.  import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  664.  import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
  665. @@ -192,20 +193,20 @@
  666.         writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_HEAD));
  667.         if (_airShipHelm == 0)
  668.         {
  669. -          writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
  670. -          writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_LHAND));
  671. +          writeD(VisualArmorController.getRHAND(_activeChar));
  672. +          writeD(VisualArmorController.getLHAND(_activeChar));
  673.         }
  674.         else
  675.         {
  676.             writeD(_airShipHelm);
  677.             writeD(0);
  678.         }
  679. -      writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_GLOVES));
  680. -      writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_CHEST));
  681. -      writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_LEGS));
  682. -      writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_FEET));
  683. -      writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_CLOAK));
  684. -      writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_RHAND));
  685. +      writeD(VisualArmorController.getVirtualGloves(_activeChar));
  686. +      writeD(VisualArmorController.getVirtualBody(_activeChar));
  687. +      writeD(VisualArmorController.getVirtualPants(_activeChar));
  688. +      writeD(VisualArmorController.getVirtualBoots(_activeChar));
  689. +      writeD(VisualArmorController.getCloak(_activeChar));
  690. +      writeD(VisualArmorController.getRHAND(_activeChar));
  691.         writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_HAIR));
  692.         writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_HAIR2));
  693.         writeD(_activeChar.getInventory().getPaperdollItemId(Inventory.PAPERDOLL_RBRACELET));
Advertisement
Add Comment
Please, Sign In to add comment