Add Actor.CanReceive (#2295)

Adds CanReceive() to Actor, called by items from CallTryPickup(). This will let actors themselves determine if they can receive the item before any other checks.

Co-authored-by: Rachael Alexanderson <18584402+madame-rachelle@users.noreply.github.com>
This commit is contained in:
jekyllgrim 2024-01-04 15:24:32 +03:00 committed by GitHub
parent 1a860185ee
commit d0288264a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View file

@ -510,7 +510,15 @@ class Actor : Thinker native
return true;
}
// Called in TryMove if the mover ran into another Actor. This isn't called on players
// [AA] Called by inventory items in CallTryPickup to see if this actor needs
// to process them in some way before they're received. Gets called before
// the item's TryPickup, allowing fully customized handling of all items.
virtual bool CanReceive(Inventory item)
{
return true;
}
// Called in TryMove if the mover ran into another Actor. This isn't called on players
// if they're currently predicting. Guarantees collisions unlike CanCollideWith.
virtual void CollidedWith(Actor other, bool passive) {}

View file

@ -597,8 +597,16 @@ class Inventory : Actor
// unmorphed versions of a currently morphed actor cannot pick up anything.
if (bUnmorphed) return false, null;
bool res;
if (CanPickup(toucher))
//[AA] starting with true, so that CanReceive can unset it,
// if necessary:
bool res = true;
// [AA] CanReceive lets the actor receiving the item process it first.
if (!toucher.CanReceive(self))
{
res = false;
}
// CanPickup processes restrictions by player class.
else if (CanPickup(toucher))
{
res = TryPickup(toucher);
}