Skip to content

Commit

Permalink
fix InvManager initialization after player death
Browse files Browse the repository at this point in the history
  • Loading branch information
GenZmeY committed Feb 25, 2024
1 parent 6d7f055 commit c2c6006
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CTI/Classes/CTI_AutoPurchaseHelper.uc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ private function CTI_GFxObject_TraderItems GetCTI_TraderItems()

private function CTI_InventoryManager GetCTI_IM()
{
if (CTI_IM == None)
if (CTI_IM != Pawn.InvManager)
{
`Log_Base("Update InvManager:" @ String(CTI_IM) @ "<-" @ String(Pawn.InvManager));
CTI_IM = CTI_InventoryManager(Pawn.InvManager);
}

Expand Down
42 changes: 42 additions & 0 deletions CTI/Classes/CTI_InventoryManager.uc
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
class CTI_InventoryManager extends KFInventoryManager;

var private CTI_RepInfo RepInfo;

public function Initialize(CTI_RepInfo _RepInfo)
{
RepInfo = _RepInfo;
}

public function OwnerDied()
{
RepInfo.SetTimer(1.0f, false, nameof(RepInfo.InitInventoryManager));
Super.OwnerDied();
}

// simulated function final BuyAmmo( float AmountPurchased, EItemType ItemType, optional byte ItemIndex, optional bool bSecondaryAmmo )
public simulated function CTI_BuyAmmo(float AmountPurchased, EItemType ItemType, optional int ItemIndex, optional bool bSecondaryAmmo)
{
Expand Down Expand Up @@ -457,6 +470,35 @@ private reliable server function CTI_ServerBuyGrenade(int AmountPurchased)
}
}

public simulated function int GetWeaponBlocks(const out STraderItem ShopItem, optional int OverrideLevelValue = INDEX_NONE)
{
local int ItemUpgradeLevel;
local KFPlayerController KFPC;
local Inventory InventoryItem;

if (ShopItem.SingleClassName != '' && OverrideLevelValue == INDEX_NONE && ClassNameIsInInventory(ShopItem.SingleClassName, InventoryItem))
{
ItemUpgradeLevel = KFWeapon(InventoryItem).CurrentWeaponUpgradeIndex;
}
else
{
if (OverrideLevelValue != INDEX_NONE)
{
ItemUpgradeLevel = OverrideLevelValue;
}
else
{
KFPC = KFPlayerController(Instigator.Owner);
if (KFPC != None)
{
ItemUpgradeLevel = KFPC.GetPurchaseHelper().GetItemUpgradeLevelByClassName(ShopItem.ClassName);
}
}
}

return ShopItem.BlocksRequired + (ItemUpgradeLevel > INDEX_NONE ? ShopItem.WeaponUpgradeWeight[ItemUpgradeLevel] : 0);
}

defaultproperties
{

Expand Down
9 changes: 8 additions & 1 deletion CTI/Classes/CTI_RepInfo.uc
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ private reliable server function Cleanup()
{
`Log_Trace();

if (PatchRequired)
{
`Log_Debug("Skip cleanup to keep CTI_RepInfo alive");
return;
}

`Log_Debug("Cleanup" @ GetKFPC() @ GetKFPRI() == None? "" : GetKFPRI().PlayerName);
if (!CTI.DestroyRepInfo(GetKFPC()))
{
Expand All @@ -466,7 +472,7 @@ public function InitInventoryManager()

`Log_Trace();

if (GetKFPRI() == None || !KFPRI.bHasSpawnedIn)
if (GetKFPRI() == None || !KFPRI.bHasSpawnedIn || KFPC.Pawn == None)
{
`Log_Debug("Wait for spawn (InventoryManager)");
SetTimer(1.0f, false, nameof(InitInventoryManager));
Expand All @@ -477,6 +483,7 @@ public function InitInventoryManager()

KFPC.Pawn.InventoryManagerClass = InventoryManager;
NextInventoryManger = Spawn(KFPC.Pawn.InventoryManagerClass, KFPC.Pawn);
CTI_InventoryManager(NextInventoryManger).Initialize(Self);

if (NextInventoryManger == None)
{
Expand Down
8 changes: 4 additions & 4 deletions CTI/Classes/RemoveItems.uc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class RemoveItems extends Object
dependson(CTI)
config(CTI);

var public config bool bAll;
var public config bool bALL;
var public config bool bHRG;
var public config bool bDLC;
var private config Array<String> Item;
Expand All @@ -29,11 +29,11 @@ public static function InitConfig(int Version, int LatestVersion)

private static function ApplyDefault()
{
default.bAll = false;
default.bALL = false;
default.bHRG = false;
default.bDLC = false;
default.Item.Length = 0;
default.Item.AddItem("KFGame.KFWeapDef_9mmDual");
default.Item.AddItem("KFGame.SomeWeapon");
}

public static function Array<class<KFWeaponDefinition> > Load(E_LogLevel LogLevel)
Expand All @@ -45,7 +45,7 @@ public static function Array<class<KFWeaponDefinition> > Load(E_LogLevel LogLeve
local int Line;

`Log_Info("Load items to remove:");
if (default.bAll)
if (default.bALL)
{
`Log_Info("Remove all default items");
}
Expand Down

0 comments on commit c2c6006

Please sign in to comment.