AttackTrait.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.effecthandlers;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import java.util.Map.Entry;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.gameserver.model.actor.stat.CharStat;
  25. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  26. import com.l2jserver.gameserver.model.effects.L2Effect;
  27. import com.l2jserver.gameserver.model.effects.L2EffectType;
  28. import com.l2jserver.gameserver.model.stats.Env;
  29. import com.l2jserver.gameserver.model.stats.TraitType;
  30. /**
  31. * Attack Trait effect implementation
  32. * @author Nos
  33. */
  34. public class AttackTrait extends L2Effect
  35. {
  36. private static final Logger _log = Logger.getLogger(AttackTrait.class.getName());
  37. private final Map<TraitType, Float> _attackTraits = new HashMap<>();
  38. /**
  39. * @param env
  40. * @param template
  41. */
  42. public AttackTrait(Env env, EffectTemplate template)
  43. {
  44. super(env, template);
  45. if (template.hasParameters())
  46. {
  47. for (Entry<String, Object> param : template.getParameters().getSet().entrySet())
  48. {
  49. try
  50. {
  51. final TraitType traitType = TraitType.valueOf(param.getKey());
  52. final float value = (Float.parseFloat((String) param.getValue()) + 100) / 100;
  53. _attackTraits.put(traitType, value);
  54. }
  55. catch (NumberFormatException e)
  56. {
  57. _log.warning(getClass().getSimpleName() + ": value of " + param.getKey() + " enum must be float value " + param.getValue() + " found.");
  58. }
  59. catch (Exception e)
  60. {
  61. _log.warning(getClass().getSimpleName() + ": value of L2TraitType enum required but found: " + param.getValue());
  62. }
  63. }
  64. }
  65. else
  66. {
  67. _log.warning(getClass().getSimpleName() + ": must have parameters.");
  68. }
  69. }
  70. @Override
  71. public L2EffectType getEffectType()
  72. {
  73. return L2EffectType.NONE;
  74. }
  75. @Override
  76. public boolean onStart()
  77. {
  78. final CharStat charStat = getEffected().getStat();
  79. synchronized (charStat.getAttackTraits())
  80. {
  81. for (Entry<TraitType, Float> trait : _attackTraits.entrySet())
  82. {
  83. charStat.getAttackTraits()[trait.getKey().getId()] *= trait.getValue();
  84. charStat.getAttackTraitsCount()[trait.getKey().getId()]++;
  85. }
  86. }
  87. return true;
  88. }
  89. @Override
  90. public void onExit()
  91. {
  92. final CharStat charStat = getEffected().getStat();
  93. synchronized (charStat.getAttackTraits())
  94. {
  95. for (Entry<TraitType, Float> trait : _attackTraits.entrySet())
  96. {
  97. charStat.getAttackTraits()[trait.getKey().getId()] /= trait.getValue();
  98. charStat.getAttackTraitsCount()[trait.getKey().getId()]--;
  99. }
  100. }
  101. }
  102. }