File size: 2,632 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
enum EPSstatsFlags
{
	EMPTY,
};

class PlayerStats
{
	ref array<ref PlayerStatBase> m_PlayerStats;
	ref array<ref StatDebugObject> m_PlayerStatsDebug;
	
	//ref PlayerStatsPCO_current m_PCO = new PlayerStatsPCO_current();
	ref PCOHandlerStats m_PCOhandler = new PCOHandlerStats();
	
	ref Timer m_SyncTimer;
	Man m_Player;
	bool m_AllowLogs;
	string m_System = "Stats"; //debuging tag
	
	//int m_SystemVersion = 101;
	
	void PlayerStats(Man player)
	{
		Init(player);
	}

	void Init(Man player)
	{
		m_Player 		= player;
	}

	PlayerStatsPCO_Base GetPCO(int version = -1 )
	{
		return m_PCOhandler.GetPCO(version);
	}
	
	void ~PlayerStats()
	{
		//if( GetGame() && GetGame().IsDebugActions() ) GatherAllRecords();
	}
	
	
	PlayerStatBase GetStatObject(int id)
	{
		PlayerStatsPCO_Base pco = GetPCO();
		if ( pco )
		{
			return pco.GetStatObject(id);
		}
		else
		{
			return null;
		}
	}
	
/*
	array<ref PlayerStatBase> Get()
	{
		return m_PlayerStats;
	}
*/
	void SetAllowLogs(bool enable)
	{
		m_AllowLogs = enable;
	}

	bool GetAllowLogs()
	{
		return 	m_AllowLogs;	
	}
	
	void GetDebugInfo( array<ref StatDebugObject> objects, int flags )
	{
		/*
		for(int i = 0; i < m_PlayerStats.Count(); i++)
		{
			m_PlayerStats.Get(i).SerializeValue(objects, flags);
		}
		*/
	}
	
	void GatherAllRecords()
	{
		/*
		FileHandle file = OpenFile("$profile:StatRecords.log", FileMode.WRITE);
		
		FPrintln(file, "================================================================");
		FPrintln(file," ================== " + m_Player.ToString() +" ================== ");
		FPrintln(file, "================================================================");
		
		for(int i = 0; i < m_PlayerStats.Count(); i++)
		{
			array<PlayerStatRecord> records =  m_PlayerStats.Get(i).GetRecords();
			
			FPrintln(file, m_PlayerStats.Get(i).GetLabel() );
			
			for(int z = 0; z < records.Count(); z++)
			{
				PlayerStatRecord record = records.Get(z);
				string output = record.GetStringOutput();
				FPrintln(file, output);
			}
		}
		*/
	}
	
	void SaveStats( ParamsWriteContext ctx )
	{
		int current_version = GetGame().SaveVersion();
		PlayerStatsPCO_Base pco = GetPCO(current_version);
		
		if ( pco )
		{
			pco.OnStoreSave(ctx);
			//Print("Saving stats in version: "+ pco.GetVersion());
		}
		else
		{
			return;
		}
	}

	bool LoadStats( ParamsReadContext ctx, int version )
	{
		PlayerStatsPCO_Base pco = GetPCO(version);
		if (pco && pco.OnStoreLoad(ctx))
		{
			//Print("********* LoadStats loading version: " + pco.GetVersion());
			return true;
		}
		else
		{
			return false;
		}
		
	}

	void ResetAllStats()
	{
		GetPCO().ResetAllStats();
	}
}