L2AccessLevel.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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.model;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.gameserver.datatables.AccessLevels;
  18. /**
  19. * @author FBIagent<br>
  20. */
  21. public class L2AccessLevel
  22. {
  23. /** The logger<br> */
  24. private static Logger _log = Logger.getLogger( L2AccessLevel.class.getName() );
  25. /** The access level<br> */
  26. private int _accessLevel = 0;
  27. /** The access level name<br> */
  28. private String _name = null;
  29. /** Child access levels */
  30. L2AccessLevel[] _childsAccessLevel = null;
  31. /** Child access levels */
  32. private String _childs = null;
  33. /** The name color for the access level<br> */
  34. private int _nameColor = 0;
  35. /** The title color for the access level<br> */
  36. private int _titleColor = 0;
  37. /** Flag to determine if the access level has gm access<br> */
  38. private boolean _isGm = false;
  39. /** Flag for peace zone attack */
  40. private boolean _allowPeaceAttack = false;
  41. /** Flag for fixed res */
  42. private boolean _allowFixedRes = false;
  43. /** Flag for transactions */
  44. private boolean _allowTransaction = false;
  45. /** Flag for AltG commands */
  46. private boolean _allowAltG = false;
  47. /** Flag to give damage */
  48. private boolean _giveDamage = false;
  49. /** Flag to take aggro */
  50. private boolean _takeAggro = false;
  51. /** Flag to gain exp in party */
  52. private boolean _gainExp = false;
  53. /**
  54. * Initializes members<br><br>
  55. *
  56. * @param accessLevel as int<br>
  57. * @param name as String<br>
  58. * @param nameColor as int<br>
  59. * @param titleColor as int<br>
  60. * @param childs as String<br>
  61. * @param isGm as boolean<br>
  62. * @param allowPeaceAttack as boolean<br>
  63. * @param allowFixedRes as boolean<br>
  64. * @param allowTransaction as boolean<br>
  65. * @param allowAltG as boolean<br>
  66. * @param giveDamage as boolean<br>
  67. * @param takeAggro as boolean<br>
  68. * @param gainExp as boolean<br>
  69. */
  70. public L2AccessLevel(int accessLevel, String name, int nameColor, int titleColor, String childs, boolean isGm,
  71. boolean allowPeaceAttack, boolean allowFixedRes, boolean allowTransaction, boolean allowAltG, boolean giveDamage, boolean takeAggro, boolean gainExp)
  72. {
  73. _accessLevel = accessLevel;
  74. _name = name;
  75. _nameColor = nameColor;
  76. _titleColor = titleColor;
  77. _childs = childs;
  78. _isGm = isGm;
  79. _allowPeaceAttack = allowPeaceAttack;
  80. _allowFixedRes = allowFixedRes;
  81. _allowTransaction = allowTransaction;
  82. _allowAltG = allowAltG;
  83. _giveDamage = giveDamage;
  84. _takeAggro = takeAggro;
  85. _gainExp = gainExp;
  86. }
  87. /**
  88. * Returns the access level<br><br>
  89. *
  90. * @return int: access level<br>
  91. */
  92. public int getLevel()
  93. {
  94. return _accessLevel;
  95. }
  96. /**
  97. * Returns the access level name<br><br>
  98. *
  99. * @return String: access level name<br>
  100. */
  101. public String getName()
  102. {
  103. return _name;
  104. }
  105. /**
  106. * Returns the name color of the access level<br><br>
  107. *
  108. * @return int: the name color for the access level<br>
  109. */
  110. public int getNameColor()
  111. {
  112. return _nameColor;
  113. }
  114. /**
  115. * Returns the title color color of the access level<br><br>
  116. *
  117. * @return int: the title color for the access level<br>
  118. */
  119. public int getTitleColor()
  120. {
  121. return _titleColor;
  122. }
  123. /**
  124. * Retuns if the access level has gm access or not<br><br>
  125. *
  126. * @return boolean: true if access level have gm access, otherwise false<br>
  127. */
  128. public boolean isGm()
  129. {
  130. return _isGm;
  131. }
  132. /**
  133. * Returns if the access level is allowed to attack in peace zone or not<br><br>
  134. *
  135. * @return boolean: true if the access level is allowed to attack in peace zone, otherwise false<br>
  136. */
  137. public boolean allowPeaceAttack()
  138. {
  139. return _allowPeaceAttack;
  140. }
  141. /**
  142. * Retruns if the access level is allowed to use fixed res or not<br><br>
  143. * @return true if the access level is allowed to use fixed res, otherwise false<br>
  144. */
  145. public boolean allowFixedRes()
  146. {
  147. return _allowFixedRes;
  148. }
  149. /**
  150. * Returns if the access level is allowed to perform transactions or not<br><br>
  151. *
  152. * @return boolean: true if access level is allowed to perform transactions, otherwise false<br>
  153. */
  154. public boolean allowTransaction()
  155. {
  156. return _allowTransaction;
  157. }
  158. /**
  159. * Returns if the access level is allowed to use AltG commands or not<br><br>
  160. *
  161. * @return boolean: true if access level is allowed to use AltG commands, otherwise false<br>
  162. */
  163. public boolean allowAltG()
  164. {
  165. return _allowAltG;
  166. }
  167. /**
  168. * Returns if the access level can give damage or not<br><br>
  169. *
  170. * @return boolean: true if the access level can give damage, otherwise false<br>
  171. */
  172. public boolean canGiveDamage()
  173. {
  174. return _giveDamage;
  175. }
  176. /**
  177. * Returns if the access level can take aggro or not<br><br>
  178. *
  179. * @return boolean: true if the access level can take aggro, otherwise false<br>
  180. */
  181. public boolean canTakeAggro()
  182. {
  183. return _takeAggro;
  184. }
  185. /**
  186. * Returns if the access level can gain exp or not<br><br>
  187. *
  188. * @return boolean: true if the access level can gain exp, otherwise false<br>
  189. */
  190. public boolean canGainExp()
  191. {
  192. return _gainExp;
  193. }
  194. /**
  195. * Returns if the access level contains allowedAccess as child<br><br>
  196. *
  197. * @param accessLevel as AccessLevel<br><br>
  198. *
  199. * @return boolean: true if a child access level is equals to allowedAccess, otherwise false<br>
  200. */
  201. public boolean hasChildAccess(L2AccessLevel accessLevel)
  202. {
  203. if (_childsAccessLevel == null)
  204. {
  205. if (_childs == null)
  206. return false;
  207. setChildAccess(_childs);
  208. for (L2AccessLevel childAccess : _childsAccessLevel)
  209. {
  210. if (childAccess != null && (childAccess.getLevel() == accessLevel.getLevel() || childAccess.hasChildAccess(accessLevel)))
  211. return true;
  212. }
  213. }
  214. else
  215. {
  216. for (L2AccessLevel childAccess : _childsAccessLevel)
  217. {
  218. if (childAccess != null && (childAccess.getLevel() == accessLevel.getLevel() || childAccess.hasChildAccess(accessLevel)))
  219. return true;
  220. }
  221. }
  222. return false;
  223. }
  224. private void setChildAccess(String childs)
  225. {
  226. String[] childsSplit = childs.split(";");
  227. _childsAccessLevel = new L2AccessLevel[childsSplit.length];
  228. for (int i = 0;i < childsSplit.length;++ i)
  229. {
  230. L2AccessLevel accessLevelInst = AccessLevels.getInstance().getAccessLevel(Integer.parseInt(childsSplit[i]));
  231. if (accessLevelInst == null)
  232. {
  233. _log.warning("AccessLevel: Undefined child access level " + childsSplit[i]);
  234. continue;
  235. }
  236. if (accessLevelInst.hasChildAccess(this))
  237. {
  238. _log.warning("AccessLevel: Child access tree overlapping for " + _name + " and " + accessLevelInst.getName());
  239. continue;
  240. }
  241. _childsAccessLevel[i] = accessLevelInst;
  242. }
  243. }
  244. }