LambdaCalc.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.skills.funcs;
  16. import com.l2jserver.gameserver.skills.Env;
  17. /**
  18. * @author mkizub
  19. *
  20. * TODO To change the template for this generated type comment go to
  21. * Window - Preferences - Java - Code Style - Code Templates
  22. */
  23. public final class LambdaCalc extends Lambda {
  24. public Func[] funcs;
  25. public LambdaCalc()
  26. {
  27. funcs = new Func[0];
  28. }
  29. @Override
  30. public double calc(Env env) {
  31. double saveValue = env.value;
  32. try
  33. {
  34. env.value = 0;
  35. for (Func f : funcs)
  36. f.calc(env);
  37. return env.value;
  38. } finally {
  39. env.value = saveValue;
  40. }
  41. }
  42. public void addFunc(Func f)
  43. {
  44. int len = funcs.length;
  45. Func[] tmp = new Func[len+1];
  46. for (int i=0; i < len; i++)
  47. tmp[i] = funcs[i];
  48. tmp[len] = f;
  49. funcs = tmp;
  50. }
  51. }