AugmentationData.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.datatables;
  16. import gnu.trove.map.hash.TIntObjectHashMap;
  17. import java.io.File;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import javax.xml.parsers.DocumentBuilderFactory;
  24. import javolution.util.FastList;
  25. import org.w3c.dom.Document;
  26. import org.w3c.dom.NamedNodeMap;
  27. import org.w3c.dom.Node;
  28. import com.l2jserver.Config;
  29. import com.l2jserver.gameserver.model.L2Augmentation;
  30. import com.l2jserver.gameserver.model.items.L2Item;
  31. import com.l2jserver.gameserver.model.skills.L2Skill;
  32. import com.l2jserver.gameserver.model.stats.Stats;
  33. import com.l2jserver.gameserver.network.clientpackets.AbstractRefinePacket;
  34. import com.l2jserver.util.Rnd;
  35. /**
  36. * This class manages the augmentation data and can also create new augmentations.
  37. * @author durgus, edited by Gigiikun
  38. */
  39. public class AugmentationData
  40. {
  41. private static final Logger _log = Logger.getLogger(AugmentationData.class.getName());
  42. public static final AugmentationData getInstance()
  43. {
  44. return SingletonHolder._instance;
  45. }
  46. // stats
  47. private static final int STAT_START = 1;
  48. private static final int STAT_END = 14560;
  49. private static final int STAT_BLOCKSIZE = 3640;
  50. private static final int STAT_NUMBEROF_BLOCKS = 4;
  51. private static final int STAT_SUBBLOCKSIZE = 91;
  52. // private static final int STAT_NUMBEROF_SUBBLOCKS = 40;
  53. private static final int STAT_NUM = 13;
  54. private static final byte[] STATS1_MAP = new byte[STAT_SUBBLOCKSIZE];
  55. private static final byte[] STATS2_MAP = new byte[STAT_SUBBLOCKSIZE];
  56. // skills
  57. private static final int BLUE_START = 14561;
  58. // private static final int PURPLE_START = 14578;
  59. // private static final int RED_START = 14685;
  60. private static final int SKILLS_BLOCKSIZE = 178;
  61. // basestats
  62. private static final int BASESTAT_STR = 16341;
  63. private static final int BASESTAT_CON = 16342;
  64. private static final int BASESTAT_INT = 16343;
  65. private static final int BASESTAT_MEN = 16344;
  66. // accessory
  67. private static final int ACC_START = 16669;
  68. private static final int ACC_BLOCKS_NUM = 10;
  69. private static final int ACC_STAT_SUBBLOCKSIZE = 21;
  70. private static final int ACC_STAT_NUM = 6;
  71. private static final int ACC_RING_START = ACC_START;
  72. private static final int ACC_RING_SKILLS = 18;
  73. private static final int ACC_RING_BLOCKSIZE = ACC_RING_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  74. private static final int ACC_RING_END = (ACC_RING_START + (ACC_BLOCKS_NUM * ACC_RING_BLOCKSIZE)) - 1;
  75. private static final int ACC_EAR_START = ACC_RING_END + 1;
  76. private static final int ACC_EAR_SKILLS = 18;
  77. private static final int ACC_EAR_BLOCKSIZE = ACC_EAR_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  78. private static final int ACC_EAR_END = (ACC_EAR_START + (ACC_BLOCKS_NUM * ACC_EAR_BLOCKSIZE)) - 1;
  79. private static final int ACC_NECK_START = ACC_EAR_END + 1;
  80. private static final int ACC_NECK_SKILLS = 24;
  81. private static final int ACC_NECK_BLOCKSIZE = ACC_NECK_SKILLS + (4 * ACC_STAT_SUBBLOCKSIZE);
  82. private static final int ACC_END = ACC_NECK_START + (ACC_BLOCKS_NUM * ACC_NECK_BLOCKSIZE);
  83. private static final byte[] ACC_STATS1_MAP = new byte[ACC_STAT_SUBBLOCKSIZE];
  84. private static final byte[] ACC_STATS2_MAP = new byte[ACC_STAT_SUBBLOCKSIZE];
  85. private final List<List<AugmentationStat>> _augStats = new ArrayList<>(4);
  86. private final List<List<AugmentationStat>> _augAccStats = new ArrayList<>(4);
  87. private final List<List<Integer>> _blueSkills = new ArrayList<>(10);
  88. private final List<List<Integer>> _purpleSkills = new ArrayList<>(10);
  89. private final List<List<Integer>> _redSkills = new ArrayList<>(10);
  90. private final List<List<Integer>> _yellowSkills = new ArrayList<>(10);
  91. private final TIntObjectHashMap<AugmentationSkill> _allSkills = new TIntObjectHashMap<>();
  92. protected AugmentationData()
  93. {
  94. for (int i = 0; i < 10; i++)
  95. {
  96. if (i < STAT_NUMBEROF_BLOCKS)
  97. {
  98. _augStats.add(new ArrayList<AugmentationStat>());
  99. _augAccStats.add(new ArrayList<AugmentationStat>());
  100. }
  101. _blueSkills.add(new ArrayList<Integer>());
  102. _purpleSkills.add(new ArrayList<Integer>());
  103. _redSkills.add(new ArrayList<Integer>());
  104. _yellowSkills.add(new ArrayList<Integer>());
  105. }
  106. // Lookup tables structure: STAT1 represent first stat, STAT2 - second.
  107. // If both values are the same - use solo stat, if different - combined.
  108. byte idx;
  109. // weapon augmentation block: solo values first
  110. // 00-00, 01-01 ... 11-11,12-12
  111. for (idx = 0; idx < STAT_NUM; idx++)
  112. {
  113. // solo stats
  114. STATS1_MAP[idx] = idx;
  115. STATS2_MAP[idx] = idx;
  116. }
  117. // combined values next.
  118. // 00-01,00-02,00-03 ... 00-11,00-12;
  119. // 01-02,01-03 ... 01-11,01-12;
  120. // ...
  121. // 09-10,09-11,09-12;
  122. // 10-11,10-12;
  123. // 11-12
  124. for (int i = 0; i < STAT_NUM; i++)
  125. {
  126. for (int j = i + 1; j < STAT_NUM; idx++, j++)
  127. {
  128. // combined stats
  129. STATS1_MAP[idx] = (byte) i;
  130. STATS2_MAP[idx] = (byte) j;
  131. }
  132. }
  133. idx = 0;
  134. // accessory augmentation block, structure is different:
  135. // 00-00,00-01,00-02,00-03,00-04,00-05
  136. // 01-01,01-02,01-03,01-04,01-05
  137. // 02-02,02-03,02-04,02-05
  138. // 03-03,03-04,03-05
  139. // 04-04 \
  140. // 05-05 - order is changed here
  141. // 04-05 /
  142. // First values always solo, next are combined, except last 3 values
  143. for (int i = 0; i < (ACC_STAT_NUM - 2); i++)
  144. {
  145. for (int j = i; j < ACC_STAT_NUM; idx++, j++)
  146. {
  147. ACC_STATS1_MAP[idx] = (byte) i;
  148. ACC_STATS2_MAP[idx] = (byte) j;
  149. }
  150. }
  151. ACC_STATS1_MAP[idx] = 4;
  152. ACC_STATS2_MAP[idx++] = 4;
  153. ACC_STATS1_MAP[idx] = 5;
  154. ACC_STATS2_MAP[idx++] = 5;
  155. ACC_STATS1_MAP[idx] = 4;
  156. ACC_STATS2_MAP[idx] = 5;
  157. load();
  158. // Use size*4: since theres 4 blocks of stat-data with equivalent size
  159. _log.info("AugmentationData: Loaded: " + (_augStats.get(0).size() * 4) + " augmentation stats.");
  160. _log.info("AugmentationData: Loaded: " + (_augAccStats.get(0).size() * 4) + " accessory augmentation stats.");
  161. for (int i = 0; i < 10; i++)
  162. {
  163. _log.info("AugmentationData: Loaded: " + _blueSkills.get(i).size() + " blue, " + _purpleSkills.get(i).size() + " purple and " + _redSkills.get(i).size() + " red skills for lifeStoneLevel " + i);
  164. }
  165. }
  166. public static class AugmentationSkill
  167. {
  168. private final int _skillId;
  169. private final int _skillLevel;
  170. public AugmentationSkill(int skillId, int skillLevel)
  171. {
  172. _skillId = skillId;
  173. _skillLevel = skillLevel;
  174. }
  175. public L2Skill getSkill()
  176. {
  177. return SkillTable.getInstance().getInfo(_skillId, _skillLevel);
  178. }
  179. }
  180. public static class AugmentationStat
  181. {
  182. private final Stats _stat;
  183. private final int _singleSize;
  184. private final int _combinedSize;
  185. private final float _singleValues[];
  186. private final float _combinedValues[];
  187. public AugmentationStat(Stats stat, float sValues[], float cValues[])
  188. {
  189. _stat = stat;
  190. _singleSize = sValues.length;
  191. _singleValues = sValues;
  192. _combinedSize = cValues.length;
  193. _combinedValues = cValues;
  194. }
  195. public int getSingleStatSize()
  196. {
  197. return _singleSize;
  198. }
  199. public int getCombinedStatSize()
  200. {
  201. return _combinedSize;
  202. }
  203. public float getSingleStatValue(int i)
  204. {
  205. if ((i >= _singleSize) || (i < 0))
  206. {
  207. return _singleValues[_singleSize - 1];
  208. }
  209. return _singleValues[i];
  210. }
  211. public float getCombinedStatValue(int i)
  212. {
  213. if ((i >= _combinedSize) || (i < 0))
  214. {
  215. return _combinedValues[_combinedSize - 1];
  216. }
  217. return _combinedValues[i];
  218. }
  219. public Stats getStat()
  220. {
  221. return _stat;
  222. }
  223. }
  224. private final void load()
  225. {
  226. // Load the skillmap
  227. // Note: the skillmap data is only used when generating new augmentations
  228. // the client expects a different id in order to display the skill in the
  229. // items description...
  230. try
  231. {
  232. int badAugmantData = 0;
  233. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  234. factory.setValidating(false);
  235. factory.setIgnoringComments(true);
  236. File file = new File(Config.DATAPACK_ROOT + "/data/stats/augmentation/augmentation_skillmap.xml");
  237. if (!file.exists())
  238. {
  239. if (Config.DEBUG)
  240. {
  241. _log.info("The augmentation skillmap file is missing.");
  242. }
  243. return;
  244. }
  245. Document doc = factory.newDocumentBuilder().parse(file);
  246. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  247. {
  248. if ("list".equalsIgnoreCase(n.getNodeName()))
  249. {
  250. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  251. {
  252. if ("augmentation".equalsIgnoreCase(d.getNodeName()))
  253. {
  254. NamedNodeMap attrs = d.getAttributes();
  255. int skillId = 0, augmentationId = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  256. int skillLvL = 0;
  257. String type = "blue";
  258. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  259. {
  260. if ("skillId".equalsIgnoreCase(cd.getNodeName()))
  261. {
  262. attrs = cd.getAttributes();
  263. skillId = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  264. }
  265. else if ("skillLevel".equalsIgnoreCase(cd.getNodeName()))
  266. {
  267. attrs = cd.getAttributes();
  268. skillLvL = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  269. }
  270. else if ("type".equalsIgnoreCase(cd.getNodeName()))
  271. {
  272. attrs = cd.getAttributes();
  273. type = attrs.getNamedItem("val").getNodeValue();
  274. }
  275. }
  276. if (skillId == 0)
  277. {
  278. if (Config.DEBUG)
  279. {
  280. _log.log(Level.SEVERE, "Bad skillId in augmentation_skillmap.xml in the augmentationId:" + augmentationId);
  281. }
  282. badAugmantData++;
  283. continue;
  284. }
  285. else if (skillLvL == 0)
  286. {
  287. if (Config.DEBUG)
  288. {
  289. _log.log(Level.SEVERE, "Bad skillLevel in augmentation_skillmap.xml in the augmentationId:" + augmentationId);
  290. }
  291. badAugmantData++;
  292. continue;
  293. }
  294. int k = (augmentationId - BLUE_START) / SKILLS_BLOCKSIZE;
  295. if (type.equalsIgnoreCase("blue"))
  296. {
  297. _blueSkills.get(k).add(augmentationId);
  298. }
  299. else if (type.equalsIgnoreCase("purple"))
  300. {
  301. _purpleSkills.get(k).add(augmentationId);
  302. }
  303. else
  304. {
  305. _redSkills.get(k).add(augmentationId);
  306. }
  307. _allSkills.put(augmentationId, new AugmentationSkill(skillId, skillLvL));
  308. }
  309. }
  310. }
  311. }
  312. if (badAugmantData != 0)
  313. {
  314. _log.info("AugmentationData: " + badAugmantData + " bad skill(s) were skipped.");
  315. }
  316. }
  317. catch (Exception e)
  318. {
  319. _log.log(Level.SEVERE, "Error parsing augmentation_skillmap.xml.", e);
  320. return;
  321. }
  322. // Load the stats from xml
  323. for (int i = 1; i < 5; i++)
  324. {
  325. try
  326. {
  327. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  328. factory.setValidating(false);
  329. factory.setIgnoringComments(true);
  330. File file = new File(Config.DATAPACK_ROOT + "/data/stats/augmentation/augmentation_stats" + i + ".xml");
  331. if (!file.exists())
  332. {
  333. if (Config.DEBUG)
  334. {
  335. _log.info("The augmentation stat data file " + i + " is missing.");
  336. }
  337. return;
  338. }
  339. Document doc = factory.newDocumentBuilder().parse(file);
  340. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  341. {
  342. if ("list".equalsIgnoreCase(n.getNodeName()))
  343. {
  344. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  345. {
  346. if ("stat".equalsIgnoreCase(d.getNodeName()))
  347. {
  348. NamedNodeMap attrs = d.getAttributes();
  349. String statName = attrs.getNamedItem("name").getNodeValue();
  350. float soloValues[] = null, combinedValues[] = null;
  351. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  352. {
  353. if ("table".equalsIgnoreCase(cd.getNodeName()))
  354. {
  355. attrs = cd.getAttributes();
  356. String tableName = attrs.getNamedItem("name").getNodeValue();
  357. StringTokenizer data = new StringTokenizer(cd.getFirstChild().getNodeValue());
  358. FastList<Float> array = new FastList<>();
  359. while (data.hasMoreTokens())
  360. {
  361. array.add(Float.parseFloat(data.nextToken()));
  362. }
  363. if (tableName.equalsIgnoreCase("#soloValues"))
  364. {
  365. soloValues = new float[array.size()];
  366. int x = 0;
  367. for (float value : array)
  368. {
  369. soloValues[x++] = value;
  370. }
  371. }
  372. else
  373. {
  374. combinedValues = new float[array.size()];
  375. int x = 0;
  376. for (float value : array)
  377. {
  378. combinedValues[x++] = value;
  379. }
  380. }
  381. }
  382. }
  383. // store this stat
  384. _augStats.get(i - 1).add(new AugmentationStat(Stats.valueOfXml(statName), soloValues, combinedValues));
  385. }
  386. }
  387. }
  388. }
  389. }
  390. catch (Exception e)
  391. {
  392. _log.log(Level.SEVERE, "Error parsing augmentation_stats" + i + ".xml.", e);
  393. return;
  394. }
  395. try
  396. {
  397. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  398. factory.setValidating(false);
  399. factory.setIgnoringComments(true);
  400. File file = new File(Config.DATAPACK_ROOT + "/data/stats/augmentation/augmentation_jewel_stats" + i + ".xml");
  401. if (!file.exists())
  402. {
  403. if (Config.DEBUG)
  404. {
  405. _log.info("The jewel augmentation stat data file " + i + " is missing.");
  406. }
  407. return;
  408. }
  409. Document doc = factory.newDocumentBuilder().parse(file);
  410. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  411. {
  412. if ("list".equalsIgnoreCase(n.getNodeName()))
  413. {
  414. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  415. {
  416. if ("stat".equalsIgnoreCase(d.getNodeName()))
  417. {
  418. NamedNodeMap attrs = d.getAttributes();
  419. String statName = attrs.getNamedItem("name").getNodeValue();
  420. float soloValues[] = null, combinedValues[] = null;
  421. for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  422. {
  423. if ("table".equalsIgnoreCase(cd.getNodeName()))
  424. {
  425. attrs = cd.getAttributes();
  426. String tableName = attrs.getNamedItem("name").getNodeValue();
  427. StringTokenizer data = new StringTokenizer(cd.getFirstChild().getNodeValue());
  428. FastList<Float> array = new FastList<>();
  429. while (data.hasMoreTokens())
  430. {
  431. array.add(Float.parseFloat(data.nextToken()));
  432. }
  433. if (tableName.equalsIgnoreCase("#soloValues"))
  434. {
  435. soloValues = new float[array.size()];
  436. int x = 0;
  437. for (float value : array)
  438. {
  439. soloValues[x++] = value;
  440. }
  441. }
  442. else
  443. {
  444. combinedValues = new float[array.size()];
  445. int x = 0;
  446. for (float value : array)
  447. {
  448. combinedValues[x++] = value;
  449. }
  450. }
  451. }
  452. }
  453. // store this stat
  454. _augAccStats.get(i - 1).add(new AugmentationStat(Stats.valueOfXml(statName), soloValues, combinedValues));
  455. }
  456. }
  457. }
  458. }
  459. }
  460. catch (Exception e)
  461. {
  462. _log.log(Level.SEVERE, "Error parsing jewel augmentation_stats" + i + ".xml.", e);
  463. return;
  464. }
  465. }
  466. }
  467. /**
  468. * Generate a new random augmentation
  469. * @param lifeStoneLevel
  470. * @param lifeStoneGrade
  471. * @param bodyPart
  472. * @return L2Augmentation
  473. */
  474. public L2Augmentation generateRandomAugmentation(int lifeStoneLevel, int lifeStoneGrade, int bodyPart)
  475. {
  476. switch (bodyPart)
  477. {
  478. case L2Item.SLOT_LR_FINGER:
  479. case L2Item.SLOT_LR_EAR:
  480. case L2Item.SLOT_NECK:
  481. return generateRandomAccessoryAugmentation(lifeStoneLevel, bodyPart);
  482. default:
  483. return generateRandomWeaponAugmentation(lifeStoneLevel, lifeStoneGrade);
  484. }
  485. }
  486. private L2Augmentation generateRandomWeaponAugmentation(int lifeStoneLevel, int lifeStoneGrade)
  487. {
  488. // Note that stat12 stands for stat 1 AND 2 (same for stat34 ;p )
  489. // this is because a value can contain up to 2 stat modifications
  490. // (there are two short values packed in one integer value, meaning 4 stat modifications at max)
  491. // for more info take a look at getAugStatsById(...)
  492. // Note: lifeStoneGrade: (0 means low grade, 3 top grade)
  493. // First: determine whether we will add a skill/baseStatModifier or not
  494. // because this determine which color could be the result
  495. int stat12 = 0;
  496. int stat34 = 0;
  497. boolean generateSkill = false;
  498. boolean generateGlow = false;
  499. // life stone level is used for stat Id and skill level, but here the max level is 9
  500. lifeStoneLevel = Math.min(lifeStoneLevel, 9);
  501. switch (lifeStoneGrade)
  502. {
  503. case AbstractRefinePacket.GRADE_NONE:
  504. if (Rnd.get(1, 100) <= Config.AUGMENTATION_NG_SKILL_CHANCE)
  505. {
  506. generateSkill = true;
  507. }
  508. if (Rnd.get(1, 100) <= Config.AUGMENTATION_NG_GLOW_CHANCE)
  509. {
  510. generateGlow = true;
  511. }
  512. break;
  513. case AbstractRefinePacket.GRADE_MID:
  514. if (Rnd.get(1, 100) <= Config.AUGMENTATION_MID_SKILL_CHANCE)
  515. {
  516. generateSkill = true;
  517. }
  518. if (Rnd.get(1, 100) <= Config.AUGMENTATION_MID_GLOW_CHANCE)
  519. {
  520. generateGlow = true;
  521. }
  522. break;
  523. case AbstractRefinePacket.GRADE_HIGH:
  524. if (Rnd.get(1, 100) <= Config.AUGMENTATION_HIGH_SKILL_CHANCE)
  525. {
  526. generateSkill = true;
  527. }
  528. if (Rnd.get(1, 100) <= Config.AUGMENTATION_HIGH_GLOW_CHANCE)
  529. {
  530. generateGlow = true;
  531. }
  532. break;
  533. case AbstractRefinePacket.GRADE_TOP:
  534. if (Rnd.get(1, 100) <= Config.AUGMENTATION_TOP_SKILL_CHANCE)
  535. {
  536. generateSkill = true;
  537. }
  538. if (Rnd.get(1, 100) <= Config.AUGMENTATION_TOP_GLOW_CHANCE)
  539. {
  540. generateGlow = true;
  541. }
  542. break;
  543. case AbstractRefinePacket.GRADE_ACC:
  544. if (Rnd.get(1, 100) <= Config.AUGMENTATION_ACC_SKILL_CHANCE)
  545. {
  546. generateSkill = true;
  547. }
  548. }
  549. if (!generateSkill && (Rnd.get(1, 100) <= Config.AUGMENTATION_BASESTAT_CHANCE))
  550. {
  551. stat34 = Rnd.get(BASESTAT_STR, BASESTAT_MEN);
  552. }
  553. // Second: decide which grade the augmentation result is going to have:
  554. // 0:yellow, 1:blue, 2:purple, 3:red
  555. // The chances used here are most likely custom,
  556. // what's known is: you can't have yellow with skill(or baseStatModifier)
  557. // noGrade stone can not have glow, mid only with skill, high has a chance(custom), top always glow
  558. int resultColor = Rnd.get(0, 100);
  559. if ((stat34 == 0) && !generateSkill)
  560. {
  561. if (resultColor <= ((15 * lifeStoneGrade) + 40))
  562. {
  563. resultColor = 1;
  564. }
  565. else
  566. {
  567. resultColor = 0;
  568. }
  569. }
  570. else
  571. {
  572. if ((resultColor <= ((10 * lifeStoneGrade) + 5)) || (stat34 != 0))
  573. {
  574. resultColor = 3;
  575. }
  576. else if (resultColor <= ((10 * lifeStoneGrade) + 10))
  577. {
  578. resultColor = 1;
  579. }
  580. else
  581. {
  582. resultColor = 2;
  583. }
  584. }
  585. // generate a skill if necessary
  586. L2Skill skill = null;
  587. if (generateSkill)
  588. {
  589. switch (resultColor)
  590. {
  591. case 1: // blue skill
  592. stat34 = _blueSkills.get(lifeStoneLevel).get(Rnd.get(0, _blueSkills.get(lifeStoneLevel).size() - 1));
  593. break;
  594. case 2: // purple skill
  595. stat34 = _purpleSkills.get(lifeStoneLevel).get(Rnd.get(0, _purpleSkills.get(lifeStoneLevel).size() - 1));
  596. break;
  597. case 3: // red skill
  598. stat34 = _redSkills.get(lifeStoneLevel).get(Rnd.get(0, _redSkills.get(lifeStoneLevel).size() - 1));
  599. break;
  600. }
  601. skill = _allSkills.get(stat34).getSkill();
  602. }
  603. // Third: Calculate the subblock offset for the chosen color,
  604. // and the level of the lifeStone
  605. // from large number of retail augmentations:
  606. // no skill part
  607. // Id for stat12:
  608. // A:1-910 B:911-1820 C:1821-2730 D:2731-3640 E:3641-4550 F:4551-5460 G:5461-6370 H:6371-7280
  609. // Id for stat34(this defines the color):
  610. // I:7281-8190(yellow) K:8191-9100(blue) L:10921-11830(yellow) M:11831-12740(blue)
  611. // you can combine I-K with A-D and L-M with E-H
  612. // using C-D or G-H Id you will get a glow effect
  613. // there seems no correlation in which grade use which Id except for the glowing restriction
  614. // skill part
  615. // Id for stat12:
  616. // same for no skill part
  617. // A same as E, B same as F, C same as G, D same as H
  618. // A - no glow, no grade LS
  619. // B - weak glow, mid grade LS?
  620. // C - glow, high grade LS?
  621. // D - strong glow, top grade LS?
  622. // is neither a skill nor basestat used for stat34? then generate a normal stat
  623. int offset;
  624. if (stat34 == 0)
  625. {
  626. int temp = Rnd.get(2, 3);
  627. int colorOffset = (resultColor * (10 * STAT_SUBBLOCKSIZE)) + (temp * STAT_BLOCKSIZE) + 1;
  628. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + colorOffset;
  629. stat34 = Rnd.get(offset, (offset + STAT_SUBBLOCKSIZE) - 1);
  630. if (generateGlow && (lifeStoneGrade >= 2))
  631. {
  632. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + ((temp - 2) * STAT_BLOCKSIZE) + (lifeStoneGrade * (10 * STAT_SUBBLOCKSIZE)) + 1;
  633. }
  634. else
  635. {
  636. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + ((temp - 2) * STAT_BLOCKSIZE) + (Rnd.get(0, 1) * (10 * STAT_SUBBLOCKSIZE)) + 1;
  637. }
  638. }
  639. else
  640. {
  641. if (!generateGlow)
  642. {
  643. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + (Rnd.get(0, 1) * STAT_BLOCKSIZE) + 1;
  644. }
  645. else
  646. {
  647. offset = (lifeStoneLevel * STAT_SUBBLOCKSIZE) + (Rnd.get(0, 1) * STAT_BLOCKSIZE) + (((lifeStoneGrade + resultColor) / 2) * (10 * STAT_SUBBLOCKSIZE)) + 1;
  648. }
  649. }
  650. stat12 = Rnd.get(offset, (offset + STAT_SUBBLOCKSIZE) - 1);
  651. if (Config.DEBUG)
  652. {
  653. _log.info("Augmentation success: stat12=" + stat12 + "; stat34=" + stat34 + "; resultColor=" + resultColor + "; level=" + lifeStoneLevel + "; grade=" + lifeStoneGrade);
  654. }
  655. return new L2Augmentation(((stat34 << 16) + stat12), skill);
  656. }
  657. private L2Augmentation generateRandomAccessoryAugmentation(int lifeStoneLevel, int bodyPart)
  658. {
  659. int stat12 = 0;
  660. int stat34 = 0;
  661. int base = 0;
  662. int skillsLength = 0;
  663. lifeStoneLevel = Math.min(lifeStoneLevel, 9);
  664. switch (bodyPart)
  665. {
  666. case L2Item.SLOT_LR_FINGER:
  667. base = ACC_RING_START + (ACC_RING_BLOCKSIZE * lifeStoneLevel);
  668. skillsLength = ACC_RING_SKILLS;
  669. break;
  670. case L2Item.SLOT_LR_EAR:
  671. base = ACC_EAR_START + (ACC_EAR_BLOCKSIZE * lifeStoneLevel);
  672. skillsLength = ACC_EAR_SKILLS;
  673. break;
  674. case L2Item.SLOT_NECK:
  675. base = ACC_NECK_START + (ACC_NECK_BLOCKSIZE * lifeStoneLevel);
  676. skillsLength = ACC_NECK_SKILLS;
  677. break;
  678. default:
  679. return null;
  680. }
  681. int resultColor = Rnd.get(0, 3);
  682. L2Skill skill = null;
  683. // first augmentation (stats only)
  684. stat12 = Rnd.get(ACC_STAT_SUBBLOCKSIZE);
  685. if (Rnd.get(1, 100) <= Config.AUGMENTATION_ACC_SKILL_CHANCE)
  686. {
  687. // second augmentation (skill)
  688. stat34 = base + Rnd.get(skillsLength);
  689. if (_allSkills.contains(stat34))
  690. {
  691. skill = _allSkills.get(stat34).getSkill();
  692. }
  693. }
  694. if (skill == null)
  695. {
  696. // second augmentation (stats)
  697. // calculating any different from stat12 value inside sub-block
  698. // starting from next and wrapping over using remainder
  699. stat34 = (stat12 + 1 + Rnd.get(ACC_STAT_SUBBLOCKSIZE - 1)) % ACC_STAT_SUBBLOCKSIZE;
  700. // this is a stats - skipping skills
  701. stat34 = base + skillsLength + (ACC_STAT_SUBBLOCKSIZE * resultColor) + stat34;
  702. }
  703. // stat12 has stats only
  704. stat12 = base + skillsLength + (ACC_STAT_SUBBLOCKSIZE * resultColor) + stat12;
  705. if (Config.DEBUG)
  706. {
  707. _log.info("Accessory augmentation success: stat12=" + stat12 + "; stat34=" + stat34 + "; level=" + lifeStoneLevel);
  708. }
  709. return new L2Augmentation(((stat34 << 16) + stat12), skill);
  710. }
  711. public static class AugStat
  712. {
  713. private final Stats _stat;
  714. private final float _value;
  715. public AugStat(Stats stat, float value)
  716. {
  717. _stat = stat;
  718. _value = value;
  719. }
  720. public Stats getStat()
  721. {
  722. return _stat;
  723. }
  724. public float getValue()
  725. {
  726. return _value;
  727. }
  728. }
  729. /**
  730. * Returns the stat and basestat boni for a given augmentation id
  731. * @param augmentationId
  732. * @return
  733. */
  734. public FastList<AugStat> getAugStatsById(int augmentationId)
  735. {
  736. FastList<AugStat> temp = new FastList<>();
  737. // An augmentation id contains 2 short values so we have to separate them here
  738. // both values contain a number from 1-16380, the first 14560 values are stats
  739. // the 14560 stats are divided into 4 blocks each holding 3640 values
  740. // each block contains 40 subblocks holding 91 stat values
  741. // the first 13 values are so called Solo-stats and they have the highest stat increase possible
  742. // after the 13 Solo-stats come 78 combined stats (thats every possible combination of the 13 solo stats)
  743. // the first 12 combined stats (14-26) is the stat 1 combined with stat 2-13
  744. // the next 11 combined stats then are stat 2 combined with stat 3-13 and so on...
  745. // to get the idea have a look @ optiondata_client-e.dat - thats where the data came from :)
  746. int stats[] = new int[2];
  747. stats[0] = 0x0000FFFF & augmentationId;
  748. stats[1] = (augmentationId >> 16);
  749. for (int i = 0; i < 2; i++)
  750. {
  751. // weapon augmentation - stats
  752. if ((stats[i] >= STAT_START) && (stats[i] <= STAT_END))
  753. {
  754. int base = stats[i] - STAT_START;
  755. int color = base / STAT_BLOCKSIZE; // 4 color blocks
  756. int subblock = base % STAT_BLOCKSIZE; // offset in color block
  757. int level = subblock / STAT_SUBBLOCKSIZE; // stat level (sub-block number)
  758. int stat = subblock % STAT_SUBBLOCKSIZE; // offset in sub-block - stat
  759. byte stat1 = STATS1_MAP[stat];
  760. byte stat2 = STATS2_MAP[stat];
  761. if (stat1 == stat2) // solo stat
  762. {
  763. AugmentationStat as = _augStats.get(color).get(stat1);
  764. temp.add(new AugStat(as.getStat(), as.getSingleStatValue(level)));
  765. }
  766. else
  767. // combined stat
  768. {
  769. AugmentationStat as = _augStats.get(color).get(stat1);
  770. temp.add(new AugStat(as.getStat(), as.getCombinedStatValue(level)));
  771. as = _augStats.get(color).get(stat2);
  772. temp.add(new AugStat(as.getStat(), as.getCombinedStatValue(level)));
  773. }
  774. }
  775. // its a base stat
  776. else if ((stats[i] >= BASESTAT_STR) && (stats[i] <= BASESTAT_MEN))
  777. {
  778. switch (stats[i])
  779. {
  780. case BASESTAT_STR:
  781. temp.add(new AugStat(Stats.STAT_STR, 1.0f));
  782. break;
  783. case BASESTAT_CON:
  784. temp.add(new AugStat(Stats.STAT_CON, 1.0f));
  785. break;
  786. case BASESTAT_INT:
  787. temp.add(new AugStat(Stats.STAT_INT, 1.0f));
  788. break;
  789. case BASESTAT_MEN:
  790. temp.add(new AugStat(Stats.STAT_MEN, 1.0f));
  791. break;
  792. }
  793. }
  794. // accessory augmentation
  795. // 3 areas for rings, earrings and necklaces
  796. // each area consist of 10 blocks (level)
  797. // each block has skills first (18 or 24 for necklaces)
  798. // and sub-block for stats next
  799. else if ((stats[i] >= ACC_START) && (stats[i] <= ACC_END))
  800. {
  801. int base, level, subblock;
  802. if (stats[i] <= ACC_RING_END) // rings area
  803. {
  804. base = stats[i] - ACC_RING_START; // calculate base offset
  805. level = base / ACC_RING_BLOCKSIZE; // stat level (block number)
  806. subblock = (base % ACC_RING_BLOCKSIZE) - ACC_RING_SKILLS; // skills first
  807. }
  808. else if (stats[i] <= ACC_EAR_END) // earrings area
  809. {
  810. base = stats[i] - ACC_EAR_START;
  811. level = base / ACC_EAR_BLOCKSIZE;
  812. subblock = (base % ACC_EAR_BLOCKSIZE) - ACC_EAR_SKILLS;
  813. }
  814. else
  815. // necklaces
  816. {
  817. base = stats[i] - ACC_NECK_START;
  818. level = base / ACC_NECK_BLOCKSIZE;
  819. subblock = (base % ACC_NECK_BLOCKSIZE) - ACC_NECK_SKILLS;
  820. }
  821. if (subblock >= 0) // stat, not skill
  822. {
  823. int color = subblock / ACC_STAT_SUBBLOCKSIZE;
  824. int stat = subblock % ACC_STAT_SUBBLOCKSIZE;
  825. byte stat1 = ACC_STATS1_MAP[stat];
  826. byte stat2 = ACC_STATS2_MAP[stat];
  827. if (stat1 == stat2) // solo
  828. {
  829. AugmentationStat as = _augAccStats.get(color).get(stat1);
  830. temp.add(new AugStat(as.getStat(), as.getSingleStatValue(level)));
  831. }
  832. else
  833. // combined
  834. {
  835. AugmentationStat as = _augAccStats.get(color).get(stat1);
  836. temp.add(new AugStat(as.getStat(), as.getCombinedStatValue(level)));
  837. as = _augAccStats.get(color).get(stat2);
  838. temp.add(new AugStat(as.getStat(), as.getCombinedStatValue(level)));
  839. }
  840. }
  841. }
  842. }
  843. return temp;
  844. }
  845. /**
  846. * @param augmentationId
  847. * @return skill by augmentation Id or null if not valid or not found.
  848. */
  849. public L2Skill getAugSkillById(int augmentationId)
  850. {
  851. final AugmentationSkill temp = _allSkills.get(augmentationId);
  852. if (temp == null)
  853. {
  854. return null;
  855. }
  856. return temp.getSkill();
  857. }
  858. private static class SingletonHolder
  859. {
  860. protected static final AugmentationData _instance = new AugmentationData();
  861. }
  862. }