KF2-Server-Extension/ServerExtMut/Classes/ExtStatList.uc

108 lines
2.9 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
Class ExtStatList extends Object
config(ServerExtStats)
abstract;
struct FTopPlayers
{
var config string N,Id;
var config int V;
};
var config array<FTopPlayers> TopPlaytimes,TopKills,TopExp;
2020-11-28 20:04:55 +00:00
static final function SetTopPlayers(ExtPlayerController Other)
2017-10-20 02:00:49 +00:00
{
local ExtPerkManager PM;
local bool bDirty;
PM = Other.ActivePerkManager;
bDirty = CheckBestTrack(Other.PlayerReplicationInfo,PM.TotalPlayTime,Default.TopPlaytimes);
bDirty = CheckBestTrack(Other.PlayerReplicationInfo,PM.TotalKills,Default.TopKills) || bDirty;
bDirty = CheckBestTrack(Other.PlayerReplicationInfo,PM.TotalEXP,Default.TopExp) || bDirty;
2020-11-28 20:12:58 +00:00
if (bDirty)
2017-10-20 02:00:49 +00:00
StaticSaveConfig();
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static final function bool CheckBestTrack(PlayerReplicationInfo PRI, int Value, out array<FTopPlayers> V)
2017-10-20 02:00:49 +00:00
{
local string S;
local int i,l;
S = class'OnlineSubsystem'.Static.UniqueNetIdToString(PRI.UniqueId);
l = class'ServerExtMut'.Default.MaxTopPlayers;
2020-11-28 20:12:58 +00:00
if (V.Length>l) // See if list has overflown incase an admin has changed the max stats value.
2017-10-20 02:00:49 +00:00
V.Length = l;
i = V.Find('ID',S); // First see if we have an entry from before.
2020-11-28 20:12:58 +00:00
if (i>=0)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (V[i].V==Value) // Stat unchanged.
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (V[i].N!=PRI.PlayerName) // Name has changed, update that.
2017-10-20 02:00:49 +00:00
{
V[i].N = PRI.PlayerName;
return true;
}
return false;
}
// Remove entry and insert it back in list only if rank changed.
2020-11-28 20:12:58 +00:00
if ((i>0 && V[i-1].V<Value) || (i<(V.Length-1) && V[i+1].V>Value))
2017-10-20 02:00:49 +00:00
V.Remove(i,1);
else // No change in rank.
{
2020-11-28 20:12:58 +00:00
if (V[i].N!=PRI.PlayerName) // Name has changed, update that.
2017-10-20 02:00:49 +00:00
{
V[i].N = PRI.PlayerName;
return true;
}
return false;
}
}
2020-11-28 20:12:58 +00:00
for (i=0; i<l; ++i)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (i==V.Length || V[i].V<Value) // At final entry, or has higher value then this ranked player.
2017-10-20 02:00:49 +00:00
{
V.Insert(i,1);
V[i].N = PRI.PlayerName;
V[i].V = Value;
V[i].ID = S;
2020-11-28 20:12:58 +00:00
if (V.Length>l) // See if list has overflown.
2017-10-20 02:00:49 +00:00
V.Length = l;
return true;
}
}
return false;
}
2020-11-28 20:04:55 +00:00
static final function bool GetStat(ExtPlayerController PC, byte ListNum, int StatIndex)
2017-10-20 02:00:49 +00:00
{
local UniqueNetId ID;
2020-11-28 20:12:58 +00:00
switch (ListNum)
2017-10-20 02:00:49 +00:00
{
case 0:
2020-11-28 20:12:58 +00:00
if (StatIndex>=Default.TopPlaytimes.Length)
2017-10-20 02:00:49 +00:00
return false;
class'OnlineSubsystem'.Static.StringToUniqueNetId(Default.TopPlaytimes[StatIndex].ID,ID);
PC.ClientGetStat(ListNum,false,Default.TopPlaytimes[StatIndex].N,ID,Default.TopPlaytimes[StatIndex].V);
return true;
case 1:
2020-11-28 20:12:58 +00:00
if (StatIndex>=Default.TopKills.Length)
2017-10-20 02:00:49 +00:00
return false;
class'OnlineSubsystem'.Static.StringToUniqueNetId(Default.TopKills[StatIndex].ID,ID);
PC.ClientGetStat(ListNum,false,Default.TopKills[StatIndex].N,ID,Default.TopKills[StatIndex].V);
return true;
case 2:
2020-11-28 20:12:58 +00:00
if (StatIndex>=Default.TopExp.Length)
2017-10-20 02:00:49 +00:00
return false;
class'OnlineSubsystem'.Static.StringToUniqueNetId(Default.TopExp[StatIndex].ID,ID);
PC.ClientGetStat(ListNum,false,Default.TopExp[StatIndex].N,ID,Default.TopExp[StatIndex].V);
return true;
default:
return false;
}
}