$cost = $toRepair * $weapon->getRepairPerPoint(); if ($user->canBuy($cost)) { $user->buy($cost); $weapon->weaponStrength += $toRepair; $user->cacheStats(); $weapon->save(); } else { $t->err = 'Not enough gold'; } } } else if ($filtered['sell'] and $filtered['wId']) { $weapon = new Weapon(); $weapon->get($filtered['wId']); if ($weapon->userId == $user->id) { $toSell = min($filtered['sell'], $weapon->weaponCount); $cost = $weapon->getSellCost($user, $toSell); $user->bank += $cost; $weapon->weaponCount -= $toSell; if ($weapon->weaponCount <= 0) { $weapon->delete(); } else { $weapon->save(); } $user->cacheStats(); } }