From 821821931274ae9b7e286c62a896cd71837929e6 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Fri, 13 May 2022 10:02:34 +0300 Subject: [PATCH] preloadcontent --- ZedSpawner/Classes/KFGI_Access.uc | 17 ++++++ ZedSpawner/Classes/ZedSpawner.uc | 81 ++++++++++++++++++++----- ZedSpawner/Classes/ZedSpawnerMut.uc | 14 +++++ ZedSpawner/Classes/ZedSpawnerRepLink.uc | 61 +++++++++++++++++++ 4 files changed, 158 insertions(+), 15 deletions(-) create mode 100644 ZedSpawner/Classes/KFGI_Access.uc create mode 100644 ZedSpawner/Classes/ZedSpawnerRepLink.uc diff --git a/ZedSpawner/Classes/KFGI_Access.uc b/ZedSpawner/Classes/KFGI_Access.uc new file mode 100644 index 0000000..771fa16 --- /dev/null +++ b/ZedSpawner/Classes/KFGI_Access.uc @@ -0,0 +1,17 @@ +class KFGI_Access extends Object + within KFGameInfo_Survival; + +// Bypass protected modifier for these lists + +function bool IsCustomZed(class KFPM) +{ + if (AIClassList.Find(KFPM) != INDEX_NONE) return false; + if (NonSpawnAIClassList.Find(KFPM) != INDEX_NONE) return false; + if (AIBossClassList.Find(KFPM) != INDEX_NONE) return false; + return true; +} + +defaultproperties +{ + +} diff --git a/ZedSpawner/Classes/ZedSpawner.uc b/ZedSpawner/Classes/ZedSpawner.uc index b89b7bb..eb09061 100644 --- a/ZedSpawner/Classes/ZedSpawner.uc +++ b/ZedSpawner/Classes/ZedSpawner.uc @@ -1,12 +1,12 @@ class ZedSpawner extends Info config(ZedSpawner); -var const int dt; +const dt = 1; -var const class CfgSpawn; -var const class CfgSpawnList; -var const class CfgSpawnListBW; -var const class CfgSpawnListSW; +const CfgSpawn = class'Spawn'; +const CfgSpawnList = class'SpawnList'; +const CfgSpawnListBW = class'SpawnListBossWaves'; +const CfgSpawnListSW = class'SpawnListSpecialWaves'; enum E_LogLevel { @@ -46,6 +46,8 @@ var private Array SpawnListSW; var private KFGameInfo_Survival KFGIS; var private KFGameInfo_Endless KFGIE; +var private KFGI_Access KFGIA; + var private int CurrentWave; var private int CurrentCycle; var private int CycleWaveShift; @@ -57,6 +59,7 @@ var private class CurrentBossClass; var private String SpawnTimerLastMessage; var private Array > BossClassCache; +var private Array > CustomZeds; event PostBeginPlay() { @@ -116,25 +119,57 @@ private function Init() return; } + KFGIA = new(KFGIS) class'KFGI_Access'; + KFGIE = KFGameInfo_Endless(KFGIS); SpawnList = CfgSpawnList.static.Load(LogLevel); SpawnListBW = CfgSpawnListBW.static.Load(LogLevel); SpawnListSW = CfgSpawnListSW.static.Load(KFGIE, LogLevel); - foreach SpawnListBW(SpawnEntry) - BossClassCache.AddItem(SpawnEntry.BossClass); - CurrentCycle = 1; CycleWaveSize = 0; CycleWaveShift = MaxInt; foreach SpawnList(SpawnEntry) { + if (CustomZeds.Find(SpawnEntry.ZedClass) == INDEX_NONE + && KFGIA.IsCustomZed(SpawnEntry.ZedClass)) + { + `ZS_Debug("Add custom zed:" @ SpawnEntry.ZedClass, LogLevel); + CustomZeds.AddItem(SpawnEntry.ZedClass); + SpawnEntry.ZedClass.static.PreloadContent(); + } + CycleWaveShift = Min(CycleWaveShift, SpawnEntry.Wave); CycleWaveSize = Max(CycleWaveSize, SpawnEntry.Wave); } CycleWaveSize = CycleWaveSize - CycleWaveShift + 1; - + + foreach SpawnListBW(SpawnEntry) + { + if (CustomZeds.Find(SpawnEntry.ZedClass) == INDEX_NONE + && KFGIA.IsCustomZed(SpawnEntry.ZedClass)) + { + `ZS_Debug("Add custom zed:" @ SpawnEntry.ZedClass, LogLevel); + CustomZeds.AddItem(SpawnEntry.ZedClass); + SpawnEntry.ZedClass.static.PreloadContent(); + } + + if (BossClassCache.Find(SpawnEntry.BossClass) == INDEX_NONE) + BossClassCache.AddItem(SpawnEntry.BossClass); + } + + foreach SpawnListSW(SpawnEntry) + { + if (CustomZeds.Find(SpawnEntry.ZedClass) == INDEX_NONE + && KFGIA.IsCustomZed(SpawnEntry.ZedClass)) + { + `ZS_Debug("Add custom zed:" @ SpawnEntry.ZedClass, LogLevel); + CustomZeds.AddItem(SpawnEntry.ZedClass); + SpawnEntry.ZedClass.static.PreloadContent(); + } + } + SetTimer(float(dt), true, nameof(SpawnTimer)); } @@ -529,6 +564,8 @@ private function int SpawnZed(class ZedClass, int SpawnAtOnce, b private function PrintSpawnEntry(S_SpawnEntry SE) { + `ZS_Trace(`Location, LogLevel); + `ZS_Debug("BossClass:" @ SE.BossClass, LogLevel); `ZS_Debug("ZedClass:" @ SE.ZedClass, LogLevel); `ZS_Debug("Wave:" @ SE.Wave, LogLevel); @@ -541,12 +578,26 @@ private function PrintSpawnEntry(S_SpawnEntry SE) `ZS_Debug("---------------------", LogLevel); } +public function NotifyLogin(Controller C) +{ + local ZedSpawnerRepLink RepLink; + + `ZS_Trace(`Location, LogLevel); + + RepLink = Spawn(class'ZedSpawnerRepLink', C); + RepLink.LogLevel = LogLevel; + RepLink.CustomZeds = CustomZeds; + RepLink.ServerSync(); +} + +public function NotifyLogout(Controller C) +{ + `ZS_Trace(`Location, LogLevel); + + return; +} + DefaultProperties { - dt = 1 - - CfgSpawn = class'Spawn' - CfgSpawnList = class'SpawnList' - CfgSpawnListBW = class'SpawnListBossWaves' - CfgSpawnListSW = class'SpawnListSpecialWaves' + } \ No newline at end of file diff --git a/ZedSpawner/Classes/ZedSpawnerMut.uc b/ZedSpawner/Classes/ZedSpawnerMut.uc index 7aa98f3..2c4d513 100644 --- a/ZedSpawner/Classes/ZedSpawnerMut.uc +++ b/ZedSpawner/Classes/ZedSpawnerMut.uc @@ -38,6 +38,20 @@ public function AddMutator(Mutator Mut) Super.AddMutator(Mut); } +function NotifyLogin(Controller C) +{ + Super.NotifyLogin(C); + + ZS.NotifyLogin(C); +} + +function NotifyLogout(Controller C) +{ + Super.NotifyLogout(C); + + ZS.NotifyLogout(C); +} + DefaultProperties { diff --git a/ZedSpawner/Classes/ZedSpawnerRepLink.uc b/ZedSpawner/Classes/ZedSpawnerRepLink.uc new file mode 100644 index 0000000..8f46e01 --- /dev/null +++ b/ZedSpawner/Classes/ZedSpawnerRepLink.uc @@ -0,0 +1,61 @@ +class ZedSpawnerRepLink extends ReplicationInfo; + +var public E_LogLevel LogLevel; +var public Array > CustomZeds; +var private int Recieved; + +replication +{ + if (bNetInitial && Role == ROLE_Authority) + LogLevel; +} + +public reliable client function ClientSync(class CustomZed) +{ + `ZS_Trace(`Location, LogLevel); + + `ZS_Debug("Received:" @ CustomZed, LogLevel); + CustomZeds.AddItem(CustomZed); + ServerSync(); +} + +public reliable client function SyncFinished() +{ + local class CustomZed; + + `ZS_Trace(`Location, LogLevel); + + foreach CustomZeds(CustomZed) + { + `ZS_Debug("Preload Content for" @ CustomZed, LogLevel); + CustomZed.static.PreloadContent(); + } + + Destroy(); +} + +public reliable server function ServerSync() +{ + `ZS_Trace(`Location, LogLevel); + + if (CustomZeds.Length == Recieved) + { + `ZS_Debug("Sync finished", LogLevel); + SyncFinished(); + Destroy(); + } + else + { + `ZS_Debug("Sync:" @ CustomZeds[Recieved], LogLevel); + ClientSync(CustomZeds[Recieved++]); + } +} + +defaultproperties +{ + bAlwaysRelevant = false; + bOnlyRelevantToOwner = true; + bSkipActorPropertyReplication = false; + + Recieved = 0 +}