File size: 3,184 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
class PlayerStatBase
{
int m_Type;
void OnStoreSave( ParamsWriteContext ctx );
bool OnStoreLoad( ParamsReadContext ctx);
void OnRPC(ParamsReadContext ctx);
float Get();
string GetLabel();
void SetByFloat(float value);
void SetByFloatEx(float value, string system = "" );
bool IsSynced();
array<PlayerStatRecord> GetRecords();
void Init(int id/*, PlayerStats manager*/);
void SerializeValue(array<ref StatDebugObject> objects, int flags);
float GetNormalized();
float GetMax();
float GetMin();
int GetType()
{
return m_Type;
}
};
class PlayerStat<Class T> extends PlayerStatBase
{
protected T m_MinValue;
protected T m_MaxValue;
protected T m_Value;
protected string m_ValueLabel;
protected int m_Flags;
ref array<PlayerStatRecord> m_Records;
PlayerStats m_Manager;
void PlayerStat(T min, T max,T init, string label, int flags)
{
m_MinValue = min;
m_MaxValue = max;
m_Value = init;
m_ValueLabel = label;
m_Flags = flags;
m_Records = new array<PlayerStatRecord>;
}
override void Init(int id/*, PlayerStats manager*/)
{
m_Type = id;
//m_Manager = manager;
}
override void SerializeValue(array<ref StatDebugObject> objects, int flags)
{
objects.Insert( new StatDebugObject(GetLabel(), Get(), eRemoteStatType.PLAYER_STATS) );
}
PlayerStats GetManager()
{
return m_Manager;
}
void Set( T value, string system = "" )
{
/*
Print("setting stat: " + this.GetLabel() + "| value:" +value.ToString());
if( this.GetLabel() == "Toxicity" )
{
DebugPrint.LogAndTrace("stack");
}
*/
if ( value > m_MaxValue )
{
m_Value = m_MaxValue;
}
else if (value < m_MinValue)
{
m_Value = m_MinValue;
}
else
{
m_Value = value;
}
//if( GetManager().GetAllowLogs() ) CreateRecord(value, system);
}
void SetByFloat(float value, string system = "" )
{
T f = value;
Set(f,system);
}
override void SetByFloatEx(float value, string system = "" )
{
SetByFloat(value, system);
}
/*
void SetByParam(Param param, string system = "" )
{
Class.CastTo(p1, param);
T v = p1.param1;
Set(v, system);
}
*/
void Add( T value, string system = "" )
{
Set(m_Value+value, system);
}
override float Get()
{
return m_Value;
}
override string GetLabel()
{
return m_ValueLabel;
}
override float GetMax()
{
return m_MaxValue;
}
override float GetMin()
{
return m_MinValue;
}
override float GetNormalized()
{
return Math.InverseLerp(GetMin(), GetMax(), Get());
}
override array<PlayerStatRecord> GetRecords()
{
return m_Records;
}
void CreateRecord(float value, string system)
{
m_Records.Insert( new PlayerStatRecord(value, GetGame().GetTime(), system ) );
}
override void OnStoreSave( ParamsWriteContext ctx )
{
//ctx.Write(m_ValueLabel);
//PrintString("saving " + GetLabel()+" value:" +m_Value);
ctx.Write(m_Value);
}
override bool OnStoreLoad( ParamsReadContext ctx)
{
//string name;
//ctx.Read(name);
T value;
if(ctx.Read(value))
{
m_Value = value;
}
else
{
return false;
}
//PrintString("loading " + GetLabel()+" value:" +m_Value);
return true;
}
} |