Living: extract an applyConsumptionResults() method from consumeObject()

inspired by #3592, which has gone stale
This commit is contained in:
Dylan K. Taylor 2020-12-28 22:27:29 +00:00
parent 15401d740f
commit aefaf73685
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 17 additions and 7 deletions

View File

@ -300,17 +300,20 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($consumable instanceof MaybeConsumable and !$consumable->canBeConsumed()){
return false;
}
if($consumable instanceof FoodSource && $consumable->requiresHunger() and !$this->isHungry()){
return false;
}
return parent::consumeObject($consumable);
}
protected function applyConsumptionResults(Consumable $consumable) : void{
if($consumable instanceof FoodSource){
if($consumable->requiresHunger() and !$this->isHungry()){
return false;
}
$this->addFood($consumable->getFoodRestore());
$this->addSaturation($consumable->getSaturationRestore());
}
return parent::consumeObject($consumable);
parent::applyConsumptionResults($consumable);
}
/**

View File

@ -363,13 +363,20 @@ abstract class Living extends Entity implements Damageable{
return false;
}
$this->applyConsumptionResults($consumable);
return true;
}
/**
* Applies effects from consuming the object. This shouldn't do any can-consume checks (those are expected to be
* handled by the caller).
*/
protected function applyConsumptionResults(Consumable $consumable) : void{
foreach($consumable->getAdditionalEffects() as $effect){
$this->addEffect($effect);
}
$consumable->onConsume($this);
return true;
}
/**