import {SocketEvent} from "../../server/socket-event.server";
-import { getService } from "../../server/map";
-import {maxHp} from '../../shared/player';
+import { getCityDetails, getService } from "../../server/map";
+import { City, Location } from "../../shared/map";
+import {maxHp, Player} from '../../shared/player';
import { updatePlayer } from "../../server/player";
import { sample } from 'lodash';
-type HealText = {
- intro_texts: string[],
- insufficient_money: string[],
- heal_successful: string[]
-}
+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> = {
- [1]: {
- intro_texts: [
- 'Welcome traveller. I am Ora, Healer of Windcross',
- 'Please come in, I am Ora - healer of Windcross'
- ],
- insufficient_money: [
- `Sorry friend, you don't have enough money...`
- ],
- heal_successful: [
- `I hope you feel better now`,
- `Good luck on your travels`
- ]
- },
[8]: {
- intro_texts: [
+ 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?'
],
]
},
[16]: {
- intro_texts: [
+ 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'
],
},
[11]: {
- intro_texts: [
+ 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'
}
}
+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);
+
+}
+
export const healer: SocketEvent = {
eventName: 'city:services:healer',
handler: async (api, data: { args: number }) => {
return;
}
+ const city = await getCityDetails(service.city_id);
+
text.push(`<p><b>${service.name}</b></p>`);
- text.push(`<p>"${sample(playerTexts[service.id].intro_texts)}"</p>`);
+ text.push(`<p>"${getText('intro', service, city)}"</p>`);
if(api.player.hp === maxHp(api.player.constitution, api.player.level)) {
text.push(`<p>You're already at full health?</p>`);
return;
}
+ const city = await getCityDetails(service.city_id);
+
text.push(`<p><b>${service.name}</b></p>`);
if(api.player.gold < healCost) {
- text.push(`<p>${sample(playerTexts[service.id].insufficient_money)}</p>`)
+ text.push(`<p>${getText('insufficient_money', service, city)}</p>`)
api.socket.emit('city:service:healer', {
text: text.join("\n")
});
api.socket.emit('updatePlayer', api.player);
- text.push(`<p>${sample(playerTexts[service.id].heal_successful)}</p>`);
+ text.push(`<p>${getText('heal_successful', service, city)}</p>`);
api.socket.emit('city:service:healer', {
text: text.join("\n")
});
-
-
- console.log(data);
}
}