SHOW:
|
|
- or go back to the newest paste.
1 | ### Eclipse Workspace Patch 1.0 | |
2 | #P aCis_datapack | |
3 | Index: data/xml/enchants.xml | |
4 | =================================================================== | |
5 | --- data/xml/enchants.xml (revision 0) | |
6 | +++ data/xml/enchants.xml (revision 0) | |
7 | @@ -0,0 +1,44 @@ | |
8 | +<?xml version='1.0' encoding='utf-8'?> | |
9 | +<list> | |
10 | + <!-- Scrolls: Enchant Weapon --> | |
11 | + <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 --> | |
12 | + <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 --> | |
13 | + <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 --> | |
14 | + <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 --> | |
15 | + <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 --> | |
16 | + | |
17 | + <!-- Scrolls: Enchant Armor --> | |
18 | + <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 --> | |
19 | + <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 --> | |
20 | + <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 --> | |
21 | + <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 --> | |
22 | + <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 --> | |
23 | + | |
24 | + <!-- Blessed Scrolls: Enchant Weapon --> | |
25 | + <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 --> | |
26 | + <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 --> | |
27 | + <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 --> | |
28 | + <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 --> | |
29 | + <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 --> | |
30 | + | |
31 | + <!-- Blessed Scrolls: Armor Weapon --> | |
32 | + <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 --> | |
33 | + <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 --> | |
34 | + <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 --> | |
35 | + <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 --> | |
36 | + <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 --> | |
37 | + | |
38 | + <!-- Crystal Scrolls: Enchant Weapon --> | |
39 | + <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 --> | |
40 | + <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 --> | |
41 | + <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 --> | |
42 | + <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 --> | |
43 | + <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 --> | |
44 | + | |
45 | + <!-- Crystal Scrolls: Enchant Armor --> | |
46 | + <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 --> | |
47 | + <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 --> | |
48 | + <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 --> | |
49 | + <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 --> | |
50 | + <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 --> | |
51 | +</list> | |
52 | \ No newline at end of file | |
53 | #P aCis_gameserver | |
54 | Index: java/net/sf/l2j/gameserver/network/clientpackets/AbstractEnchantPacket.java | |
55 | =================================================================== | |
56 | --- java/net/sf/l2j/gameserver/network/clientpackets/AbstractEnchantPacket.java (revision 5) | |
57 | +++ java/net/sf/l2j/gameserver/network/clientpackets/AbstractEnchantPacket.java (working copy) | |
58 | @@ -1,212 +0,0 @@ | |
59 | -/* | |
60 | - * This program is free software: you can redistribute it and/or modify it under | |
61 | - * the terms of the GNU General Public License as published by the Free Software | |
62 | - * Foundation, either version 3 of the License, or (at your option) any later | |
63 | - * version. | |
64 | - * | |
65 | - * This program is distributed in the hope that it will be useful, but WITHOUT | |
66 | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
67 | - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
68 | - * details. | |
69 | - * | |
70 | - * You should have received a copy of the GNU General Public License along with | |
71 | - * this program. If not, see <http://www.gnu.org/licenses/>. | |
72 | - */ | |
73 | -package net.sf.l2j.gameserver.network.clientpackets; | |
74 | - | |
75 | -import java.util.HashMap; | |
76 | -import java.util.Map; | |
77 | - | |
78 | -import net.sf.l2j.Config; | |
79 | -import net.sf.l2j.gameserver.model.item.instance.ItemInstance; | |
80 | -import net.sf.l2j.gameserver.model.item.kind.Item; | |
81 | -import net.sf.l2j.gameserver.model.item.kind.Weapon; | |
82 | -import net.sf.l2j.gameserver.model.item.type.CrystalType; | |
83 | -import net.sf.l2j.gameserver.model.item.type.WeaponType; | |
84 | - | |
85 | -public abstract class AbstractEnchantPacket extends L2GameClientPacket | |
86 | -{ | |
87 | - public static final Map<Integer, EnchantScroll> _scrolls = new HashMap<>(); | |
88 | - | |
89 | - public static final class EnchantScroll | |
90 | - { | |
91 | - protected final boolean _isWeapon; | |
92 | - protected final CrystalType _grade; | |
93 | - private final boolean _isBlessed; | |
94 | - private final boolean _isCrystal; | |
95 | - | |
96 | - public EnchantScroll(boolean wep, boolean bless, boolean crystal, CrystalType type) | |
97 | - { | |
98 | - _isWeapon = wep; | |
99 | - _grade = type; | |
100 | - _isBlessed = bless; | |
101 | - _isCrystal = crystal; | |
102 | - } | |
103 | - | |
104 | - /** | |
105 | - * @param enchantItem : The item to enchant. | |
106 | - * @return true if support item can be used for this item | |
107 | - */ | |
108 | - public final boolean isValid(ItemInstance enchantItem) | |
109 | - { | |
110 | - if (enchantItem == null) | |
111 | - return false; | |
112 | - | |
113 | - // checking scroll type and configured maximum enchant level | |
114 | - switch (enchantItem.getItem().getType2()) | |
115 | - { | |
116 | - case Item.TYPE2_WEAPON: | |
117 | - if (!_isWeapon || (Config.ENCHANT_MAX_WEAPON > 0 && enchantItem.getEnchantLevel() >= Config.ENCHANT_MAX_WEAPON)) | |
118 | - return false; | |
119 | - break; | |
120 | - | |
121 | - case Item.TYPE2_SHIELD_ARMOR: | |
122 | - case Item.TYPE2_ACCESSORY: | |
123 | - if (_isWeapon || (Config.ENCHANT_MAX_ARMOR > 0 && enchantItem.getEnchantLevel() >= Config.ENCHANT_MAX_ARMOR)) | |
124 | - return false; | |
125 | - break; | |
126 | - | |
127 | - default: | |
128 | - return false; | |
129 | - } | |
130 | - | |
131 | - // check for crystal type | |
132 | - if (_grade != enchantItem.getItem().getCrystalType()) | |
133 | - return false; | |
134 | - | |
135 | - return true; | |
136 | - } | |
137 | - | |
138 | - /** | |
139 | - * @return true if item is a blessed scroll. | |
140 | - */ | |
141 | - public final boolean isBlessed() | |
142 | - { | |
143 | - return _isBlessed; | |
144 | - } | |
145 | - | |
146 | - /** | |
147 | - * @return true if item is a crystal scroll. | |
148 | - */ | |
149 | - public final boolean isCrystal() | |
150 | - { | |
151 | - return _isCrystal; | |
152 | - } | |
153 | - | |
154 | - /** | |
155 | - * Regarding enchant system :<br> | |
156 | - * <br> | |
157 | - * <u>Weapons</u> | |
158 | - * <ul> | |
159 | - * <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> | |
160 | - * <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> | |
161 | - * </ul> | |
162 | - * <u>Armors</u> | |
163 | - * <ul> | |
164 | - * <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> | |
165 | - * <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> | |
166 | - * </ul> | |
167 | - * @param enchantItem : The item to enchant. | |
168 | - * @return the enchant chance under double format (0.7 / 0.35 / 0.44324...). | |
169 | - */ | |
170 | - public final double getChance(ItemInstance enchantItem) | |
171 | - { | |
172 | - if (!isValid(enchantItem)) | |
173 | - return -1; | |
174 | - | |
175 | - boolean fullBody = enchantItem.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR; | |
176 | - if (enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX || (fullBody && enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL)) | |
177 | - return 1; | |
178 | - | |
179 | - double chance = 0; | |
180 | - | |
181 | - // Armor formula : 0.66^(current-2), chance is lower and lower for each enchant. | |
182 | - if (enchantItem.isArmor()) | |
183 | - chance = Math.pow(Config.ENCHANT_CHANCE_ARMOR, (enchantItem.getEnchantLevel() - 2)); | |
184 | - // Weapon formula is 70% for fighter weapon, 40% for mage weapon. Special rates after +14. | |
185 | - else if (enchantItem.isWeapon()) | |
186 | - { | |
187 | - if (((Weapon) enchantItem.getItem()).isMagical()) | |
188 | - chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS : Config.ENCHANT_CHANCE_WEAPON_MAGIC; | |
189 | - else | |
190 | - chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS : Config.ENCHANT_CHANCE_WEAPON_NONMAGIC; | |
191 | - } | |
192 | - | |
193 | - return chance; | |
194 | - } | |
195 | - } | |
196 | - | |
197 | - /** | |
198 | - * Format : itemId, (isWeapon, isBlessed, isCrystal, grade)<br> | |
199 | - * Allowed items IDs must be sorted by ascending order. | |
200 | - */ | |
201 | - static | |
202 | - { | |
203 | - // Scrolls: Enchant Weapon | |
204 | - _scrolls.put(729, new EnchantScroll(true, false, false, CrystalType.A)); | |
205 | - _scrolls.put(947, new EnchantScroll(true, false, false, CrystalType.B)); | |
206 | - _scrolls.put(951, new EnchantScroll(true, false, false, CrystalType.C)); | |
207 | - _scrolls.put(955, new EnchantScroll(true, false, false, CrystalType.D)); | |
208 | - _scrolls.put(959, new EnchantScroll(true, false, false, CrystalType.S)); | |
209 | - | |
210 | - // Scrolls: Enchant Armor | |
211 | - _scrolls.put(730, new EnchantScroll(false, false, false, CrystalType.A)); | |
212 | - _scrolls.put(948, new EnchantScroll(false, false, false, CrystalType.B)); | |
213 | - _scrolls.put(952, new EnchantScroll(false, false, false, CrystalType.C)); | |
214 | - _scrolls.put(956, new EnchantScroll(false, false, false, CrystalType.D)); | |
215 | - _scrolls.put(960, new EnchantScroll(false, false, false, CrystalType.S)); | |
216 | - | |
217 | - // Blessed Scrolls: Enchant Weapon | |
218 | - _scrolls.put(6569, new EnchantScroll(true, true, false, CrystalType.A)); | |
219 | - _scrolls.put(6571, new EnchantScroll(true, true, false, CrystalType.B)); | |
220 | - _scrolls.put(6573, new EnchantScroll(true, true, false, CrystalType.C)); | |
221 | - _scrolls.put(6575, new EnchantScroll(true, true, false, CrystalType.D)); | |
222 | - _scrolls.put(6577, new EnchantScroll(true, true, false, CrystalType.S)); | |
223 | - | |
224 | - // Blessed Scrolls: Enchant Armor | |
225 | - _scrolls.put(6570, new EnchantScroll(false, true, false, CrystalType.A)); | |
226 | - _scrolls.put(6572, new EnchantScroll(false, true, false, CrystalType.B)); | |
227 | - _scrolls.put(6574, new EnchantScroll(false, true, false, CrystalType.C)); | |
228 | - _scrolls.put(6576, new EnchantScroll(false, true, false, CrystalType.D)); | |
229 | - _scrolls.put(6578, new EnchantScroll(false, true, false, CrystalType.S)); | |
230 | - | |
231 | - // Crystal Scrolls: Enchant Weapon | |
232 | - _scrolls.put(731, new EnchantScroll(true, false, true, CrystalType.A)); | |
233 | - _scrolls.put(949, new EnchantScroll(true, false, true, CrystalType.B)); | |
234 | - _scrolls.put(953, new EnchantScroll(true, false, true, CrystalType.C)); | |
235 | - _scrolls.put(957, new EnchantScroll(true, false, true, CrystalType.D)); | |
236 | - _scrolls.put(961, new EnchantScroll(true, false, true, CrystalType.S)); | |
237 | - | |
238 | - // Crystal Scrolls: Enchant Armor | |
239 | - _scrolls.put(732, new EnchantScroll(false, false, true, CrystalType.A)); | |
240 | - _scrolls.put(950, new EnchantScroll(false, false, true, CrystalType.B)); | |
241 | - _scrolls.put(954, new EnchantScroll(false, false, true, CrystalType.C)); | |
242 | - _scrolls.put(958, new EnchantScroll(false, false, true, CrystalType.D)); | |
243 | - _scrolls.put(962, new EnchantScroll(false, false, true, CrystalType.S)); | |
244 | - } | |
245 | - | |
246 | - /** | |
247 | - * @param scroll The instance of item to make checks on. | |
248 | - * @return enchant template for scroll. | |
249 | - */ | |
250 | - protected static final EnchantScroll getEnchantScroll(ItemInstance scroll) | |
251 | - { | |
252 | - return _scrolls.get(scroll.getItemId()); | |
253 | - } | |
254 | - | |
255 | - /** | |
256 | - * @param item The instance of item to make checks on. | |
257 | - * @return true if item can be enchanted. | |
258 | - */ | |
259 | - protected static final boolean isEnchantable(ItemInstance item) | |
260 | - { | |
261 | - if (item.isHeroItem() || item.isShadowItem() || item.isEtcItem() || item.getItem().getItemType() == WeaponType.FISHINGROD) | |
262 | - return false; | |
263 | - | |
264 | - // only equipped items or in inventory can be enchanted | |
265 | - if (item.getLocation() != ItemInstance.ItemLocation.INVENTORY && item.getLocation() != ItemInstance.ItemLocation.PAPERDOLL) | |
266 | - return false; | |
267 | - | |
268 | - return true; | |
269 | - } | |
270 | -} | |
271 | \ No newline at end of file | |
272 | Index: config/players.properties | |
273 | =================================================================== | |
274 | --- config/players.properties (revision 5) | |
275 | +++ config/players.properties (working copy) | |
276 | @@ -72,30 +72,6 @@ | |
277 | AltGameFreightPrice = 1000 | |
278 | ||
279 | #============================================================= | |
280 | -# Enchant | |
281 | -#============================================================= | |
282 | -# % chance of success to enchant a magic weapon | |
283 | -EnchantChanceMagicWeapon = 0.4 | |
284 | -EnchantChanceMagicWeapon15Plus = 0.2 | |
285 | - | |
286 | -# % chance of success to enchant a non magic weapon | |
287 | -EnchantChanceNonMagicWeapon = 0.7 | |
288 | -EnchantChanceNonMagicWeapon15Plus = 0.35 | |
289 | - | |
290 | -# % chance of success to enchant an armor part (both jewelry or armor) | |
291 | -EnchantChanceArmor = 0.66 | |
292 | - | |
293 | -# Enchant limit [default = 0] | |
294 | -EnchantMaxWeapon = 0 | |
295 | -EnchantMaxArmor = 0 | |
296 | - | |
297 | -# if EnchantSafeMax is set to for ex '8' the item will be safly enchanted to '8' regardless of | |
298 | -# enchant chance(default = 3 for EnchantSafeMax and default = 4 for EnchantSafeMaxFull) | |
299 | -# EnchantSafeMaxFull is for full body armor (upper and lower), value should be > 0. | |
300 | -EnchantSafeMax = 3 | |
301 | -EnchantSafeMaxFull = 4 | |
302 | - | |
303 | -#============================================================= | |
304 | # Augmentations | |
305 | #============================================================= | |
306 | # Control the chance to get a skill in the augmentation process. | |
307 | Index: java/net/sf/l2j/gameserver/datatables/EnchantTable.java | |
308 | =================================================================== | |
309 | --- java/net/sf/l2j/gameserver/datatables/EnchantTable.java (revision 0) | |
310 | +++ java/net/sf/l2j/gameserver/datatables/EnchantTable.java (revision 0) | |
311 | @@ -0,0 +1,117 @@ | |
312 | +/* | |
313 | + * This program is free software: you can redistribute it and/or modify it under | |
314 | + * the terms of the GNU General Public License as published by the Free Software | |
315 | + * Foundation, either version 3 of the License, or (at your option) any later | |
316 | + * version. | |
317 | + * | |
318 | + * This program is distributed in the hope that it will be useful, but WITHOUT | |
319 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
320 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
321 | + * details. | |
322 | + * | |
323 | + * You should have received a copy of the GNU General Public License along with | |
324 | + * this program. If not, see <http://www.gnu.org/licenses/>. | |
325 | + */ | |
326 | +package net.sf.l2j.gameserver.datatables; | |
327 | + | |
328 | +import java.io.File; | |
329 | +import java.util.HashMap; | |
330 | +import java.util.Map; | |
331 | +import java.util.logging.Logger; | |
332 | + | |
333 | +import net.sf.l2j.gameserver.model.L2EnchantScroll; | |
334 | +import net.sf.l2j.gameserver.model.item.instance.ItemInstance; | |
335 | +import net.sf.l2j.gameserver.model.item.type.CrystalType; | |
336 | +import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory; | |
337 | + | |
338 | +import org.w3c.dom.Document; | |
339 | +import org.w3c.dom.NamedNodeMap; | |
340 | +import org.w3c.dom.Node; | |
341 | + | |
342 | +/** | |
343 | + * @author Thug | |
344 | + * | |
345 | + */ | |
346 | +public class EnchantTable | |
347 | +{ | |
348 | + private static Logger _log = Logger.getLogger(EnchantTable.class.getName()); | |
349 | + | |
350 | + private static final Map<Integer, L2EnchantScroll> _map = new HashMap<>(); | |
351 | + | |
352 | + public static EnchantTable getInstance() | |
353 | + { | |
354 | + return SingletonHolder._instance; | |
355 | + } | |
356 | + | |
357 | + protected EnchantTable() | |
358 | + { | |
359 | + try | |
360 | + { | |
361 | + File f = new File("./data/xml/enchants.xml"); | |
362 | + Document doc = XMLDocumentFactory.getInstance().loadDocument(f); | |
363 | + | |
364 | + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) | |
365 | + { | |
366 | + if ("list".equalsIgnoreCase(n.getNodeName())) | |
367 | + { | |
368 | + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) | |
369 | + { | |
370 | + if ("enchant".equalsIgnoreCase(d.getNodeName())) | |
371 | + { | |
372 | + NamedNodeMap attrs = d.getAttributes(); | |
373 | + | |
374 | + int id = Integer.valueOf(attrs.getNamedItem("id").getNodeValue()); | |
375 | + byte grade = Byte.valueOf(attrs.getNamedItem("grade").getNodeValue()); | |
376 | + boolean weapon = Boolean.valueOf(attrs.getNamedItem("weapon").getNodeValue()); | |
377 | + boolean breaks = Boolean.valueOf(attrs.getNamedItem("break").getNodeValue()); | |
378 | + boolean maintain = Boolean.valueOf(attrs.getNamedItem("maintain").getNodeValue()); | |
379 | + | |
380 | + String[] list = attrs.getNamedItem("chance").getNodeValue().split(";"); | |
381 | + byte[] chance = new byte[list.length]; | |
382 | + for (int i = 0; i < list.length; i++) | |
383 | + chance[i] = Byte.valueOf(list[i]); | |
384 | + | |
385 | + CrystalType grade_test = CrystalType.NONE; | |
386 | + switch (grade) | |
387 | + { | |
388 | + case 1: | |
389 | + grade_test = CrystalType.D; | |
390 | + break; | |
391 | + case 2: | |
392 | + grade_test = CrystalType.C; | |
393 | + break; | |
394 | + case 3: | |
395 | + grade_test = CrystalType.B; | |
396 | + break; | |
397 | + case 4: | |
398 | + grade_test = CrystalType.A; | |
399 | + break; | |
400 | + case 5: | |
401 | + grade_test = CrystalType.S; | |
402 | + break; | |
403 | + } | |
404 | + | |
405 | + _map.put(id, new L2EnchantScroll(grade_test, weapon, breaks, maintain, chance)); | |
406 | + } | |
407 | + } | |
408 | + } | |
409 | + } | |
410 | + | |
411 | + _log.info("EnchantTable: Loaded " + _map.size() + " enchants."); | |
412 | + } | |
413 | + catch (Exception e) | |
414 | + { | |
415 | + _log.warning("EnchantTable: Error while loading enchant table: " + e); | |
416 | + } | |
417 | + } | |
418 | + | |
419 | + public L2EnchantScroll getEnchantScroll(ItemInstance item) | |
420 | + { | |
421 | + return _map.get(item.getItemId()); | |
422 | + } | |
423 | + | |
424 | + private static class SingletonHolder | |
425 | + { | |
426 | + protected static final EnchantTable _instance = new EnchantTable(); | |
427 | + } | |
428 | +} | |
429 | Index: java/net/sf/l2j/gameserver/GameServer.java | |
430 | =================================================================== | |
431 | --- java/net/sf/l2j/gameserver/GameServer.java (revision 5) | |
432 | +++ java/net/sf/l2j/gameserver/GameServer.java (working copy) | |
433 | @@ -42,6 +42,7 @@ | |
434 | import net.sf.l2j.gameserver.datatables.CharTemplateTable; | |
435 | import net.sf.l2j.gameserver.datatables.ClanTable; | |
436 | import net.sf.l2j.gameserver.datatables.DoorTable; | |
437 | +import net.sf.l2j.gameserver.datatables.EnchantTable; | |
438 | import net.sf.l2j.gameserver.datatables.FishTable; | |
439 | import net.sf.l2j.gameserver.datatables.GmListTable; | |
440 | import net.sf.l2j.gameserver.datatables.HelperBuffTable; | |
441 | @@ -166,6 +167,7 @@ | |
442 | FishTable.getInstance(); | |
443 | SpellbookTable.getInstance(); | |
444 | SoulCrystalsTable.load(); | |
445 | + EnchantTable.getInstance(); | |
446 | ||
447 | Util.printSection("Augments"); | |
448 | AugmentationData.getInstance(); | |
449 | Index: java/net/sf/l2j/gameserver/model/L2EnchantScroll.java | |
450 | =================================================================== | |
451 | --- java/net/sf/l2j/gameserver/model/L2EnchantScroll.java (revision 0) | |
452 | +++ java/net/sf/l2j/gameserver/model/L2EnchantScroll.java (revision 0) | |
453 | @@ -0,0 +1,104 @@ | |
454 | +/* | |
455 | + * This program is free software: you can redistribute it and/or modify it under | |
456 | + * the terms of the GNU General Public License as published by the Free Software | |
457 | + * Foundation, either version 3 of the License, or (at your option) any later | |
458 | + * version. | |
459 | + * | |
460 | + * This program is distributed in the hope that it will be useful, but WITHOUT | |
461 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
462 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
463 | + * details. | |
464 | + * | |
465 | + * You should have received a copy of the GNU General Public License along with | |
466 | + * this program. If not, see <http://www.gnu.org/licenses/>. | |
467 | + */ | |
468 | +package net.sf.l2j.gameserver.model; | |
469 | + | |
470 | +import net.sf.l2j.gameserver.model.item.instance.ItemInstance; | |
471 | +import net.sf.l2j.gameserver.model.item.kind.Item; | |
472 | +import net.sf.l2j.gameserver.model.item.type.CrystalType; | |
473 | + | |
474 | +/** | |
475 | + * @author Thug | |
476 | + * | |
477 | + */ | |
478 | +public class L2EnchantScroll | |
479 | +{ | |
480 | + private final CrystalType _grade; | |
481 | + private final boolean _weapon; | |
482 | + private final boolean _breaks; | |
483 | + private final boolean _maintain; | |
484 | + private final byte[] _chance; | |
485 | + | |
486 | + public L2EnchantScroll(CrystalType grade, boolean weapon, boolean breaks, boolean maintain, byte[] chance) | |
487 | + { | |
488 | + _grade = grade; | |
489 | + _weapon = weapon; | |
490 | + _breaks = breaks; | |
491 | + _maintain = maintain; | |
492 | + _chance = chance; | |
493 | + } | |
494 | + | |
495 | + /** | |
496 | + * @param enchantItem : The item to enchant. | |
497 | + * @return the enchant chance under double format. | |
498 | + */ | |
499 | + public final byte getChance(ItemInstance enchantItem) | |
500 | + { | |
501 | + int level = enchantItem.getEnchantLevel(); | |
502 | + if (enchantItem.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR && level != 0) | |
503 | + level--; | |
504 | + | |
505 | + if (level >= _chance.length) | |
506 | + return 0; | |
507 | + | |
508 | + return _chance[level]; | |
509 | + } | |
510 | + | |
511 | + public final boolean canBreak() | |
512 | + { | |
513 | + return _breaks; | |
514 | + } | |
515 | + | |
516 | + public final boolean canMaintain() | |
517 | + { | |
518 | + return _maintain; | |
519 | + } | |
520 | + | |
521 | + // TODO: methods | |
522 | + | |
523 | + /** | |
524 | + * @param enchantItem : The item to enchant. | |
525 | + * @return True if enchant can be used on selected item. | |
526 | + */ | |
527 | + public final boolean isValid(ItemInstance enchantItem) | |
528 | + { | |
529 | + // check for crystal type | |
530 | + if (_grade != enchantItem.getItem().getCrystalType()) | |
531 | + return false; | |
532 | + | |
533 | + // check enchant max level | |
534 | + if (enchantItem.getEnchantLevel() >= _chance.length) | |
535 | + return false; | |
536 | + | |
537 | + // checking scroll type | |
538 | + switch (enchantItem.getItem().getType2()) | |
539 | + { | |
540 | + case Item.TYPE2_WEAPON: | |
541 | + if (!_weapon) | |
542 | + return false; | |
543 | + break; | |
544 | + | |
545 | + case Item.TYPE2_SHIELD_ARMOR: | |
546 | + case Item.TYPE2_ACCESSORY: | |
547 | + if (_weapon) | |
548 | + return false; | |
549 | + break; | |
550 | + | |
551 | + default: | |
552 | + return false; | |
553 | + } | |
554 | + | |
555 | + return true; | |
556 | + } | |
557 | +} | |
558 | Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java | |
559 | =================================================================== | |
560 | --- java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java (revision 5) | |
561 | +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java (working copy) | |
562 | @@ -16,7 +16,9 @@ | |
563 | ||
564 | import net.sf.l2j.Config; | |
565 | import net.sf.l2j.gameserver.datatables.ArmorSetsTable; | |
566 | +import net.sf.l2j.gameserver.datatables.EnchantTable; | |
567 | import net.sf.l2j.gameserver.datatables.SkillTable; | |
568 | +import net.sf.l2j.gameserver.model.L2EnchantScroll; | |
569 | import net.sf.l2j.gameserver.model.L2Skill; | |
570 | import net.sf.l2j.gameserver.model.L2World; | |
571 | import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; | |
572 | @@ -25,6 +27,7 @@ | |
573 | import net.sf.l2j.gameserver.model.item.kind.Armor; | |
574 | import net.sf.l2j.gameserver.model.item.kind.Item; | |
575 | import net.sf.l2j.gameserver.model.item.kind.Weapon; | |
576 | +import net.sf.l2j.gameserver.model.item.type.WeaponType; | |
577 | import net.sf.l2j.gameserver.model.itemcontainer.Inventory; | |
578 | import net.sf.l2j.gameserver.network.SystemMessageId; | |
579 | import net.sf.l2j.gameserver.network.serverpackets.EnchantResult; | |
580 | @@ -35,7 +38,7 @@ | |
581 | import net.sf.l2j.gameserver.util.Util; | |
582 | import net.sf.l2j.util.Rnd; | |
583 | ||
584 | -public final class RequestEnchantItem extends AbstractEnchantPacket | |
585 | +public final class RequestEnchantItem extends L2GameClientPacket | |
586 | { | |
587 | private int _objectId = 0; | |
588 | ||
589 | @@ -48,16 +51,19 @@ | |
590 | @Override | |
591 | protected void runImpl() | |
592 | { | |
593 | + // get player | |
594 | final L2PcInstance activeChar = getClient().getActiveChar(); | |
595 | if (activeChar == null || _objectId == 0) | |
596 | return; | |
597 | ||
598 | + // player online and active | |
599 | if (!activeChar.isOnline() || getClient().isDetached()) | |
600 | { | |
601 | activeChar.setActiveEnchantItem(null); | |
602 | return; | |
603 | } | |
604 | ||
605 | + // player on shop/craft | |
606 | if (activeChar.isProcessingTransaction() || activeChar.isInStoreMode()) | |
607 | { | |
608 | activeChar.sendPacket(SystemMessageId.CANNOT_ENCHANT_WHILE_STORE); | |
609 | @@ -65,7 +71,18 @@ | |
610 | activeChar.sendPacket(EnchantResult.CANCELLED); | |
611 | return; | |
612 | } | |
613 | + | |
614 | + // player trading | |
615 | + if (activeChar.getActiveTradeList() != null) | |
616 | + { | |
617 | + activeChar.cancelActiveTrade(); | |
618 | + activeChar.sendPacket(SystemMessageId.TRADE_ATTEMPT_FAILED); | |
619 | + activeChar.setActiveEnchantItem(null); | |
620 | + activeChar.sendPacket(EnchantResult.CANCELLED); | |
621 | + return; | |
622 | + } | |
623 | ||
624 | + // get item and enchant scroll | |
625 | ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId); | |
626 | ItemInstance scroll = activeChar.getActiveEnchantItem(); | |
627 | ||
628 | @@ -77,13 +94,13 @@ | |
629 | return; | |
630 | } | |
631 | ||
632 | - // template for scroll | |
633 | - EnchantScroll scrollTemplate = getEnchantScroll(scroll); | |
634 | - if (scrollTemplate == null) | |
635 | + // get scroll enchant data | |
636 | + L2EnchantScroll enchant = EnchantTable.getInstance().getEnchantScroll(scroll); | |
637 | + if (enchant == null) | |
638 | return; | |
639 | ||
640 | - // first validation check | |
641 | - if (!scrollTemplate.isValid(item) || !isEnchantable(item)) | |
642 | + // validation check | |
643 | + if (!isEnchantable(item) || !enchant.isValid(item) || item.getOwnerId() != activeChar.getObjectId()) | |
644 | { | |
645 | activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION); | |
646 | activeChar.setActiveEnchantItem(null); | |
647 | @@ -91,7 +108,7 @@ | |
648 | return; | |
649 | } | |
650 | ||
651 | - // attempting to destroy scroll | |
652 | + // destroy enchant scroll | |
653 | scroll = activeChar.getInventory().destroyItem("Enchant", scroll.getObjectId(), 1, activeChar, item); | |
654 | if (scroll == null) | |
655 | { | |
656 | @@ -102,46 +119,27 @@ | |
657 | return; | |
658 | } | |
659 | ||
660 | - if (activeChar.getActiveTradeList() != null) | |
661 | - { | |
662 | - activeChar.cancelActiveTrade(); | |
663 | - activeChar.sendPacket(SystemMessageId.TRADE_ATTEMPT_FAILED); | |
664 | - return; | |
665 | - } | |
666 | - | |
667 | synchronized (item) | |
668 | { | |
669 | - double chance = scrollTemplate.getChance(item); | |
670 | - | |
671 | - // last validation check | |
672 | - if (item.getOwnerId() != activeChar.getObjectId() || !isEnchantable(item) || chance < 0) | |
673 | - { | |
674 | - activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION); | |
675 | - activeChar.setActiveEnchantItem(null); | |
676 | - activeChar.sendPacket(EnchantResult.CANCELLED); | |
677 | - return; | |
678 | - } | |
679 | - | |
680 | // success | |
681 | - if (Rnd.get() < chance) | |
682 | + if (Rnd.get(100) < enchant.getChance(item)) | |
683 | { | |
684 | - // announce the success | |
685 | + // send message | |
686 | SystemMessage sm; | |
687 | ||
688 | if (item.getEnchantLevel() == 0) | |
689 | { | |
690 | sm = SystemMessage.getSystemMessage(SystemMessageId.S1_SUCCESSFULLY_ENCHANTED); | |
691 | - sm.addItemName(item.getItemId()); | |
692 | - activeChar.sendPacket(sm); | |
693 | } | |
694 | else | |
695 | { | |
696 | sm = SystemMessage.getSystemMessage(SystemMessageId.S1_S2_SUCCESSFULLY_ENCHANTED); | |
697 | sm.addNumber(item.getEnchantLevel()); | |
698 | - sm.addItemName(item.getItemId()); | |
699 | - activeChar.sendPacket(sm); | |
700 | } | |
701 | + sm.addItemName(item.getItemId()); | |
702 | + activeChar.sendPacket(sm); | |
703 | ||
704 | + // update item | |
705 | item.setEnchantLevel(item.getEnchantLevel() + 1); | |
706 | item.updateDatabase(); | |
707 | ||
708 | @@ -186,6 +184,7 @@ | |
709 | } | |
710 | activeChar.sendPacket(EnchantResult.SUCCESS); | |
711 | } | |
712 | + // fail | |
713 | else | |
714 | { | |
715 | // Drop passive skills from items. | |
716 | @@ -228,39 +227,46 @@ | |
717 | } | |
718 | } | |
719 | ||
720 | - if (scrollTemplate.isBlessed()) | |
721 | + if (!enchant.canBreak()) | |
722 | { | |
723 | - // blessed enchant - clear enchant value | |
724 | + // keep item | |
725 | activeChar.sendPacket(SystemMessageId.BLESSED_ENCHANT_FAILED); | |
726 | ||
727 | - item.setEnchantLevel(0); | |
728 | - item.updateDatabase(); | |
729 | + if (!enchant.canMaintain()) | |
730 | + { | |
731 | + item.setEnchantLevel(0); | |
732 | + item.updateDatabase(); | |
733 | + } | |
734 | activeChar.sendPacket(EnchantResult.UNSUCCESS); | |
735 | } | |
736 | else | |
737 | { | |
738 | - // enchant failed, destroy item | |
739 | - int crystalId = item.getItem().getCrystalItemId(); | |
740 | - int count = item.getCrystalCount() - (item.getItem().getCrystalCount() + 1) / 2; | |
741 | - if (count < 1) | |
742 | - count = 1; | |
743 | - | |
744 | + // destroy item | |
745 | ItemInstance destroyItem = activeChar.getInventory().destroyItem("Enchant", item, activeChar, null); | |
746 | if (destroyItem == null) | |
747 | { | |
748 | - // unable to destroy item, cheater ? | |
749 | Util.handleIllegalPlayerAction(activeChar, "Unable to delete item on enchant failure from player " + activeChar.getName() + ", possible cheater !", Config.DEFAULT_PUNISH); | |
750 | activeChar.setActiveEnchantItem(null); | |
751 | activeChar.sendPacket(EnchantResult.CANCELLED); | |
752 | return; | |
753 | } | |
754 | ||
755 | - if (crystalId != 0) | |
756 | + // add crystals, if item crystalizable | |
757 | + int crystalType = item.getItem().getCrystalItemId(); | |
758 | + ItemInstance crystals = null; | |
759 | + if (crystalType != 0) | |
760 | { | |
761 | - activeChar.getInventory().addItem("Enchant", crystalId, count, activeChar, destroyItem); | |
762 | - activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(crystalId).addItemNumber(count)); | |
763 | + // get crystals count | |
764 | + int crystalCount = item.getCrystalCount() - (item.getItem().getCrystalCount() + 1) / 2; | |
765 | + if (crystalCount < 1) | |
766 | + crystalCount = 1; | |
767 | + | |
768 | + // add crystals to inventory | |
769 | + crystals = activeChar.getInventory().addItem("Enchant", crystalType, crystalCount, activeChar, destroyItem); | |
770 | + activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(crystals.getItemId()).addItemNumber(crystalCount)); | |
771 | } | |
772 | ||
773 | + // update inventory | |
774 | InventoryUpdate iu = new InventoryUpdate(); | |
775 | if (destroyItem.getCount() == 0) | |
776 | iu.addRemovedItem(destroyItem); | |
777 | @@ -269,27 +275,49 @@ | |
778 | ||
779 | activeChar.sendPacket(iu); | |
780 | ||
781 | - // Messages. | |
782 | + // remove item | |
783 | + L2World.getInstance().removeObject(destroyItem); | |
784 | + | |
785 | + // send message | |
786 | if (item.getEnchantLevel() > 0) | |
787 | activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_S2_EVAPORATED).addNumber(item.getEnchantLevel()).addItemName(item.getItemId())); | |
788 | else | |
789 | activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_EVAPORATED).addItemName(item.getItemId())); | |
790 | ||
791 | - L2World.getInstance().removeObject(destroyItem); | |
792 | - if (crystalId == 0) | |
793 | + // send enchant result | |
794 | + if (crystalType == 0) | |
795 | activeChar.sendPacket(EnchantResult.UNK_RESULT_4); | |
796 | else | |
797 | activeChar.sendPacket(EnchantResult.UNK_RESULT_1); | |
798 | ||
799 | + // update weight | |
800 | StatusUpdate su = new StatusUpdate(activeChar); | |
801 | su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad()); | |
802 | activeChar.sendPacket(su); | |
803 | } | |
804 | } | |
805 | ||
806 | + // send item list | |
807 | activeChar.sendPacket(new ItemList(activeChar, false)); | |
808 | + | |
809 | + // update appearance | |
810 | activeChar.broadcastUserInfo(); | |
811 | activeChar.setActiveEnchantItem(null); | |
812 | } | |
813 | } | |
814 | + /** | |
815 | + * @param item The instance of item to make checks on. | |
816 | + * @return true if item can be enchanted. | |
817 | + */ | |
818 | + private static final boolean isEnchantable(ItemInstance item) | |
819 | + { | |
820 | + if (item.isHeroItem() || item.isShadowItem() || item.isEtcItem() || item.getItem().getItemType() == WeaponType.FISHINGROD) | |
821 | + return false; | |
822 | + | |
823 | + // only equipped items or in inventory can be enchanted | |
824 | + if (item.getLocation() != ItemInstance.ItemLocation.INVENTORY && item.getLocation() != ItemInstance.ItemLocation.PAPERDOLL) | |
825 | + return false; | |
826 | + | |
827 | + return true; | |
828 | + } | |
829 | } | |
830 | \ No newline at end of file | |
831 | Index: java/net/sf/l2j/Config.java | |
832 | =================================================================== | |
833 | --- java/net/sf/l2j/Config.java (revision 5) | |
834 | +++ java/net/sf/l2j/Config.java (working copy) | |
835 | @@ -405,17 +405,6 @@ | |
836 | public static boolean ALT_GAME_FREIGHTS; | |
837 | public static int ALT_GAME_FREIGHT_PRICE; | |
838 | ||
839 | - /** Enchant */ | |
840 | - public static double ENCHANT_CHANCE_WEAPON_MAGIC; | |
841 | - public static double ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS; | |
842 | - public static double ENCHANT_CHANCE_WEAPON_NONMAGIC; | |
843 | - public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS; | |
844 | - public static double ENCHANT_CHANCE_ARMOR; | |
845 | - public static int ENCHANT_MAX_WEAPON; | |
846 | - public static int ENCHANT_MAX_ARMOR; | |
847 | - public static int ENCHANT_SAFE_MAX; | |
848 | - public static int ENCHANT_SAFE_MAX_FULL; | |
849 | - | |
850 | /** Augmentations */ | |
851 | public static int AUGMENTATION_NG_SKILL_CHANCE; | |
852 | public static int AUGMENTATION_NG_GLOW_CHANCE; | |
853 | @@ -1020,16 +1009,6 @@ | |
854 | ALT_GAME_FREIGHTS = players.getProperty("AltGameFreights", false); | |
855 | ALT_GAME_FREIGHT_PRICE = players.getProperty("AltGameFreightPrice", 1000); | |
856 | ||
857 | - ENCHANT_CHANCE_WEAPON_MAGIC = players.getProperty("EnchantChanceMagicWeapon", 0.4); | |
858 | - ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS = players.getProperty("EnchantChanceMagicWeapon15Plus", 0.2); | |
859 | - ENCHANT_CHANCE_WEAPON_NONMAGIC = players.getProperty("EnchantChanceNonMagicWeapon", 0.7); | |
860 | - ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS = players.getProperty("EnchantChanceNonMagicWeapon15Plus", 0.35); | |
861 | - ENCHANT_CHANCE_ARMOR = players.getProperty("EnchantChanceArmor", 0.66); | |
862 | - ENCHANT_MAX_WEAPON = players.getProperty("EnchantMaxWeapon", 0); | |
863 | - ENCHANT_MAX_ARMOR = players.getProperty("EnchantMaxArmor", 0); | |
864 | - ENCHANT_SAFE_MAX = players.getProperty("EnchantSafeMax", 3); | |
865 | - ENCHANT_SAFE_MAX_FULL = players.getProperty("EnchantSafeMaxFull", 4); | |
866 | - | |
867 | AUGMENTATION_NG_SKILL_CHANCE = players.getProperty("AugmentationNGSkillChance", 15); | |
868 | AUGMENTATION_NG_GLOW_CHANCE = players.getProperty("AugmentationNGGlowChance", 0); | |
869 | AUGMENTATION_MID_SKILL_CHANCE = players.getProperty("AugmentationMidSkillChance", 30); |