Elementals.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.model;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.model.actor.L2Character;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.skills.Stats;
  20. import com.l2jserver.gameserver.skills.funcs.FuncAdd;
  21. import com.l2jserver.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. public final static int[] ROUGHORES = {
  107. 10521,
  108. 10522,
  109. 10524,
  110. 10523,
  111. 10526,
  112. 10525
  113. };
  114. private byte _element = NONE;
  115. private int _value = 0;
  116. public byte getElement()
  117. {
  118. return _element;
  119. }
  120. public void setElement(byte type)
  121. {
  122. _element = type;
  123. _boni.setElement(type);
  124. }
  125. public int getValue()
  126. {
  127. return _value;
  128. }
  129. public void setValue(int val)
  130. {
  131. _value = val;
  132. _boni.setValue(val);
  133. }
  134. public static String getElementName(byte element)
  135. {
  136. switch(element)
  137. {
  138. case FIRE:
  139. return "Fire";
  140. case WATER:
  141. return "Water";
  142. case WIND:
  143. return "Wind";
  144. case EARTH:
  145. return "Earth";
  146. case DARK:
  147. return "Dark";
  148. case HOLY:
  149. return "Holy";
  150. }
  151. return "None";
  152. }
  153. public static byte getElementId(String name)
  154. {
  155. String tmp = name.toLowerCase();
  156. if (tmp.equals("fire"))
  157. return FIRE;
  158. if (tmp.equals("water"))
  159. return WATER;
  160. if (tmp.equals("wind"))
  161. return WIND;
  162. if (tmp.equals("earth"))
  163. return EARTH;
  164. if (tmp.equals("dark"))
  165. return DARK;
  166. if (tmp.equals("holy"))
  167. return HOLY;
  168. return NONE;
  169. }
  170. public static byte getOppositeElement(byte element)
  171. {
  172. return (byte)((element % 2 == 0) ? (element + 1) : (element - 1));
  173. }
  174. @Override
  175. public String toString()
  176. {
  177. return getElementName(_element) + " +" + _value;
  178. }
  179. public Elementals(byte type, int value)
  180. {
  181. _element = type;
  182. _value = value;
  183. _boni = new ElementalStatBoni(_element, _value);
  184. }
  185. public class ElementalStatBoni
  186. {
  187. private byte _elementalType;
  188. private int _elementalValue;
  189. private boolean _active;
  190. public ElementalStatBoni(byte type, int value)
  191. {
  192. _elementalType = type;
  193. _elementalValue = value;
  194. _active = false;
  195. }
  196. public void applyBonus(L2PcInstance player, boolean isArmor)
  197. {
  198. // make sure the bonuses are not applied twice..
  199. if (_active)
  200. return;
  201. switch (_elementalType)
  202. {
  203. case FIRE:
  204. if (isArmor)
  205. player.addStatFunc(new FuncAdd(Stats.FIRE_RES, 0x40, this, new LambdaConst(_elementalValue)));
  206. else
  207. player.addStatFunc(new FuncAdd(Stats.FIRE_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  208. break;
  209. case WATER:
  210. if (isArmor)
  211. player.addStatFunc(new FuncAdd(Stats.WATER_RES, 0x40, this, new LambdaConst(_elementalValue)));
  212. else
  213. player.addStatFunc(new FuncAdd(Stats.WATER_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  214. break;
  215. case WIND:
  216. if (isArmor)
  217. player.addStatFunc(new FuncAdd(Stats.WIND_RES, 0x40, this, new LambdaConst(_elementalValue)));
  218. else
  219. player.addStatFunc(new FuncAdd(Stats.WIND_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  220. break;
  221. case EARTH:
  222. if (isArmor)
  223. player.addStatFunc(new FuncAdd(Stats.EARTH_RES, 0x40, this, new LambdaConst(_elementalValue)));
  224. else
  225. player.addStatFunc(new FuncAdd(Stats.EARTH_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  226. break;
  227. case DARK:
  228. if (isArmor)
  229. player.addStatFunc(new FuncAdd(Stats.DARK_RES, 0x40, this, new LambdaConst(_elementalValue)));
  230. else
  231. player.addStatFunc(new FuncAdd(Stats.DARK_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  232. break;
  233. case HOLY:
  234. if (isArmor)
  235. player.addStatFunc(new FuncAdd(Stats.HOLY_RES, 0x40, this, new LambdaConst(_elementalValue)));
  236. else
  237. player.addStatFunc(new FuncAdd(Stats.HOLY_POWER, 0x40, this, new LambdaConst(_elementalValue)));
  238. break;
  239. }
  240. _active = true;
  241. }
  242. public void removeBonus(L2PcInstance player)
  243. {
  244. // make sure the bonuses are not removed twice
  245. if (!_active)
  246. return;
  247. ((L2Character) player).removeStatsOwner(this);
  248. _active = false;
  249. }
  250. public void setValue(int val)
  251. {
  252. _elementalValue = val;
  253. }
  254. public void setElement(byte type)
  255. {
  256. _elementalType = type;
  257. }
  258. }
  259. public void applyBonus(L2PcInstance player, boolean isArmor)
  260. {
  261. _boni.applyBonus(player, isArmor);
  262. }
  263. public void removeBonus(L2PcInstance player)
  264. {
  265. _boni.removeBonus(player);
  266. }
  267. public void updateBonus(L2PcInstance player, boolean isArmor)
  268. {
  269. _boni.removeBonus(player);
  270. _boni.applyBonus(player, isArmor);
  271. }
  272. }