remove DLC clones along with their originals from [CTI.RemoveItems]

This commit is contained in:
GenZmeY 2023-10-20 22:53:11 +03:00
parent 8b446c735f
commit 37944a25c4
Signed by: GenZmeY
GPG Key ID: 424DA4BC3CB2CF39
4 changed files with 52 additions and 46 deletions

View File

@ -187,18 +187,7 @@ private function PostInit()
return;
}
if (Unlocker.static.UnlockDLC(KFGI, KFGRI, UnlockDLC, RemoveItems, AddItems, DLCSkinUpdateRequired, LogLevel))
{
`Log_Info("DLC unlocked");
}
`Log_Debug("DLCSkinUpdateRequired:" @ String(DLCSkinUpdateRequired.Value));
if (bPreloadContent)
{
Preload(AddItems);
}
Trader.static.ModifyTrader(
WeapDefs = Trader.static.GenerateWeapDefList(
KFGRI,
RemoveItems,
AddItems,
@ -208,7 +197,20 @@ private function PostInit()
bDisableItemLimitCheck,
LogLevel);
WeapDefs = Trader.static.GetTraderWeapDefs(KFGRI, LogLevel);
if (Unlocker.static.UnlockDLC(KFGI, KFGRI, UnlockDLC, WeapDefs, DLCSkinUpdateRequired, LogLevel))
{
`Log_Info("DLC unlocked");
}
`Log_Debug("DLCSkinUpdateRequired:" @ String(DLCSkinUpdateRequired.Value));
Trader.static.OverwriteTraderItems(KFGRI, WeapDefs, LogLevel);
`Log_Info("Trader items:" @ WeapDefs.Length);
if (bPreloadContent)
{
Preload(WeapDefs);
}
ReadyToSync = true;

View File

@ -332,6 +332,7 @@ private simulated function KeepNotification()
private simulated function ClientCleanup()
{
`Log_Debug("Cleanup");
ServerCleanup();
SafeDestroy();
}
@ -340,7 +341,7 @@ private reliable server function ServerCleanup()
{
`Log_Trace();
`Log_Debug("Cleanup");
`Log_Debug("Cleanup" @ GetKFPC() @ GetKFPRI() == None? "" : GetKFPRI().PlayerName);
if (!CTI.DestroyRepInfo(GetKFPC()))
{
`Log_Debug("Cleanup (forced)");

View File

@ -91,11 +91,11 @@ public static function Array<class<KFWeaponDefinition> > GetTraderWeapDefsDLC(KF
return WeapDefs;
}
public static simulated function ModifyTrader(
public static simulated function Array< class<KFWeaponDefinition> > GenerateWeapDefList(
KFGameReplicationInfo KFGRI,
const out Array<class<KFWeaponDefinition> > RemoveItems,
const out Array<class<KFWeaponDefinition> > AddItems,
bool ReplaceMode,
bool RemoveAll,
bool RemoveHRG,
bool RemoveDLC,
bool bDisableItemLimitCheck,
@ -103,14 +103,14 @@ public static simulated function ModifyTrader(
{
local KFGFxObject_TraderItems TraderItems;
local STraderItem Item;
local Array<class<KFWeaponDefinition> > WeapDefs;
local Array< class<KFWeaponDefinition> > WeapDefs;
local int Index;
`Log_TraceStatic();
TraderItems = GetTraderItems(KFGRI, LogLevel);
if (!ReplaceMode)
if (!RemoveAll)
{
foreach TraderItems.SaleItems(Item)
{
@ -126,9 +126,12 @@ public static simulated function ModifyTrader(
}
for (Index = 0; Index < AddItems.Length; ++Index)
{
if (WeaponClassIsUnique(AddItems[Index].default.WeaponClassPath, WeapDefs, LogLevel))
{
WeapDefs.AddItem(AddItems[Index]);
}
}
WeapDefs.Sort(ByPrice);
@ -143,7 +146,7 @@ public static simulated function ModifyTrader(
WeapDefs.Length = ITEMS_LIMIT;
}
OverwriteTraderItems(KFGRI, WeapDefs, LogLevel);
return WeapDefs;
}
public static simulated function OverwriteTraderItems(

View File

@ -31,8 +31,7 @@ public static function bool UnlockDLC(
KFGameInfo KFGI,
KFGameReplicationInfo KFGRI,
String UnlockType,
out Array<class<KFWeaponDefinition> > RemoveItems,
out Array<class<KFWeaponDefinition> > AddItems,
out Array<class<KFWeaponDefinition> > WeapDefs,
out BoolWrapper DLCSkinUpdateRequired,
E_LogLevel LogLevel)
{
@ -42,11 +41,10 @@ public static function bool UnlockDLC(
{
case "true":
case "auto":
return Auto(KFGI, KFGRI, RemoveItems, AddItems, DLCSkinUpdateRequired, LogLevel);
return Auto(KFGI, KFGRI, WeapDefs, DLCSkinUpdateRequired, LogLevel);
case "replaceweapons":
DLCSkinUpdateRequired.Value = true;
return ReplaceWeapons(KFGRI, RemoveItems, AddItems, LogLevel);
return ReplaceWeapons(KFGRI, WeapDefs, DLCSkinUpdateRequired, LogLevel);
case "replacefilter":
DLCSkinUpdateRequired.Value = false;
@ -61,8 +59,7 @@ public static function bool UnlockDLC(
private static function bool Auto(
KFGameInfo KFGI,
KFGameReplicationInfo KFGRI,
out Array<class<KFWeaponDefinition> > RemoveItems,
out Array<class<KFWeaponDefinition> > AddItems,
out Array<class<KFWeaponDefinition> > WeapDefs,
out BoolWrapper DLCSkinUpdateRequired,
E_LogLevel LogLevel)
{
@ -83,8 +80,7 @@ private static function bool Auto(
if (CustomGFxManager)
{
DLCSkinUpdateRequired.Value = true;
return ReplaceWeapons(KFGRI, RemoveItems, AddItems, LogLevel);
return ReplaceWeapons(KFGRI, WeapDefs, DLCSkinUpdateRequired, LogLevel);
}
else
{
@ -95,14 +91,14 @@ private static function bool Auto(
private static function bool ReplaceWeapons(
KFGameReplicationInfo KFGRI,
out Array<class<KFWeaponDefinition> > RemoveItems,
out Array<class<KFWeaponDefinition> > AddItems,
out Array<class<KFWeaponDefinition> > WeapDefs,
out BoolWrapper DLCSkinUpdateRequired,
E_LogLevel LogLevel)
{
local Array<class<KFWeaponDefinition> > WeapDefsDLCs;
local class<KFWeaponDefinition> WeapDefDLC;
local class<KFWeaponDefinition> WeapDef;
local class<KFWeaponDefinition> WeapDefReplacement;
local bool Unlock, PartialUnlock;
local int Index;
`Log_TraceStatic();
@ -110,30 +106,34 @@ private static function bool ReplaceWeapons(
Unlock = false;
PartialUnlock = false;
DLCSkinUpdateRequired.Value = false;
WeapDefsDLCs = Trader.static.GetTraderWeapDefsDLC(KFGRI, LogLevel);
foreach WeapDefsDLCs(WeapDefDLC)
for (Index = 0; Index < WeapDefs.Length; Index++)
{
WeapDefReplacement = PickReplacementWeapDefDLC(WeapDefDLC, LogLevel);
WeapDef = WeapDefs[Index];
if (WeapDef.default.SharedUnlockId == SCU_None) continue;
WeapDefReplacement = PickReplacementWeapDefDLC(WeapDef, LogLevel);
if (WeapDefReplacement != None)
{
Unlock = true;
if (AddItems.Find(WeapDefReplacement) == INDEX_NONE)
DLCSkinUpdateRequired.Value = true;
if (WeapDefs.Find(WeapDefReplacement) == INDEX_NONE)
{
AddItems.AddItem(WeapDefReplacement);
WeapDefs[Index] = WeapDefReplacement;
`Log_Debug(WeapDef @ "replaced by" @ WeapDefReplacement);
}
else
{
WeapDefs.Remove(Index--, 1);
`Log_Debug("Skip already unlocked weapon:" @ WeapDef);
}
`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);
`Log_Warn("Can't unlock item:" @ WeapDef @ "SharedUnlockId:" @ WeapDef.default.SharedUnlockId);
}
}