L2AccessLevel.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 com.l2jserver.gameserver.datatables.AdminTable;
  17. /**
  18. * @author FBIagent<br>
  19. */
  20. public class L2AccessLevel
  21. {
  22. /** The access level<br> */
  23. private int _accessLevel = 0;
  24. /** The access level name<br> */
  25. private String _name = null;
  26. /** Child access levels */
  27. L2AccessLevel _childsAccessLevel = null;
  28. /** Child access levels */
  29. private int _child = 0;
  30. /** The name color for the access level<br> */
  31. private int _nameColor = 0;
  32. /** The title color for the access level<br> */
  33. private int _titleColor = 0;
  34. /** Flag to determine if the access level has gm access<br> */
  35. private boolean _isGm = false;
  36. /** Flag for peace zone attack */
  37. private boolean _allowPeaceAttack = false;
  38. /** Flag for fixed res */
  39. private boolean _allowFixedRes = false;
  40. /** Flag for transactions */
  41. private boolean _allowTransaction = false;
  42. /** Flag for AltG commands */
  43. private boolean _allowAltG = false;
  44. /** Flag to give damage */
  45. private boolean _giveDamage = false;
  46. /** Flag to take aggro */
  47. private boolean _takeAggro = false;
  48. /** Flag to gain exp in party */
  49. private boolean _gainExp = false;
  50. public L2AccessLevel(StatsSet set)
  51. {
  52. _accessLevel = set.getInteger("level");
  53. _name = set.getString("name");
  54. _nameColor = Integer.decode("0x" + set.getString("nameColor", "FFFFFF"));
  55. _titleColor = Integer.decode("0x" + set.getString("titleColor", "FFFFFF"));
  56. _child = set.getInteger("childAccess", 0);
  57. _isGm = set.getBool("isGM", false);
  58. _allowPeaceAttack = set.getBool("allowPeaceAttack", false);
  59. _allowFixedRes = set.getBool("allowFixedRes", false);
  60. _allowTransaction = set.getBool("allowTransaction", true);
  61. _allowAltG = set.getBool("allowAltg", false);
  62. _giveDamage = set.getBool("giveDamage", true);
  63. _takeAggro = set.getBool("takeAggro", true);
  64. _gainExp = set.getBool("gainExp", true);
  65. }
  66. public L2AccessLevel()
  67. {
  68. _accessLevel = 0;
  69. _name = "User";
  70. _nameColor = Integer.decode("0xFFFFFF");
  71. _titleColor = Integer.decode("0xFFFFFF");
  72. _child = 0;
  73. _isGm = false;
  74. _allowPeaceAttack = false;
  75. _allowFixedRes = false;
  76. _allowTransaction = true;
  77. _allowAltG = false;
  78. _giveDamage = true;
  79. _takeAggro = true;
  80. _gainExp = true;
  81. }
  82. /**
  83. * Returns the access level<br>
  84. * <br>
  85. * @return int: access level<br>
  86. */
  87. public int getLevel()
  88. {
  89. return _accessLevel;
  90. }
  91. /**
  92. * Returns the access level name<br>
  93. * <br>
  94. * @return String: access level name<br>
  95. */
  96. public String getName()
  97. {
  98. return _name;
  99. }
  100. /**
  101. * Returns the name color of the access level<br>
  102. * <br>
  103. * @return int: the name color for the access level<br>
  104. */
  105. public int getNameColor()
  106. {
  107. return _nameColor;
  108. }
  109. /**
  110. * Returns the title color color of the access level<br>
  111. * <br>
  112. * @return int: the title color for the access level<br>
  113. */
  114. public int getTitleColor()
  115. {
  116. return _titleColor;
  117. }
  118. /**
  119. * Retuns if the access level has gm access or not<br>
  120. * <br>
  121. * @return boolean: true if access level have gm access, otherwise false<br>
  122. */
  123. public boolean isGm()
  124. {
  125. return _isGm;
  126. }
  127. /**
  128. * Returns if the access level is allowed to attack in peace zone or not<br>
  129. * <br>
  130. * @return boolean: true if the access level is allowed to attack in peace zone, otherwise false<br>
  131. */
  132. public boolean allowPeaceAttack()
  133. {
  134. return _allowPeaceAttack;
  135. }
  136. /**
  137. * Retruns if the access level is allowed to use fixed res or not<br>
  138. * <br>
  139. * @return true if the access level is allowed to use fixed res, otherwise false<br>
  140. */
  141. public boolean allowFixedRes()
  142. {
  143. return _allowFixedRes;
  144. }
  145. /**
  146. * Returns if the access level is allowed to perform transactions or not<br>
  147. * <br>
  148. * @return boolean: true if access level is allowed to perform transactions, otherwise false<br>
  149. */
  150. public boolean allowTransaction()
  151. {
  152. return _allowTransaction;
  153. }
  154. /**
  155. * Returns if the access level is allowed to use AltG commands or not<br>
  156. * <br>
  157. * @return boolean: true if access level is allowed to use AltG commands, otherwise false<br>
  158. */
  159. public boolean allowAltG()
  160. {
  161. return _allowAltG;
  162. }
  163. /**
  164. * Returns if the access level can give damage or not<br>
  165. * <br>
  166. * @return boolean: true if the access level can give damage, otherwise false<br>
  167. */
  168. public boolean canGiveDamage()
  169. {
  170. return _giveDamage;
  171. }
  172. /**
  173. * Returns if the access level can take aggro or not<br>
  174. * <br>
  175. * @return boolean: true if the access level can take aggro, otherwise false<br>
  176. */
  177. public boolean canTakeAggro()
  178. {
  179. return _takeAggro;
  180. }
  181. /**
  182. * Returns if the access level can gain exp or not<br>
  183. * <br>
  184. * @return boolean: true if the access level can gain exp, otherwise false<br>
  185. */
  186. public boolean canGainExp()
  187. {
  188. return _gainExp;
  189. }
  190. /**
  191. * Returns if the access level contains allowedAccess as child<br>
  192. * @param accessLevel as AccessLevel<br>
  193. * @return boolean: true if a child access level is equals to allowedAccess, otherwise false<br>
  194. */
  195. public boolean hasChildAccess(L2AccessLevel accessLevel)
  196. {
  197. if (_childsAccessLevel == null)
  198. {
  199. if (_child <= 0)
  200. {
  201. return false;
  202. }
  203. _childsAccessLevel = AdminTable.getInstance().getAccessLevel(_child);
  204. }
  205. return (_childsAccessLevel.getLevel() == accessLevel.getLevel() || _childsAccessLevel.hasChildAccess(accessLevel));
  206. }
  207. }