Jump to content
  • 0

Enchant All Grades for aCis ( system Hasha Enchant)


Question

Posted

Hello how would you put a scroll to all grids? I can not set the scroll grid for all.

 

### Eclipse Workspace Patch 1.0
#P aCis_datapack
Index: data/xml/enchants.xml
===================================================================
--- data/xml/enchants.xml       (revision 0)
+++ data/xml/enchants.xml       (revision 0)
@@ -0,0 +1,44 @@
+<?xml version='1.0' encoding='utf-8'?>
+<list>
+       <!-- Scrolls: Enchant Weapon -->
+       <enchant id="959" grade="5" weapon="True" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- S grade - Scrolls: Enchant Weapon -->
+       <enchant id="729" grade="4" weapon="True" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- A grade - Scrolls: Enchant Weapon -->
+       <enchant id="947" grade="3" weapon="True" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- B grade - Scrolls: Enchant Weapon -->
+       <enchant id="951" grade="2" weapon="True" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- C grade - Scrolls: Enchant Weapon -->
+       <enchant id="955" grade="1" weapon="True" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- D grade - Scrolls: Enchant Weapon -->
+      
+       <!-- Scrolls: Enchant Armor -->
+       <enchant id="960" grade="5" weapon="False" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- S grade - Scrolls: Enchant Armor -->
+       <enchant id="730" grade="4" weapon="False" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- A grade - Scrolls: Enchant Armor -->
+       <enchant id="948" grade="3" weapon="False" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- B grade - Scrolls: Enchant Armor -->
+       <enchant id="952" grade="2" weapon="False" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- C grade - Scrolls: Enchant Armor -->
+       <enchant id="956" grade="1" weapon="False" break="True" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- D grade - Scrolls: Enchant Armor -->
+      
+       <!-- Blessed Scrolls: Enchant Weapon -->
+       <enchant id="6577" grade="5" weapon="True" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- S grade - Blessed Scrolls: Enchant Weapon -->
+       <enchant id="6569" grade="4" weapon="True" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- A grade - Blessed Scrolls: Enchant Weapon -->
+       <enchant id="6571" grade="3" weapon="True" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- B grade - Blessed Scrolls: Enchant Weapon -->
+       <enchant id="6573" grade="2" weapon="True" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- C grade - Blessed Scrolls: Enchant Weapon -->
+       <enchant id="6575" grade="1" weapon="True" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- D grade - Blessed Scrolls: Enchant Weapon -->
+      
+       <!-- Blessed Scrolls: Armor Weapon -->
+       <enchant id="6578" grade="5" weapon="False" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- S grade - Blessed Scrolls: Enchant Armor -->
+       <enchant id="6570" grade="4" weapon="False" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- A grade - Blessed Scrolls: Enchant Armor -->
+       <enchant id="6572" grade="3" weapon="False" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- B grade - Blessed Scrolls: Enchant Armor -->
+       <enchant id="6574" grade="2" weapon="False" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- C grade - Blessed Scrolls: Enchant Armor -->
+       <enchant id="6576" grade="1" weapon="False" break="False" maintain="False" chance="100;100;100;95;90;85;80;75" /> <!-- D grade - Blessed Scrolls: Enchant Armor -->
+      
+       <!-- Crystal Scrolls: Enchant Weapon -->
+       <enchant id="961" grade="5" weapon="True" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- S grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="731" grade="4" weapon="True" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- A grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="949" grade="3" weapon="True" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- B grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="953" grade="2" weapon="True" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- C grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="957" grade="1" weapon="True" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- D grade - Crystal Scrolls: Enchant Weapon -->
+      
+       <!-- Crystal Scrolls: Enchant Armor -->
+       <enchant id="962" grade="5" weapon="False" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- S grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="732" grade="4" weapon="False" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- A grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="950" grade="3" weapon="False" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- B grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="954" grade="2" weapon="False" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- C grade - Crystal Scrolls: Enchant Weapon -->
+       <enchant id="958" grade="1" weapon="False" break="False" maintain="True" chance="100;100;100;95;90;85;80;75" /> <!-- D grade - Crystal Scrolls: Enchant Weapon -->
+</list>
\ No newline at end of file
#P aCis_gameserver
Index: java/net/sf/l2j/gameserver/network/clientpackets/AbstractEnchantPacket.java
===================================================================
--- java/net/sf/l2j/gameserver/network/clientpackets/AbstractEnchantPacket.java (revision 5)
+++ java/net/sf/l2j/gameserver/network/clientpackets/AbstractEnchantPacket.java (working copy)
@@ -1,212 +0,0 @@
-/*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package net.sf.l2j.gameserver.network.clientpackets;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import net.sf.l2j.Config;
-import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
-import net.sf.l2j.gameserver.model.item.kind.Item;
-import net.sf.l2j.gameserver.model.item.kind.Weapon;
-import net.sf.l2j.gameserver.model.item.type.CrystalType;
-import net.sf.l2j.gameserver.model.item.type.WeaponType;
-
-public abstract class AbstractEnchantPacket extends L2GameClientPacket
-{
-       public static final Map<Integer, EnchantScroll> _scrolls = new HashMap<>();
-      
-       public static final class EnchantScroll
-       {
-               protected final boolean _isWeapon;
-               protected final CrystalType _grade;
-               private final boolean _isBlessed;
-               private final boolean _isCrystal;
-              
-               public EnchantScroll(boolean wep, boolean bless, boolean crystal, CrystalType type)
-               {
-                       _isWeapon = wep;
-                       _grade = type;
-                       _isBlessed = bless;
-                       _isCrystal = crystal;
-               }
-              
-               /**
-                * @param enchantItem : The item to enchant.
-                * @return true if support item can be used for this item
-                */
-               public final boolean isValid(ItemInstance enchantItem)
-               {
-                       if (enchantItem == null)
-                               return false;
-                      
-                       // checking scroll type and configured maximum enchant level
-                       switch (enchantItem.getItem().getType2())
-                       {
-                               case Item.TYPE2_WEAPON:
-                                       if (!_isWeapon || (Config.ENCHANT_MAX_WEAPON > 0 && enchantItem.getEnchantLevel() >= Config.ENCHANT_MAX_WEAPON))
-                                               return false;
-                                       break;
-                              
-                               case Item.TYPE2_SHIELD_ARMOR:
-                               case Item.TYPE2_ACCESSORY:
-                                       if (_isWeapon || (Config.ENCHANT_MAX_ARMOR > 0 && enchantItem.getEnchantLevel() >= Config.ENCHANT_MAX_ARMOR))
-                                               return false;
-                                       break;
-                              
-                               default:
-                                       return false;
-                       }
-                      
-                       // check for crystal type
-                       if (_grade != enchantItem.getItem().getCrystalType())
-                               return false;
-                      
-                       return true;
-               }
-              
-               /**
-                * @return true if item is a blessed scroll.
-                */
-               public final boolean isBlessed()
-               {
-                       return _isBlessed;
-               }
-              
-               /**
-                * @return true if item is a crystal scroll.
-                */
-               public final boolean isCrystal()
-               {
-                       return _isCrystal;
-               }
-              
-               /**
-                * Regarding enchant system :<br>
-                * <br>
-                * <u>Weapons</u>
-                * <ul>
-                * <li>magic weapons has chance of 40% until +15 and 20% from +15 and higher. There is no upper limit, there is no dependance on current enchant level.</li>
-                * <li>non magic weapons has chance of 70% until +15 and 35% from +15 and higher. There is no upper limit, there is no dependance on current enchant level.</li>
-                * </ul>
-                * <u>Armors</u>
-                * <ul>
-                * <li>non fullbody armors (jewelry, upper armor, lower armor, boots, gloves, helmets and shirts) has chance of 2/3 for +4, 1/3 for +5, 1/4 for +6, ...., 1/18 +20. If you've made a +20 armor, chance to make it +21 will be equal to zero (0%).</li>
-                * <li>full body armors has a chance of 1/1 for +4, 2/3 for +5, 1/3 for +6, ..., 1/17 for +20. If you've made a +20 armor, chance to make it +21 will be equal to zero (0%).</li>
-                * </ul>
-                * @param enchantItem : The item to enchant.
-                * @return the enchant chance under double format (0.7 / 0.35 / 0.44324...).
-                */
-               public final double getChance(ItemInstance enchantItem)
-               {
-                       if (!isValid(enchantItem))
-                               return -1;
-                      
-                       boolean fullBody = enchantItem.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR;
-                       if (enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX || (fullBody && enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL))
-                               return 1;
-                      
-                       double chance = 0;
-                      
-                       // Armor formula : 0.66^(current-2), chance is lower and lower for each enchant.
-                       if (enchantItem.isArmor())
-                               chance = Math.pow(Config.ENCHANT_CHANCE_ARMOR, (enchantItem.getEnchantLevel() - 2));
-                       // Weapon formula is 70% for fighter weapon, 40% for mage weapon. Special rates after +14.
-                       else if (enchantItem.isWeapon())
-                       {
-                               if (((Weapon) enchantItem.getItem()).isMagical())
-                                       chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS : Config.ENCHANT_CHANCE_WEAPON_MAGIC;
-                               else
-                                       chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS : Config.ENCHANT_CHANCE_WEAPON_NONMAGIC;
-                       }
-                      
-                       return chance;
-               }
-       }
-      
-       /**
-        * Format : itemId, (isWeapon, isBlessed, isCrystal, grade)<br>
-        * Allowed items IDs must be sorted by ascending order.
-        */
-       static
-       {
-               // Scrolls: Enchant Weapon
-               _scrolls.put(729, new EnchantScroll(true, false, false, CrystalType.A));
-               _scrolls.put(947, new EnchantScroll(true, false, false, CrystalType.B));
-               _scrolls.put(951, new EnchantScroll(true, false, false, CrystalType.C));
-               _scrolls.put(955, new EnchantScroll(true, false, false, CrystalType.D));
-               _scrolls.put(959, new EnchantScroll(true, false, false, CrystalType.S));
-              
-               // Scrolls: Enchant Armor
-               _scrolls.put(730, new EnchantScroll(false, false, false, CrystalType.A));
-               _scrolls.put(948, new EnchantScroll(false, false, false, CrystalType.B));
-               _scrolls.put(952, new EnchantScroll(false, false, false, CrystalType.C));
-               _scrolls.put(956, new EnchantScroll(false, false, false, CrystalType.D));
-               _scrolls.put(960, new EnchantScroll(false, false, false, CrystalType.S));
-              
-               // Blessed Scrolls: Enchant Weapon
-               _scrolls.put(6569, new EnchantScroll(true, true, false, CrystalType.A));
-               _scrolls.put(6571, new EnchantScroll(true, true, false, CrystalType.B));
-               _scrolls.put(6573, new EnchantScroll(true, true, false, CrystalType.C));
-               _scrolls.put(6575, new EnchantScroll(true, true, false, CrystalType.D));
-               _scrolls.put(6577, new EnchantScroll(true, true, false, CrystalType.S));
-              
-               // Blessed Scrolls: Enchant Armor
-               _scrolls.put(6570, new EnchantScroll(false, true, false, CrystalType.A));
-               _scrolls.put(6572, new EnchantScroll(false, true, false, CrystalType.B));
-               _scrolls.put(6574, new EnchantScroll(false, true, false, CrystalType.C));
-               _scrolls.put(6576, new EnchantScroll(false, true, false, CrystalType.D));
-               _scrolls.put(6578, new EnchantScroll(false, true, false, CrystalType.S));
-              
-               // Crystal Scrolls: Enchant Weapon
-               _scrolls.put(731, new EnchantScroll(true, false, true, CrystalType.A));
-               _scrolls.put(949, new EnchantScroll(true, false, true, CrystalType.B));
-               _scrolls.put(953, new EnchantScroll(true, false, true, CrystalType.C));
-               _scrolls.put(957, new EnchantScroll(true, false, true, CrystalType.D));
-               _scrolls.put(961, new EnchantScroll(true, false, true, CrystalType.S));
-              
-               // Crystal Scrolls: Enchant Armor
-               _scrolls.put(732, new EnchantScroll(false, false, true, CrystalType.A));
-               _scrolls.put(950, new EnchantScroll(false, false, true, CrystalType.B));
-               _scrolls.put(954, new EnchantScroll(false, false, true, CrystalType.C));
-               _scrolls.put(958, new EnchantScroll(false, false, true, CrystalType.D));
-               _scrolls.put(962, new EnchantScroll(false, false, true, CrystalType.S));
-       }
-      
-       /**
-        * @param scroll The instance of item to make checks on.
-        * @return enchant template for scroll.
-        */
-       protected static final EnchantScroll getEnchantScroll(ItemInstance scroll)
-       {
-               return _scrolls.get(scroll.getItemId());
-       }
-      
-       /**
-        * @param item The instance of item to make checks on.
-        * @return true if item can be enchanted.
-        */
-       protected static final boolean isEnchantable(ItemInstance item)
-       {
-               if (item.isHeroItem() || item.isShadowItem() || item.isEtcItem() || item.getItem().getItemType() == WeaponType.FISHINGROD)
-                       return false;
-              
-               // only equipped items or in inventory can be enchanted
-               if (item.getLocation() != ItemInstance.ItemLocation.INVENTORY && item.getLocation() != ItemInstance.ItemLocation.PAPERDOLL)
-                       return false;
-              
-               return true;
-       }
-}
\ No newline at end of file
Index: config/players.properties
===================================================================
--- config/players.properties   (revision 5)
+++ config/players.properties   (working copy)
@@ -72,30 +72,6 @@
 AltGameFreightPrice = 1000
 
 #=============================================================
-#                           Enchant
-#=============================================================
-# % chance of success to enchant a magic weapon
-EnchantChanceMagicWeapon = 0.4
-EnchantChanceMagicWeapon15Plus = 0.2
-
-# % chance of success to enchant a non magic weapon
-EnchantChanceNonMagicWeapon = 0.7
-EnchantChanceNonMagicWeapon15Plus = 0.35
-
-# % chance of success to enchant an armor part (both jewelry or armor)
-EnchantChanceArmor = 0.66
-
-# Enchant limit [default = 0]
-EnchantMaxWeapon = 0
-EnchantMaxArmor = 0
-
-# if EnchantSafeMax is set to for ex '8' the item will be safly enchanted to '8' regardless of
-# enchant chance(default = 3 for EnchantSafeMax and default = 4 for EnchantSafeMaxFull)
-# EnchantSafeMaxFull is for full body armor (upper and lower), value should be > 0.
-EnchantSafeMax = 3
-EnchantSafeMaxFull = 4
-
-#=============================================================
 #                        Augmentations
 #=============================================================
 # Control the chance to get a skill in the augmentation process.
Index: java/net/sf/l2j/gameserver/datatables/EnchantTable.java
===================================================================
--- java/net/sf/l2j/gameserver/datatables/EnchantTable.java     (revision 0)
+++ java/net/sf/l2j/gameserver/datatables/EnchantTable.java     (revision 0)
@@ -0,0 +1,117 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.datatables;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import net.sf.l2j.gameserver.model.L2EnchantScroll;
+import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
+import net.sf.l2j.gameserver.model.item.type.CrystalType;
+import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+public class EnchantTable
+{
+       private static Logger _log = Logger.getLogger(EnchantTable.class.getName());
+      
+       private static final Map<Integer, L2EnchantScroll> _map = new HashMap<>();
+      
+       public static EnchantTable getInstance()
+       {
+               return SingletonHolder._instance;
+       }
+      
+       protected EnchantTable()
+       {
+               try
+               {
+                       File f = new File("./data/xml/enchants.xml");
+                       Document doc = XMLDocumentFactory.getInstance().loadDocument(f);
+                      
+                       for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
+                       {
+                               if ("list".equalsIgnoreCase(n.getNodeName()))
+                               {
+                                       for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
+                                       {
+                                               if ("enchant".equalsIgnoreCase(d.getNodeName()))
+                                               {
+                                                       NamedNodeMap attrs = d.getAttributes();
+                                                      
+                                                       int id = Integer.valueOf(attrs.getNamedItem("id").getNodeValue());
+                                                       byte grade = Byte.valueOf(attrs.getNamedItem("grade").getNodeValue());
+                                                       boolean weapon = Boolean.valueOf(attrs.getNamedItem("weapon").getNodeValue());
+                                                       boolean breaks = Boolean.valueOf(attrs.getNamedItem("break").getNodeValue());
+                                                       boolean maintain = Boolean.valueOf(attrs.getNamedItem("maintain").getNodeValue());
+                                                      
+                                                       String[] list = attrs.getNamedItem("chance").getNodeValue().split(";");
+                                                       byte[] chance = new byte[list.length];
+                                                       for (int i = 0; i < list.length; i++)
+                                                               chance[i] = Byte.valueOf(list[i]);
+                                                      
+                                                       CrystalType grade_test = CrystalType.NONE;
+                                                       switch (grade)
+                                                       {
+                                                               case 1:
+                                                                       grade_test = CrystalType.D;
+                                                                       break;
+                                                               case 2:
+                                                                       grade_test = CrystalType.C;
+                                                                       break;
+                                                               case 3:
+                                                                       grade_test = CrystalType.B;
+                                                                       break;
+                                                               case 4:
+                                                                       grade_test = CrystalType.A;
+                                                                       break;
+                                                               case 5:
+                                                                       grade_test = CrystalType.S;
+                                                                       break;
+                                                       }                                                      
+                                                      
+                                                       _map.put(id, new L2EnchantScroll(grade_test, weapon, breaks, maintain, chance));
+                                               }
+                                       }
+                               }
+                       }
+                              
+                       _log.info("EnchantTable: Loaded " + _map.size() + " enchants.");
+               }
+               catch (Exception e)
+               {
+                       _log.warning("EnchantTable: Error while loading enchant table: " + e);
+               }
+       }
+      
+       public L2EnchantScroll getEnchantScroll(ItemInstance item)
+       {
+               return _map.get(item.getItemId());
+       }
+      
+       private static class SingletonHolder
+       {
+               protected static final EnchantTable _instance = new EnchantTable();
+       }
+}
Index: java/net/sf/l2j/gameserver/GameServer.java
===================================================================
--- java/net/sf/l2j/gameserver/GameServer.java  (revision 5)
+++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
@@ -42,6 +42,7 @@
 import net.sf.l2j.gameserver.datatables.CharTemplateTable;
 import net.sf.l2j.gameserver.datatables.ClanTable;
 import net.sf.l2j.gameserver.datatables.DoorTable;
+import net.sf.l2j.gameserver.datatables.EnchantTable;
 import net.sf.l2j.gameserver.datatables.FishTable;
 import net.sf.l2j.gameserver.datatables.GmListTable;
 import net.sf.l2j.gameserver.datatables.HelperBuffTable;
@@ -166,6 +167,7 @@
                FishTable.getInstance();
                SpellbookTable.getInstance();
                SoulCrystalsTable.load();
+               EnchantTable.getInstance();
               
                Util.printSection("Augments");
                AugmentationData.getInstance();
Index: java/net/sf/l2j/gameserver/model/L2EnchantScroll.java
===================================================================
--- java/net/sf/l2j/gameserver/model/L2EnchantScroll.java       (revision 0)
+++ java/net/sf/l2j/gameserver/model/L2EnchantScroll.java       (revision 0)
@@ -0,0 +1,104 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.model;
+
+import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
+import net.sf.l2j.gameserver.model.item.kind.Item;
+import net.sf.l2j.gameserver.model.item.type.CrystalType;
+
+public class L2EnchantScroll
+{
+       private final CrystalType _grade;
+       private final boolean _weapon;
+       private final boolean _breaks;
+       private final boolean _maintain;
+       private final byte[] _chance;
+      
+       public L2EnchantScroll(CrystalType grade, boolean weapon, boolean breaks, boolean maintain, byte[] chance)
+       {
+               _grade = grade;
+               _weapon = weapon;
+               _breaks = breaks;
+               _maintain = maintain;
+               _chance = chance;
+       }
+      
+       /**
+        * @param enchantItem : The item to enchant.
+        * @return the enchant chance under double format.
+        */
+       public final byte getChance(ItemInstance enchantItem)
+       {
+               int level = enchantItem.getEnchantLevel();
+               if (enchantItem.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR && level != 0)
+                       level--;
+              
+               if (level >= _chance.length)
+                       return 0;
+                      
+               return _chance[level];
+       }
+      
+       public final boolean canBreak()
+       {
+               return _breaks;
+       }
+      
+       public final boolean canMaintain()
+       {
+               return _maintain;
+       }
+      
+       // TODO: methods
+      
+       /**
+        * @param enchantItem : The item to enchant.
+        * @return True if enchant can be used on selected item.
+        */
+       public final boolean isValid(ItemInstance enchantItem)
+       {
+               // check for crystal type
+               if (_grade != enchantItem.getItem().getCrystalType())
+                       return false;
+              
+               // check enchant max level
+               if (enchantItem.getEnchantLevel() >= _chance.length)
+                       return false;
+              
+               // checking scroll type
+               switch (enchantItem.getItem().getType2())
+               {
+                       case Item.TYPE2_WEAPON:
+                               if (!_weapon)
+                                       return false;
+                               break;
+                      
+                       case Item.TYPE2_SHIELD_ARMOR:
+                       case Item.TYPE2_ACCESSORY:
+                               if (_weapon)
+                                       return false;
+                               break;
+                      
+                       default:
+                               return false;
+               }
+              
+               return true;
+       }
+}
Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java
===================================================================
--- java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java    (revision 5)
+++ java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java    (working copy)
@@ -16,7 +16,9 @@
 
 import net.sf.l2j.Config;
 import net.sf.l2j.gameserver.datatables.ArmorSetsTable;
+import net.sf.l2j.gameserver.datatables.EnchantTable;
 import net.sf.l2j.gameserver.datatables.SkillTable;
+import net.sf.l2j.gameserver.model.L2EnchantScroll;
 import net.sf.l2j.gameserver.model.L2Skill;
 import net.sf.l2j.gameserver.model.L2World;
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
@@ -25,6 +27,7 @@
 import net.sf.l2j.gameserver.model.item.kind.Armor;
 import net.sf.l2j.gameserver.model.item.kind.Item;
 import net.sf.l2j.gameserver.model.item.kind.Weapon;
+import net.sf.l2j.gameserver.model.item.type.WeaponType;
 import net.sf.l2j.gameserver.model.itemcontainer.Inventory;
 import net.sf.l2j.gameserver.network.SystemMessageId;
 import net.sf.l2j.gameserver.network.serverpackets.EnchantResult;
@@ -35,7 +38,7 @@
 import net.sf.l2j.gameserver.util.Util;
 import net.sf.l2j.util.Rnd;
 
-public final class RequestEnchantItem extends AbstractEnchantPacket
+public final class RequestEnchantItem extends L2GameClientPacket
 {
        private int _objectId = 0;
       
@@ -48,16 +51,19 @@
        @Override
        protected void runImpl()
        {
+               // get player
                final L2PcInstance activeChar = getClient().getActiveChar();
                if (activeChar == null || _objectId == 0)
                        return;
               
+               // player online and active
                if (!activeChar.isOnline() || getClient().isDetached())
                {
                        activeChar.setActiveEnchantItem(null);
                        return;
                }
               
+               // player on shop/craft
                if (activeChar.isProcessingTransaction() || activeChar.isInStoreMode())
                {
                        activeChar.sendPacket(SystemMessageId.CANNOT_ENCHANT_WHILE_STORE);
@@ -65,7 +71,18 @@
                        activeChar.sendPacket(EnchantResult.CANCELLED);
                        return;
                }
+
+               // player trading
+               if (activeChar.getActiveTradeList() != null)
+               {
+                       activeChar.cancelActiveTrade();
+                       activeChar.sendPacket(SystemMessageId.TRADE_ATTEMPT_FAILED);
+                       activeChar.setActiveEnchantItem(null);
+                       activeChar.sendPacket(EnchantResult.CANCELLED);
+                       return;
+               }
               
+               // get item and enchant scroll
                ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
                ItemInstance scroll = activeChar.getActiveEnchantItem();
               
@@ -77,13 +94,13 @@
                        return;
                }
               
-               // template for scroll
-               EnchantScroll scrollTemplate = getEnchantScroll(scroll);
-               if (scrollTemplate == null)
+               // get scroll enchant data
+               L2EnchantScroll enchant = EnchantTable.getInstance().getEnchantScroll(scroll);
+               if (enchant == null)
                        return;
               
-               // first validation check
-               if (!scrollTemplate.isValid(item) || !isEnchantable(item))
+               // validation check
+               if (!isEnchantable(item) || !enchant.isValid(item) || item.getOwnerId() != activeChar.getObjectId())
                {
                        activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION);
                        activeChar.setActiveEnchantItem(null);
@@ -91,7 +108,7 @@
                        return;
                }
               
-               // attempting to destroy scroll
+               // destroy enchant scroll
                scroll = activeChar.getInventory().destroyItem("Enchant", scroll.getObjectId(), 1, activeChar, item);
                if (scroll == null)
                {
@@ -102,46 +119,27 @@
                        return;
                }
               
-               if (activeChar.getActiveTradeList() != null)
-               {
-                       activeChar.cancelActiveTrade();
-                       activeChar.sendPacket(SystemMessageId.TRADE_ATTEMPT_FAILED);
-                       return;
-               }
-              
                synchronized (item)
                {
-                       double chance = scrollTemplate.getChance(item);
-                      
-                       // last validation check
-                       if (item.getOwnerId() != activeChar.getObjectId() || !isEnchantable(item) || chance < 0)
-                       {
-                               activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION);
-                               activeChar.setActiveEnchantItem(null);
-                               activeChar.sendPacket(EnchantResult.CANCELLED);
-                               return;
-                       }
-                      
                        // success
-                       if (Rnd.get() < chance)
+                       if (Rnd.get(100) < enchant.getChance(item))
                        {
-                               // announce the success
+                               // send message
                                SystemMessage sm;
                               
                                if (item.getEnchantLevel() == 0)
                                {
                                        sm = SystemMessage.getSystemMessage(SystemMessageId.S1_SUCCESSFULLY_ENCHANTED);
-                                       sm.addItemName(item.getItemId());
-                                       activeChar.sendPacket(sm);
                                }
                                else
                                {
                                        sm = SystemMessage.getSystemMessage(SystemMessageId.S1_S2_SUCCESSFULLY_ENCHANTED);
                                        sm.addNumber(item.getEnchantLevel());
-                                       sm.addItemName(item.getItemId());
-                                       activeChar.sendPacket(sm);
                                }
+                               sm.addItemName(item.getItemId());
                               
+                               // update item
                                item.setEnchantLevel(item.getEnchantLevel() + 1);
                                item.updateDatabase();
                               
@@ -186,6 +184,7 @@
                                }
                                activeChar.sendPacket(EnchantResult.SUCCESS);
                        }
+                       // fail
                        else
                        {
                                // Drop passive skills from items.
@@ -228,39 +227,46 @@
                                        }
                                }
                               
-                               if (scrollTemplate.isBlessed())
+                               if (!enchant.canBreak())
                                {
-                                       // blessed enchant - clear enchant value
+                                       // keep item
                                        activeChar.sendPacket(SystemMessageId.BLESSED_ENCHANT_FAILED);
                                       
-                                       item.setEnchantLevel(0);
-                                       item.updateDatabase();
+                                       if (!enchant.canMaintain())
+                                       {
+                                               item.setEnchantLevel(0);
+                                               item.updateDatabase();
+                                       }
                                        activeChar.sendPacket(EnchantResult.UNSUCCESS);
                                }
                                else
                                {
-                                       // enchant failed, destroy item
-                                       int crystalId = item.getItem().getCrystalItemId();
-                                       int count = item.getCrystalCount() - (item.getItem().getCrystalCount() + 1) / 2;
-                                       if (count < 1)
-                                               count = 1;
-                                      
+                                       // destroy item
                                        ItemInstance destroyItem = activeChar.getInventory().destroyItem("Enchant", item, activeChar, null);
                                        if (destroyItem == null)
                                        {
-                                               // unable to destroy item, cheater ?
                                                Util.handleIllegalPlayerAction(activeChar, "Unable to delete item on enchant failure from player " + activeChar.getName() + ", possible cheater !", Config.DEFAULT_PUNISH);
                                                activeChar.setActiveEnchantItem(null);
                                                activeChar.sendPacket(EnchantResult.CANCELLED);
                                                return;
                                        }
                                       
-                                       if (crystalId != 0)
+                                       // add crystals, if item crystalizable
+                                       int crystalType = item.getItem().getCrystalItemId();
+                                       ItemInstance crystals = null;                                  
+                                       if (crystalType != 0)
                                        {
-                                               activeChar.getInventory().addItem("Enchant", crystalId, count, activeChar, destroyItem);
-                                               activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(crystalId).addItemNumber(count));
+                                               // get crystals count
+                                               int crystalCount = item.getCrystalCount() - (item.getItem().getCrystalCount() + 1) / 2;
+                                               if (crystalCount < 1)
+                                                       crystalCount = 1;
+                                                                                      
+                                               // add crystals to inventory
+                                               crystals = activeChar.getInventory().addItem("Enchant", crystalType, crystalCount, activeChar, destroyItem);
+                                               activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(crystals.getItemId()).addItemNumber(crystalCount));
                                        }
                                       
+                                       // update inventory
                                        InventoryUpdate iu = new InventoryUpdate();
                                        if (destroyItem.getCount() == 0)
                                                iu.addRemovedItem(destroyItem);
@@ -269,27 +275,49 @@
                                       
                                        activeChar.sendPacket(iu);
                                       
-                                       // Messages.
+                                       // remove item
+                                       L2World.getInstance().removeObject(destroyItem);
+                                      
+                                       // send message
                                        if (item.getEnchantLevel() > 0)
                                                activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_S2_EVAPORATED).addNumber(item.getEnchantLevel()).addItemName(item.getItemId()));
                                        else
                                                activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_EVAPORATED).addItemName(item.getItemId()));
                                       
-                                       L2World.getInstance().removeObject(destroyItem);
-                                       if (crystalId == 0)
+                                       // send enchant result
+                                       if (crystalType == 0)
                                                activeChar.sendPacket(EnchantResult.UNK_RESULT_4);
                                        else
                                                activeChar.sendPacket(EnchantResult.UNK_RESULT_1);
                                       
+                                       // update weight
                                        StatusUpdate su = new StatusUpdate(activeChar);
                                        su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
                                        activeChar.sendPacket(su);
                                }
                        }
                       
+                       // send item list
                        activeChar.sendPacket(new ItemList(activeChar, false));
+                      
+                       // update appearance
                        activeChar.broadcastUserInfo();
                        activeChar.setActiveEnchantItem(null);
                }
        }
+       /**
+        * @param item The instance of item to make checks on.
+        * @return true if item can be enchanted.
+        */
+       private static final boolean isEnchantable(ItemInstance item)
+       {
+               if (item.isHeroItem() || item.isShadowItem() || item.isEtcItem() || item.getItem().getItemType() == WeaponType.FISHINGROD)
+                       return false;
+              
+               // only equipped items or in inventory can be enchanted
+               if (item.getLocation() != ItemInstance.ItemLocation.INVENTORY && item.getLocation() != ItemInstance.ItemLocation.PAPERDOLL)
+                       return false;
+              
+               return true;
+       }      
 }
\ No newline at end of file
Index: java/net/sf/l2j/Config.java
===================================================================
--- java/net/sf/l2j/Config.java (revision 5)
+++ java/net/sf/l2j/Config.java (working copy)
@@ -405,17 +405,6 @@
        public static boolean ALT_GAME_FREIGHTS;
        public static int ALT_GAME_FREIGHT_PRICE;
       
-       /** Enchant */
-       public static double ENCHANT_CHANCE_WEAPON_MAGIC;
-       public static double ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS;
-       public static double ENCHANT_CHANCE_WEAPON_NONMAGIC;
-       public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS;
-       public static double ENCHANT_CHANCE_ARMOR;
-       public static int ENCHANT_MAX_WEAPON;
-       public static int ENCHANT_MAX_ARMOR;
-       public static int ENCHANT_SAFE_MAX;
-       public static int ENCHANT_SAFE_MAX_FULL;
-      
        /** Augmentations */
        public static int AUGMENTATION_NG_SKILL_CHANCE;
        public static int AUGMENTATION_NG_GLOW_CHANCE;
@@ -1020,16 +1009,6 @@
                        ALT_GAME_FREIGHTS = players.getProperty("AltGameFreights", false);
                        ALT_GAME_FREIGHT_PRICE = players.getProperty("AltGameFreightPrice", 1000);
                       
-                       ENCHANT_CHANCE_WEAPON_MAGIC = players.getProperty("EnchantChanceMagicWeapon", 0.4);
-                       ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS = players.getProperty("EnchantChanceMagicWeapon15Plus", 0.2);
-                       ENCHANT_CHANCE_WEAPON_NONMAGIC = players.getProperty("EnchantChanceNonMagicWeapon", 0.7);
-                       ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS = players.getProperty("EnchantChanceNonMagicWeapon15Plus", 0.35);
-                       ENCHANT_CHANCE_ARMOR = players.getProperty("EnchantChanceArmor", 0.66);
-                       ENCHANT_MAX_WEAPON = players.getProperty("EnchantMaxWeapon", 0);
-                       ENCHANT_MAX_ARMOR = players.getProperty("EnchantMaxArmor", 0);
-                       ENCHANT_SAFE_MAX = players.getProperty("EnchantSafeMax", 3);
-                       ENCHANT_SAFE_MAX_FULL = players.getProperty("EnchantSafeMaxFull", 4);
-                      
                        AUGMENTATION_NG_SKILL_CHANCE = players.getProperty("AugmentationNGSkillChance", 15);
                        AUGMENTATION_NG_GLOW_CHANCE = players.getProperty("AugmentationNGGlowChance", 0);
                        AUGMENTATION_MID_SKILL_CHANCE = players.getProperty("AugmentationMidSkillChance", 30);

 

1 answer to this question

Recommended Posts

  • 0
Posted (edited)

hi i add this code on acis 401 

i have error on if (_grade != enchantItem.getItem().getCrystalType())

https://prnt.sc/pxDh8yDowhm3

 

edit* if anyone have the problem change to 

if (_grade.ordinal() != enchantItem.getItem().getCrystalType().ordinal())

thanks melron for help

Edited by MarGaZeaS
fix

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...