KF2-YetAnotherScoreboard/YAS/Classes/YAS_RepInfoOwner.uc

273 lines
5.5 KiB
Ucode
Raw Normal View History

class YAS_RepInfoOwner extends ReplicationInfo;
2022-09-03 17:26:40 +00:00
2022-09-07 12:57:47 +00:00
var public YAS YAS;
2022-09-03 17:26:40 +00:00
2022-09-07 12:57:47 +00:00
var public repnotify E_LogLevel LogLevel;
var public repnotify SystemRank RankPlayer, RankAdmin;
2022-09-08 18:20:04 +00:00
var public repnotify String DynamicServerName, MessageOfTheDay;
2022-09-07 12:57:47 +00:00
var public repnotify bool UsesStats, Custom, PasswordRequired;
var public YAS_RepInfoPlayer PlayerRepInfo;
2022-09-07 12:57:47 +00:00
var private KFPlayerController KFPC;
2022-09-03 17:26:40 +00:00
var private YAS_ScoreBoard SC;
2022-09-07 12:57:47 +00:00
var private OnlineSubsystemSteamworks OSS;
2022-09-07 16:13:13 +00:00
var private Array<UniqueNetID> PendingGroupIDs;
2022-09-07 12:57:47 +00:00
const CheckGroupTimer = 0.2f;
const UpdatePlayerStatsTimer = 2.0f;
const MaxRetries = 3;
2022-09-07 12:57:47 +00:00
var private int Retries;
replication
{
if (bNetInitial)
2022-09-08 19:17:55 +00:00
LogLevel, RankPlayer, RankAdmin;
2022-09-07 12:57:47 +00:00
if (bNetDirty)
2022-09-08 19:17:55 +00:00
DynamicServerName, UsesStats, Custom, PasswordRequired, MessageOfTheDay;
2022-09-07 12:57:47 +00:00
}
2022-09-07 16:13:13 +00:00
public simulated function bool SafeDestroy()
{
`Log_Trace();
2022-09-07 16:13:13 +00:00
return (bPendingDelete || bDeleteMe || Destroy());
}
2022-09-07 12:57:47 +00:00
public simulated event ReplicatedEvent(name VarName)
{
`Log_Trace();
2022-09-07 12:57:47 +00:00
switch (VarName)
{
case 'LogLevel':
if (SC != None) SC.LogLevel = LogLevel;
break;
2022-09-07 12:57:47 +00:00
case 'RankPlayer':
if (SC != None) SC.RankPlayer = RankPlayer;
break;
2022-09-07 12:57:47 +00:00
case 'RankAdmin':
if (SC != None) SC.RankAdmin = RankAdmin;
break;
2022-09-07 12:57:47 +00:00
case 'DynamicServerName':
if (SC != None) SC.DynamicServerName = DynamicServerName;
break;
2022-09-08 18:20:04 +00:00
case 'MessageOfTheDay':
if (SC != None) SC.MessageOfTheDay = MessageOfTheDay;
break;
2022-09-07 12:57:47 +00:00
case 'UsesStats':
if (SC != None) SC.UsesStats = UsesStats;
break;
2022-09-07 12:57:47 +00:00
case 'Custom':
if (SC != None) SC.Custom = Custom;
break;
2022-09-07 12:57:47 +00:00
case 'PasswordRequired':
if (SC != None) SC.PasswordRequired = PasswordRequired;
break;
2022-09-07 12:57:47 +00:00
default:
super.ReplicatedEvent(VarName);
break;
}
}
2022-09-03 17:26:40 +00:00
public simulated event PreBeginPlay()
{
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-03 17:26:40 +00:00
if (bPendingDelete || bDeleteMe) return;
2022-09-03 17:26:40 +00:00
Super.PreBeginPlay();
2022-09-03 17:26:40 +00:00
if (Role < ROLE_Authority || WorldInfo.NetMode == NM_StandAlone)
{
GetScoreboard();
}
if (Role == ROLE_Authority || WorldInfo.NetMode == NM_StandAlone)
{
SetTimer(UpdatePlayerStatsTimer, true, nameof(UpdatePlayerStats));
}
2022-09-07 12:57:47 +00:00
GetOnlineSubsystem();
2022-09-03 17:26:40 +00:00
}
public simulated event PostBeginPlay()
{
if (bPendingDelete || bDeleteMe) return;
2022-09-03 17:26:40 +00:00
Super.PostBeginPlay();
}
public function UpdatePlayerStats()
{
if (GetKFPC() == None || KFPC.MatchStats == None) return;
if (WorldInfo.GRI == None || KFGameReplicationInfo(WorldInfo.GRI) == None) return;
// At the end of the wave, TotalDamageDealt is incremented by GetDamageDealtInWave(),
// but GetDamageDealtInWave() is not reset immediately.
// In order not to receive a short-term doubling of damage in statistics,
// Count damage only when the wave is active
if (KFGameReplicationInfo(WorldInfo.GRI).bWaveStarted)
{
PlayerRepInfo.DamageDealt = KFPC.MatchStats.TotalDamageDealt + KFPC.MatchStats.GetDamageDealtInWave();
}
}
2022-09-07 12:57:47 +00:00
public reliable client function CheckGroupRanks(String JoinedGroupIDs)
{
local Array<String> StringGroupIDs;
local String StringGroupID;
local UniqueNetId GroupUID;
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-07 12:57:47 +00:00
StringGroupIDs = SplitString(JoinedGroupIDs);
2022-09-07 12:57:47 +00:00
if (GetOnlineSubsystem() == None)
{
`Log_Error("Can't get online subsystem");
return;
}
2022-09-07 12:57:47 +00:00
foreach StringGroupIDs(StringGroupID)
{
if (OSS.Int64ToUniqueNetId(StringGroupID, GroupUID))
{
PendingGroupIDs.AddItem(GroupUID);
}
}
2022-09-07 12:57:47 +00:00
Retries = 0;
CheckGroupsCycle();
}
private simulated function CheckGroupsCycle()
{
local UniqueNetId GroupUID;
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-07 12:57:47 +00:00
if (Retries++ >= MaxRetries) return;
2022-09-07 12:57:47 +00:00
// CheckPlayerGroup doesn't return real values right away,
// so we do a dry run and a few checks just in case
foreach PendingGroupIDs(GroupUID) OSS.CheckPlayerGroup(GroupUID);
2022-09-07 12:57:47 +00:00
foreach PendingGroupIDs(GroupUID)
{
if (OSS.CheckPlayerGroup(GroupUID))
{
PendingGroupIDs.Length = 0;
ServerApplyMembership(GroupUID);
return;
}
}
2022-09-07 12:57:47 +00:00
SetTimer(0.2f, false, nameof(CheckGroupsCycle));
}
private reliable server function ServerApplyMembership(UniqueNetId GroupUID)
{
2022-09-07 16:13:13 +00:00
local Rank Rank;
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-07 16:13:13 +00:00
Rank = YAS.RankByGroupID(GroupUID);
if (Rank.RankID > 0)
2022-09-07 12:57:47 +00:00
{
PlayerRepInfo.Rank = Rank;
2022-09-03 17:26:40 +00:00
}
else
{
2022-09-07 16:13:13 +00:00
`Log_Warn("Cant find related rank for groupUID");
PlayerRepInfo.Rank = class'YAS_Types'.static.FromSystemRank(RankPlayer);
2022-09-07 12:57:47 +00:00
}
}
public simulated function KFPlayerController GetKFPC()
{
`Log_Trace();
2022-09-07 12:57:47 +00:00
if (KFPC != None) return KFPC;
2022-09-07 12:57:47 +00:00
KFPC = KFPlayerController(Owner);
2022-09-07 12:57:47 +00:00
if (KFPC == None && ROLE < ROLE_Authority)
{
KFPC = KFPlayerController(GetALocalPlayerController());
}
2022-09-07 12:57:47 +00:00
return KFPC;
}
private simulated function OnlineSubsystemSteamworks GetOnlineSubsystem()
{
`Log_Trace();
2022-09-07 12:57:47 +00:00
if (OSS == None)
{
OSS = OnlineSubsystemSteamworks(class'GameEngine'.static.GetOnlineSubsystem());
}
2022-09-07 12:57:47 +00:00
return OSS;
}
private reliable client function GetScoreboard()
{
`Log_Trace();
2022-09-07 12:57:47 +00:00
if (SC == None)
{
if (GetKFPC() != None && KFPC.myHUD != None)
{
SC = YAS_HUD(KFPC.myHUD).Scoreboard;
}
}
2022-09-07 12:57:47 +00:00
if (SC == None)
{
SetTimer(0.2f, false, nameof(GetScoreboard));
return;
2022-09-03 17:26:40 +00:00
}
2022-09-07 12:57:47 +00:00
InitScoreboard();
2022-09-03 17:26:40 +00:00
}
2022-09-07 12:57:47 +00:00
private simulated function InitScoreboard()
2022-09-03 17:26:40 +00:00
{
2022-09-07 12:57:47 +00:00
`Log_Trace();
2022-09-07 12:57:47 +00:00
if (SC == None) return;
2022-09-07 12:57:47 +00:00
SC.LogLevel = LogLevel;
SC.RankPlayer = RankPlayer;
SC.RankAdmin = RankAdmin;
SC.DynamicServerName = DynamicServerName;
SC.UsesStats = UsesStats;
SC.Custom = Custom;
SC.PasswordRequired = PasswordRequired;
2022-09-08 18:20:04 +00:00
SC.MessageOfTheDay = MessageOfTheDay;
2022-09-03 17:26:40 +00:00
}
defaultproperties
{
Role = ROLE_Authority
RemoteRole = ROLE_SimulatedProxy
2022-09-03 17:26:40 +00:00
bAlwaysRelevant = false
bOnlyRelevantToOwner = true
bSkipActorPropertyReplication = false
2022-09-07 12:57:47 +00:00
Retries = 0
}