AugmentationData.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /*
  2. * Copyright © 2004-2019 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 static com.l2jserver.gameserver.config.Configuration.character;
  21. import static com.l2jserver.gameserver.config.Configuration.general;
  22. import static com.l2jserver.gameserver.config.Configuration.server;
  23. import java.io.File;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Map;
  28. import javax.xml.parsers.DocumentBuilderFactory;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. import org.w3c.dom.Document;
  32. import org.w3c.dom.NamedNodeMap;
  33. import org.w3c.dom.Node;
  34. import com.l2jserver.commons.util.Rnd;
  35. import com.l2jserver.gameserver.data.xml.impl.OptionData;
  36. import com.l2jserver.gameserver.model.L2Augmentation;
  37. import com.l2jserver.gameserver.model.holders.SkillHolder;
  38. import com.l2jserver.gameserver.model.items.L2Item;
  39. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  40. import com.l2jserver.gameserver.model.options.Options;
  41. import com.l2jserver.gameserver.network.clientpackets.AbstractRefinePacket;
  42. /**
  43. * Loads augmentation bonuses and skills.
  44. * @author durgus, Gigiikun, Sandro, UnAfraid
  45. */
  46. public class AugmentationData {
  47. // TODO(Zoey76): Implement using IXmlReader.
  48. private static final Logger LOG = LoggerFactory.getLogger(AugmentationData.class);
  49. // stats
  50. private static final int STAT_BLOCKSIZE = 3640;
  51. private static final int STAT_SUBBLOCKSIZE = 91;
  52. public static final int MIN_SKILL_ID = STAT_BLOCKSIZE * 4;
  53. // skills
  54. private static final int BLUE_START = 14561;
  55. private static final int SKILLS_BLOCKSIZE = 178;
  56. // basestats
  57. private static final int BASESTAT_STR = 16341;
  58. private static final int BASESTAT_MEN = 16344;
  59. // accessory
  60. private static final int ACC_START = 16669;
  61. private static final int ACC_BLOCKS_NUM = 10;
  62. private static final int ACC_STAT_SUBBLOCKSIZE = 21;
  63. private static final int ACC_RING_START = ACC_START;
  64. private static final int ACC_RING_SKILLS = 18;
  65. private static final int ACC_RING_BLOCKSIZE = ACC_RING_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  66. private static final int ACC_RING_END = (ACC_RING_START + (ACC_BLOCKS_NUM * ACC_RING_BLOCKSIZE)) - 1;
  67. private static final int ACC_EAR_START = ACC_RING_END + 1;
  68. private static final int ACC_EAR_SKILLS = 18;
  69. private static final int ACC_EAR_BLOCKSIZE = ACC_EAR_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  70. private static final int ACC_EAR_END = (ACC_EAR_START + (ACC_BLOCKS_NUM * ACC_EAR_BLOCKSIZE)) - 1;
  71. private static final int ACC_NECK_START = ACC_EAR_END + 1;
  72. private static final int ACC_NECK_SKILLS = 24;
  73. private static final int ACC_NECK_BLOCKSIZE = ACC_NECK_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  74. private final List<List<Integer>> _blueSkills = new ArrayList<>();
  75. private final List<List<Integer>> _purpleSkills = new ArrayList<>();
  76. private final List<List<Integer>> _redSkills = new ArrayList<>();
  77. private final List<AugmentationChance> _augmentationChances = new ArrayList<>();
  78. private final List<augmentationChanceAcc> _augmentationChancesAcc = new ArrayList<>();
  79. private final Map<Integer, SkillHolder> _allSkills = new HashMap<>();
  80. protected AugmentationData() {
  81. for (int i = 0; i < 10; i++) {
  82. _blueSkills.add(new ArrayList<Integer>());
  83. _purpleSkills.add(new ArrayList<Integer>());
  84. _redSkills.add(new ArrayList<Integer>());
  85. }
  86. load();
  87. if (!character().retailLikeAugmentation()) {
  88. for (int i = 0; i < 10; i++) {
  89. LOG.info("Loaded {} blue, {} purple and {} red skills for life stone level {}.", _blueSkills.get(i).size(), _purpleSkills.get(i).size(), _redSkills.get(i).size(), i);
  90. }
  91. } else {
  92. LOG.info("Loaded {} augmentations.", _augmentationChances.size());
  93. LOG.info("Loaded {} accessory augmentations.", _augmentationChancesAcc.size());
  94. }
  95. }
  96. public class AugmentationChance {
  97. private final String _WeaponType;
  98. private final int _StoneId;
  99. private final int _VariationId;
  100. private final int _CategoryChance;
  101. private final int _AugmentId;
  102. private final float _AugmentChance;
  103. public AugmentationChance(String WeaponType, int StoneId, int VariationId, int CategoryChance, int AugmentId, float AugmentChance) {
  104. _WeaponType = WeaponType;
  105. _StoneId = StoneId;
  106. _VariationId = VariationId;
  107. _CategoryChance = CategoryChance;
  108. _AugmentId = AugmentId;
  109. _AugmentChance = AugmentChance;
  110. }
  111. public String getWeaponType() {
  112. return _WeaponType;
  113. }
  114. public int getStoneId() {
  115. return _StoneId;
  116. }
  117. public int getVariationId() {
  118. return _VariationId;
  119. }
  120. public int getCategoryChance() {
  121. return _CategoryChance;
  122. }
  123. public int getAugmentId() {
  124. return _AugmentId;
  125. }
  126. public float getAugmentChance() {
  127. return _AugmentChance;
  128. }
  129. }
  130. public class augmentationChanceAcc {
  131. private final String _WeaponType;
  132. private final int _StoneId;
  133. private final int _VariationId;
  134. private final int _CategoryChance;
  135. private final int _AugmentId;
  136. private final float _AugmentChance;
  137. public augmentationChanceAcc(String WeaponType, int StoneId, int VariationId, int CategoryChance, int AugmentId, float AugmentChance) {
  138. _WeaponType = WeaponType;
  139. _StoneId = StoneId;
  140. _VariationId = VariationId;
  141. _CategoryChance = CategoryChance;
  142. _AugmentId = AugmentId;
  143. _AugmentChance = AugmentChance;
  144. }
  145. public String getWeaponType() {
  146. return _WeaponType;
  147. }
  148. public int getStoneId() {
  149. return _StoneId;
  150. }
  151. public int getVariationId() {
  152. return _VariationId;
  153. }
  154. public int getCategoryChance() {
  155. return _CategoryChance;
  156. }
  157. public int getAugmentId() {
  158. return _AugmentId;
  159. }
  160. public float getAugmentChance() {
  161. return _AugmentChance;
  162. }
  163. }
  164. private final void load() {
  165. // Load stats
  166. DocumentBuilderFactory factory2 = DocumentBuilderFactory.newInstance();
  167. factory2.setValidating(false);
  168. factory2.setIgnoringComments(true);
  169. // Load the skillmap
  170. // Note: the skillmap data is only used when generating new augmentations
  171. // the client expects a different id in order to display the skill in the
  172. // items description...
  173. if (!character().retailLikeAugmentation()) {
  174. try {
  175. int badAugmantData = 0;
  176. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  177. factory.setValidating(false);
  178. factory.setIgnoringComments(true);
  179. File file = new File(server().getDatapackRoot(), "data/stats/augmentation/augmentation_skillmap.xml");
  180. if (!file.exists()) {
  181. LOG.warn("The augmentation skillmap file is missing!");
  182. return;
  183. }
  184. Document doc = factory.newDocumentBuilder().parse(file);
  185. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) {
  186. if ("list".equalsIgnoreCase(n.getNodeName())) {
  187. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) {
  188. if ("augmentation".equalsIgnoreCase(d.getNodeName())) {
  189. NamedNodeMap attrs = d.getAttributes();
  190. int skillId = 0, augmentationId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  191. int skillLvL = 0;
  192. String type = "blue";
  193. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling()) {
  194. if ("skillId".equalsIgnoreCase(cd.getNodeName())) {
  195. attrs = cd.getAttributes();
  196. skillId = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  197. } else if ("skillLevel".equalsIgnoreCase(cd.getNodeName())) {
  198. attrs = cd.getAttributes();
  199. skillLvL = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  200. } else if ("type".equalsIgnoreCase(cd.getNodeName())) {
  201. attrs = cd.getAttributes();
  202. type = attrs.getNamedItem("val").getNodeValue();
  203. }
  204. }
  205. if (skillId == 0) {
  206. badAugmantData++;
  207. continue;
  208. } else if (skillLvL == 0) {
  209. badAugmantData++;
  210. continue;
  211. }
  212. int k = (augmentationId - BLUE_START) / SKILLS_BLOCKSIZE;
  213. if (type.equalsIgnoreCase("blue")) {
  214. _blueSkills.get(k).add(augmentationId);
  215. } else if (type.equalsIgnoreCase("purple")) {
  216. _purpleSkills.get(k).add(augmentationId);
  217. } else {
  218. _redSkills.get(k).add(augmentationId);
  219. }
  220. _allSkills.put(augmentationId, new SkillHolder(skillId, skillLvL));
  221. }
  222. }
  223. }
  224. }
  225. if (badAugmantData != 0) {
  226. LOG.warn("{} bad skill(s) were skipped.", badAugmantData);
  227. }
  228. } catch (Exception ex) {
  229. LOG.warn("There has been an error parsing augmentation_skillmap.xml!", ex);
  230. return;
  231. }
  232. } else {
  233. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  234. factory.setValidating(false);
  235. factory.setIgnoringComments(true);
  236. File aFile = new File(server().getDatapackRoot(), "data/stats/augmentation/retailchances.xml");
  237. if (aFile.exists()) {
  238. Document aDoc = null;
  239. try {
  240. aDoc = factory.newDocumentBuilder().parse(aFile);
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. return;
  244. }
  245. String aWeaponType = null;
  246. int aStoneId = 0;
  247. int aVariationId = 0;
  248. int aCategoryChance = 0;
  249. int aAugmentId = 0;
  250. float aAugmentChance = 0;
  251. for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling()) {
  252. if (l.getNodeName().equals("list")) {
  253. NamedNodeMap aNodeAttributes = null;
  254. for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling()) {
  255. if (n.getNodeName().equals("weapon")) {
  256. aNodeAttributes = n.getAttributes();
  257. aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
  258. for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling()) {
  259. if (c.getNodeName().equals("stone")) {
  260. aNodeAttributes = c.getAttributes();
  261. aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  262. for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling()) {
  263. if (v.getNodeName().equals("variation")) {
  264. aNodeAttributes = v.getAttributes();
  265. aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  266. for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling()) {
  267. if (j.getNodeName().equals("category")) {
  268. aNodeAttributes = j.getAttributes();
  269. aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
  270. for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling()) {
  271. if (e.getNodeName().equals("augment")) {
  272. aNodeAttributes = e.getAttributes();
  273. aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  274. aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
  275. _augmentationChances.add(new AugmentationChance(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. } else {
  289. LOG.warn("The retailchances.xml data file is missing!");
  290. return;
  291. }
  292. }
  293. if (character().retailLikeAugmentationAccessory()) {
  294. DocumentBuilderFactory factory3 = DocumentBuilderFactory.newInstance();
  295. factory3.setValidating(false);
  296. factory3.setIgnoringComments(true);
  297. File aFile3 = new File(server().getDatapackRoot(), "data/stats/augmentation/retailchances_accessory.xml");
  298. if (aFile3.exists()) {
  299. Document aDoc = null;
  300. try {
  301. aDoc = factory3.newDocumentBuilder().parse(aFile3);
  302. } catch (Exception e) {
  303. e.printStackTrace();
  304. return;
  305. }
  306. String aWeaponType = null;
  307. int aStoneId = 0;
  308. int aVariationId = 0;
  309. int aCategoryChance = 0;
  310. int aAugmentId = 0;
  311. float aAugmentChance = 0;
  312. for (Node l = aDoc.getFirstChild(); l != null; l = l.getNextSibling()) {
  313. if (l.getNodeName().equals("list")) {
  314. NamedNodeMap aNodeAttributes = null;
  315. for (Node n = l.getFirstChild(); n != null; n = n.getNextSibling()) {
  316. if (n.getNodeName().equals("weapon")) {
  317. aNodeAttributes = n.getAttributes();
  318. aWeaponType = aNodeAttributes.getNamedItem("type").getNodeValue();
  319. for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling()) {
  320. if (c.getNodeName().equals("stone")) {
  321. aNodeAttributes = c.getAttributes();
  322. aStoneId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  323. for (Node v = c.getFirstChild(); v != null; v = v.getNextSibling()) {
  324. if (v.getNodeName().equals("variation")) {
  325. aNodeAttributes = v.getAttributes();
  326. aVariationId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  327. for (Node j = v.getFirstChild(); j != null; j = j.getNextSibling()) {
  328. if (j.getNodeName().equals("category")) {
  329. aNodeAttributes = j.getAttributes();
  330. aCategoryChance = Integer.parseInt(aNodeAttributes.getNamedItem("probability").getNodeValue());
  331. for (Node e = j.getFirstChild(); e != null; e = e.getNextSibling()) {
  332. if (e.getNodeName().equals("augment")) {
  333. aNodeAttributes = e.getAttributes();
  334. aAugmentId = Integer.parseInt(aNodeAttributes.getNamedItem("id").getNodeValue());
  335. aAugmentChance = Float.parseFloat(aNodeAttributes.getNamedItem("chance").getNodeValue());
  336. _augmentationChancesAcc.add(new augmentationChanceAcc(aWeaponType, aStoneId, aVariationId, aCategoryChance, aAugmentId, aAugmentChance));
  337. }
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. } else {
  350. LOG.warn("The retailchances_accessory.xml data file is missing!");
  351. return;
  352. }
  353. }
  354. }
  355. /**
  356. * Generate a new random augmentation
  357. * @param lifeStoneLevel
  358. * @param lifeStoneGrade
  359. * @param bodyPart
  360. * @param lifeStoneId
  361. * @param targetItem
  362. * @return
  363. */
  364. public L2Augmentation generateRandomAugmentation(int lifeStoneLevel, int lifeStoneGrade, int bodyPart, int lifeStoneId, L2ItemInstance targetItem) {
  365. switch (bodyPart) {
  366. case L2Item.SLOT_LR_FINGER:
  367. case L2Item.SLOT_LR_EAR:
  368. case L2Item.SLOT_NECK:
  369. return generateRandomAccessoryAugmentation(lifeStoneLevel, bodyPart, lifeStoneId);
  370. default:
  371. return generateRandomWeaponAugmentation(lifeStoneLevel, lifeStoneGrade, lifeStoneId, targetItem);
  372. }
  373. }
  374. private L2Augmentation generateRandomWeaponAugmentation(int lifeStoneLevel, int lifeStoneGrade, int lifeStoneId, L2ItemInstance item) {
  375. int stat12 = 0;
  376. int stat34 = 0;
  377. if (character().retailLikeAugmentation()) {
  378. if (item.getItem().isMagicWeapon()) {
  379. List<AugmentationChance> _selectedChances12 = new ArrayList<>();
  380. List<AugmentationChance> _selectedChances34 = new ArrayList<>();
  381. for (AugmentationChance ac : _augmentationChances) {
  382. if (ac.getWeaponType().equals("mage") && (ac.getStoneId() == lifeStoneId)) {
  383. if (ac.getVariationId() == 1) {
  384. _selectedChances12.add(ac);
  385. } else {
  386. _selectedChances34.add(ac);
  387. }
  388. }
  389. }
  390. int r = Rnd.get(10000);
  391. float s = 10000;
  392. for (AugmentationChance ac : _selectedChances12) {
  393. if (s > r) {
  394. s -= (ac.getAugmentChance() * 100);
  395. stat12 = ac.getAugmentId();
  396. }
  397. }
  398. List<Integer> gradeChance = null;
  399. switch (lifeStoneGrade) {
  400. case AbstractRefinePacket.GRADE_NONE:
  401. gradeChance = character().getRetailLikeAugmentationNoGradeChance();
  402. break;
  403. case AbstractRefinePacket.GRADE_MID:
  404. gradeChance = character().getRetailLikeAugmentationMidGradeChance();
  405. break;
  406. case AbstractRefinePacket.GRADE_HIGH:
  407. gradeChance = character().getRetailLikeAugmentationHighGradeChance();
  408. break;
  409. case AbstractRefinePacket.GRADE_TOP:
  410. gradeChance = character().getRetailLikeAugmentationTopGradeChance();
  411. break;
  412. default:
  413. gradeChance = character().getRetailLikeAugmentationNoGradeChance();
  414. }
  415. int c = Rnd.get(100);
  416. if (c < gradeChance.get(0)) {
  417. c = 55;
  418. } else if (c < (gradeChance.get(0) + gradeChance.get(1))) {
  419. c = 35;
  420. } else if (c < (gradeChance.get(0) + gradeChance.get(1) + gradeChance.get(2))) {
  421. c = 7;
  422. } else {
  423. c = 3;
  424. }
  425. List<AugmentationChance> _selectedChances34final = new ArrayList<>();
  426. for (AugmentationChance ac : _selectedChances34) {
  427. if (ac.getCategoryChance() == c) {
  428. _selectedChances34final.add(ac);
  429. }
  430. }
  431. r = Rnd.get(10000);
  432. s = 10000;
  433. for (AugmentationChance ac : _selectedChances34final) {
  434. if (s > r) {
  435. s -= (ac.getAugmentChance() * 100);
  436. stat34 = ac.getAugmentId();
  437. }
  438. }
  439. } else {
  440. List<AugmentationChance> _selectedChances12 = new ArrayList<>();
  441. List<AugmentationChance> _selectedChances34 = new ArrayList<>();
  442. for (AugmentationChance ac : _augmentationChances) {
  443. if (ac.getWeaponType().equals("warrior") && (ac.getStoneId() == lifeStoneId)) {
  444. if (ac.getVariationId() == 1) {
  445. _selectedChances12.add(ac);
  446. } else {
  447. _selectedChances34.add(ac);
  448. }
  449. }
  450. }
  451. int r = Rnd.get(10000);
  452. float s = 10000;
  453. for (AugmentationChance ac : _selectedChances12) {
  454. if (s > r) {
  455. s -= (ac.getAugmentChance() * 100);
  456. stat12 = ac.getAugmentId();
  457. }
  458. }
  459. List<Integer> gradeChance = null;
  460. switch (lifeStoneGrade) {
  461. case AbstractRefinePacket.GRADE_NONE:
  462. gradeChance = character().getRetailLikeAugmentationNoGradeChance();
  463. break;
  464. case AbstractRefinePacket.GRADE_MID:
  465. gradeChance = character().getRetailLikeAugmentationMidGradeChance();
  466. break;
  467. case AbstractRefinePacket.GRADE_HIGH:
  468. gradeChance = character().getRetailLikeAugmentationHighGradeChance();
  469. break;
  470. case AbstractRefinePacket.GRADE_TOP:
  471. gradeChance = character().getRetailLikeAugmentationTopGradeChance();
  472. break;
  473. default:
  474. gradeChance = character().getRetailLikeAugmentationNoGradeChance();
  475. }
  476. int c = Rnd.get(100);
  477. if (c < gradeChance.get(0)) {
  478. c = 55;
  479. } else if (c < (gradeChance.get(0) + gradeChance.get(1))) {
  480. c = 35;
  481. } else if (c < (gradeChance.get(0) + gradeChance.get(1) + gradeChance.get(2))) {
  482. c = 7;
  483. } else {
  484. c = 3;
  485. }
  486. List<AugmentationChance> _selectedChances34final = new ArrayList<>();
  487. for (AugmentationChance ac : _selectedChances34) {
  488. if (ac.getCategoryChance() == c) {
  489. _selectedChances34final.add(ac);
  490. }
  491. }
  492. r = Rnd.get(10000);
  493. s = 10000;
  494. for (AugmentationChance ac : _selectedChances34final) {
  495. if (s > r) {
  496. s -= (ac.getAugmentChance() * 100);
  497. stat34 = ac.getAugmentId();
  498. }
  499. }
  500. }
  501. return new L2Augmentation(((stat34 << 16) + stat12));
  502. }
  503. boolean generateSkill = false;
  504. boolean generateGlow = false;
  505. // life stone level is used for stat Id and skill level, but here the max level is 9
  506. lifeStoneLevel = Math.min(lifeStoneLevel, 9);
  507. switch (lifeStoneGrade) {
  508. case AbstractRefinePacket.GRADE_NONE:
  509. if (Rnd.get(1, 100) <= character().getAugmentationNGSkillChance()) {
  510. generateSkill = true;
  511. }
  512. if (Rnd.get(1, 100) <= character().getAugmentationNGGlowChance()) {
  513. generateGlow = true;
  514. }
  515. break;
  516. case AbstractRefinePacket.GRADE_MID:
  517. if (Rnd.get(1, 100) <= character().getAugmentationMidSkillChance()) {
  518. generateSkill = true;
  519. }
  520. if (Rnd.get(1, 100) <= character().getAugmentationMidGlowChance()) {
  521. generateGlow = true;
  522. }
  523. break;
  524. case AbstractRefinePacket.GRADE_HIGH:
  525. if (Rnd.get(1, 100) <= character().getAugmentationHighSkillChance()) {
  526. generateSkill = true;
  527. }
  528. if (Rnd.get(1, 100) <= character().getAugmentationHighGlowChance()) {
  529. generateGlow = true;
  530. }
  531. break;
  532. case AbstractRefinePacket.GRADE_TOP:
  533. if (Rnd.get(1, 100) <= character().getAugmentationTopSkillChance()) {
  534. generateSkill = true;
  535. }
  536. if (Rnd.get(1, 100) <= character().getAugmentationTopGlowChance()) {
  537. generateGlow = true;
  538. }
  539. break;
  540. case AbstractRefinePacket.GRADE_ACC:
  541. if (Rnd.get(1, 100) <= character().getAugmentationAccSkillChance()) {
  542. generateSkill = true;
  543. }
  544. }
  545. if (!generateSkill && (Rnd.get(1, 100) <= character().getAugmentationBaseStatChance())) {
  546. stat34 = Rnd.get(BASESTAT_STR, BASESTAT_MEN);
  547. }
  548. // Second: decide which grade the augmentation result is going to have:
  549. // 0:yellow, 1:blue, 2:purple, 3:red
  550. // The chances used here are most likely custom,
  551. // what's known is: you can't have yellow with skill(or baseStatModifier)
  552. // noGrade stone can not have glow, mid only with skill, high has a chance(custom), top allways glow
  553. int resultColor = Rnd.get(0, 100);
  554. if ((stat34 == 0) && !generateSkill) {
  555. if (resultColor <= ((15 * lifeStoneGrade) + 40)) {
  556. resultColor = 1;
  557. } else {
  558. resultColor = 0;
  559. }
  560. } else {
  561. if ((resultColor <= ((10 * lifeStoneGrade) + 5)) || (stat34 != 0)) {
  562. resultColor = 3;
  563. } else if (resultColor <= ((10 * lifeStoneGrade) + 10)) {
  564. resultColor = 1;
  565. } else {
  566. resultColor = 2;
  567. }
  568. }
  569. // generate a skill if necessary
  570. if (generateSkill) {
  571. switch (resultColor) {
  572. case 1: // blue skill
  573. stat34 = _blueSkills.get(lifeStoneLevel).get(Rnd.get(0, _blueSkills.get(lifeStoneLevel).size() - 1));
  574. break;
  575. case 2: // purple skill
  576. stat34 = _purpleSkills.get(lifeStoneLevel).get(Rnd.get(0, _purpleSkills.get(lifeStoneLevel).size() - 1));
  577. break;
  578. case 3: // red skill
  579. stat34 = _redSkills.get(lifeStoneLevel).get(Rnd.get(0, _redSkills.get(lifeStoneLevel).size() - 1));
  580. break;
  581. }
  582. }
  583. // Third: Calculate the subblock offset for the chosen color,
  584. // and the level of the lifeStone
  585. // from large number of retail augmentations:
  586. // no skill part
  587. // Id for stat12:
  588. // A:1-910 B:911-1820 C:1821-2730 D:2731-3640 E:3641-4550 F:4551-5460 G:5461-6370 H:6371-7280
  589. // Id for stat34(this defines the color):
  590. // I:7281-8190(yellow) K:8191-9100(blue) L:10921-11830(yellow) M:11831-12740(blue)
  591. // you can combine I-K with A-D and L-M with E-H
  592. // using C-D or G-H Id you will get a glow effect
  593. // there seems no correlation in which grade use which Id except for the glowing restriction
  594. // skill part
  595. // Id for stat12:
  596. // same for no skill part
  597. // A same as E, B same as F, C same as G, D same as H
  598. // A - no glow, no grade LS
  599. // B - weak glow, mid grade LS?
  600. // C - glow, high grade LS?
  601. // D - strong glow, top grade LS?
  602. // is neither a skill nor basestat used for stat34? then generate a normal stat
  603. int offset;
  604. if (stat34 == 0) {
  605. int temp = Rnd.get(2, 3);
  606. int colorOffset = (resultColor * (10 * STAT_SUBBLOCKSIZE)) + (temp * STAT_BLOCKSIZE) + 1;
  607. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + colorOffset;
  608. stat34 = Rnd.get(offset, (offset + STAT_SUBBLOCKSIZE) - 1);
  609. if (generateGlow && (lifeStoneGrade >= 2)) {
  610. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + ((temp - 2) * STAT_BLOCKSIZE) + (lifeStoneGrade * (10 * STAT_SUBBLOCKSIZE)) + 1;
  611. } else {
  612. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + ((temp - 2) * STAT_BLOCKSIZE) + (Rnd.get(0, 1) * (10 * STAT_SUBBLOCKSIZE)) + 1;
  613. }
  614. } else {
  615. if (!generateGlow) {
  616. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + (Rnd.get(0, 1) * STAT_BLOCKSIZE) + 1;
  617. } else {
  618. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + (Rnd.get(0, 1) * STAT_BLOCKSIZE) + (((lifeStoneGrade + resultColor) / 2) * (10 * STAT_SUBBLOCKSIZE)) + 1;
  619. }
  620. }
  621. stat12 = Rnd.get(offset, (offset + STAT_SUBBLOCKSIZE) - 1);
  622. if (general().debug()) {
  623. LOG.info("Augmentation success: stat12={}; stat34={}; resultColor={}; level={}; grade={}", stat12, stat34, resultColor, lifeStoneLevel, lifeStoneGrade);
  624. }
  625. return new L2Augmentation(((stat34 << 16) + stat12));
  626. }
  627. private L2Augmentation generateRandomAccessoryAugmentation(int lifeStoneLevel, int bodyPart, int lifeStoneId) {
  628. int stat12 = 0;
  629. int stat34 = 0;
  630. if (character().retailLikeAugmentationAccessory()) {
  631. List<augmentationChanceAcc> _selectedChances12 = new ArrayList<>();
  632. List<augmentationChanceAcc> _selectedChances34 = new ArrayList<>();
  633. for (augmentationChanceAcc ac : _augmentationChancesAcc) {
  634. if (ac.getWeaponType().equals("warrior") && (ac.getStoneId() == lifeStoneId)) {
  635. if (ac.getVariationId() == 1) {
  636. _selectedChances12.add(ac);
  637. } else {
  638. _selectedChances34.add(ac);
  639. }
  640. }
  641. }
  642. int r = Rnd.get(10000);
  643. float s = 10000;
  644. for (augmentationChanceAcc ac : _selectedChances12) {
  645. if (s > r) {
  646. s -= (ac.getAugmentChance() * 100);
  647. stat12 = ac.getAugmentId();
  648. }
  649. }
  650. int c = Rnd.get(100);
  651. if (c < 55) {
  652. c = 55;
  653. } else if (c < 90) {
  654. c = 35;
  655. } else if (c < 99) {
  656. c = 9;
  657. } else {
  658. c = 1;
  659. }
  660. List<augmentationChanceAcc> _selectedChances34final = new ArrayList<>();
  661. for (augmentationChanceAcc ac : _selectedChances34) {
  662. if (ac.getCategoryChance() == c) {
  663. _selectedChances34final.add(ac);
  664. }
  665. }
  666. r = Rnd.get(10000);
  667. s = 10000;
  668. for (augmentationChanceAcc ac : _selectedChances34final) {
  669. if (s > r) {
  670. s -= (ac.getAugmentChance() * 100);
  671. stat34 = ac.getAugmentId();
  672. }
  673. }
  674. return new L2Augmentation(((stat34 << 16) + stat12));
  675. }
  676. lifeStoneLevel = Math.min(lifeStoneLevel, 9);
  677. int base = 0;
  678. int skillsLength = 0;
  679. switch (bodyPart) {
  680. case L2Item.SLOT_LR_FINGER:
  681. base = ACC_RING_START + (ACC_RING_BLOCKSIZE * lifeStoneLevel);
  682. skillsLength = ACC_RING_SKILLS;
  683. break;
  684. case L2Item.SLOT_LR_EAR:
  685. base = ACC_EAR_START + (ACC_EAR_BLOCKSIZE * lifeStoneLevel);
  686. skillsLength = ACC_EAR_SKILLS;
  687. break;
  688. case L2Item.SLOT_NECK:
  689. base = ACC_NECK_START + (ACC_NECK_BLOCKSIZE * lifeStoneLevel);
  690. skillsLength = ACC_NECK_SKILLS;
  691. break;
  692. default:
  693. return null;
  694. }
  695. int resultColor = Rnd.get(0, 3);
  696. // first augmentation (stats only)
  697. stat12 = Rnd.get(ACC_STAT_SUBBLOCKSIZE);
  698. Options op = null;
  699. if (Rnd.get(1, 100) <= character().getAugmentationAccSkillChance()) {
  700. // second augmentation (skill)
  701. stat34 = base + Rnd.get(skillsLength);
  702. op = OptionData.getInstance().getOptions(stat34);
  703. }
  704. if ((op == null) || (!op.hasActiveSkill() && !op.hasPassiveSkill() && !op.hasActivationSkills())) {
  705. // second augmentation (stats)
  706. // calculating any different from stat12 value inside sub-block
  707. // starting from next and wrapping over using remainder
  708. stat34 = (stat12 + 1 + Rnd.get(ACC_STAT_SUBBLOCKSIZE - 1)) % ACC_STAT_SUBBLOCKSIZE;
  709. // this is a stats - skipping skills
  710. stat34 = base + skillsLength + (ACC_STAT_SUBBLOCKSIZE * resultColor) + stat34;
  711. }
  712. // stat12 has stats only
  713. stat12 = base + skillsLength + (ACC_STAT_SUBBLOCKSIZE * resultColor) + stat12;
  714. if (general().debug()) {
  715. LOG.info("Accessory augmentation success: stat12={}; stat34={}; level={}", stat12, stat34, lifeStoneLevel);
  716. }
  717. return new L2Augmentation(((stat34 << 16) + stat12));
  718. }
  719. public static final AugmentationData getInstance() {
  720. return SingletonHolder._instance;
  721. }
  722. private static class SingletonHolder {
  723. protected static final AugmentationData _instance = new AugmentationData();
  724. }
  725. }