KF2-YetAnotherScoreboard/YAS/Classes/YASRepInfo.uc

258 lines
5.1 KiB
Ucode
Raw Normal View History

2021-06-20 05:04:22 +00:00
class YASRepInfo extends ReplicationInfo;
2021-05-31 01:46:53 +00:00
2021-06-12 20:11:37 +00:00
`include(Build.uci)
`include(Logger.uci)
2021-06-12 18:44:20 +00:00
// Server vars
2021-06-20 05:04:22 +00:00
var public YASMut Mut;
2021-06-12 18:44:20 +00:00
// Client vars
var private KFScoreBoard SC;
var private OnlineSubsystemSteamworks SW;
2021-05-31 01:46:53 +00:00
2021-06-12 18:44:20 +00:00
// Fitst time replication
2021-06-13 03:17:40 +00:00
var public array<UIDRankRelation> SteamGroupRelations;
var private array<UIDRankRelation> RankRelations;
var public array<RankInfo> CustomRanks;
2021-06-08 23:43:00 +00:00
var public SCESettings Settings;
2021-06-12 18:44:20 +00:00
var public UIDRankRelation RankRelation; // Current player rank relation
2021-05-31 01:46:53 +00:00
2021-06-12 18:44:20 +00:00
var private int CustomRanksRepProgress, SteamGroupsRepProgress;
2021-05-31 04:04:26 +00:00
2021-06-12 18:44:20 +00:00
simulated event PostBeginPlay()
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
super.PostBeginPlay();
2021-05-31 04:04:26 +00:00
2021-06-12 18:44:20 +00:00
if (bDeleteMe) return;
2021-06-13 00:02:17 +00:00
if (Role < ROLE_Authority || WorldInfo.NetMode == NM_StandAlone)
2021-06-12 18:44:20 +00:00
{
2021-06-13 00:02:17 +00:00
GetScoreboard();
GetOnlineSubsystem();
2021-06-12 18:44:20 +00:00
}
}
2021-06-13 00:02:17 +00:00
private reliable client function GetScoreboard()
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
if (SC == None)
2021-06-20 05:04:22 +00:00
SC = YASHUD(GetALocalPlayerController().myHUD).Scoreboard;
2021-05-31 04:04:26 +00:00
2021-06-13 00:02:17 +00:00
if (SC == None)
SetTimer(0.1f, false, nameof(GetScoreboard));
else
ClearTimer(nameof(GetScoreboard));
}
private reliable client function GetOnlineSubsystem()
{
`callstack();
2021-06-12 18:44:20 +00:00
if (SW == None)
SW = OnlineSubsystemSteamworks(class'GameEngine'.static.GetOnlineSubsystem());
2021-06-13 00:02:17 +00:00
if (SW == None)
SetTimer(0.1f, false, nameof(GetOnlineSubsystem));
2021-06-12 18:44:20 +00:00
else
2021-06-13 00:02:17 +00:00
ClearTimer(nameof(GetOnlineSubsystem));
2021-06-12 18:44:20 +00:00
}
public function StartFirstTimeReplication()
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 02:12:30 +00:00
ClientAddSettings(Settings);
2021-06-12 18:44:20 +00:00
SetTimer(0.01f, true, nameof(ReplicateCustomRanks));
SetTimer(0.01f, true, nameof(ReplicateSteamGroupRelations));
}
2021-06-13 02:12:30 +00:00
private reliable client function ClientAddSettings(SCESettings Set)
{
`callstack();
Settings = Set;
ClientApplySettings();
}
2021-06-13 00:02:17 +00:00
private reliable client function ClientApplySettings()
{
`callstack();
if (SC == None)
{
SetTimer(0.1f, false, nameof(ClientApplySettings));
return;
}
ClearTimer(nameof(ClientApplySettings));
2021-06-13 03:31:09 +00:00
if (class'ScoreboardStyleClient'.default.bEnabled)
Settings.Style = class'ScoreboardStyleClient'.static.Settings();
2021-06-13 00:02:17 +00:00
SC.Settings = Settings;
}
private reliable client function ClientApplyCustomRanks()
{
`callstack();
if (SC == None)
{
SetTimer(0.1f, false, nameof(ClientApplyCustomRanks));
return;
}
ClearTimer(nameof(ClientApplyCustomRanks));
SC.CustomRanks = CustomRanks;
}
private reliable client function ClientApplyRankRelations()
2021-06-12 18:44:20 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
if (SC == None)
{
SetTimer(0.1f, false, nameof(ClientApplyRankRelations));
return;
}
ClearTimer(nameof(ClientApplyRankRelations));
SC.RankRelations = RankRelations;
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
private function ReplicateCustomRanks()
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
if (WorldInfo.NetMode != NM_StandAlone && CustomRanksRepProgress < CustomRanks.Length)
2021-05-31 04:04:26 +00:00
{
2021-06-12 18:44:20 +00:00
ClientAddCustomRank(CustomRanks[CustomRanksRepProgress]);
++CustomRanksRepProgress;
2021-05-31 04:04:26 +00:00
}
else
{
2021-06-12 18:44:20 +00:00
ClearTimer(nameof(ReplicateCustomRanks));
2021-06-13 00:02:17 +00:00
ClientApplyCustomRanks();
2021-05-31 04:04:26 +00:00
}
}
2021-06-12 18:44:20 +00:00
private reliable client function ClientAddCustomRank(RankInfo Rank)
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
CustomRanks.AddItem(Rank);
}
private function ReplicateSteamGroupRelations()
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
if (WorldInfo.NetMode != NM_StandAlone && SteamGroupsRepProgress < SteamGroupRelations.Length)
2021-05-31 04:04:26 +00:00
{
2021-06-12 18:44:20 +00:00
ClientAddSteamGroupRelation(SteamGroupRelations[SteamGroupsRepProgress]);
++SteamGroupsRepProgress;
2021-05-31 04:04:26 +00:00
}
else
{
2021-06-12 18:44:20 +00:00
ClearTimer(nameof(ReplicateSteamGroupRelations));
if (RankRelation.RankID == INDEX_NONE)
FindMyRankInSteamGroups();
2021-05-31 04:04:26 +00:00
}
}
2021-06-12 18:44:20 +00:00
private reliable client function ClientAddSteamGroupRelation(UIDRankRelation Rel)
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
SteamGroupRelations.AddItem(Rel);
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
private reliable client function FindMyRankInSteamGroups()
2021-05-31 04:04:26 +00:00
{
2021-06-12 18:44:20 +00:00
local UIDRankRelation SteamGroupRel;
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
2021-06-12 18:44:20 +00:00
foreach SteamGroupRelations(SteamGroupRel)
if (SW.CheckPlayerGroup(SteamGroupRel.UID))
RankRelation.RankID = SteamGroupRel.RankID;
2021-06-13 00:02:17 +00:00
2021-06-12 18:44:20 +00:00
if (RankRelation.RankID != INDEX_NONE)
ServerApplyRank(RankRelation.RankID);
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
private reliable server function ServerApplyRank(int RankID)
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
RankRelation.RankID = RankID;
Mut.UpdatePlayerRank(RankRelation);
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
public function AddRankRelation(UIDRankRelation Rel)
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
ClientAddRankRelation(Rel);
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
private reliable client function ClientAddRankRelation(UIDRankRelation Rel)
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
RankRelations.AddItem(Rel);
ClientApplyRankRelations();
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
public function RemoveRankRelation(UIDRankRelation Rel)
2021-05-31 01:46:53 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
ClientRemoveRankRelation(Rel);
2021-05-31 01:46:53 +00:00
}
2021-06-13 00:02:17 +00:00
private reliable client function ClientRemoveRankRelation(UIDRankRelation Rel)
2021-05-31 01:46:53 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
RankRelations.RemoveItem(Rel);
ClientApplyRankRelations();
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
public function UpdateRankRelation(UIDRankRelation Rel)
2021-05-31 04:04:26 +00:00
{
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-12 18:44:20 +00:00
ClientUpdateRankRelation(Rel);
2021-05-31 04:04:26 +00:00
}
2021-06-12 18:44:20 +00:00
private reliable client function ClientUpdateRankRelation(UIDRankRelation Rel)
2021-05-31 04:04:26 +00:00
{
2021-06-12 18:44:20 +00:00
local int Index;
2021-05-31 04:04:26 +00:00
2021-06-12 20:11:37 +00:00
`callstack();
2021-06-13 00:02:17 +00:00
Index = RankRelations.Find('UID', Rel.UID);
2021-06-12 18:44:20 +00:00
if (Index != INDEX_NONE)
2021-06-13 00:02:17 +00:00
RankRelations[Index] = Rel;
2021-06-13 01:57:20 +00:00
else
RankRelations.AddItem(Rel);
2021-06-13 00:02:17 +00:00
ClientApplyRankRelations();
2021-05-31 01:46:53 +00:00
}
defaultproperties
2021-06-13 00:02:17 +00:00
{
bAlwaysRelevant = false;
2021-06-13 01:57:20 +00:00
bOnlyRelevantToOwner = true;
Role = ROLE_Authority;
RemoteRole = ROLE_SimulatedProxy;
bSkipActorPropertyReplication = false; // This is needed, otherwise the client-to-server RPC fails
2021-06-13 00:02:17 +00:00
2021-06-12 18:44:20 +00:00
CustomRanksRepProgress = 0;
SteamGroupsRepProgress = 0;
2021-05-31 01:46:53 +00:00
}