KF2-CustomTraderInventory/CTI/Classes/Unlocker.uc

189 lines
4.0 KiB
Ucode
Raw Normal View History

2023-05-12 23:33:32 +00:00
class Unlocker extends Object
2023-10-01 22:55:09 +00:00
dependson(WeaponReplacements)
2023-05-12 23:33:32 +00:00
abstract;
// TODO:
// replace shopContainer (KFGFxTraderContainer_Store)
// without replacing KFGFxMoviePlayer_Manager
// but how? 🤔
2023-10-01 22:55:09 +00:00
const Trader = class'Trader';
const Replacements = class'WeaponReplacements';
2023-05-12 23:33:32 +00:00
public static function bool IsValidTypeUnlockDLC(String UnlockType, E_LogLevel LogLevel)
{
`Log_TraceStatic();
switch (Locs(UnlockType))
{
case "true":
case "false":
case "auto":
case "replaceweapons":
case "replacefilter":
return true;
}
return false;
}
public static function bool UnlockDLC(
KFGameInfo KFGI,
KFGameReplicationInfo KFGRI,
String UnlockType,
out Array<class<KFWeaponDefinition> > WeapDefs,
2023-10-01 22:55:09 +00:00
out BoolWrapper DLCSkinUpdateRequired,
2023-05-12 23:33:32 +00:00
E_LogLevel LogLevel)
{
`Log_TraceStatic();
switch (Locs(UnlockType))
{
case "true":
case "auto":
return Auto(KFGI, KFGRI, WeapDefs, DLCSkinUpdateRequired, LogLevel);
2023-05-12 23:33:32 +00:00
case "replaceweapons":
return ReplaceWeapons(KFGRI, WeapDefs, DLCSkinUpdateRequired, LogLevel);
2023-05-12 23:33:32 +00:00
case "replacefilter":
2023-10-01 22:55:09 +00:00
DLCSkinUpdateRequired.Value = false;
2023-05-12 23:33:32 +00:00
return ReplaceFilter(KFGI, LogLevel);
case "false":
default:
return false;
}
}
private static function bool Auto(
KFGameInfo KFGI,
KFGameReplicationInfo KFGRI,
out Array<class<KFWeaponDefinition> > WeapDefs,
2023-10-01 22:55:09 +00:00
out BoolWrapper DLCSkinUpdateRequired,
2023-05-12 23:33:32 +00:00
E_LogLevel LogLevel)
{
local bool CustomGFxManager;
`Log_TraceStatic();
if (KFGI == None) return false;
if (KFGameInfo_VersusSurvival(KFGI) != None)
{
CustomGFxManager = (KFGI.KFGFxManagerClass != class'KFGameInfo_VersusSurvival'.default.KFGFxManagerClass);
}
else
{
CustomGFxManager = (KFGI.KFGFxManagerClass != class'KFGameInfo'.default.KFGFxManagerClass);
}
if (CustomGFxManager)
{
return ReplaceWeapons(KFGRI, WeapDefs, DLCSkinUpdateRequired, LogLevel);
2023-05-12 23:33:32 +00:00
}
else
{
2023-10-01 22:55:09 +00:00
DLCSkinUpdateRequired.Value = false;
2023-05-12 23:33:32 +00:00
return ReplaceFilter(KFGI, LogLevel);
}
}
private static function bool ReplaceWeapons(
KFGameReplicationInfo KFGRI,
out Array<class<KFWeaponDefinition> > WeapDefs,
out BoolWrapper DLCSkinUpdateRequired,
2023-05-12 23:33:32 +00:00
E_LogLevel LogLevel)
{
local class<KFWeaponDefinition> WeapDef;
2023-05-12 23:33:32 +00:00
local class<KFWeaponDefinition> WeapDefReplacement;
local bool Unlock, PartialUnlock;
local int Index;
2023-05-12 23:33:32 +00:00
`Log_TraceStatic();
2023-10-01 22:55:09 +00:00
`Log_Debug("Unlock by replace weapons");
2023-05-12 23:33:32 +00:00
Unlock = false;
PartialUnlock = false;
DLCSkinUpdateRequired.Value = false;
2023-05-12 23:33:32 +00:00
for (Index = 0; Index < WeapDefs.Length; Index++)
2023-05-12 23:33:32 +00:00
{
WeapDef = WeapDefs[Index];
if (WeapDef.default.SharedUnlockId == SCU_None) continue;
WeapDefReplacement = PickReplacementWeapDefDLC(WeapDef, LogLevel);
2023-05-12 23:33:32 +00:00
if (WeapDefReplacement != None)
{
Unlock = true;
DLCSkinUpdateRequired.Value = true;
if (WeapDefs.Find(WeapDefReplacement) == INDEX_NONE)
2023-05-12 23:33:32 +00:00
{
WeapDefs[Index] = WeapDefReplacement;
`Log_Debug(WeapDef @ "replaced by" @ WeapDefReplacement);
}
else
{
WeapDefs.Remove(Index--, 1);
`Log_Debug("Skip already unlocked weapon:" @ WeapDef);
2023-05-12 23:33:32 +00:00
}
}
else
{
PartialUnlock = true;
`Log_Warn("Can't unlock item:" @ WeapDef @ "SharedUnlockId:" @ WeapDef.default.SharedUnlockId);
}
2023-05-12 23:33:32 +00:00
}
if (PartialUnlock)
{
`Log_Warn("Some DLCs are not unlocked. Try to set 'UnlockDLC=ReplaceFilter' or ask the author to update the mod");
}
return Unlock;
}
private static function class<KFWeaponDefinition> PickReplacementWeapDefDLC(class<KFWeaponDefinition> WeapDefDLC, E_LogLevel LogLevel)
{
2023-10-01 22:55:09 +00:00
local SWeapReplace WeapReplace;
2023-05-12 23:33:32 +00:00
`Log_TraceStatic();
2023-10-01 22:55:09 +00:00
foreach Replacements.default.DLC(WeapReplace)
2023-05-12 23:33:32 +00:00
{
2023-10-01 22:55:09 +00:00
if (ClassIsChildOf(WeapReplace.WeapDef, WeapDefDLC))
2023-05-12 23:33:32 +00:00
{
2023-10-01 22:55:09 +00:00
return WeapReplace.WeapDef;
2023-05-12 23:33:32 +00:00
}
}
return None;
}
private static function bool ReplaceFilter(KFGameInfo KFGI, E_LogLevel LogLevel)
{
`Log_TraceStatic();
2023-10-01 22:55:09 +00:00
`Log_Debug("Unlock by replace filter");
2023-05-12 23:33:32 +00:00
if (KFGI == None) return false;
if (KFGameInfo_VersusSurvival(KFGI) != None)
{
KFGI.KFGFxManagerClass = class'CTI_GFxMoviePlayer_Manager_Versus';
}
else
{
KFGI.KFGFxManagerClass = class'CTI_GFxMoviePlayer_Manager';
}
return true;
}
defaultproperties
{
2023-10-01 22:55:09 +00:00
2023-05-12 23:33:32 +00:00
}