Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with only lowercase player name working with PvP combat (and a BountyGoal.js) #306

Merged
merged 4 commits into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions bundles/ranvier-quests/lib/BountyGoal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

const QuestGoal = require('../../../src/QuestGoal');
const Logger = require('../../../src/Logger');

/**
* A quest goal requiring the player to locate and/or return an NPC.
*/
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
}, config);

super(quest, config, player);

this.state = {
found: false,
delivered: false
};

this.on('enterRoom', this._enterRoom);
}

getProgress() {
// Has target been located?
let percent = this.state.found ? 50 : 0;

if (this.config.home) {
// Has target been returned home?
percent += this.state.delivered ? 50 : 0;
} else {
// No return location necessary.
percent += 50;
}

const display = this.state.found ? 'Complete' : 'Not Complete';
return { percent, display };
}

_enterRoom(room) {
if (this.state.found) {
if (room.entityReference == this.config.home) {
// Check if we have taken the NPC home
this.state.delivered = true;
}
this.emit('progress', this.getProgress());
} else {
let located = false;
const goalNpcId = this.config.npc;
if (goalNpcId !== null) {
room.npcs.forEach(npc => {
if (npc.entityReference == goalNpcId) {
located = true;
npc.follow(this.player);
}
});
} else {
Logger.error(`Quest: BountyGoal [${this.config.title}] does not have target npc defined.`);
}
if (located) {
this.state.found = true;
}
this.emit('progress', this.getProgress());
}
}

serialize() {
let data = super.serialize();
data.config = this.config;
return data;
}
}

module.exports = BountyGoal;
2 changes: 1 addition & 1 deletion src/CommandParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CommandParser {
continue;
}

if (entry.name && entry.name.toLowerCase().includes(keyword)) {
if (entry.name && entry.name.toLowerCase().includes(keyword.toLowerCase())) {
encountered++;
if (encountered === findNth) {
return returnKey ? [key, entry] : entry;
Expand Down