BaseInventory: change dumb variable names in internalAddItem()

This commit is contained in:
Dylan K. Taylor 2023-04-27 20:29:02 +01:00
parent 709d874204
commit 4228880509
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -216,25 +216,25 @@ abstract class BaseInventory implements Inventory{
return $returnSlots; return $returnSlots;
} }
private function internalAddItem(Item $slot) : Item{ private function internalAddItem(Item $newItem) : Item{
$emptySlots = []; $emptySlots = [];
$maxStackSize = min($this->getMaxStackSize(), $slot->getMaxStackSize()); $maxStackSize = min($this->getMaxStackSize(), $newItem->getMaxStackSize());
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
if($this->isSlotEmpty($i)){ if($this->isSlotEmpty($i)){
$emptySlots[] = $i; $emptySlots[] = $i;
continue; continue;
} }
$item = $this->getItem($i); $slotItem = $this->getItem($i);
if($slot->canStackWith($item) && $item->getCount() < $maxStackSize){ if($newItem->canStackWith($slotItem) && $slotItem->getCount() < $maxStackSize){
$amount = min($maxStackSize - $item->getCount(), $slot->getCount()); $amount = min($maxStackSize - $slotItem->getCount(), $newItem->getCount());
if($amount > 0){ if($amount > 0){
$slot->setCount($slot->getCount() - $amount); $newItem->setCount($newItem->getCount() - $amount);
$item->setCount($item->getCount() + $amount); $slotItem->setCount($slotItem->getCount() + $amount);
$this->setItem($i, $item); $this->setItem($i, $slotItem);
if($slot->getCount() <= 0){ if($newItem->getCount() <= 0){
break; break;
} }
} }
@ -243,18 +243,18 @@ abstract class BaseInventory implements Inventory{
if(count($emptySlots) > 0){ if(count($emptySlots) > 0){
foreach($emptySlots as $slotIndex){ foreach($emptySlots as $slotIndex){
$amount = min($maxStackSize, $slot->getCount()); $amount = min($maxStackSize, $newItem->getCount());
$slot->setCount($slot->getCount() - $amount); $newItem->setCount($newItem->getCount() - $amount);
$item = clone $slot; $slotItem = clone $newItem;
$item->setCount($amount); $slotItem->setCount($amount);
$this->setItem($slotIndex, $item); $this->setItem($slotIndex, $slotItem);
if($slot->getCount() <= 0){ if($newItem->getCount() <= 0){
break; break;
} }
} }
} }
return $slot; return $newItem;
} }
public function remove(Item $item) : void{ public function remove(Item $item) : void{