HitConditionBonus.java 4.1 KB

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