HitConditionBonus.java 4.0 KB

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