Elementals.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 net.sf.l2j.gameserver.model;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.model.actor.L2Character;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.skills.Stats;
  20. import net.sf.l2j.gameserver.skills.funcs.FuncAdd;
  21. import net.sf.l2j.gameserver.skills.funcs.LambdaConst;
  22. public final class Elementals
  23. {
  24. private ElementalStatBoni _boni = null;
  25. public final static byte NONE = -1;
  26. public final static byte FIRE = 0;
  27. public final static byte WATER = 1;
  28. public final static byte WIND = 2;
  29. public final static byte EARTH = 3;
  30. public final static byte HOLY = 4;
  31. public final static byte DARK = 5;
  32. public final static int ENCHANT_CHANCE = Config.ENCHANT_CHANCE_ELEMENT;
  33. public final static int FIRST_WEAPON_BONUS = 20;
  34. public final static int NEXT_WEAPON_BONUS = 5;
  35. public final static int ARMOR_BONUS = 6;
  36. public final static int[] WEAPON_VALUES =
  37. {
  38. 0, // Level 1
  39. 25, // Level 2
  40. 75, // Level 3
  41. 150, // Level 4
  42. 175, // Level 5
  43. 225, // Level 6
  44. 300, // Level 7
  45. 325, // Level 8
  46. 375, // Level 9
  47. 450, // Level 10
  48. 475, // Level 11
  49. 525, // Level 12
  50. 600, // Level 13
  51. Integer.MAX_VALUE // TODO: Higher stones
  52. };
  53. public final static int[] ARMOR_VALUES =
  54. {
  55. 0, // Level 1
  56. 12, // Level 2
  57. 30, // Level 3
  58. 60, // Level 4
  59. 72, // Level 5
  60. 90, // Level 6
  61. 120, // Level 7
  62. 132, // Level 8
  63. 150, // Level 9
  64. 180, // Level 10
  65. 192, // Level 11
  66. 210, // Level 12
  67. 240, // Level 13
  68. Integer.MAX_VALUE // TODO: Higher stones
  69. };
  70. public final static int[] STONES =
  71. {
  72. 9546,
  73. 9547,
  74. 9549,
  75. 9548,
  76. 9551,
  77. 9550
  78. };
  79. public final static int[] CRYSTALS =
  80. {
  81. 9552,
  82. 9553,
  83. 9555,
  84. 9554,
  85. 9557,
  86. 9556
  87. };
  88. public final static int[] JEWELS =
  89. {
  90. 9558,
  91. 9559,
  92. 9561,
  93. 9560,
  94. 9563,
  95. 9562
  96. };
  97. public final static int[] ENERGIES =
  98. {
  99. 9564,
  100. 9565,
  101. 9567,
  102. 9566,
  103. 9569,
  104. 9568
  105. };
  106. private byte _element = NONE;
  107. private int _value = 0;
  108. public byte getElement()
  109. {
  110. return _element;
  111. }
  112. public void setElement(byte type)
  113. {
  114. _element = type;
  115. _boni.setElement(type);
  116. }
  117. public int getValue()
  118. {
  119. return _value;
  120. }
  121. public void setValue(int val)
  122. {
  123. _value = val;
  124. _boni.setValue(val);
  125. }
  126. public static String getElementName(byte element)
  127. {
  128. switch(element)
  129. {
  130. case FIRE:
  131. return "Fire";
  132. case WATER:
  133. return "Water";
  134. case WIND:
  135. return "Wind";
  136. case EARTH:
  137. return "Earth";
  138. case DARK:
  139. return "Dark";
  140. case HOLY:
  141. return "Holy";
  142. }
  143. return "None";
  144. }
  145. public static byte getElementId(String name)
  146. {
  147. String tmp = name.toLowerCase();
  148. if (tmp.equals("fire"))
  149. return FIRE;
  150. if (tmp.equals("water"))
  151. return WATER;
  152. if (tmp.equals("wind"))
  153. return WIND;
  154. if (tmp.equals("earth"))
  155. return EARTH;
  156. if (tmp.equals("dark"))
  157. return DARK;
  158. if (tmp.equals("holy"))
  159. return HOLY;
  160. return NONE;
  161. }
  162. public static byte getOppositeElement(byte element)
  163. {
  164. return (byte)((element % 2 == 0) ? (element + 1) : (element - 1));
  165. }
  166. @Override
  167. public String toString()
  168. {
  169. return getElementName(_element) + " +" + _value;
  170. }
  171. public Elementals(byte type, int value)
  172. {
  173. _element = type;
  174. _value = value;
  175. _boni = new ElementalStatBoni(_element, _value);
  176. }
  177. public class ElementalStatBoni
  178. {
  179. private byte _elementalType;
  180. private int _elementalValue;
  181. private boolean _active;
  182. public ElementalStatBoni(byte type, int value)
  183. {
  184. _elementalType = type;
  185. _elementalValue = value;
  186. _active = false;
  187. }
  188. public void applyBonus(L2PcInstance player, boolean isArmor)
  189. {
  190. // make sure the bonuses are not applied twice..
  191. if (_active)
  192. return;
  193. switch (_elementalType)
  194. {
  195. case FIRE:
  196. if (isArmor)
  197. player.addStatFunc(new FuncAdd(Stats.FIRE_RES, 0x40, this, new LambdaConst(_elementalValue)));
  198. else
  199. player.addStatFunc(new FuncAdd(Stats.FIRE_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  200. break;
  201. case WATER:
  202. if (isArmor)
  203. player.addStatFunc(new FuncAdd(Stats.WATER_RES, 0x40, this, new LambdaConst(_elementalValue)));
  204. else
  205. player.addStatFunc(new FuncAdd(Stats.WATER_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  206. break;
  207. case WIND:
  208. if (isArmor)
  209. player.addStatFunc(new FuncAdd(Stats.WIND_RES, 0x40, this, new LambdaConst(_elementalValue)));
  210. else
  211. player.addStatFunc(new FuncAdd(Stats.WIND_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  212. break;
  213. case EARTH:
  214. if (isArmor)
  215. player.addStatFunc(new FuncAdd(Stats.EARTH_RES, 0x40, this, new LambdaConst(_elementalValue)));
  216. else
  217. player.addStatFunc(new FuncAdd(Stats.EARTH_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  218. break;
  219. case DARK:
  220. if (isArmor)
  221. player.addStatFunc(new FuncAdd(Stats.DARK_RES, 0x40, this, new LambdaConst(_elementalValue)));
  222. else
  223. player.addStatFunc(new FuncAdd(Stats.DARK_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  224. break;
  225. case HOLY:
  226. if (isArmor)
  227. player.addStatFunc(new FuncAdd(Stats.HOLY_RES, 0x40, this, new LambdaConst(_elementalValue)));
  228. else
  229. player.addStatFunc(new FuncAdd(Stats.HOLY_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  230. break;
  231. }
  232. _active = true;
  233. }
  234. public void removeBonus(L2PcInstance player)
  235. {
  236. // make sure the bonuses are not removed twice
  237. if (!_active)
  238. return;
  239. ((L2Character) player).removeStatsOwner(this);
  240. _active = false;
  241. }
  242. public void setValue(int val)
  243. {
  244. _elementalValue = val;
  245. }
  246. public void setElement(byte type)
  247. {
  248. _elementalType = type;
  249. }
  250. }
  251. public void applyBonus(L2PcInstance player, boolean isArmor)
  252. {
  253. _boni.applyBonus(player, isArmor);
  254. }
  255. public void removeBonus(L2PcInstance player)
  256. {
  257. _boni.removeBonus(player);
  258. }
  259. public void updateBonus(L2PcInstance player, boolean isArmor)
  260. {
  261. _boni.removeBonus(player);
  262. _boni.applyBonus(player, isArmor);
  263. }
  264. }