Line | |
---|
1 | using System;
|
---|
2 | using System.Runtime.Serialization;
|
---|
3 | using UnityEngine;
|
---|
4 |
|
---|
5 | namespace 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;
|
---|
15 | private Inventory inventory;
|
---|
16 | [NonSerialized]
|
---|
17 | private ClientInfo
|
---|
18 | clientInfo;
|
---|
19 |
|
---|
20 | public string SteamID {
|
---|
21 | get { return steamId; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public int EntityID {
|
---|
25 | get { return entityId; }
|
---|
26 | }
|
---|
27 |
|
---|
28 | public string Name {
|
---|
29 | get { return name; }
|
---|
30 | }
|
---|
31 |
|
---|
32 | public string IP {
|
---|
33 | get { return ip; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public Inventory Inventory {
|
---|
37 | get {
|
---|
38 | if (inventory == null)
|
---|
39 | inventory = new Inventory ();
|
---|
40 | return inventory;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public bool IsOnline {
|
---|
45 | get { return clientInfo != null; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public ClientInfo ClientInfo {
|
---|
49 | get { return clientInfo; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public EntityPlayer Entity {
|
---|
53 | get {
|
---|
54 | if (IsOnline) {
|
---|
55 | return CommonMappingFunctions.GetEntityPlayer (clientInfo);
|
---|
56 | } else {
|
---|
57 | return null;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public long TotalPlayTime {
|
---|
63 | get {
|
---|
64 | if (IsOnline) {
|
---|
65 | return totalPlayTime + (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
|
---|
66 | } else {
|
---|
67 | return totalPlayTime;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void SetOffline ()
|
---|
73 | {
|
---|
74 | Log.Out ("Player set to offline: " + steamId);
|
---|
75 | totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad);
|
---|
76 | clientInfo = null;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void SetOnline (ClientInfo ci)
|
---|
80 | {
|
---|
81 | Log.Out ("Player set to online: " + steamId);
|
---|
82 | clientInfo = ci;
|
---|
83 | entityId = CommonMappingFunctions.GetEntityID (ci);
|
---|
84 | name = CommonMappingFunctions.GetPlayerName (ci);
|
---|
85 | ip = ci.networkPlayer.ipAddress;
|
---|
86 | }
|
---|
87 |
|
---|
88 | public Player (string steamId)
|
---|
89 | {
|
---|
90 | this.steamId = steamId;
|
---|
91 | this.inventory = new Inventory ();
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | }
|
---|
96 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.