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 net.sf.l2j.gameserver.model;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.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. *
  144. * @return: true if the access level is allowed to use fixed res, otherwise false<br>
  145. */
  146. public boolean allowFixedRes()
  147. {
  148. return _allowFixedRes;
  149. }
  150. /**
  151. * Returns if the access level is allowed to perform transactions or not<br><br>
  152. *
  153. * @return boolean: true if access level is allowed to perform transactions, otherwise false<br>
  154. */
  155. public boolean allowTransaction()
  156. {
  157. return _allowTransaction;
  158. }
  159. /**
  160. * Returns if the access level is allowed to use AltG commands or not<br><br>
  161. *
  162. * @return boolean: true if access level is allowed to use AltG commands, otherwise false<br>
  163. */
  164. public boolean allowAltG()
  165. {
  166. return _allowAltG;
  167. }
  168. /**
  169. * Returns if the access level can give damage or not<br><br>
  170. *
  171. * @return boolean: true if the access level can give damage, otherwise false<br>
  172. */
  173. public boolean canGiveDamage()
  174. {
  175. return _giveDamage;
  176. }
  177. /**
  178. * Returns if the access level can take aggro or not<br><br>
  179. *
  180. * @return boolean: true if the access level can take aggro, otherwise false<br>
  181. */
  182. public boolean canTakeAggro()
  183. {
  184. return _takeAggro;
  185. }
  186. /**
  187. * Returns if the access level can gain exp or not<br><br>
  188. *
  189. * @return boolean: true if the access level can gain exp, otherwise false<br>
  190. */
  191. public boolean canGainExp()
  192. {
  193. return _gainExp;
  194. }
  195. /**
  196. * Returns if the access level contains allowedAccess as child<br><br>
  197. *
  198. * @param accessLevel as AccessLevel<br><br>
  199. *
  200. * @return boolean: true if a child access level is equals to allowedAccess, otherwise false<br>
  201. */
  202. public boolean hasChildAccess(L2AccessLevel accessLevel)
  203. {
  204. if (_childsAccessLevel == null)
  205. {
  206. if (_childs == null)
  207. return false;
  208. setChildAccess(_childs);
  209. for (L2AccessLevel childAccess : _childsAccessLevel)
  210. {
  211. if (childAccess != null && (childAccess.getLevel() == accessLevel.getLevel() || childAccess.hasChildAccess(accessLevel)))
  212. return true;
  213. }
  214. }
  215. else
  216. {
  217. for (L2AccessLevel childAccess : _childsAccessLevel)
  218. {
  219. if (childAccess != null && (childAccess.getLevel() == accessLevel.getLevel() || childAccess.hasChildAccess(accessLevel)))
  220. return true;
  221. }
  222. }
  223. return false;
  224. }
  225. private void setChildAccess(String childs)
  226. {
  227. String[] childsSplit = childs.split(";");
  228. _childsAccessLevel = new L2AccessLevel[childsSplit.length];
  229. for (int i = 0;i < childsSplit.length;++ i)
  230. {
  231. L2AccessLevel accessLevelInst = AccessLevels.getInstance().getAccessLevel(Integer.valueOf(childsSplit[i]));
  232. if (accessLevelInst == null)
  233. {
  234. _log.warning("AccessLevel: Undefined child access level " + childsSplit[i]);
  235. continue;
  236. }
  237. if (accessLevelInst.hasChildAccess(this))
  238. {
  239. _log.warning("AccessLevel: Child access tree overlapping for " + _name + " and " + accessLevelInst.getName());
  240. continue;
  241. }
  242. _childsAccessLevel[i] = accessLevelInst;
  243. }
  244. }
  245. }