-
-
Notifications
You must be signed in to change notification settings - Fork 9
Adding a new Quest
Quests are simple things if you think about it. All of them consist of one thing: steps. A quest is a list of steps, each step of a quest you need to do some thing. In Tiny Land you can do five different things:
- Kill a certain amount of certain types of enemies
- Talk to a specific NPC
- Reach a certain level before continuing
- Have a certain amount of certain types of items in your bag
- Receive an item from a certain NPC
and in the end, a quest gives you some reward. In Tiny Land there are 2 types of rewards: Item or XP (or both).
Let's go ahead and create our own quest, where Lonely Man asks us to kill Evil Denture.
- ./shared/Enums.ts
- ./server/entities/npcs/quests/humans folder
- ./server/entities/npcs/passive (where our NPC is)
Find the enum "Quests" and let's add our new quest identifier: LonelyQuest
export enum Quests {
FlowerForMytklash,
...
...
LonelyQuest
}
Let's go ahead and create our quest file at ./server/entities/npcs/quests/humans. Add a file called "lonelyQuest.ts" and insert this code:
import { Items, Npcs, Quests, RewardType, StepType } from "../../../../Enums.ts"
import QuestBase from "../questBase.ts"
import StepBase from "../stepBase.ts"
import { MonstersToKillBase } from "../monstersToKillBase.ts"
import Bread from "../../../items/consumable/bread.ts"
export default class LonelyQuest extends QuestBase {
constructor() {
super(Quests.LonelyQuest, // quest id you created at enums.ts
[ // start of the list of steps
new StepBase(StepType.MonstersToKill, // first step consists of enemies to kill
[
new MonstersToKillBase(Npcs.EvilDenture, 1), //step receives a list of monsters to kill as 2nd argument
],
'lonelyman',[],[],0), // we owe these dead enemies to 'lonelyman'
new StepBase(StepType.NpcToTalk,[],'lonelyman', //second step we just talk to lonely man again
[
'Thank you so much!',
'You killed my evil denture',
'I\'ll reward you with xp and bread',
'-you received 1xp-',
'-you received bread-',
],[],0),
],
RewardType.Both, // reward type is xp and item
new Bread(0), // we receive bread
1, // and 1 xp
'I only exist as a test. At least no more evil dentures.') // this is the new dialog whenever we talk to lonely man
}
}
Let's now actually make Lonly Man give us the quest by going back to it's file (lonelyMan.ts) at ./server/entities/npcs/passive and paste this code:
import { Npcs } from '../../../Enums.ts'
import NpcBase from '../npcBase.ts'
import LonelyQuest from "../quests/humans/lonelyQuest.ts"
import LonelyManDialog from "./dialogs/lonelyManDialog.ts"
export default class LonelyMan extends NpcBase {
constructor() {
super(Npcs.CityOldMale2, false, 'lonelyman', 0, 0, 0, 0, 1000, 0, 0, 36, new LonelyManDialog(), [], new LonelyQuest())
}
}
notice our last argument, that's our quest. Let's tweak Lonely Man's dialog a bit too! Go to Lonely Man's dialog and change it to this:
import DialogBase from "./dialogBase.ts"
export default class LonelyManDialog extends DialogBase {
constructor() {
super(['Hi! Have you seen my dentures?',
'They just popped out of my mouth',
'as a living creature',
'You have to kill it before it\'s too late',
'can you do this?',
'-quest: Lonely Man\'s Quest-',''])
}
}
We're already done but there's still one annoying step. It goes against the second rule of SOLID principles, which states that your code must be extensible but not modifiable. But for now, that's how it goes, maybe this will be more automatic in the future: go to ./server/entities/npcs/quests/quest.ts and you'll notice this at around line 200:
public static getQuestFromQuestId(questId: Quests): any {
if (questId == Quests.DamnRats) {
return new DamnRats()
}
...
...
// add this conditional
if (questId == Quests.LonelyQuest) {
return new LonelyQuest()
}
return null
}
This is needed in order to load quests from our save point. Someday in the future this might be automatic, but not for now...
Let's test it!
Now you know how to create all of the main features in tiny land! Maybe you should dive a little more into the code to understand how everything connects, so you can start creating your own features, or even improving how existent ones work!
Thank you so much for taking time to play and to code for Tiny Land!