KF2-CustomTraderInventory/CTI/Classes/Unlocker.uc

189 lines
4.1 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> > RemoveItems,
out Array<class<KFWeaponDefinition> > AddItems,
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":
2023-10-01 22:55:09 +00:00
return Auto(KFGI, KFGRI, RemoveItems, AddItems, DLCSkinUpdateRequired, LogLevel);
2023-05-12 23:33:32 +00:00
case "replaceweapons":
2023-10-01 22:55:09 +00:00
DLCSkinUpdateRequired.Value = true;
2023-05-12 23:33:32 +00:00
return ReplaceWeapons(KFGRI, RemoveItems, AddItems, LogLevel);
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> > RemoveItems,
out Array<class<KFWeaponDefinition> > AddItems,
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)
{
2023-10-01 22:55:09 +00:00
DLCSkinUpdateRequired.Value = true;
2023-05-12 23:33:32 +00:00
return ReplaceWeapons(KFGRI, RemoveItems, AddItems, LogLevel);
}
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> > RemoveItems,
out Array<class<KFWeaponDefinition> > AddItems,
E_LogLevel LogLevel)
{
local Array<class<KFWeaponDefinition> > WeapDefsDLCs;
local class<KFWeaponDefinition> WeapDefDLC;
local class<KFWeaponDefinition> WeapDefReplacement;
local bool Unlock, PartialUnlock;
`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;
WeapDefsDLCs = Trader.static.GetTraderWeapDefsDLC(KFGRI, LogLevel);
foreach WeapDefsDLCs(WeapDefDLC)
{
WeapDefReplacement = PickReplacementWeapDefDLC(WeapDefDLC, LogLevel);
if (WeapDefReplacement != None)
{
Unlock = true;
if (AddItems.Find(WeapDefReplacement) == INDEX_NONE)
{
AddItems.AddItem(WeapDefReplacement);
}
`Log_Debug(WeapDefDLC @ "replaced by" @ WeapDefReplacement);
}
else
{
PartialUnlock = true;
`Log_Warn("Can't unlock item:" @ WeapDefDLC @ "SharedUnlockId:" @ WeapDefDLC.default.SharedUnlockId);
}
if (RemoveItems.Find(WeapDefDLC) == INDEX_NONE)
{
RemoveItems.AddItem(WeapDefDLC);
}
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
}