DesireTable.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * $Header$
  3. *
  4. * $Author$
  5. * $Date$
  6. * $Revision$
  7. * $Log$
  8. * Revision 1.1.2.1 2005/04/08 08:03:40 luisantonioa
  9. * *** empty log message ***
  10. *
  11. * Revision 1.1 4/04/2005 17:15:07 luisantonioa
  12. * Created New Class
  13. *
  14. *
  15. * This program is free software: you can redistribute it and/or modify it under
  16. * the terms of the GNU General Public License as published by the Free Software
  17. * Foundation, either version 3 of the License, or (at your option) any later
  18. * version.
  19. *
  20. * This program is distributed in the hope that it will be useful, but WITHOUT
  21. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  22. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  23. * details.
  24. *
  25. * You should have received a copy of the GNU General Public License along with
  26. * this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. package com.l2jserver.gameserver.model;
  29. import java.util.Map;
  30. import javolution.util.FastMap;
  31. /**
  32. * This class ...
  33. *
  34. * @version $Revision$ $Date$
  35. */
  36. public class DesireTable
  37. {
  38. public static final DesireType[] DEFAULT_DESIRES = {DesireType.FEAR, DesireType.DISLIKE,
  39. DesireType.HATE, DesireType.DAMAGE};
  40. public enum DesireType {
  41. FEAR, DISLIKE, HATE, DAMAGE;
  42. }
  43. static class DesireValue
  44. {
  45. private float _value;
  46. DesireValue()
  47. {
  48. this(0f);
  49. }
  50. DesireValue(Float pValue)
  51. {
  52. _value = pValue;
  53. }
  54. public void addValue(float pValue)
  55. {
  56. _value += pValue;
  57. }
  58. public float getValue()
  59. {
  60. return _value;
  61. }
  62. }
  63. class Desires
  64. {
  65. private Map<DesireType, DesireValue> _desireTable;
  66. public Desires(DesireType... desireList)
  67. {
  68. _desireTable = new FastMap<DesireType, DesireValue>();
  69. for (DesireType desire : desireList)
  70. {
  71. _desireTable.put(desire, new DesireValue());
  72. }
  73. }
  74. public DesireValue getDesireValue(DesireType type)
  75. {
  76. return _desireTable.get(type);
  77. }
  78. public void addValue(DesireType type, float value)
  79. {
  80. DesireValue temp = getDesireValue(type);
  81. if (temp != null)
  82. {
  83. temp.addValue(value);
  84. }
  85. }
  86. public void createDesire(DesireType type)
  87. {
  88. _desireTable.put(type, new DesireValue());
  89. }
  90. public void deleteDesire(DesireType type)
  91. {
  92. _desireTable.remove(type);
  93. }
  94. }
  95. private Map<L2Object, Desires> _objectDesireTable;
  96. private Desires _generalDesires;
  97. private DesireType[] _desireTypes;
  98. public DesireTable(DesireType... desireList)
  99. {
  100. _desireTypes = desireList;
  101. _objectDesireTable = new FastMap<L2Object, Desires>();
  102. _generalDesires = new Desires(_desireTypes);
  103. }
  104. public float getDesireValue(DesireType type)
  105. {
  106. return _generalDesires.getDesireValue(type).getValue();
  107. }
  108. public float getDesireValue(L2Object object, DesireType type)
  109. {
  110. Desires desireList = _objectDesireTable.get(object);
  111. if (desireList == null) return 0f;
  112. return desireList.getDesireValue(type).getValue();
  113. }
  114. public void addDesireValue(DesireType type, float value)
  115. {
  116. _generalDesires.addValue(type, value);
  117. }
  118. public void addDesireValue(L2Object object, DesireType type, float value)
  119. {
  120. Desires desireList = _objectDesireTable.get(object);
  121. if (desireList != null) desireList.addValue(type, value);
  122. }
  123. public void createDesire(DesireType type)
  124. {
  125. _generalDesires.createDesire(type);
  126. }
  127. public void deleteDesire(DesireType type)
  128. {
  129. _generalDesires.deleteDesire(type);
  130. }
  131. public void createDesire(L2Object object, DesireType type)
  132. {
  133. Desires desireList = _objectDesireTable.get(object);
  134. if (desireList != null) desireList.createDesire(type);
  135. }
  136. public void deleteDesire(L2Object object, DesireType type)
  137. {
  138. Desires desireList = _objectDesireTable.get(object);
  139. if (desireList != null) desireList.deleteDesire(type);
  140. }
  141. public void addKnownObject(L2Object object)
  142. {
  143. if (object != null)
  144. {
  145. addKnownObject(object, DesireType.DISLIKE, DesireType.FEAR, DesireType.DAMAGE,
  146. DesireType.HATE);
  147. }
  148. }
  149. public void addKnownObject(L2Object object, DesireType... desireList)
  150. {
  151. if (object != null) _objectDesireTable.put(object, new Desires(desireList));
  152. }
  153. }