LambdaStats.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 LambdaStats extends Lambda {
  24. public enum StatsType
  25. {
  26. PLAYER_LEVEL,
  27. CUBIC_LEVEL,
  28. TARGET_LEVEL,
  29. PLAYER_MAX_HP,
  30. PLAYER_MAX_MP
  31. }
  32. private final StatsType _stat;
  33. public LambdaStats(StatsType stat)
  34. {
  35. _stat = stat;
  36. }
  37. @Override
  38. public double calc(Env env) {
  39. switch (_stat)
  40. {
  41. case PLAYER_LEVEL:
  42. if (env.player == null)
  43. return 1;
  44. return env.player.getLevel();
  45. case CUBIC_LEVEL:
  46. if(env.cubic == null)
  47. return 1;
  48. return env.cubic.getOwner().getLevel();
  49. case TARGET_LEVEL:
  50. if (env.target == null)
  51. return 1;
  52. return env.target.getLevel();
  53. case PLAYER_MAX_HP:
  54. if (env.player == null)
  55. return 1;
  56. return env.player.getMaxHp();
  57. case PLAYER_MAX_MP:
  58. if (env.player == null)
  59. return 1;
  60. return env.player.getMaxMp();
  61. }
  62. return 0;
  63. }
  64. }