From b43c440552964578f35782714ca6765a4030ce37 Mon Sep 17 00:00:00 2001 From: Boondorl Date: Mon, 22 Apr 2024 20:45:33 -0400 Subject: [PATCH] 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). --- wadsrc/static/zscript/actors/inventory/inv_misc.zs | 10 ++++++++++ wadsrc/static/zscript/actors/inventory/inventory.zs | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/actors/inventory/inv_misc.zs b/wadsrc/static/zscript/actors/inventory/inv_misc.zs index 318d294913..7dd374932a 100644 --- a/wadsrc/static/zscript/actors/inventory/inv_misc.zs +++ b/wadsrc/static/zscript/actors/inventory/inv_misc.zs @@ -43,6 +43,11 @@ class Key : Inventory static native clearscope Color GetMapColorForKey(Key key); static native clearscope int GetKeyTypeCount(); static native clearscope class 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) { diff --git a/wadsrc/static/zscript/actors/inventory/inventory.zs b/wadsrc/static/zscript/actors/inventory/inventory.zs index a2af103987..5649894592 100644 --- a/wadsrc/static/zscript/actors/inventory/inventory.zs +++ b/wadsrc/static/zscript/actors/inventory/inventory.zs @@ -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;