source: binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs@ 277

Last change on this file since 277 was 276, checked in by alloc, 9 years ago

fixes 8_11_13_1

File size: 4.0 KB
RevLine 
[144]1using System;
2using System.Runtime.Serialization;
3using UnityEngine;
4
5namespace AllocsFixes.PersistentData
6{
7 [Serializable]
8 public class Player
9 {
10 private readonly string steamId;
11 private int entityId;
12 private string name;
13 private string ip;
14 private long totalPlayTime;
[146]15 [OptionalField]
16 private DateTime
17 lastOnline;
[144]18 private Inventory inventory;
[154]19 [OptionalField]
20 private int
21 lastPositionX, lastPositionY, lastPositionZ;
[233]22 [OptionalField]
23 private uint experience;
[273]24 [OptionalField]
25 private bool chatMuted;
26 [OptionalField]
27 private int maxChatLength;
[276]28 [OptionalField]
29 private uint expToNextLevel;
30 [OptionalField]
31 private int level;
32
[144]33 [NonSerialized]
34 private ClientInfo
35 clientInfo;
36
37 public string SteamID {
38 get { return steamId; }
39 }
40
41 public int EntityID {
42 get { return entityId; }
43 }
44
45 public string Name {
[161]46 get { return name == null ? string.Empty : name; }
[144]47 }
48
49 public string IP {
[161]50 get { return ip == null ? string.Empty : ip; }
[144]51 }
52
53 public Inventory Inventory {
54 get {
55 if (inventory == null)
56 inventory = new Inventory ();
57 return inventory;
58 }
59 }
60
61 public bool IsOnline {
62 get { return clientInfo != null; }
63 }
64
65 public ClientInfo ClientInfo {
66 get { return clientInfo; }
67 }
68
69 public EntityPlayer Entity {
70 get {
71 if (IsOnline) {
[230]72 return GameManager.Instance.World.Players.dict [clientInfo.entityId];
[144]73 } else {
74 return null;
75 }
76 }
77 }
78
79 public long TotalPlayTime {
80 get {
81 if (IsOnline) {
82 return totalPlayTime + (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
83 } else {
84 return totalPlayTime;
85 }
86 }
87 }
88
[146]89 public DateTime LastOnline {
90 get {
91 if (IsOnline)
92 return DateTime.Now;
93 else
94 return lastOnline;
95 }
96 }
97
[154]98 public Vector3i LastPosition {
99 get {
100 if (IsOnline)
101 return new Vector3i (Entity.GetPosition ());
102 else
103 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ);
104 }
105 }
106
[253]107 public bool LandProtectionActive {
108 get {
109 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance.GetPersistentPlayerList ().GetPlayerData (SteamID));
110 }
111 }
112
113 public float LandProtectionMultiplier {
114 get {
115 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance.GetPersistentPlayerList ().GetPlayerData (SteamID));
116 }
117 }
118
[276]119
120 // Deprecated
[233]121 public uint Experience {
122 get {
[276]123 return 0;
[233]124 }
125 }
126
127 public float Level {
128 get {
[276]129 float expForNextLevel = (int)Math.Min ((Progression.BaseExpToLevel * Mathf.Pow (Progression.ExpMultiplier, level + 1)), int.MaxValue);
130 float fLevel = level + 1f - ((float)expToNextLevel / expForNextLevel);
131 return fLevel;
[233]132 }
133 }
134
[273]135 public bool IsChatMuted{
136 get {
137 return chatMuted;
138 }
139 set {
140 chatMuted = value;
141 }
142 }
143
144 public int MaxChatLength {
145 get {
146 if (maxChatLength == 0 ) {
147 maxChatLength = 255;
148 }
149 return maxChatLength;
150 }
151 set {
152 maxChatLength = value;
153 }
154 }
155
[144]156 public void SetOffline ()
157 {
[161]158 if (clientInfo != null) {
159 Log.Out ("Player set to offline: " + steamId);
160 lastOnline = DateTime.Now;
[198]161 try {
162 Vector3i lastPos = new Vector3i (Entity.GetPosition ());
163 lastPositionX = lastPos.x;
164 lastPositionY = lastPos.y;
165 lastPositionZ = lastPos.z;
166 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
167 } catch (NullReferenceException) {
168 Log.Out ("Entity not available. Something seems to be wrong here...");
169 }
[161]170 clientInfo = null;
171 }
[144]172 }
173
174 public void SetOnline (ClientInfo ci)
175 {
176 Log.Out ("Player set to online: " + steamId);
177 clientInfo = ci;
[230]178 entityId = ci.entityId;
179 name = ci.playerName;
[228]180 ip = ci.ip;
[238]181 lastOnline = DateTime.Now;
[144]182 }
183
[233]184 public void Update (PlayerDataFile _pdf) {
[276]185 experience = 0;
186 expToNextLevel = _pdf.experience;
187 level = _pdf.level;
[233]188 inventory.Update (_pdf);
189 }
190
[144]191 public Player (string steamId)
192 {
193 this.steamId = steamId;
194 this.inventory = new Inventory ();
195 }
196
197
198 }
199}
Note: See TracBrowser for help on using the repository browser.