Skip to content

Commit

Permalink
Added ShouldShareItem virtual
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Boondorl authored and RicardoLuis0 committed Apr 27, 2024
1 parent 12d0c94 commit b43c440
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions wadsrc/static/zscript/actors/inventory/inv_misc.zs
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion wadsrc/static/zscript/actors/inventory/inventory.zs
Expand Up @@ -261,6 +261,11 @@ class Inventory : Actor
}
}

virtual bool ShouldShareItem(Actor giver)
{
return false;
}

protected void ShareItemWithPlayers(Actor giver)
{
if (bSharingItem)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b43c440

Please sign in to comment.