- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r351 r369 1 1 using System; 2 using System.Runtime.Serialization;3 2 using UnityEngine; 4 3 … … 6 5 [Serializable] 7 6 public class Player { 8 private readonly string steamId;7 private readonly PlatformUserIdentifierAbs platformId; 9 8 private int entityId; 10 9 private string name; … … 12 11 private long totalPlayTime; 13 12 14 [OptionalField]private DateTime lastOnline;13 private DateTime lastOnline; 15 14 16 15 private Inventory inventory; 17 16 18 [OptionalField]private int lastPositionX, lastPositionY, lastPositionZ;17 private int lastPositionX, lastPositionY, lastPositionZ; 19 18 20 [OptionalField] [Obsolete ("experience no longer available, use level and expToNextLevel instead")] 21 private uint experience; 22 23 [OptionalField] private bool chatMuted; 24 [OptionalField] private int maxChatLength; 25 [OptionalField] private string chatColor; 26 [OptionalField] private bool chatName; 27 [OptionalField] private uint expToNextLevel; 28 [OptionalField] private int level; 19 private bool chatMuted; 20 private int maxChatLength; 21 private string chatColor; 22 private bool chatName; 23 private uint expToNextLevel; 24 private int level; 29 25 30 26 [NonSerialized] private ClientInfo clientInfo; 31 27 32 public string SteamID { 33 get { return steamId; } 34 } 28 public PlatformUserIdentifierAbs PlatformId => platformId; 35 29 36 public int EntityID { 37 get { return entityId; } 38 } 30 public int EntityID => entityId; 39 31 40 public string Name { 41 get { return name == null ? string.Empty : name; } 42 } 32 public string Name => name ?? string.Empty; 43 33 44 public string IP { 45 get { return ip == null ? string.Empty : ip; } 46 } 34 public string IP => ip ?? string.Empty; 47 35 48 public Inventory Inventory { 49 get { 50 if (inventory == null) { 51 inventory = new Inventory (); 52 } 36 public Inventory Inventory => inventory ?? (inventory = new Inventory ()); 53 37 54 return inventory; 55 } 56 } 38 public bool IsOnline => clientInfo != null; 57 39 58 public bool IsOnline { 59 get { return clientInfo != null; } 60 } 40 public ClientInfo ClientInfo => clientInfo; 61 41 62 public ClientInfo ClientInfo { 63 get { return clientInfo; } 64 } 65 66 public EntityPlayer Entity { 67 get { 68 if (IsOnline) { 69 return GameManager.Instance.World.Players.dict [clientInfo.entityId]; 70 } 71 72 return null; 73 } 74 } 42 public EntityPlayer Entity => IsOnline ? GameManager.Instance.World.Players.dict [clientInfo.entityId] : null; 75 43 76 44 public long TotalPlayTime { … … 84 52 } 85 53 86 public DateTime LastOnline { 87 get { 88 if (IsOnline) { 89 return DateTime.Now; 90 } 54 public DateTime LastOnline => IsOnline ? DateTime.Now : lastOnline; 91 55 92 return lastOnline; 93 } 94 } 56 public Vector3i LastPosition => IsOnline ? new Vector3i (Entity.GetPosition ()) : new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 95 57 96 public Vector3i LastPosition { 97 get { 98 if (IsOnline) { 99 return new Vector3i (Entity.GetPosition ()); 100 } 58 public bool LandProtectionActive => 59 GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 60 .GetPersistentPlayerList ().GetPlayerData (PlatformId)); 101 61 102 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 103 } 104 } 105 106 public bool LandProtectionActive { 107 get { 108 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 109 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 110 } 111 } 112 113 public float LandProtectionMultiplier { 114 get { 115 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 116 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 117 } 118 } 119 120 121 [Obsolete ("Experience no longer available, use Level instead")] 122 public uint Experience { 123 get { return 0; } 124 } 62 public float LandProtectionMultiplier => 63 GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 64 .GetPersistentPlayerList ().GetPlayerData (PlatformId)); 125 65 126 66 public float Level { … … 135 75 136 76 public bool IsChatMuted { 137 get { return chatMuted; }138 set { chatMuted = value; }77 get => chatMuted; 78 set => chatMuted = value; 139 79 } 140 80 … … 147 87 return maxChatLength; 148 88 } 149 set { maxChatLength = value; }89 set => maxChatLength = value; 150 90 } 151 91 152 92 public string ChatColor { 153 93 get { 154 if ( chatColor == null || chatColor == "") {94 if (string.IsNullOrEmpty (chatColor)) { 155 95 chatColor = ""; 156 96 } … … 159 99 } 160 100 161 set { chatColor = value; }101 set => chatColor = value; 162 102 } 163 103 164 104 public bool ChatName { 165 get { return chatName; } 166 167 set { chatName = value; } 105 get => chatName; 106 set => chatName = value; 168 107 } 169 108 170 public Player ( string _steamId) {171 steamId = _steamId;109 public Player (PlatformUserIdentifierAbs _platformId) { 110 platformId = _platformId; 172 111 inventory = new Inventory (); 173 112 } … … 178 117 } 179 118 180 Log.Out ("Player set to offline: " + steamId);119 Log.Out ("Player set to offline: " + platformId); 181 120 lastOnline = DateTime.Now; 182 121 try { … … 194 133 195 134 public void SetOnline (ClientInfo _ci) { 196 Log.Out ("Player set to online: " + steamId);135 Log.Out ("Player set to online: " + platformId); 197 136 clientInfo = _ci; 198 137 entityId = _ci.entityId; … … 222 161 } 223 162 } 163 224 164 } 225 165 }
Note:
See TracChangeset
for help on using the changeset viewer.