add default texts for all healers
authorxangelo <git@xangelo.ca>
Fri, 30 Jun 2023 18:39:09 +0000 (14:39 -0400)
committerxangelo <git@xangelo.ca>
Fri, 30 Jun 2023 18:39:09 +0000 (14:39 -0400)
src/events/healer/server.ts

index fd7bbb1d74a14ecc317f56918b2e7a71befd0994..f621c41939af33dc7597bb0d97708fe4534ade69 100644 (file)
@@ -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<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?'
     ],
@@ -40,7 +44,7 @@ const playerTexts: Record<number, HealText> = {
     ]
   },
   [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<number, HealText> = {
 
   },
   [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<number, HealText> = {
   }
 }
 
+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(`<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>`);
@@ -116,10 +135,12 @@ export const heal: SocketEvent = {
       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")
       });
@@ -133,12 +154,9 @@ export const heal: SocketEvent = {
     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);
   }
 }