Skip to content

Commit

Permalink
Fixed Market Compare, Shop Compare, Shop Buy Multiple and Character I…
Browse files Browse the repository at this point in the history
…nventory error messages
  • Loading branch information
AdamKyle committed Dec 16, 2023
1 parent 8561cd5 commit 202c602
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public function unequipItem(Request $request, Character $character, InventorySet
$foundItem = $character->inventory->slots->find($request->item_to_remove);

if (is_null($foundItem)) {
return response()->json(['error' => 'No item found to be unequipped.'], 422);
return response()->json(['message' => 'No item found to be unequipped.'], 422);
}

$foundItem->update([
Expand Down Expand Up @@ -608,7 +608,7 @@ public function unequipAll(Request $request, Character $character, InventorySetS

if ($character->isInventoryFull()) {
return response()->json([
'message' => 'Your inventory is full. Cannot unequip item.s You have no room in your inventory.'
'message' => 'Your inventory is full. Cannot unequip items You have no room in your inventory.'
], 422);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Game/Core/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use App\Game\Core\Handlers\HandleGoldBarsAsACurrency;
use App\Game\CharacterInventory\Services\CharacterInventoryService;
use App\Game\Core\Services\CharacterPassiveSkills;
use App\Game\Core\Services\ComparisonService;
use App\Game\CharacterInventory\Services;
use App\Game\Core\Services\DropCheckService;
use App\Game\CharacterInventory\Services\EquipItemService;
use App\Game\CharacterInventory\Services\InventorySetService;
Expand Down
2 changes: 1 addition & 1 deletion app/Game/Market/Controllers/MarketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace App\Game\Market\Controllers;


use App\Game\CharacterInventory\Services\ComparisonService;
use Cache;
use App\Flare\Models\Item;
use App\Flare\Traits\Controllers\ItemsShowInformation;
use App\Game\Core\Services\ComparisonService;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand Down
9 changes: 5 additions & 4 deletions app/Game/Shop/Controllers/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Game\Shop\Controllers;

use App\Game\CharacterInventory\Services\ComparisonService;
use App\Game\Shop\Requests\ShopBuyMultipleOfItem;
use Cache;
use Illuminate\Http\Request;
use League\Fractal\Manager;
Expand All @@ -13,10 +15,8 @@
use App\Flare\Transformers\CharacterSheetBaseInfoTransformer;
use App\Flare\Values\MaxCurrenciesValue;
use App\Game\Core\Events\UpdateTopBarEvent;
use App\Game\Shop\Requests\ShopBuyMultipleValidation;
use App\Game\Shop\Requests\ShopPurchaseMultipleValidation;
use App\Game\CharacterInventory\Services\EquipItemService;
use App\Game\Core\Services\ComparisonService;
use App\Game\Shop\Events\BuyItemEvent;
use App\Game\Shop\Services\ShopService;
use App\Game\Shop\Requests\ShopReplaceItemValidation;
Expand Down Expand Up @@ -145,7 +145,8 @@ public function sell(Request $request, Character $character) {
return redirect()->back()->with('success', 'Sold: ' . $item->affix_name . ' for: ' . $totalSoldFor . ' gold.');
}

public function shopCompare(Request $request, Character $character, ComparisonService $comparisonService) {
public function shopCompare(Request $request, Character $character,
ComparisonService $comparisonService) {

$viewData = $comparisonService->buildShopData($character, Item::where('name', $request->item_name)->first(), $request->item_type);

Expand Down Expand Up @@ -194,7 +195,7 @@ public function buyAndReplace(ShopReplaceItemValidation $request, Character $cha
return redirect()->to(route('game.shop.buy', ['character' => $character]))->with('success', 'Purchased and equipped: ' . $item->affix_name . '.');
}

public function puracheMultiple(ShopBuyMultipleValidation $request, Character $character) {
public function puracheMultiple(ShopBuyMultipleOfItem $request, Character $character) {
$item = Item::where('name', $request->item_name)
->whereNotIn('type', ['alchemy', 'trinket', 'artifact', 'quest'])
->whereNull('item_suffix_id')
Expand Down
5 changes: 4 additions & 1 deletion app/Game/Shop/Requests/ShopBuyMultipleValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ public function rules()
{
return [
'item_name' => 'required|string|exists:items,name',
'amount' => 'required|int'
];
}

public function messages() {
return [
'item_id.required' => 'What are you trying to buy multiple of child?',
'item_name.required' => 'What are you trying to buy multiple of child?',
'item_name.exists' => 'Item does not exist at all ...Huh?',
'amount.required' => 'How much of the item child? How much?',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default interface EquippedTableState {

success_message: string | null;

error_message: string | null;

item_id: number | null;

view_item: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import EquippedTableState from "../../../../../lib/game/character-sheet/types/ta
import SuccessAlert from "../../../../../components/ui/alerts/simple-alerts/success-alert";
import UsableItemsDetails from "../../../../../lib/game/character-sheet/types/inventory/usable-items-details";
import InventoryUseDetails from "../../modals/inventory-item-details";
import DangerAlert from "../../../../../components/ui/alerts/simple-alerts/danger-alert";

export default class EquippedTable extends React.Component<EquippedInventoryTabProps, EquippedTableState> implements ActionsInterface {
constructor(props: EquippedInventoryTabProps) {
Expand All @@ -24,6 +25,7 @@ export default class EquippedTable extends React.Component<EquippedInventoryTabP
loading: false,
search_string: '',
success_message: null,
error_message: null,
item_id: null,
view_item: false,
}
Expand Down Expand Up @@ -114,9 +116,17 @@ export default class EquippedTable extends React.Component<EquippedInventoryTabP
});
}

manageErrorMessage() {
this.setState({
error_message: null
});
}

unequipAll() {
this.setState({
loading: true,
success_message: null,
error_message: null,
}, () => {
this.props.disable_tabs();

Expand All @@ -132,14 +142,25 @@ export default class EquippedTable extends React.Component<EquippedInventoryTabP
this.props.disable_tabs();
});
}, (error: AxiosError) => {

const response = error.response;

if (response) {
this.setState({
loading: false,
error_message: response.data.message
}, () => {
this.props.disable_tabs();
})
}
});
})
}

unequip(id: number) {
this.setState({
loading: true,
success_message: null,
error_message: null,
}, () => {
(new Ajax()).setRoute('character/'+this.props.character_id+'/inventory/unequip').setParameters({
inventory_set_equipped: this.props.is_set_equipped,
Expand All @@ -152,15 +173,20 @@ export default class EquippedTable extends React.Component<EquippedInventoryTabP
this.props.update_inventory(result.data.inventory);
});
}, (error: AxiosError) => {

const response = error.response;

if (response) {
this.setState({
loading: false,
error_message: response.data.message
}, () => {
this.props.disable_tabs();
})
}
});
});
}

saveAsSet() {

}

render() {
return (
<Fragment>
Expand All @@ -171,6 +197,14 @@ export default class EquippedTable extends React.Component<EquippedInventoryTabP
</SuccessAlert>
: null
}

{
this.state.error_message !== null ?
<DangerAlert additional_css={'mb-4 mt-4'} close_alert={this.manageErrorMessage.bind(this)}>
{this.state.error_message}
</DangerAlert>
: null
}
<div className='mb-5'>
<div className='flex flex-row flex-wrap items-center'>
<div>
Expand Down
2 changes: 1 addition & 1 deletion resources/vendor/theme/assets/css/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Menu Bar
Workspace
*/
.workspace {
@apply relative flex flex-auto flex-col mt-20 px-5 pt-5;
@apply relative flex flex-auto flex-col mt-20 px-5 pt-5 my-10;

@screen md {
@apply px-10 pt-10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
])

<button class="{{'hover:bg-blue-700 hover:drop-shadow-md hover:text-gray-300 bg-blue-600 dark:bg-blue-700 text-white dark:hover:text-white font-semibold
py-2 px-4 rounded-sm drop-shadow-sm ' . $css}}"
py-2 px-4 rounded-sm drop-shadow-sm disabled:opacity-75 disabled:cursor-not-allowed ' . $css}}"
{{$attributes}}
>
{{ $slot }}
Expand Down
60 changes: 28 additions & 32 deletions resources/views/game/shop/multiple.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,43 @@

<dl class="my-4">
<dt>Your Gold:</dt>
<dd>{{number_format($gold)}}</dd>
<dd>{{ number_format($gold) }}</dd>
<dt>Item Cost:</dt>
<dd>{{number_format($cost)}}</dd>
<dd>{{ number_format($cost) }}</dd>
</dl>

<form method="post" action="{{route('game.shop.purchase.multiple', ['character' => $characterId])}}">
@csrf

<input type="hidden" name="item_id" value="{{$itemId}}" />

<div class="mb-5" x-data="{
amount: 0,
get cost() {
let amount = this.amount * {{$cost}};
if ({{$character->classType()->isMerchant()}}) {
amount = amount - amount * .025;
}
return Math.floor(amount);
},
get isDisabled() { return true; }
}">
<label class="label block mb-2" for="amount">Amount</label>
<input x-model="amount" id="amount" type="number" class="form-control" name="amount" min="0" max="75" value="{{ old('amount') }}" required autofocus>
@error('amount')
<div class="text-red-800 dark:text-red-500 pt-3" role="alert">
<strong>{{$message}}</strong>
</div>
@enderror
<dl class="my-4">
<dt>Cost</dt>
<dd x-text="cost" :class="{'text-red-500': cost > {{$gold}}}"></dd>
</dl>
<form x-data="{ quantity: 1, cost: @json($cost), gold: @json($gold) }" x-init="quantity = 1" method="post" action="{{ route('game.shop.purchase.multiple', ['character' => $characterId]) }}">
@csrf()

<input type="hidden" value="{{$itemId}}" name="item_id" id="item_id" />

<div class="my-4" x-cloak>
<label for="quantity">Enter Quantity:</label>
<input x-model="quantity" type="number" id="amount" name="amount" min="1" max="75" class="w-1/3 border rounded-md p-2">
</div>

<x-core.buttons.primary-button type="submit">
<div x-show="quantity > 75" x-cloak>
<x-core.alerts.danger-alert>
Quantity cannot exceed 75.
</x-core.alerts.danger-alert>
</div>

<div x-show="quantity * cost > gold" x-cloak>
<x-core.alerts.danger-alert>
You don't have enough gold to purchase that many items.
</x-core.alerts.danger-alert>
</div>

<div class="my-4 text-green-700 dark:text-green-500" x-cloak x-show="quantity <= 75 && quantity * cost <= gold">
<p x-text="'You want to purchase ' + quantity + ', that will cost you ' + (quantity * cost).toLocaleString() + '.'"></p>
</div>

<x-core.buttons.primary-button x-bind:disabled="quantity > 75 || quantity * cost > gold" type="submit">
Purchase Amount
</x-core.buttons.primary-button>
</form>
</x-core.cards.card-with-title>

</x-core.layout.info-container>

@endsection

0 comments on commit 202c602

Please sign in to comment.