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; return;
} }
if (Unlocker.static.UnlockDLC(KFGI, KFGRI, UnlockDLC, RemoveItems, AddItems, DLCSkinUpdateRequired, LogLevel)) WeapDefs = Trader.static.GenerateWeapDefList(
{
`Log_Info("DLC unlocked");
}
`Log_Debug("DLCSkinUpdateRequired:" @ String(DLCSkinUpdateRequired.Value));
if (bPreloadContent)
{
Preload(AddItems);
}
Trader.static.ModifyTrader(
KFGRI, KFGRI,
RemoveItems, RemoveItems,
AddItems, AddItems,
@ -208,7 +197,20 @@ private function PostInit()
bDisableItemLimitCheck, bDisableItemLimitCheck,
LogLevel); 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; ReadyToSync = true;

View File

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

View File

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

View File

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