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

Last change on this file since 255 was 253, checked in by alloc, 9 years ago

Fixes 6_8_10

File size: 3.4 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;
[144]24 [NonSerialized]
25 private ClientInfo
26 clientInfo;
27
28 public string SteamID {
29 get { return steamId; }
30 }
31
32 public int EntityID {
33 get { return entityId; }
34 }
35
36 public string Name {
[161]37 get { return name == null ? string.Empty : name; }
[144]38 }
39
40 public string IP {
[161]41 get { return ip == null ? string.Empty : ip; }
[144]42 }
43
44 public Inventory Inventory {
45 get {
46 if (inventory == null)
47 inventory = new Inventory ();
48 return inventory;
49 }
50 }
51
52 public bool IsOnline {
53 get { return clientInfo != null; }
54 }
55
56 public ClientInfo ClientInfo {
57 get { return clientInfo; }
58 }
59
60 public EntityPlayer Entity {
61 get {
62 if (IsOnline) {
[230]63 return GameManager.Instance.World.Players.dict [clientInfo.entityId];
[144]64 } else {
65 return null;
66 }
67 }
68 }
69
70 public long TotalPlayTime {
71 get {
72 if (IsOnline) {
73 return totalPlayTime + (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
74 } else {
75 return totalPlayTime;
76 }
77 }
78 }
79
[146]80 public DateTime LastOnline {
81 get {
82 if (IsOnline)
83 return DateTime.Now;
84 else
85 return lastOnline;
86 }
87 }
88
[154]89 public Vector3i LastPosition {
90 get {
91 if (IsOnline)
92 return new Vector3i (Entity.GetPosition ());
93 else
94 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ);
95 }
96 }
97
[253]98 public bool LandProtectionActive {
99 get {
100 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance.GetPersistentPlayerList ().GetPlayerData (SteamID));
101 }
102 }
103
104 public float LandProtectionMultiplier {
105 get {
106 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance.GetPersistentPlayerList ().GetPlayerData (SteamID));
107 }
108 }
109
[233]110 public uint Experience {
111 get {
112 return experience;
113 }
114 }
115
116 public float Level {
117 get {
118 float perc = (float)experience / 600000;
119 perc = Mathf.Sqrt (perc);
120 return Mathf.Clamp ((perc * 60) + 1, 1, 60);
121 }
122 }
123
[144]124 public void SetOffline ()
125 {
[161]126 if (clientInfo != null) {
127 Log.Out ("Player set to offline: " + steamId);
128 lastOnline = DateTime.Now;
[198]129 try {
130 Vector3i lastPos = new Vector3i (Entity.GetPosition ());
131 lastPositionX = lastPos.x;
132 lastPositionY = lastPos.y;
133 lastPositionZ = lastPos.z;
134 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
135 } catch (NullReferenceException) {
136 Log.Out ("Entity not available. Something seems to be wrong here...");
137 }
[161]138 clientInfo = null;
139 }
[144]140 }
141
142 public void SetOnline (ClientInfo ci)
143 {
144 Log.Out ("Player set to online: " + steamId);
145 clientInfo = ci;
[230]146 entityId = ci.entityId;
147 name = ci.playerName;
[228]148 ip = ci.ip;
[238]149 lastOnline = DateTime.Now;
[144]150 }
151
[233]152 public void Update (PlayerDataFile _pdf) {
153 experience = _pdf.experience;
154 inventory.Update (_pdf);
155 }
156
[144]157 public Player (string steamId)
158 {
159 this.steamId = steamId;
160 this.inventory = new Inventory ();
161 }
162
163
164 }
165}
Note: See TracBrowser for help on using the repository browser.