Advertisement
Guest User

Register

a guest
Feb 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Xml.Serialization;
  3. using V_MP.Server.API;
  4. using V_MP.Server.APIStreamed;
  5. namespace Atlantis_Gamemode
  6. {
  7.  
  8. /// <summary>
  9. /// Main class for handling all player commands and events
  10. /// </summary>
  11. public class RegisteredUser
  12. {
  13. public string Name { get; set; }
  14. public string UID;
  15. public uint SkinID;
  16. public Vector3 LoginPos;
  17. public System.DateTime lastDied;
  18.  
  19. public string Password { get; set; }
  20. public int AdminLevel;
  21. public int PlayerLevel;
  22. public int XP;
  23. public int Cash;
  24. public string JobName;
  25. public int PRoute;
  26. public int DRoute;
  27. public int HInsurance;
  28. public int JobID;
  29. public int PayCheck;
  30.  
  31. #region Licnese's
  32. public int TruckLicense;
  33. public int LightCargo;
  34. #endregion
  35. #region Inventory
  36. public int Phone;
  37. public int Suitcase;
  38. #endregion
  39.  
  40.  
  41. public List<Job.Requirements> AllPlayerLicences = new List<Job.Requirements>();
  42.  
  43. /// <summary>
  44. /// User's current job
  45. /// </summary>
  46. [XmlIgnore]
  47. public Job PlayerJob { get; private set; } = Job.NONE;
  48.  
  49. /// <summary>
  50. /// This session reference for API's User. (Simplifies RegisteredUser - User communication)
  51. /// </summary>
  52. [XmlIgnore]
  53. public User userReference;
  54.  
  55. public RegisteredUser(string name, string password)
  56. {
  57. Name = name;
  58. Password = Extensions.CalculateMD5Hash(password);
  59. AdminLevel = 0;
  60. PlayerLevel = 1;
  61. XP = 0;
  62. Cash = 1000;
  63. Phone = 0;
  64. Suitcase = 1;
  65. PRoute = 0;
  66. DRoute = 0;
  67. TruckLicense = 0;
  68. LightCargo = 0;
  69. HInsurance = 0;
  70. JobID = 0;
  71. JobName = "NONE";
  72. lastDied = System.DateTime.Now;
  73. SkinID = (uint)APIScript.PedHash.StripperLite;
  74. LoginPos = new Vector3(-1034.62f, -2732.11f, 13.756f);
  75. AllPlayerLicences.Add(Job.Requirements.NONE);
  76. }
  77.  
  78. /// <summary>
  79. /// Empty constructor for Xml
  80. /// </summary>
  81. public RegisteredUser()
  82. {
  83.  
  84. }
  85.  
  86. /// <summary>
  87. /// Returns true if user is admin (of any level)
  88. /// </summary>
  89. /// <returns></returns>
  90. public bool IsUserAdmin() => AdminLevel > 0;
  91.  
  92. /// <summary>
  93. /// Returns true if user is admin of level "<paramref name="level"/>" or above
  94. /// </summary>
  95. /// <param name="level"></param>
  96. /// <returns></returns>
  97. public bool IsUserAdminOfLevel(int level) => AdminLevel >= level;
  98.  
  99. /// <summary>
  100. /// Returns true only if user's admin level is <paramref name="level"/> exactly
  101. /// </summary>
  102. /// <param name="level"></param>
  103. /// <returns></returns>
  104. public bool IsUserAdminOfLevelEx(int level) => AdminLevel == level;
  105.  
  106. /// <summary>
  107. /// Returns true if user's job is Job.None or from-XML-loaded JobName is "NONE"
  108. /// </summary>
  109. /// <returns></returns>
  110. public bool HasJob() => PlayerJob != Job.NONE || JobName != "NONE";
  111.  
  112. /// <summary>
  113. /// Adds licence to <paramref name="AllPlayerLicences"/> to be able to pick up some jobs. This should be called
  114. /// from ingame licence-providing service (i.e. driving school)
  115. /// </summary>
  116. /// <param name="licence"></param>
  117. public void AddLicence(Job.Requirements licence)
  118. {
  119. if (AllPlayerLicences.Contains(licence)) return;
  120.  
  121. if (AllPlayerLicences.Contains(Job.Requirements.NONE))
  122. AllPlayerLicences.Remove(Job.Requirements.NONE);
  123.  
  124. AllPlayerLicences.Add(licence);
  125. }
  126.  
  127. /// <summary>
  128. /// Sets player job to <paramref name="job"/>
  129. /// </summary>
  130. /// <param name="job"></param>
  131. public void SetPlayerJob(Job job)
  132. {
  133. PlayerJob = job;
  134. }
  135.  
  136. /// <summary>
  137. /// Gives a licence to player by its <paramref name="id"/>
  138. /// </summary>
  139. /// <param name="id"></param>
  140. public bool GiveLicence(int id)
  141. {
  142. Job.Requirements lic = (Job.Requirements) id;
  143.  
  144. if (lic != Job.Requirements.NONE)
  145. {
  146. if (!AllPlayerLicences.Contains(lic))
  147. {
  148. AllPlayerLicences.Add((Job.Requirements) id);
  149. if (AllPlayerLicences.Contains(Job.Requirements.NONE)) AllPlayerLicences.Remove(Job.Requirements.NONE);
  150.  
  151. return true;
  152. }
  153. return false;
  154. }
  155.  
  156. return false;
  157. }
  158.  
  159. /// <summary>
  160. /// Removes all licences of this user
  161. /// </summary>
  162. public void RemoveAllLicences()
  163. {
  164. AllPlayerLicences.RemoveAll(x => true);
  165. AllPlayerLicences.Add(Job.Requirements.NONE);
  166. }
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement