HitConditionBonusData.java 4.5 KB

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