HitConditionBonusData.java 4.4 KB

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