AugmentationData.java 30 KB

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