import * as Alert from "../../views/alert";
import { updatePlayer } from "../../player";
import { renderPlayerBar } from "../../views/player-bar";
+import { Button } from '@server/views/components/button';
export const repairRouter = Router();
+ Alert.SuccessAlert(`You repaired your ${item.name} for ${cost}G`)
);
});
+
+// check if the player has enough gold to repair the item
+repairRouter.get('/city/services/:location_id/repair/:item_id/check', authEndpoint, async (req: Request, res: Response) => {
+ const service = await getService(parseInt(req.params.location_id));
+
+ if(!service || service.city_id !== req.player.city_id) {
+ req.logger.error(`Invalid location: [${req.params.location_id}]`);
+ return res.sendStatus(400);
+ }
+
+ const item = await getInventoryItem(req.player.id, req.params.item_id);
+
+ if(!item) {
+ req.logger.error(`Invalid item [${req.params.item_id}]`);
+ return res.sendStatus(400);
+ }
+
+ const cost = repairCost(item);
+ const repair_button = Button({
+ id: `repair-${item.item_id}`,
+ class: ['repair-button', 'green'],
+ 'hx-swap-oob': 'true',
+ 'hx-target': '#explore',
+ 'hx-swap': 'innerHTML',
+ 'hx-post': `/city/services/${service.id}/repair/${item.item_id}`,
+ }, 'Confirm');
+
+ const original_button = Button({
+ id: `repair-${item.item_id}`,
+ class: ['repair-button'],
+ 'hx-swap-oob': 'true',
+ 'hx-get': `/city/services/${service.id}/repair/${item.item_id}/check`,
+ }, 'Repair');
+
+ if(req.player.gold < cost) {
+ res.send(Alert.ErrorAlert(`Sorry, you need at least ${cost.toLocaleString()}G to repair your ${item.name}`) + original_button);
+ return;
+ }
+
+ return res.send(repair_button);
+});
import { ProgressBar } from "./components/progress-bar";
import * as City from './components/city';
import { BackToTown } from "./components/button";
-
+import { Button } from './components/button';
type RenderStatOptions = {
unsigned: boolean
}
listing[filter] += renderEquipmentToRepair(item, i => {
- return `<button type="button" hx-post="/city/services/${location.id}/repair/${i.item_id}" hx-target="#explore">Repair</button>`
+ return Button({
+ id: `repair-${i.item_id}`,
+ class: ['repair-button'],
+ 'hx-get': `/city/services/${location.id}/repair/${i.item_id}/check`,
+ }, 'Repair');
}, player);
});