Elementals.java 6.9 KB

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