AugmentationData.java 29 KB

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