--- /dev/null
+import { Response, Router } from "express";
+import { maxHp, maxVigor } from "../../shared/player";
+import { authEndpoint, AuthRequest } from '../auth';
+import { logger } from "../lib/logger";
+import { updatePlayer } from "../player";
+import { getCityDetails, getService } from '../map';
+import { sample } from 'lodash';
+import { City, Location } from "../../shared/map";
+import { renderPlayerBar } from "../views/player-bar";
+import { BackToTown } from "../views/components/button";
+
+export const router = Router();
+
+type TextSegment = 'intro' | 'insufficient_money' | 'heal_successful';
+
+type HealText = Record<TextSegment, string[]>;
+
+const healCost = 10;
+
+const defaultTexts: HealText = {
+ intro: [
+ `Welcome traveller, I am {{NAME}}, Healer of {{CITY_NAME}}`,
+ "Please come in traveller, I am {{NAME}}, Healer of {{CITY_NAME}}",
+ ],
+ insufficient_money: [
+ "Sorry friend, you don't have enough money..",
+ "Sorry, that won't be enough..",
+ "Healing is hard work.. I'm afraid that won't cover it.."
+ ],
+ heal_successful: [
+ "I hope you feel better now",
+ "Good luck on your travels!",
+ "Glad to be of service..."
+ ]
+};
+
+// overrides for specific areas
+const playerTexts: Record<number, HealText> = {
+ [8]: {
+ intro: [
+ 'Welcome to Midfield traveller, I am Casim - healer in these parts',
+ 'I am Casim the Healer here... how are you enjoying your stay at Midfield?'
+ ],
+ insufficient_money: [
+ 'Sorry friend, you don\'t have enough money',
+ 'Look.. I\'m sorry.. that won\'t be enough...'
+ ],
+ heal_successful: [
+ 'Glad to help!'
+ ]
+ },
+ [16]: {
+ intro: [
+ 'Ah, welcome to Wildegard, one of the few safehavens in the Akari Woods. I am Adovras, healer in these parts.',
+ 'Welcome traveller, I am Adovras - healer in these parts'
+ ],
+ insufficient_money: [
+ `Sorry friend, you don't have enough money...`
+ ],
+ heal_successful: [
+ "Hope this small healing will be helpful on your journeys"
+ ]
+
+ },
+ [11]: {
+ intro: [
+ 'Ah, welcome traveler - I am Uthar, healer of Davelfell',
+ 'Hello, I am Uthar, healer of Davelfell',
+ 'Sorry I\'m a bit busy today, I am Uthar, healer of Davelfell'
+ ],
+ insufficient_money: [
+ "Bah, don't bother me if you don't have the money",
+ "Look, I'm very busy - come back when you have the money"
+ ],
+ heal_successful: [
+ "*Fizz* *POOF* YOU'RE HEALED!"
+ ]
+ }
+}
+
+function getText(type: TextSegment, location: Location, city: City): string {
+ let selected = sample(defaultTexts[type]);
+
+ if(playerTexts[location.id]) {
+ if(playerTexts[location.id][type].length) {
+ selected = sample(playerTexts[location.id][type]);
+ }
+ }
+
+ return selected.replace("{{NAME}}", location.name).replace("{{CITY_NAME}}", city.name);
+
+}
+
+router.get('/city/services/healer/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+ const service = await getService(parseInt(req.params.location_id));
+ const city = await getCityDetails(service.city_id);
+
+ if(!service || service.city_id !== req.player.city_id) {
+ logger.log(`Invalid location: [${req.params.location_id}]`);
+ res.sendStatus(400);
+ }
+
+ const text: string[] = [];
+
+ text.push(`<p>"${getText('intro', service, city)}"</p>`);
+
+ if(req.player.hp === maxHp(req.player.constitution, req.player.level) && req.player.vigor === maxVigor(req.player.constitution, req.player.level)) {
+ text.push(`<p>You're already in peak condition!</p>`);
+ }
+ else {
+ if(req.player.gold <= (healCost * 2)) {
+ text.push(`<p>You don't seem to have too much money... I guess I can do it for free this time...</p>`);
+ text.push(`<p><button type="button" hx-post="/city/services/healer/heal/${service.id}" hx-target="#explore">Heal for Free!</button></p>`);
+ }
+ else {
+ text.push(`<p><button type="button" hx-post="/city/services/healer/heal/${service.id}" hx-target="#explore">Heal for ${healCost}g!</button></p>`);
+ }
+
+ }
+
+ res.send(`
+<div class="city-title-wrapper"><div class="city-title">${service.city_name}</div></div>
+<div class="city-details">
+<h3 class="location-name"><span>${service.name}</span></h3>
+<div class="service-in-town">
+${text.join("\n")}
+${BackToTown()}
+</div>
+</div>
+ `);
+
+ //res.send(`<div class="service-in-town">${text.join("\n")}</div>`);
+});
+
+
+
+router.post('/city/services/healer/heal/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+ const service = await getService(parseInt(req.params.location_id));
+ const city = await getCityDetails(service.city_id);
+
+ if(!service || service.city_id !== req.player.city_id) {
+ logger.log(`Invalid location: [${req.params.location_id}]`);
+ res.sendStatus(400);
+ }
+
+ const text: string[] = [];
+ const cost = req.player.gold <= (healCost * 2) ? 0 : healCost;
+
+ if(req.player.gold < cost) {
+ text.push(`<p>${getText('insufficient_money', service, city)}</p>`)
+ }
+ else {
+ req.player.hp = maxHp(req.player.constitution, req.player.level);
+ req.player.vigor = maxVigor(req.player.constitution, req.player.level);
+ req.player.gold -= cost;
+
+ await updatePlayer(req.player);
+
+ text.push(`<p>${getText('heal_successful', service, city)}</p>`);
+ }
+
+ res.send(`
+<div class="city-title-wrapper"><div class="city-title">${service.city_name}</div></div>
+<div class="city-details">
+<h3 class="location-name"><span>${service.name}</span></h3>
+<div class="service-in-town">
+${text.join("\n")}
+${BackToTown()}
+</div>
+</div>
+${renderPlayerBar(req.player)}
+`);
+});
+++ /dev/null
-import { Response, Router } from "express";
-import { maxHp, maxVigor } from "../../../shared/player";
-import { authEndpoint, AuthRequest } from '../../auth';
-import { logger } from "../../lib/logger";
-import { updatePlayer } from "../../player";
-import { getCityDetails, getService } from '../../map';
-import { sample } from 'lodash';
-import { City, Location } from "../../../shared/map";
-import { renderPlayerBar } from "../../views/player-bar";
-import { BackToTown } from "../../views/components/button";
-
-export const router = Router();
-
-type TextSegment = 'intro' | 'insufficient_money' | 'heal_successful';
-
-type HealText = Record<TextSegment, string[]>;
-
-const healCost = 10;
-
-const defaultTexts: HealText = {
- intro: [
- `Welcome traveller, I am {{NAME}}, Healer of {{CITY_NAME}}`,
- "Please come in traveller, I am {{NAME}}, Healer of {{CITY_NAME}}",
- ],
- insufficient_money: [
- "Sorry friend, you don't have enough money..",
- "Sorry, that won't be enough..",
- "Healing is hard work.. I'm afraid that won't cover it.."
- ],
- heal_successful: [
- "I hope you feel better now",
- "Good luck on your travels!",
- "Glad to be of service..."
- ]
-};
-
-// overrides for specific areas
-const playerTexts: Record<number, HealText> = {
- [8]: {
- intro: [
- 'Welcome to Midfield traveller, I am Casim - healer in these parts',
- 'I am Casim the Healer here... how are you enjoying your stay at Midfield?'
- ],
- insufficient_money: [
- 'Sorry friend, you don\'t have enough money',
- 'Look.. I\'m sorry.. that won\'t be enough...'
- ],
- heal_successful: [
- 'Glad to help!'
- ]
- },
- [16]: {
- intro: [
- 'Ah, welcome to Wildegard, one of the few safehavens in the Akari Woods. I am Adovras, healer in these parts.',
- 'Welcome traveller, I am Adovras - healer in these parts'
- ],
- insufficient_money: [
- `Sorry friend, you don't have enough money...`
- ],
- heal_successful: [
- "Hope this small healing will be helpful on your journeys"
- ]
-
- },
- [11]: {
- intro: [
- 'Ah, welcome traveler - I am Uthar, healer of Davelfell',
- 'Hello, I am Uthar, healer of Davelfell',
- 'Sorry I\'m a bit busy today, I am Uthar, healer of Davelfell'
- ],
- insufficient_money: [
- "Bah, don't bother me if you don't have the money",
- "Look, I'm very busy - come back when you have the money"
- ],
- heal_successful: [
- "*Fizz* *POOF* YOU'RE HEALED!"
- ]
- }
-}
-
-function getText(type: TextSegment, location: Location, city: City): string {
- let selected = sample(defaultTexts[type]);
-
- if(playerTexts[location.id]) {
- if(playerTexts[location.id][type].length) {
- selected = sample(playerTexts[location.id][type]);
- }
- }
-
- return selected.replace("{{NAME}}", location.name).replace("{{CITY_NAME}}", city.name);
-
-}
-
-router.get('/city/services/healer/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
- const service = await getService(parseInt(req.params.location_id));
- const city = await getCityDetails(service.city_id);
-
- if(!service || service.city_id !== req.player.city_id) {
- logger.log(`Invalid location: [${req.params.location_id}]`);
- res.sendStatus(400);
- }
-
- const text: string[] = [];
-
- text.push(`<p>"${getText('intro', service, city)}"</p>`);
-
- if(req.player.hp === maxHp(req.player.constitution, req.player.level) && req.player.vigor === maxVigor(req.player.constitution, req.player.level)) {
- text.push(`<p>You're already in peak condition!</p>`);
- }
- else {
- if(req.player.gold <= (healCost * 2)) {
- text.push(`<p>You don't seem to have too much money... I guess I can do it for free this time...</p>`);
- text.push(`<p><button type="button" hx-post="/city/services/healer/heal/${service.id}" hx-target="#explore">Heal for Free!</button></p>`);
- }
- else {
- text.push(`<p><button type="button" hx-post="/city/services/healer/heal/${service.id}" hx-target="#explore">Heal for ${healCost}g!</button></p>`);
- }
-
- }
-
- res.send(`
-<div class="city-title-wrapper"><div class="city-title">${service.city_name}</div></div>
-<div class="city-details">
-<h3 class="location-name"><span>${service.name}</span></h3>
-<div class="service-in-town">
-${text.join("\n")}
-${BackToTown()}
-</div>
-</div>
- `);
-
- //res.send(`<div class="service-in-town">${text.join("\n")}</div>`);
-});
-
-
-
-router.post('/city/services/healer/heal/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
- const service = await getService(parseInt(req.params.location_id));
- const city = await getCityDetails(service.city_id);
-
- if(!service || service.city_id !== req.player.city_id) {
- logger.log(`Invalid location: [${req.params.location_id}]`);
- res.sendStatus(400);
- }
-
- const text: string[] = [];
- const cost = req.player.gold <= (healCost * 2) ? 0 : healCost;
-
- if(req.player.gold < cost) {
- text.push(`<p>${getText('insufficient_money', service, city)}</p>`)
- }
- else {
- req.player.hp = maxHp(req.player.constitution, req.player.level);
- req.player.vigor = maxVigor(req.player.constitution, req.player.level);
- req.player.gold -= cost;
-
- await updatePlayer(req.player);
-
- text.push(`<p>${getText('heal_successful', service, city)}</p>`);
- }
-
- res.send(`
-<div class="city-title-wrapper"><div class="city-title">${service.city_name}</div></div>
-<div class="city-details">
-<h3 class="location-name"><span>${service.name}</span></h3>
-<div class="service-in-town">
-${text.join("\n")}
-${BackToTown()}
-</div>
-</div>
-${renderPlayerBar(req.player)}
-`);
-});