Added ShouldShareItem virtual

Allows for easier customizing of whether or not an item should be shared with players upon pickup in co-op (e.g. it allows it to be expanded to weapons with custom cvars).
This commit is contained in:
Boondorl 2024-04-22 20:45:33 -04:00 committed by Ricardo Luís Vaz Silva
parent 12d0c946f0
commit b43c440552
2 changed files with 16 additions and 1 deletions

View file

@ -43,6 +43,11 @@ class Key : Inventory
static native clearscope Color GetMapColorForKey(Key key);
static native clearscope int GetKeyTypeCount();
static native clearscope class<Key> GetKeyType(int index);
override bool ShouldShareItem(Actor giver)
{
return sv_coopsharekeys;
}
override bool HandlePickup (Inventory item)
{
@ -113,6 +118,11 @@ class PuzzleItem : Inventory
PuzzleItem.FailMessage("$TXT_USEPUZZLEFAILED");
PuzzleItem.FailSound "*puzzfail";
}
override bool ShouldShareItem(Actor giver)
{
return sv_coopsharekeys;
}
override bool HandlePickup (Inventory item)
{

View file

@ -261,6 +261,11 @@ class Inventory : Actor
}
}
virtual bool ShouldShareItem(Actor giver)
{
return false;
}
protected void ShareItemWithPlayers(Actor giver)
{
if (bSharingItem)
@ -695,7 +700,7 @@ class Inventory : Actor
toucher.HasReceived(self);
// If the item can be shared, make sure every player gets a copy.
if (multiplayer && !deathmatch && sv_coopsharekeys && bIsKeyItem)
if (multiplayer && !deathmatch && ShouldShareItem(toucher))
ShareItemWithPlayers(toucher);
}
return res, toucher;