From c367e00f63fc61ce507fbf82aa5d18e0764bd8f6 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Sat, 20 May 2023 22:11:37 +0300 Subject: [PATCH] optimize boss override --- StartWave/Classes/KFGI_Access.uc | 22 +++++++++ StartWave/Classes/StartWave.uc | 81 ++++++++++++++++++-------------- 2 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 StartWave/Classes/KFGI_Access.uc diff --git a/StartWave/Classes/KFGI_Access.uc b/StartWave/Classes/KFGI_Access.uc new file mode 100644 index 0000000..bba0e2f --- /dev/null +++ b/StartWave/Classes/KFGI_Access.uc @@ -0,0 +1,22 @@ +class KFGI_Access extends Object + within KFGameInfo; + +public function OverrideBossIndex(int Index, optional bool Force = false) +{ + if (Index < 0 || Index >= default.AIBossClassList.Length) + { + return; + } + + if (!UseSpecificBossIndex(BossIndex) || Force) + { + BossIndex = Index; + } + + MyKFGRI.CacheSelectedBoss(BossIndex); +} + +defaultproperties +{ + +} diff --git a/StartWave/Classes/StartWave.uc b/StartWave/Classes/StartWave.uc index 4162061..a20fbf6 100644 --- a/StartWave/Classes/StartWave.uc +++ b/StartWave/Classes/StartWave.uc @@ -7,6 +7,8 @@ var private KFGameInfo KFGI; var private KFGameInfo_Survival KFGIS; var private KFGameInfo_Endless KFGIE; +var private KFGI_Access KFGIA; + var private KFGameReplicationInfo KFGRI; /********************************************************************************************************* @@ -112,15 +114,55 @@ private function PreInit() `Log_Debug("bStartWithTrader:" @ bStartWithTrader); bOverridenDifficultySettings = false; - bOverridenTraderDuration = false; + bOverridenTraderDuration = false; +} + +private function PostInit() +{ + `Log_Trace(); + + if (WorldInfo.Game == None || WorldInfo.GRI == None) + { + SetTimer(0.2, false, nameof(PostInit)); + return; + } + + KFGI = KFGameInfo(WorldInfo.Game); + if (KFGI == None) + { + `Log_Fatal("Incompatible gamemode:" @ WorldInfo.Game $ ". Destroy..."); + SafeDestroy(); + return; + } + + KFGIA = new(KFGI) class'KFGI_Access'; + if (KFGIA == None) + { + `Log_Fatal("Can't create KFGI_Access object"); + SafeDestroy(); + return; + } + + KFGIS = KFGameInfo_Survival(KFGI); + if (KFGIS == None) + { + `Log_Warn("The game mode does not extend KFGameInfo_Survival. Most features of this mutator are not compatible with non-wave-based game modes."); + } + + KFGIE = KFGameInfo_Endless(KFGIS); + + KFGRI = KFGameReplicationInfo(WorldInfo.GRI); + if (KFGRI == None) + { + `Log_Fatal("Incompatible game replication info:" @ WorldInfo.GRI $ ". Destroy..."); + SafeDestroy(); + return; + } SetTimer(0.1, false, nameof(OverrideTimer)); //Override the boss with the boss corresponding to the specified boss index. -1 signifies random. - if (Boss != -1) - { - SetTimer(0.1, false, nameof(OverrideBoss)); - } + KFGIA.OverrideBossIndex(Boss); CheckForceInitialTrader(); @@ -142,28 +184,6 @@ private function PreInit() } } -private function PostInit() -{ - `Log_Trace(); - - KFGI = KFGameInfo(WorldInfo.Game); - if (KFGIS == None) - { - `Log_Fatal("Incompatible gamemode:" @ WorldInfo.Game $ ". Destroy..."); - SafeDestroy(); - return; - } - - KFGIS = KFGameInfo_Survival(KFGI); - if (KFGIS == None) - { - `Log_Warn("The game mode does not extend KFGameInfo_Survival. Most features of this mutator are not compatible with non-wave-based game modes."); - } - - KFGIE = KFGameInfo_Endless(KFGIS); - KFGRI = KFGI.MyKFGRI; -} - /** Allows for handling player input in the console by the mutator. */ public function Mutate(string MutateString, PlayerController Sender) { @@ -316,13 +336,6 @@ private function OverrideBoss() `Log_Trace(); - //We need a valid KFGRI reference as we use its public BossIndex field. - if (KFGRI == None) - { - SetTimer(0.2, false, nameof(OverrideBoss)); - return; - } - //Unfortunately, we cannot directly set the boss index since KFGameInfo.BossIndex is protected. The only //way we can affect BossIndex is through KFGameInfo.SetBossIndex which randomly chooses a value in the //valid range. So we have to continue calling SetBossIndex until the desired index has been chosen. We