2
0

HitConditionBonus.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2004-2014 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.datatables;
  20. import org.w3c.dom.NamedNodeMap;
  21. import org.w3c.dom.Node;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.GameTimeController;
  24. import com.l2jserver.gameserver.engines.DocumentParser;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. /**
  27. * This class load, holds and calculates the hit condition bonuses.
  28. * @author Nik
  29. */
  30. public final class HitConditionBonus extends DocumentParser
  31. {
  32. private int frontBonus = 0;
  33. private int sideBonus = 0;
  34. private int backBonus = 0;
  35. private int highBonus = 0;
  36. private int lowBonus = 0;
  37. private int darkBonus = 0;
  38. private int rainBonus = 0;
  39. /**
  40. * Instantiates a new hit condition bonus.
  41. */
  42. protected HitConditionBonus()
  43. {
  44. load();
  45. }
  46. @Override
  47. public void load()
  48. {
  49. parseDatapackFile("data/stats/hitConditionBonus.xml");
  50. _log.info(getClass().getSimpleName() + ": Loaded Hit Condition bonuses.");
  51. if (Config.DEBUG)
  52. {
  53. _log.info(getClass().getSimpleName() + ": Front bonus: " + frontBonus);
  54. _log.info(getClass().getSimpleName() + ": Side bonus: " + sideBonus);
  55. _log.info(getClass().getSimpleName() + ": Back bonus: " + backBonus);
  56. _log.info(getClass().getSimpleName() + ": High bonus: " + highBonus);
  57. _log.info(getClass().getSimpleName() + ": Low bonus: " + lowBonus);
  58. _log.info(getClass().getSimpleName() + ": Dark bonus: " + darkBonus);
  59. _log.info(getClass().getSimpleName() + ": Rain bonus: " + rainBonus);
  60. }
  61. }
  62. @Override
  63. protected void parseDocument()
  64. {
  65. final Node n = getCurrentDocument().getFirstChild();
  66. NamedNodeMap attrs;
  67. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  68. {
  69. attrs = d.getAttributes();
  70. switch (d.getNodeName())
  71. {
  72. case "front":
  73. frontBonus = parseInteger(attrs, "val");
  74. break;
  75. case "side":
  76. sideBonus = parseInteger(attrs, "val");
  77. break;
  78. case "back":
  79. backBonus = parseInteger(attrs, "val");
  80. break;
  81. case "high":
  82. highBonus = parseInteger(attrs, "val");
  83. break;
  84. case "low":
  85. lowBonus = parseInteger(attrs, "val");
  86. break;
  87. case "dark":
  88. darkBonus = parseInteger(attrs, "val");
  89. break;
  90. case "rain":
  91. rainBonus = parseInteger(attrs, "val");
  92. break;
  93. }
  94. }
  95. }
  96. /**
  97. * Gets the condition bonus.
  98. * @param attacker the attacking character.
  99. * @param target the attacked character.
  100. * @return the bonus of the attacker against the target.
  101. */
  102. public double getConditionBonus(L2Character attacker, L2Character target)
  103. {
  104. double mod = 100;
  105. // Get high or low bonus
  106. if ((attacker.getZ() - target.getZ()) > 50)
  107. {
  108. mod += highBonus;
  109. }
  110. else if ((attacker.getZ() - target.getZ()) < -50)
  111. {
  112. mod += lowBonus;
  113. }
  114. // Get weather bonus
  115. if (GameTimeController.getInstance().isNight())
  116. {
  117. mod += darkBonus;
  118. // else if () No rain support yet.
  119. // chance += hitConditionBonus.rainBonus;
  120. }
  121. // Get side bonus
  122. if (attacker.isBehindTarget())
  123. {
  124. mod += backBonus;
  125. }
  126. else if (attacker.isInFrontOfTarget())
  127. {
  128. mod += frontBonus;
  129. }
  130. else
  131. {
  132. mod += sideBonus;
  133. }
  134. // If (mod / 100) is less than 0, return 0, because we can't lower more than 100%.
  135. return Math.max(mod / 100, 0);
  136. }
  137. /**
  138. * Gets the single instance of HitConditionBonus.
  139. * @return single instance of HitConditionBonus
  140. */
  141. public static HitConditionBonus getInstance()
  142. {
  143. return SingletonHolder._instance;
  144. }
  145. private static class SingletonHolder
  146. {
  147. protected static final HitConditionBonus _instance = new HitConditionBonus();
  148. }
  149. }