Skip to content

Commit

Permalink
feat(server): new quest
Browse files Browse the repository at this point in the history
  • Loading branch information
Veradictus committed Sep 14, 2023
1 parent ce7519b commit 50654ee
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
48 changes: 48 additions & 0 deletions packages/server/data/quests/anvilsechoes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "Anvil's Echoes",
"description": "The local blacksmith has lost his hammer and needs your help.|Seriously, he was just using it and now it's gone. I'm sure he'll be offering you a very nice reward for it if you help him out. Just go talk to him, he should be located somewhere in Mudwich, like right in the centre or something.",
"rewards": ["Blacksmith's Boots", "420 Smithing experience", "Access to the Smithing skill"],
"stages": {
"0": {
"task": "talk",
"npc": "blacksmith",
"text": [
"Dear adventurer, I have a huge problem.",
"My ancestral hammer has been stolen by a thief.",
"Without it I cannot produce some of my finest work.",
"I'm now stuck having to use this old hammer.",
"Listen, if you help me out I will give you something cool.",
"How about some smithing boots? They will help you smith faster.",
"It's definitely not some voodoo magic, I promise.",
"I last seen it when I was trying to smith on the beach.",
"I looked away for a second and it was gone.",
"I think you should start there and see if you can find any clues."
],
"completedText": ["Please, go check out the beach for any clues."]
},
"1": {
"task": "talk",
"npc": "blacksmith",
"hasItemText": [
"Oh! My wonderful hammer!",
"I can finally get back to break- I mean smithing.",
"Here, take these smithing boots as a reward.",
"You can also use my anvil to smith anything you want.",
"I'm sure you'll find it useful."
],
"skill": "smithing",
"experience": 420,
"itemRewards": [
{
"key": "smithingboots",
"count": 1
}
],
"popup": {
"title": "Quest completed!",
"text": "@green@You've been awarded @crimson@3000 Smithing experience@green@ and @crimson@Smithing Gloves@green@.",
"colour": "#33cc33"
}
}
}
}
11 changes: 11 additions & 0 deletions packages/server/src/controllers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,17 @@ export default class Entities {
);
}

/**
* Attempts to find an NPC based on a key. Note that this will find the first
* NPC we come across with the key, so it is not recommended to use this
* function if there are multiple NPCs with the same key.
* @param key The key of the NPC we are looking for.
*/

public getNPCByKey(key: string): NPC | undefined {
return Object.values(this.npcs).find((npc: NPC) => npc.key === key);
}

/**
* Looks for the string of the entity in all the data files
* and returns the type of entity it is.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Quest from '../quest';
import Data from '../../../../../../../data/quests/anvilsechoes.json';

import type { ProcessedDoor } from '@kaetram/common/types/map';
import type Player from '../../player';

export default class AnvilsEchoes extends Quest {
public constructor(key: string) {
super(key, Data);
}

/**
* Override for when the player goes through the door. We want to trigger an NPC
* dialogue when the player attempts to go through the door but hasn't finished
* the quest yet.
* @param door The door the player is going through.
* @param player The player going through the door.
*/

protected override handleDoor(door: ProcessedDoor, player: Player): void {
if (this.stage < door.stage) {
let npc = player.world.entities.getNPCByKey(door.npc);

npc?.talk(player, [`Hey, don't go in there, it's dangerous!`]);

return;
}

super.handleDoor(door, player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import royaldrama from './royaldrama';
import clamchowder from './clamchowder';
import royalpet from './royalpet';
import scientistspotion from './scientistspotion';
import anvilsechoes from './anvilsechoes.ts';

export default {
tutorial,
Expand All @@ -29,5 +30,6 @@ export default {
royaldrama,
clamchowder,
royalpet,
scientistspotion
scientistspotion,
anvilsechoes
};

0 comments on commit 50654ee

Please sign in to comment.