import {SkillID, Skills} from '../shared/skills';
import { router as healerRouter } from './locations/healer';
+import { router as professionRouter } from './locations/recruiter';
import * as Alert from './views/alert';
import { renderPlayerBar } from './views/player-bar'
};
app.use(healerRouter);
+app.use(professionRouter);
app.get('/chat/history', authEndpoint, async (req: AuthRequest, res: Response) => {
</div>
</div>
<div class="actions">
- <button hx-put="/location/${equipment.location_id}/equipment/${equipment.id}" formmethod="dialog" value="cancel">Buy</button>
+ <button hx-put="/location/${equipment.location_id}/equipment/${equipment.id}" formmethod="dialog" value="cancel" class="green">Buy</button>
<button class="close-modal" formmethod="dialog" value="cancel">Cancel</button>
</div>
</dialog>
}
-router.get('/city/services/city:services:healer/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+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);
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/city:services:healer:heal/${service.id}" hx-target="#explore">Heal for Free!</button></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/city:services:healer:heal/${service.id}" hx-target="#explore">Heal for ${healCost}g!</button></p>`);
+ text.push(`<p><button type="button" hx-post="/city/services/healer/heal/${service.id}" hx-target="#explore">Heal for ${healCost}g!</button></p>`);
}
}
-router.post('/city/services/city:services:healer:heal/:location_id', authEndpoint, async (req: AuthRequest, res: Response) => {
+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);
--- /dev/null
+import { Response, Router } from "express";
+import { getService } from "../map";
+import { authEndpoint, AuthRequest } from '../auth';
+import { logger } from "../lib/logger";
+import * as Alert from "../views/alert";
+import { changeProfession } from "../player";
+import { renderPlayerBar } from "../views/player-bar";
+import { getEquippedItems } from "../inventory";
+
+function p(str: string) {
+ return `<p>${str}</p>`;
+}
+
+export const router = Router();
+
+const MIN_LEVEL = 25;
+
+router.get('/city/services/profession_recruitor/:location_id', authEndpoint, async(req: AuthRequest, res: Response) => {
+ const service = await getService(parseInt(req.params.location_id));
+
+ if(!service || service.city_id !== req.player.city_id) {
+ logger.log(`Invalid location: [${req.params.location_id}]`);
+ res.sendStatus(400);
+ }
+
+ let html: string[] = [];
+ if(req.player.profession === 'Wanderer') {
+ html.push(`<p>Our duty is to help Wanderers such as yourself become more than they are. By helping you achieve new levels in service of the King, we can ensure that the Kingdom of Khatis continues to grow!</p>`);
+ html.push(`<p>You have 3 choices laid before you.</p>`);
+ html.push(`<p>You could become a great and mighty <b>Warrior</b>! Wielding powerful swords and maces.</p>`);
+ html.push(`<p>You could become a powerful <b>Mage</b>! Casting spells to rain fire upon our enemies.</p>`);
+ html.push(`<p>You could become a lithe <b>Rogue</b>! Attacking our enemies swiftly when they least expect!</p>`);
+
+ if(req.player.level < MIN_LEVEL) {
+ html.push(p(`Unfortunately you have to be at least level ${MIN_LEVEL} to take part in our training...`));
+ }
+ else {
+ html.push(p(`<b>Be Careful!</b> Once you change your profession, you'll never be a Wanderer again...`));
+ html.push(`
+ <div>
+ <form hx-post="/city/services/profession_change/${service.id}">
+ <button type="submit" value="warrior" name="profession">Become a Warrior</button>
+ <button type="submit" value="mage" name="profession">Become a Mage</button>
+ <button type="submit" value="rogue" name="profession">Become a Rogue</button>
+ </form>
+ </div>
+ `);
+ }
+ }
+ else {
+ let town = 'UNSET';
+ let place = 'UNSETPLACE';
+ switch(req.player.profession) {
+ case 'Warrior':
+ town = 'Stether';
+ place = 'Highbreaker Inn'
+ break;
+ case 'Mage':
+ town = 'Davelfell';
+ place = 'Mages Tower';
+ break;
+ case 'Rogue':
+ town = 'Ferbalt Gap';
+ place = 'Keepers Tavern';
+ break;
+ }
+
+ html.push(p(`Welcome <b>${req.player.profession}</b>!`));
+ html.push(`<p>Unfortunately I won't be of much help to you now that you are no longer a wanderer...</p>`);
+ html.push(`<p>However, you should visit the ${place} in ${town} that can probably provide some guidance!</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" id="recruiter-target">${html.join("\n")}</div>
+ </div>
+ `);
+});
+
+router.post('/city/services/profession_change/:location_id', authEndpoint, async(req: AuthRequest, res: Response) => {
+ const service = await getService(parseInt(req.params.location_id));
+
+ if(!service || service.city_id !== req.player.city_id) {
+ logger.log(`Invalid location: [${req.params.location_id}]`);
+ res.sendStatus(400);
+ }
+
+ let update: {level: number, exp: number};
+
+ switch(req.body.profession.toLowerCase()) {
+ case 'warrior':
+ update = await changeProfession(req.player.id, 'Warrior');
+ req.player.profession = 'Warrior';
+ break;
+ case 'mage':
+ update = await changeProfession(req.player.id, 'Mage');
+ req.player.profession = 'Mage';
+ break;
+ case 'rogue':
+ update = await changeProfession(req.player.id, 'Rogue');
+ req.player.profession = 'Rogue';
+ break;
+ default:
+ res.send(Alert.ErrorAlert(`Invalid profession`));
+ break;
+ }
+
+ if(update) {
+ const equipped = await getEquippedItems(req.player.id);
+ req.player.level = update.level;
+ req.player.exp = update.exp;
+ res.send(renderPlayerBar(req.player, equipped) + `<div id="recruiter-target" class="service-in-town" hx-swap-oob="true">Congrats! You are now a ${req.player.profession}</div>`);
+ }
+
+});