Skip to content

Instantly share code, notes, and snippets.

@bostrt
Created December 13, 2017 04:26
Show Gist options
  • Save bostrt/25314a76af502c419f8d945ac17dbf5b to your computer and use it in GitHub Desktop.
Save bostrt/25314a76af502c419f8d945ac17dbf5b to your computer and use it in GitHub Desktop.
'use strict';
const QuestGoal = require('../../../src/QuestGoal');
/**
* A quest goal requiring the player to locate a NPC.
* TODO: Add Dead-or-Alive feature.
*/
class BountyGoal extends QuestGoal {
constructor(quest, config, player) {
config = Object.assign({
title: 'Locate NPC',
npc: null, // NPC ID to capture
home: null, // Area ID to return to
dead: false // Capture dead or alive?
}, config);
super(quest, config, player);
this.state = {
found: false
};
this.on('enterRoom', this._enterRoom);
}
getProgress() {
let percent = this.state.found ? 100 : 0;
const display = this.state.found ? 'Complete' : 'Not Complete';
return { percent, display };
}
_enterRoom(room) {
if (this.state.found) {
return;
}
let located = false;
const goalnpcid = this.config.npc;
if (goalnpcid != null) {
room.npcs.forEach(npc => {
if (npc.entityReference == goalnpcid) {
located = true;
}
});
}
if (located) {
this.state.found = true;
// TODO: handle dead-or-alive.
// TODO: Handle logic for make NPC follow, or go home.
}
this.emit('progress', this.getProgress());
}
serialize() {
let data = super.serialize();
data.config = this.config;
return data;
}
}
module.exports = BountyGoal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment