AggroInfo.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.model;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. /**
  22. * @author xban1x
  23. */
  24. public final class AggroInfo
  25. {
  26. private final L2Character _attacker;
  27. private int _hate = 0;
  28. private int _damage = 0;
  29. public AggroInfo(L2Character pAttacker)
  30. {
  31. _attacker = pAttacker;
  32. }
  33. public L2Character getAttacker()
  34. {
  35. return _attacker;
  36. }
  37. public int getHate()
  38. {
  39. return _hate;
  40. }
  41. public int checkHate(L2Character owner)
  42. {
  43. if (_attacker.isAlikeDead() || !_attacker.isVisible() || !owner.getKnownList().knowsObject(_attacker))
  44. {
  45. _hate = 0;
  46. }
  47. return _hate;
  48. }
  49. public void addHate(int value)
  50. {
  51. _hate = (int) Math.min(_hate + (long) value, 999999999);
  52. }
  53. public void stopHate()
  54. {
  55. _hate = 0;
  56. }
  57. public int getDamage()
  58. {
  59. return _damage;
  60. }
  61. public void addDamage(int value)
  62. {
  63. _damage = (int) Math.min(_damage + (long) value, 999999999);
  64. }
  65. @Override
  66. public final boolean equals(Object obj)
  67. {
  68. if (this == obj)
  69. {
  70. return true;
  71. }
  72. if (obj instanceof AggroInfo)
  73. {
  74. return (((AggroInfo) obj).getAttacker() == _attacker);
  75. }
  76. return false;
  77. }
  78. @Override
  79. public final int hashCode()
  80. {
  81. return _attacker.getObjectId();
  82. }
  83. }