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