AugmentationData.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.io.File;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.logging.Level;
  26. import java.util.logging.Logger;
  27. import javax.xml.parsers.DocumentBuilderFactory;
  28. import org.w3c.dom.Document;
  29. import org.w3c.dom.NamedNodeMap;
  30. import org.w3c.dom.Node;
  31. import com.l2jserver.Config;
  32. import com.l2jserver.gameserver.data.xml.impl.OptionData;
  33. import com.l2jserver.gameserver.model.L2Augmentation;
  34. import com.l2jserver.gameserver.model.holders.SkillHolder;
  35. import com.l2jserver.gameserver.model.items.L2Item;
  36. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  37. import com.l2jserver.gameserver.model.options.Options;
  38. import com.l2jserver.gameserver.network.clientpackets.AbstractRefinePacket;
  39. import com.l2jserver.util.Rnd;
  40. /**
  41. * Loads augmentation bonuses and skills.
  42. * @author durgus, Gigiikun, Sandro, UnAfraid
  43. */
  44. public class AugmentationData
  45. {
  46. // Zoey76: TODO: Implement using IXmlReader.
  47. private static final Logger LOGGER = Logger.getLogger(AugmentationData.class.getName());
  48. // stats
  49. private static final int STAT_BLOCKSIZE = 3640;
  50. private static final int STAT_SUBBLOCKSIZE = 91;
  51. public static final int MIN_SKILL_ID = STAT_BLOCKSIZE * 4;
  52. // skills
  53. private static final int BLUE_START = 14561;
  54. private static final int SKILLS_BLOCKSIZE = 178;
  55. // basestats
  56. private static final int BASESTAT_STR = 16341;
  57. private static final int BASESTAT_MEN = 16344;
  58. // accessory
  59. private static final int ACC_START = 16669;
  60. private static final int ACC_BLOCKS_NUM = 10;
  61. private static final int ACC_STAT_SUBBLOCKSIZE = 21;
  62. private static final int ACC_RING_START = ACC_START;
  63. private static final int ACC_RING_SKILLS = 18;
  64. private static final int ACC_RING_BLOCKSIZE = ACC_RING_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  65. private static final int ACC_RING_END = (ACC_RING_START + (ACC_BLOCKS_NUM * ACC_RING_BLOCKSIZE)) - 1;
  66. private static final int ACC_EAR_START = ACC_RING_END + 1;
  67. private static final int ACC_EAR_SKILLS = 18;
  68. private static final int ACC_EAR_BLOCKSIZE = ACC_EAR_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  69. private static final int ACC_EAR_END = (ACC_EAR_START + (ACC_BLOCKS_NUM * ACC_EAR_BLOCKSIZE)) - 1;
  70. private static final int ACC_NECK_START = ACC_EAR_END + 1;
  71. private static final int ACC_NECK_SKILLS = 24;
  72. private static final int ACC_NECK_BLOCKSIZE = ACC_NECK_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  73. private final List<List<Integer>> _blueSkills = new ArrayList<>();
  74. private final List<List<Integer>> _purpleSkills = new ArrayList<>();
  75. private final List<List<Integer>> _redSkills = new ArrayList<>();
  76. private final List<AugmentationChance> _augmentationChances = new ArrayList<>();
  77. private final List<augmentationChanceAcc> _augmentationChancesAcc = new ArrayList<>();
  78. private final Map<Integer, SkillHolder> _allSkills = new HashMap<>();
  79. protected AugmentationData()
  80. {
  81. for (int i = 0; i < 10; i++)
  82. {
  83. _blueSkills.add(new ArrayList<Integer>());
  84. _purpleSkills.add(new ArrayList<Integer>());
  85. _redSkills.add(new ArrayList<Integer>());
  86. }
  87. load();
  88. if (!Config.RETAIL_LIKE_AUGMENTATION)
  89. {
  90. for (int i = 0; i < 10; i++)
  91. {
  92. LOGGER.info(getClass().getSimpleName() + ": Loaded: " + _blueSkills.get(i).size() + " blue, " + _purpleSkills.get(i).size() + " purple and " + _redSkills.get(i).size() + " red skills for lifeStoneLevel " + i);
  93. }
  94. }
  95. else
  96. {
  97. LOGGER.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _augmentationChances.size() + " augmentations.");
  98. LOGGER.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _augmentationChancesAcc.size() + " accessory augmentations.");
  99. }
  100. }
  101. public class AugmentationChance
  102. {
  103. private final String _WeaponType;
  104. private final int _StoneId;
  105. private final int _VariationId;
  106. private final int _CategoryChance;
  107. private final int _AugmentId;
  108. private final float _AugmentChance;
  109. public AugmentationChance(String WeaponType, int StoneId, int VariationId, int CategoryChance, int AugmentId, float AugmentChance)
  110. {
  111. _WeaponType = WeaponType;
  112. _StoneId = StoneId;
  113. _VariationId = VariationId;
  114. _CategoryChance = CategoryChance;
  115. _AugmentId = AugmentId;
  116. _AugmentChance = AugmentChance;
  117. }
  118. public String getWeaponType()
  119. {
  120. return _WeaponType;
  121. }
  122. public int getStoneId()
  123. {
  124. return _StoneId;
  125. }
  126. public int getVariationId()
  127. {
  128. return _VariationId;
  129. }
  130. public int getCategoryChance()
  131. {
  132. return _CategoryChance;
  133. }
  134. public int getAugmentId()
  135. {
  136. return _AugmentId;
  137. }
  138. public float getAugmentChance()
  139. {
  140. return _AugmentChance;
  141. }
  142. }
  143. public class augmentationChanceAcc
  144. {
  145. private final String _WeaponType;
  146. private final int _StoneId;
  147. private final int _VariationId;
  148. private final int _CategoryChance;
  149. private final int _AugmentId;
  150. private final float _AugmentChance;
  151. public augmentationChanceAcc(String WeaponType, int StoneId, int VariationId, int CategoryChance, int AugmentId, float AugmentChance)
  152. {
  153. _WeaponType = WeaponType;
  154. _StoneId = StoneId;
  155. _VariationId = VariationId;
  156. _CategoryChance = CategoryChance;
  157. _AugmentId = AugmentId;
  158. _AugmentChance = AugmentChance;
  159. }
  160. public String getWeaponType()
  161. {
  162. return _WeaponType;
  163. }
  164. public int getStoneId()
  165. {
  166. return _StoneId;
  167. }
  168. public int getVariationId()
  169. {
  170. return _VariationId;
  171. }
  172. public int getCategoryChance()
  173. {
  174. return _CategoryChance;
  175. }
  176. public int getAugmentId()
  177. {
  178. return _AugmentId;
  179. }
  180. public float getAugmentChance()
  181. {
  182. return _AugmentChance;
  183. }
  184. }
  185. private final void load()
  186. {
  187. // Load stats
  188. DocumentBuilderFactory factory2 = DocumentBuilderFactory.newInstance();
  189. factory2.setValidating(false);
  190. factory2.setIgnoringComments(true);
  191. // Load the skillmap
  192. // Note: the skillmap data is only used when generating new augmentations
  193. // the client expects a different id in order to display the skill in the
  194. // items description...
  195. if (!Config.RETAIL_LIKE_AUGMENTATION)
  196. {
  197. try
  198. {
  199. int badAugmantData = 0;
  200. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  201. factory.setValidating(false);
  202. factory.setIgnoringComments(true);
  203. File file = new File(Config.DATAPACK_ROOT + "/data/stats/augmentation/augmentation_skillmap.xml");
  204. if (!file.exists())
  205. {
  206. LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR The augmentation skillmap file is missing.");
  207. return;
  208. }
  209. Document doc = factory.newDocumentBuilder().parse(file);
  210. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  211. {
  212. if ("list".equalsIgnoreCase(n.getNodeName()))
  213. {
  214. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  215. {
  216. if ("augmentation".equalsIgnoreCase(d.getNodeName()))
  217. {
  218. NamedNodeMap attrs = d.getAttributes();
  219. int skillId = 0, augmentationId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  220. int skillLvL = 0;
  221. String type = "blue";
  222. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  223. {
  224. if ("skillId".equalsIgnoreCase(cd.getNodeName()))
  225. {
  226. attrs = cd.getAttributes();
  227. skillId = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  228. }
  229. else if ("skillLevel".equalsIgnoreCase(cd.getNodeName()))
  230. {
  231. attrs = cd.getAttributes();
  232. skillLvL = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  233. }
  234. else if ("type".equalsIgnoreCase(cd.getNodeName()))
  235. {
  236. attrs = cd.getAttributes();
  237. type = attrs.getNamedItem("val").getNodeValue();
  238. }
  239. }
  240. if (skillId == 0)
  241. {
  242. badAugmantData++;
  243. continue;
  244. }
  245. else if (skillLvL == 0)
  246. {
  247. badAugmantData++;
  248. continue;
  249. }
  250. int k = (augmentationId - BLUE_START) / SKILLS_BLOCKSIZE;
  251. if (type.equalsIgnoreCase("blue"))
  252. {
  253. _blueSkills.get(k).add(augmentationId);
  254. }
  255. else if (type.equalsIgnoreCase("purple"))
  256. {
  257. _purpleSkills.get(k).add(augmentationId);
  258. }
  259. else
  260. {
  261. _redSkills.get(k).add(augmentationId);
  262. }
  263. _allSkills.put(augmentationId, new SkillHolder(skillId, skillLvL));
  264. }
  265. }
  266. }
  267. }
  268. if (badAugmantData != 0)
  269. {
  270. LOGGER.info(getClass().getSimpleName() + ": " + badAugmantData + " bad skill(s) were skipped.");
  271. }
  272. }
  273. catch (Exception e)
  274. {
  275. LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR parsing augmentation_skillmap.xml.", e);
  276. return;
  277. }
  278. }
  279. else
  280. {
  281. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  282. factory.setValidating(false);
  283. factory.setIgnoringComments(true);
  284. File aFile = new File(Config.DATAPACK_ROOT + "/data/stats/augmentation/retailchances.xml");
  285. if (aFile.exists())
  286. {
  287. Document aDoc = null;
  288. try
  289. {
  290. aDoc = factory.newDocumentBuilder().parse(aFile);
  291. }
  292. catch (Exception e)
  293. {
  294. e.printStackTrace();
  295. return;
  296. }
  297. String aWeaponType = null;
  298. int aStoneId = 0;
  299. int aVariationId = 0;
  300. int aCategoryChance = 0;
  301. int aAugmentId = 0;
  302. float aAugmentChance = 0;
  303. for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling())
  304. {
  305. if (l.getNodeName().equals("list"))
  306. {
  307. NamedNodeMap aNodeAttributes = null;
  308. // System.out.println("We're going through the list now.");
  309. for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling())
  310. {
  311. if (n.getNodeName().equals("weapon"))
  312. {
  313. aNodeAttributes = n.getAttributes();
  314. aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
  315. // System.out.println("Now showing Augmentations for " + aWeaponType + " Weapons.");
  316. for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
  317. {
  318. if (c.getNodeName().equals("stone"))
  319. {
  320. aNodeAttributes = c.getAttributes();
  321. aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  322. for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling())
  323. {
  324. if (v.getNodeName().equals("variation"))
  325. {
  326. aNodeAttributes = v.getAttributes();
  327. aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  328. for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling())
  329. {
  330. if (j.getNodeName().equals("category"))
  331. {
  332. aNodeAttributes = j.getAttributes();
  333. aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
  334. // System.out.println("Stone Id: " + aStoneId + ", Variation Id: " + aVariationId + ", Category Chances: " + aCategoryChance);
  335. for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling())
  336. {
  337. if (e.getNodeName().equals("augment"))
  338. {
  339. aNodeAttributes = e.getAttributes();
  340. aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  341. aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
  342. _augmentationChances.add(new AugmentationChance(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. else
  357. {
  358. LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR The retailchances.xml data file is missing.");
  359. return;
  360. }
  361. }
  362. if (Config.RETAIL_LIKE_AUGMENTATION_ACCESSORY)
  363. {
  364. DocumentBuilderFactory factory3 = DocumentBuilderFactory.newInstance();
  365. factory3.setValidating(false);
  366. factory3.setIgnoringComments(true);
  367. File aFile3 = new File(Config.DATAPACK_ROOT + "/data/stats/augmentation/retailchances_accessory.xml");
  368. if (aFile3.exists())
  369. {
  370. Document aDoc = null;
  371. try
  372. {
  373. aDoc = factory3.newDocumentBuilder().parse(aFile3);
  374. }
  375. catch (Exception e)
  376. {
  377. e.printStackTrace();
  378. return;
  379. }
  380. String aWeaponType = null;
  381. int aStoneId = 0;
  382. int aVariationId = 0;
  383. int aCategoryChance = 0;
  384. int aAugmentId = 0;
  385. float aAugmentChance = 0;
  386. for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling())
  387. {
  388. if (l.getNodeName().equals("list"))
  389. {
  390. NamedNodeMap aNodeAttributes = null;
  391. for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling())
  392. {
  393. if (n.getNodeName().equals("weapon"))
  394. {
  395. aNodeAttributes = n.getAttributes();
  396. aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
  397. for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
  398. {
  399. if (c.getNodeName().equals("stone"))
  400. {
  401. aNodeAttributes = c.getAttributes();
  402. aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  403. for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling())
  404. {
  405. if (v.getNodeName().equals("variation"))
  406. {
  407. aNodeAttributes = v.getAttributes();
  408. aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  409. for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling())
  410. {
  411. if (j.getNodeName().equals("category"))
  412. {
  413. aNodeAttributes = j.getAttributes();
  414. aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
  415. for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling())
  416. {
  417. if (e.getNodeName().equals("augment"))
  418. {
  419. aNodeAttributes = e.getAttributes();
  420. aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  421. aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
  422. _augmentationChancesAcc.add(new augmentationChanceAcc(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. else
  437. {
  438. LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": ERROR The retailchances_accessory.xml data file is missing.");
  439. return;
  440. }
  441. }
  442. }
  443. /**
  444. * Generate a new random augmentation
  445. * @param lifeStoneLevel
  446. * @param lifeStoneGrade
  447. * @param bodyPart
  448. * @param lifeStoneId
  449. * @param targetItem
  450. * @return
  451. */
  452. public L2Augmentation generateRandomAugmentation(int lifeStoneLevel, int lifeStoneGrade, int bodyPart, int lifeStoneId, L2ItemInstance targetItem)
  453. {
  454. switch (bodyPart)
  455. {
  456. case L2Item.SLOT_LR_FINGER:
  457. case L2Item.SLOT_LR_EAR:
  458. case L2Item.SLOT_NECK:
  459. return generateRandomAccessoryAugmentation(lifeStoneLevel, bodyPart, lifeStoneId);
  460. default:
  461. return generateRandomWeaponAugmentation(lifeStoneLevel, lifeStoneGrade, lifeStoneId, targetItem);
  462. }
  463. }
  464. private L2Augmentation generateRandomWeaponAugmentation(int lifeStoneLevel, int lifeStoneGrade, int lifeStoneId, L2ItemInstance item)
  465. {
  466. int stat12 = 0;
  467. int stat34 = 0;
  468. if (Config.RETAIL_LIKE_AUGMENTATION)
  469. {
  470. if (item.getItem().isMagicWeapon())
  471. {
  472. List<AugmentationChance> _selectedChances12 = new ArrayList<>();
  473. List<AugmentationChance> _selectedChances34 = new ArrayList<>();
  474. for (AugmentationChance ac : _augmentationChances)
  475. {
  476. if (ac.getWeaponType().equals("mage") && (ac.getStoneId() == lifeStoneId))
  477. {
  478. if (ac.getVariationId() == 1)
  479. {
  480. _selectedChances12.add(ac);
  481. }
  482. else
  483. {
  484. _selectedChances34.add(ac);
  485. }
  486. }
  487. }
  488. int r = Rnd.get(10000);
  489. float s = 10000;
  490. for (AugmentationChance ac : _selectedChances12)
  491. {
  492. if (s > r)
  493. {
  494. s -= (ac.getAugmentChance() * 100);
  495. stat12 = ac.getAugmentId();
  496. }
  497. }
  498. int[] gradeChance = null;
  499. switch (lifeStoneGrade)
  500. {
  501. case AbstractRefinePacket.GRADE_NONE:
  502. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_NG_CHANCE;
  503. break;
  504. case AbstractRefinePacket.GRADE_MID:
  505. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_MID_CHANCE;
  506. break;
  507. case AbstractRefinePacket.GRADE_HIGH:
  508. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_HIGH_CHANCE;
  509. break;
  510. case AbstractRefinePacket.GRADE_TOP:
  511. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_TOP_CHANCE;
  512. break;
  513. default:
  514. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_NG_CHANCE;
  515. }
  516. int c = Rnd.get(100);
  517. if (c < gradeChance[0])
  518. {
  519. c = 55;
  520. }
  521. else if (c < (gradeChance[0] + gradeChance[1]))
  522. {
  523. c = 35;
  524. }
  525. else if (c < (gradeChance[0] + gradeChance[1] + gradeChance[2]))
  526. {
  527. c = 7;
  528. }
  529. else
  530. {
  531. c = 3;
  532. }
  533. List<AugmentationChance> _selectedChances34final = new ArrayList<>();
  534. for (AugmentationChance ac : _selectedChances34)
  535. {
  536. if (ac.getCategoryChance() == c)
  537. {
  538. _selectedChances34final.add(ac);
  539. }
  540. }
  541. r = Rnd.get(10000);
  542. s = 10000;
  543. for (AugmentationChance ac : _selectedChances34final)
  544. {
  545. if (s > r)
  546. {
  547. s -= (ac.getAugmentChance() * 100);
  548. stat34 = ac.getAugmentId();
  549. }
  550. }
  551. }
  552. else
  553. {
  554. List<AugmentationChance> _selectedChances12 = new ArrayList<>();
  555. List<AugmentationChance> _selectedChances34 = new ArrayList<>();
  556. for (AugmentationChance ac : _augmentationChances)
  557. {
  558. if (ac.getWeaponType().equals("warrior") && (ac.getStoneId() == lifeStoneId))
  559. {
  560. if (ac.getVariationId() == 1)
  561. {
  562. _selectedChances12.add(ac);
  563. }
  564. else
  565. {
  566. _selectedChances34.add(ac);
  567. }
  568. }
  569. }
  570. int r = Rnd.get(10000);
  571. float s = 10000;
  572. for (AugmentationChance ac : _selectedChances12)
  573. {
  574. if (s > r)
  575. {
  576. s -= (ac.getAugmentChance() * 100);
  577. stat12 = ac.getAugmentId();
  578. }
  579. }
  580. int[] gradeChance = null;
  581. switch (lifeStoneGrade)
  582. {
  583. case AbstractRefinePacket.GRADE_NONE:
  584. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_NG_CHANCE;
  585. break;
  586. case AbstractRefinePacket.GRADE_MID:
  587. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_MID_CHANCE;
  588. break;
  589. case AbstractRefinePacket.GRADE_HIGH:
  590. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_HIGH_CHANCE;
  591. break;
  592. case AbstractRefinePacket.GRADE_TOP:
  593. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_TOP_CHANCE;
  594. break;
  595. default:
  596. gradeChance = Config.RETAIL_LIKE_AUGMENTATION_NG_CHANCE;
  597. }
  598. int c = Rnd.get(100);
  599. if (c < gradeChance[0])
  600. {
  601. c = 55;
  602. }
  603. else if (c < (gradeChance[0] + gradeChance[1]))
  604. {
  605. c = 35;
  606. }
  607. else if (c < (gradeChance[0] + gradeChance[1] + gradeChance[2]))
  608. {
  609. c = 7;
  610. }
  611. else
  612. {
  613. c = 3;
  614. }
  615. List<AugmentationChance> _selectedChances34final = new ArrayList<>();
  616. for (AugmentationChance ac : _selectedChances34)
  617. {
  618. if (ac.getCategoryChance() == c)
  619. {
  620. _selectedChances34final.add(ac);
  621. }
  622. }
  623. r = Rnd.get(10000);
  624. s = 10000;
  625. for (AugmentationChance ac : _selectedChances34final)
  626. {
  627. if (s > r)
  628. {
  629. s -= (ac.getAugmentChance() * 100);
  630. stat34 = ac.getAugmentId();
  631. }
  632. }
  633. }
  634. return new L2Augmentation(((stat34 << 16) + stat12));
  635. }
  636. boolean generateSkill = false;
  637. boolean generateGlow = false;
  638. // life stone level is used for stat Id and skill level, but here the max level is 9
  639. lifeStoneLevel = Math.min(lifeStoneLevel, 9);
  640. switch (lifeStoneGrade)
  641. {
  642. case AbstractRefinePacket.GRADE_NONE:
  643. if (Rnd.get(1, 100) <= Config.AUGMENTATION_NG_SKILL_CHANCE)
  644. {
  645. generateSkill = true;
  646. }
  647. if (Rnd.get(1, 100) <= Config.AUGMENTATION_NG_GLOW_CHANCE)
  648. {
  649. generateGlow = true;
  650. }
  651. break;
  652. case AbstractRefinePacket.GRADE_MID:
  653. if (Rnd.get(1, 100) <= Config.AUGMENTATION_MID_SKILL_CHANCE)
  654. {
  655. generateSkill = true;
  656. }
  657. if (Rnd.get(1, 100) <= Config.AUGMENTATION_MID_GLOW_CHANCE)
  658. {
  659. generateGlow = true;
  660. }
  661. break;
  662. case AbstractRefinePacket.GRADE_HIGH:
  663. if (Rnd.get(1, 100) <= Config.AUGMENTATION_HIGH_SKILL_CHANCE)
  664. {
  665. generateSkill = true;
  666. }
  667. if (Rnd.get(1, 100) <= Config.AUGMENTATION_HIGH_GLOW_CHANCE)
  668. {
  669. generateGlow = true;
  670. }
  671. break;
  672. case AbstractRefinePacket.GRADE_TOP:
  673. if (Rnd.get(1, 100) <= Config.AUGMENTATION_TOP_SKILL_CHANCE)
  674. {
  675. generateSkill = true;
  676. }
  677. if (Rnd.get(1, 100) <= Config.AUGMENTATION_TOP_GLOW_CHANCE)
  678. {
  679. generateGlow = true;
  680. }
  681. break;
  682. case AbstractRefinePacket.GRADE_ACC:
  683. if (Rnd.get(1, 100) <= Config.AUGMENTATION_ACC_SKILL_CHANCE)
  684. {
  685. generateSkill = true;
  686. }
  687. }
  688. if (!generateSkill && (Rnd.get(1, 100) <= Config.AUGMENTATION_BASESTAT_CHANCE))
  689. {
  690. stat34 = Rnd.get(BASESTAT_STR, BASESTAT_MEN);
  691. }
  692. // Second: decide which grade the augmentation result is going to have:
  693. // 0:yellow, 1:blue, 2:purple, 3:red
  694. // The chances used here are most likely custom,
  695. // what's known is: you can't have yellow with skill(or baseStatModifier)
  696. // noGrade stone can not have glow, mid only with skill, high has a chance(custom), top allways glow
  697. int resultColor = Rnd.get(0, 100);
  698. if ((stat34 == 0) && !generateSkill)
  699. {
  700. if (resultColor <= ((15 * lifeStoneGrade) + 40))
  701. {
  702. resultColor = 1;
  703. }
  704. else
  705. {
  706. resultColor = 0;
  707. }
  708. }
  709. else
  710. {
  711. if ((resultColor <= ((10 * lifeStoneGrade) + 5)) || (stat34 != 0))
  712. {
  713. resultColor = 3;
  714. }
  715. else if (resultColor <= ((10 * lifeStoneGrade) + 10))
  716. {
  717. resultColor = 1;
  718. }
  719. else
  720. {
  721. resultColor = 2;
  722. }
  723. }
  724. // generate a skill if necessary
  725. if (generateSkill)
  726. {
  727. switch (resultColor)
  728. {
  729. case 1: // blue skill
  730. stat34 = _blueSkills.get(lifeStoneLevel).get(Rnd.get(0, _blueSkills.get(lifeStoneLevel).size() - 1));
  731. break;
  732. case 2: // purple skill
  733. stat34 = _purpleSkills.get(lifeStoneLevel).get(Rnd.get(0, _purpleSkills.get(lifeStoneLevel).size() - 1));
  734. break;
  735. case 3: // red skill
  736. stat34 = _redSkills.get(lifeStoneLevel).get(Rnd.get(0, _redSkills.get(lifeStoneLevel).size() - 1));
  737. break;
  738. }
  739. }
  740. // Third: Calculate the subblock offset for the chosen color,
  741. // and the level of the lifeStone
  742. // from large number of retail augmentations:
  743. // no skill part
  744. // Id for stat12:
  745. // A:1-910 B:911-1820 C:1821-2730 D:2731-3640 E:3641-4550 F:4551-5460 G:5461-6370 H:6371-7280
  746. // Id for stat34(this defines the color):
  747. // I:7281-8190(yellow) K:8191-9100(blue) L:10921-11830(yellow) M:11831-12740(blue)
  748. // you can combine I-K with A-D and L-M with E-H
  749. // using C-D or G-H Id you will get a glow effect
  750. // there seems no correlation in which grade use which Id except for the glowing restriction
  751. // skill part
  752. // Id for stat12:
  753. // same for no skill part
  754. // A same as E, B same as F, C same as G, D same as H
  755. // A - no glow, no grade LS
  756. // B - weak glow, mid grade LS?
  757. // C - glow, high grade LS?
  758. // D - strong glow, top grade LS?
  759. // is neither a skill nor basestat used for stat34? then generate a normal stat
  760. int offset;
  761. if (stat34 == 0)
  762. {
  763. int temp = Rnd.get(2, 3);
  764. int colorOffset = (resultColor * (10 * STAT_SUBBLOCKSIZE)) + (temp * STAT_BLOCKSIZE) + 1;
  765. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + colorOffset;
  766. stat34 = Rnd.get(offset, (offset + STAT_SUBBLOCKSIZE) - 1);
  767. if (generateGlow && (lifeStoneGrade >= 2))
  768. {
  769. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + ((temp - 2) * STAT_BLOCKSIZE) + (lifeStoneGrade * (10 * STAT_SUBBLOCKSIZE)) + 1;
  770. }
  771. else
  772. {
  773. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + ((temp - 2) * STAT_BLOCKSIZE) + (Rnd.get(0, 1) * (10 * STAT_SUBBLOCKSIZE)) + 1;
  774. }
  775. }
  776. else
  777. {
  778. if (!generateGlow)
  779. {
  780. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + (Rnd.get(0, 1) * STAT_BLOCKSIZE) + 1;
  781. }
  782. else
  783. {
  784. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + (Rnd.get(0, 1) * STAT_BLOCKSIZE) + (((lifeStoneGrade + resultColor) / 2) * (10 * STAT_SUBBLOCKSIZE)) + 1;
  785. }
  786. }
  787. stat12 = Rnd.get(offset, (offset + STAT_SUBBLOCKSIZE) - 1);
  788. if (Config.DEBUG)
  789. {
  790. LOGGER.info(getClass().getSimpleName() + ": Augmentation success: stat12=" + stat12 + "; stat34=" + stat34 + "; resultColor=" + resultColor + "; level=" + lifeStoneLevel + "; grade=" + lifeStoneGrade);
  791. }
  792. return new L2Augmentation(((stat34 << 16) + stat12));
  793. }
  794. private L2Augmentation generateRandomAccessoryAugmentation(int lifeStoneLevel, int bodyPart, int lifeStoneId)
  795. {
  796. int stat12 = 0;
  797. int stat34 = 0;
  798. if (Config.RETAIL_LIKE_AUGMENTATION_ACCESSORY)
  799. {
  800. List<augmentationChanceAcc> _selectedChances12 = new ArrayList<>();
  801. List<augmentationChanceAcc> _selectedChances34 = new ArrayList<>();
  802. for (augmentationChanceAcc ac : _augmentationChancesAcc)
  803. {
  804. if (ac.getWeaponType().equals("warrior") && (ac.getStoneId() == lifeStoneId))
  805. {
  806. if (ac.getVariationId() == 1)
  807. {
  808. _selectedChances12.add(ac);
  809. }
  810. else
  811. {
  812. _selectedChances34.add(ac);
  813. }
  814. }
  815. }
  816. int r = Rnd.get(10000);
  817. float s = 10000;
  818. for (augmentationChanceAcc ac : _selectedChances12)
  819. {
  820. if (s > r)
  821. {
  822. s -= (ac.getAugmentChance() * 100);
  823. stat12 = ac.getAugmentId();
  824. }
  825. }
  826. int c = Rnd.get(100);
  827. if (c < 55)
  828. {
  829. c = 55;
  830. }
  831. else if (c < 90)
  832. {
  833. c = 35;
  834. }
  835. else if (c < 99)
  836. {
  837. c = 9;
  838. }
  839. else
  840. {
  841. c = 1;
  842. }
  843. List<augmentationChanceAcc> _selectedChances34final = new ArrayList<>();
  844. for (augmentationChanceAcc ac : _selectedChances34)
  845. {
  846. if (ac.getCategoryChance() == c)
  847. {
  848. _selectedChances34final.add(ac);
  849. }
  850. }
  851. r = Rnd.get(10000);
  852. s = 10000;
  853. for (augmentationChanceAcc ac : _selectedChances34final)
  854. {
  855. if (s > r)
  856. {
  857. s -= (ac.getAugmentChance() * 100);
  858. stat34 = ac.getAugmentId();
  859. }
  860. }
  861. return new L2Augmentation(((stat34 << 16) + stat12));
  862. }
  863. lifeStoneLevel = Math.min(lifeStoneLevel, 9);
  864. int base = 0;
  865. int skillsLength = 0;
  866. switch (bodyPart)
  867. {
  868. case L2Item.SLOT_LR_FINGER:
  869. base = ACC_RING_START + (ACC_RING_BLOCKSIZE * lifeStoneLevel);
  870. skillsLength = ACC_RING_SKILLS;
  871. break;
  872. case L2Item.SLOT_LR_EAR:
  873. base = ACC_EAR_START + (ACC_EAR_BLOCKSIZE * lifeStoneLevel);
  874. skillsLength = ACC_EAR_SKILLS;
  875. break;
  876. case L2Item.SLOT_NECK:
  877. base = ACC_NECK_START + (ACC_NECK_BLOCKSIZE * lifeStoneLevel);
  878. skillsLength = ACC_NECK_SKILLS;
  879. break;
  880. default:
  881. return null;
  882. }
  883. int resultColor = Rnd.get(0, 3);
  884. // first augmentation (stats only)
  885. stat12 = Rnd.get(ACC_STAT_SUBBLOCKSIZE);
  886. Options op = null;
  887. if (Rnd.get(1, 100) <= Config.AUGMENTATION_ACC_SKILL_CHANCE)
  888. {
  889. // second augmentation (skill)
  890. stat34 = base + Rnd.get(skillsLength);
  891. op = OptionData.getInstance().getOptions(stat34);
  892. }
  893. if ((op == null) || (!op.hasActiveSkill() && !op.hasPassiveSkill() && !op.hasActivationSkills()))
  894. {
  895. // second augmentation (stats)
  896. // calculating any different from stat12 value inside sub-block
  897. // starting from next and wrapping over using remainder
  898. stat34 = (stat12 + 1 + Rnd.get(ACC_STAT_SUBBLOCKSIZE - 1)) % ACC_STAT_SUBBLOCKSIZE;
  899. // this is a stats - skipping skills
  900. stat34 = base + skillsLength + (ACC_STAT_SUBBLOCKSIZE * resultColor) + stat34;
  901. }
  902. // stat12 has stats only
  903. stat12 = base + skillsLength + (ACC_STAT_SUBBLOCKSIZE * resultColor) + stat12;
  904. if (Config.DEBUG)
  905. {
  906. LOGGER.info(getClass().getSimpleName() + ": Accessory augmentation success: stat12=" + stat12 + "; stat34=" + stat34 + "; level=" + lifeStoneLevel);
  907. }
  908. return new L2Augmentation(((stat34 << 16) + stat12));
  909. }
  910. public static final AugmentationData getInstance()
  911. {
  912. return SingletonHolder._instance;
  913. }
  914. private static class SingletonHolder
  915. {
  916. protected static final AugmentationData _instance = new AugmentationData();
  917. }
  918. }