From 537c19f09fc0db249c3d589f1e78c162d31790e7 Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 30 Jun 2023 14:39:09 -0400 Subject: [PATCH] add default texts for all healers --- src/events/healer/server.ts | 76 +++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/src/events/healer/server.ts b/src/events/healer/server.ts index fd7bbb1..f621c41 100644 --- a/src/events/healer/server.ts +++ b/src/events/healer/server.ts @@ -1,33 +1,37 @@ 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; 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 = { - [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?' ], @@ -40,7 +44,7 @@ const playerTexts: Record = { ] }, [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' ], @@ -53,7 +57,7 @@ const playerTexts: Record = { }, [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' @@ -68,6 +72,19 @@ const playerTexts: Record = { } } +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 }) => { @@ -83,8 +100,10 @@ export const healer: SocketEvent = { return; } + const city = await getCityDetails(service.city_id); + text.push(`

${service.name}

`); - text.push(`

"${sample(playerTexts[service.id].intro_texts)}"

`); + text.push(`

"${getText('intro', service, city)}"

`); if(api.player.hp === maxHp(api.player.constitution, api.player.level)) { text.push(`

You're already at full health?

`); @@ -116,10 +135,12 @@ export const heal: SocketEvent = { return; } + const city = await getCityDetails(service.city_id); + text.push(`

${service.name}

`); if(api.player.gold < healCost) { - text.push(`

${sample(playerTexts[service.id].insufficient_money)}

`) + text.push(`

${getText('insufficient_money', service, city)}

`) api.socket.emit('city:service:healer', { text: text.join("\n") }); @@ -133,12 +154,9 @@ export const heal: SocketEvent = { api.socket.emit('updatePlayer', api.player); - text.push(`

${sample(playerTexts[service.id].heal_successful)}

`); + text.push(`

${getText('heal_successful', service, city)}

`); api.socket.emit('city:service:healer', { text: text.join("\n") }); - - - console.log(data); } } -- 2.25.1