Skip to content

Commit

Permalink
fix(checks): check for non debits also
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Oct 6, 2024
1 parent c2a678f commit 0617481
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions app/Services/LimitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public function checkLimits($object, $is_unlock = false) {
}
}

// if the limit is not unlocked, check if it is auto unlocked
if (!$is_unlock && $limits->first()->is_unlocked && !$limits->first()->is_auto_unlocked) {
throw new \Exception(($limits->first()->object->displayName ?? $limits->first()->object->name).' requires manual unlocking!');
}

$plucked_stacks = [];
foreach ($limits as $limit) {
switch ($limit->limit_type) {
Expand All @@ -60,11 +65,6 @@ public function checkLimits($object, $is_unlock = false) {
}

if ($limit->debit) {
// if the limit is not unlocked, check if it is auto unlocked
if (!$is_unlock && $limits->first()->is_unlocked && !$limits->first()->is_auto_unlocked) {
throw new \Exception(($limits->first()->object->displayName ?? $limits->first()->object->name).' requires manual unlocking!');
}

$stacks = UserItem::where('user_id', $user->id)->where('item_id', $limit->limit_id)->orderBy('count', 'asc')->get(); // asc because pop() removes from the end

$count = $limit->quantity;
Expand All @@ -82,11 +82,6 @@ public function checkLimits($object, $is_unlock = false) {
}

if ($limit->debit) {
// if the limit is not unlocked, check if it is auto unlocked
if (!$is_unlock && $limits->first()->is_unlocked && !$limits->first()->is_auto_unlocked) {
throw new \Exception(($limits->first()->object->displayName ?? $limits->first()->object->name).' requires manual unlocking!');
}

$service = new CurrencyManager;
if (!$service->debitCurrency($user, null, 'Limit Requirements', 'Used in '.$limit->object->displayName.' limit requirements.', $limit->limit, $limit->quantity)) {
foreach ($service->errors()->getMessages()['error'] as $error) {
Expand Down Expand Up @@ -119,11 +114,13 @@ public function checkLimits($object, $is_unlock = false) {
}
}

if ($limits->first()->is_unlocked) {
if ($limits->first()->is_unlocked && $limits->first()->is_auto_unlocked || $is_unlock) {
$user->unlockedLimits()->create([
'object_model' => get_class($object),
'object_id' => $object->id,
]);
} else if (!$is_unlock && $limits->first()->is_unlocked && !$limits->first()->is_auto_unlocked) {
throw new \Exception(($limits->first()->object->displayName ?? $limits->first()->object->name).' requires manual unlocking!');
}

return true;
Expand Down

0 comments on commit 0617481

Please sign in to comment.