Elementals.java 6.3 KB

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