HitConditionBonus.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 java.io.File;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import javax.xml.parsers.DocumentBuilderFactory;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.Node;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.GameTimeController;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. /**
  26. *
  27. * @author Nik
  28. *
  29. */
  30. public class HitConditionBonus
  31. {
  32. protected static final Logger _log = Logger.getLogger(HitConditionBonus.class.getName());
  33. private static int frontBonus = 0;
  34. private static int sideBonus = 0;
  35. private static int backBonus = 0;
  36. private static int highBonus = 0;
  37. private static int lowBonus = 0;
  38. private static int darkBonus = 0;
  39. //private static int rainBonus = 0;
  40. public static double getConditionBonus(L2Character attacker, L2Character target)
  41. {
  42. double mod = 100;
  43. // Get high or low bonus
  44. if (attacker.getZ() - target.getZ() > 50)
  45. mod += HitConditionBonus.highBonus;
  46. else if (attacker.getZ() - target.getZ() < -50)
  47. mod += HitConditionBonus.lowBonus;
  48. // Get weather bonus
  49. if (GameTimeController.getInstance().isNowNight())
  50. mod += HitConditionBonus.darkBonus;
  51. //else if () No rain support yet.
  52. //chance += hitConditionBonus.rainBonus;
  53. // Get side bonus
  54. if(attacker.isBehindTarget())
  55. mod += HitConditionBonus.backBonus;
  56. else if(attacker.isInFrontOfTarget())
  57. mod += HitConditionBonus.frontBonus;
  58. else
  59. mod += HitConditionBonus.sideBonus;
  60. // If (mod / 10) is less than 0, return 0, because we cant lower more than 100%.
  61. return Math.max(mod / 100, 0);
  62. }
  63. static
  64. {
  65. final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  66. factory.setIgnoringElementContentWhitespace(true);
  67. factory.setIgnoringComments(true);
  68. final File file = new File(Config.DATAPACK_ROOT, "data/stats/hitConditionBonus.xml");
  69. Document doc = null;
  70. if (file.exists())
  71. {
  72. try
  73. {
  74. doc = factory.newDocumentBuilder().parse(file);
  75. }
  76. catch (Exception e)
  77. {
  78. _log.log(Level.WARNING, "[hitConditionBonus] Could not parse file: " + e.getMessage(), e);
  79. }
  80. String name;
  81. for (Node list = doc.getFirstChild(); list != null; list = list.getNextSibling())
  82. {
  83. if ("hitConditionBonus".equalsIgnoreCase(list.getNodeName()) || "list".equalsIgnoreCase(list.getNodeName()))
  84. {
  85. for (Node cond = list.getFirstChild(); cond != null; cond = cond.getNextSibling())
  86. {
  87. int bonus = 0;
  88. name = cond.getNodeName();
  89. try
  90. {
  91. if (cond.hasAttributes())
  92. bonus = Integer.parseInt(cond.getAttributes().getNamedItem("val").getNodeValue());
  93. }
  94. catch (Exception e)
  95. {
  96. _log.log(Level.WARNING, "[hitConditionBonus] Could not parse condition: " + e.getMessage(), e);
  97. }
  98. finally
  99. {
  100. if ("front".equals(name))
  101. frontBonus = bonus;
  102. else if ("side".equals(name))
  103. sideBonus = bonus;
  104. else if ("back".equals(name))
  105. backBonus = bonus;
  106. else if ("high".equals(name))
  107. highBonus = bonus;
  108. else if ("low".equals(name))
  109. lowBonus = bonus;
  110. else if ("dark".equals(name))
  111. darkBonus = bonus;
  112. //else if ("rain".equals(name))
  113. //rainBonus = bonus;
  114. }
  115. }
  116. }
  117. }
  118. }
  119. else
  120. {
  121. throw new Error("[hitConditionBonus] File not found: "+file.getName());
  122. }
  123. }
  124. }