Skip to content

Commit

Permalink
Remove failed localization experiment as a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shawncplus committed Jan 8, 2017
1 parent ab408bd commit ca16dda
Show file tree
Hide file tree
Showing 111 changed files with 948 additions and 3,706 deletions.
1 change: 0 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ NodeJS based MUD engine with full localization support
See the [staging](https://github.com/shawncplus/ranviermud/tree/staging) branch for the latest features. The master branch will be the latest 'stable' release.

## Features
* Full localization (to be deprecated, without special characters it is not very useful right now.)
* Scripting support: It's in Javascript! No need for a shitty DSL. The codebase is javascript, the scripting is javascript.
* Scripting is event-based. Put a listener in the script attached to your mob and it'll automagically happen when the event is emitted. Adding new events is easy as npc.emit('eventName'); See documentation on node event emitters for more.
* Pfile saving in JSON, easy to parse for external usage.
Expand Down
33 changes: 19 additions & 14 deletions commands/commands.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
'use strict';
const sprintf = require('sprintf').sprintf;
exports.command = (rooms, items, players, npcs, Commands) => {
return (args, player) => {
let commands = [];
let maxlength = 0;
for (let command in Commands.player_commands) {
if (command.length > maxlength) maxlength = command.length;
commands.push(command);
}
return (args, player) => {
let commands = [];
let maxlength = 0;
for (const command in Commands.player_commands) {
if(command[0] === '_') {
continue;
}
if (command.length > maxlength) {
maxlength = command.length;
}
commands.push(command);
}

commands.sort();
commands.sort();

let len = commands.length + 1;
for (let i = 1; i < len; i++) {
let endOfColumn = i % 5 === 0;
player[endOfColumn ? 'say' : 'write'](sprintf('%-' + (maxlength + 1) + 's', commands[i-1]));
}
};
let len = commands.length + 1;
for (let i = 1; i < len; i++) {
let endOfColumn = i % 5 === 0;
player[endOfColumn ? 'say' : 'write'](sprintf('%-' + (maxlength + 1) + 's', commands[i-1]));
}
};
};
17 changes: 7 additions & 10 deletions commands/drop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';
const l10nFile = __dirname + '/../l10n/commands/drop.yml';
const l10n = require('../src/l10n')(l10nFile);
const CommandUtil = require('../src/command_util').CommandUtil;
const util = require('util');

Expand All @@ -10,7 +8,7 @@ exports.command = (rooms, items, players, npcs, Commands) => {

//TODO: Does this handle dropping a container with items in it?
// Should remove all contents from player inventory and set the room for each of them.

args = args.toLowerCase();

if (args === 'all') {
Expand Down Expand Up @@ -39,26 +37,26 @@ exports.command = (rooms, items, players, npcs, Commands) => {
function drop(item) {
let playerName = player.getName();

if (item.isEquipped() || isDead) {
if (item.isEquipped() || isDead) {
const isDropping = true;
const location = player.unequip(item, items, players, isDropping);
const location = player.unequip(item, items, players, isDropping);
if (!isDead) { item.emit('remove', location, room, player, players); }
}

var shortDesc = item.getShortDesc();
players.eachIf(
p => CommandUtil.inSameRoom(p, player),
p => p.sayL10n(l10n, 'OTHER_DROPS', playerName, item.getShortDesc(p.getLocale()))
p => p.say(`${playerName} drops the ${shortDesc}`)
);

let itemName = item.getShortDesc('en');
if (!isDead) {
player.sayL10n(l10n, 'ITEM_DROP', itemName, false);
player.say(`You drop ${shortDesc}.`);
room.getNpcs().forEach( id => {
let npc = npcs.get(id);
npc.emit('playerDropItem', room, rooms, player, players, npc, npcs, item, items);
});
}
util.log(`${playerName} drops ${itemName} at ${room.getLocation()}.`);
util.log(`${playerName} drops ${shortDesc} at ${room.getLocation()}.`);

player.removeItem(item);
const container = items.get(item.getContainer());
Expand All @@ -67,6 +65,5 @@ exports.command = (rooms, items, players, npcs, Commands) => {
item.setHolder(null);
item.setRoom(room.getLocation());
}

};
};
21 changes: 0 additions & 21 deletions commands/emote.js

This file was deleted.

26 changes: 1 addition & 25 deletions commands/flee.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
const CommandUtil = require('../src/command_util').CommandUtil;
const Random = require('../src/random').Random;
const move = require('../src/commands').Commands.move;
const l10nFile = __dirname + '/../l10n/commands/flee.yml';
const util = require('util');
const l10n = require('../src/l10n')(l10nFile);

exports.command = (rooms, items, players, npcs, Commands) => {
return (args, player) => {

Expand All @@ -22,32 +18,12 @@ exports.command = (rooms, items, players, npcs, Commands) => {
const exit = Random.fromArray(room.getExits());

if (fleed && move(exit, player)) {

opponents.forEach(opp => opp.removeFromCombat(player));
player.fleeFromCombat();

player.say(`<red>You manage to escape in one piece!</red>`);
util.log(player.getName() + " fled successfully.");

const duration = player.getAttribute('level') * 1000;
player.addEffect('cowardice', {
type: 'debuff',
name: 'Cowardice',
description: 'Recovering from fleeing in fear',
aura: 'cowardly',
penalty: 1,
duration
});


const cumulativeOpponentLevel = opponents.reduce((sum, opp) => sum += opp.getAttribute('level'), 0);
const level = player.getAttribute('level');

if (cumulativeOpponentLevel > level + 2) {
const expGain = (cumulativeOpponentLevel - level) * 10;
player.emit('experience', expGain, 'surviving to fight again another day');
}

} else {
player.warn('You are cornered and unable to escape!');
}
Expand Down
2 changes: 0 additions & 2 deletions commands/get.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';
const l10nFile = __dirname + '/../l10n/commands/get.yml';
const l10n = require('../src/l10n')(l10nFile);
const CommandUtil = require('../src/command_util').CommandUtil;
const ItemUtil = require('../src/item_util').ItemUtil;
const util = require('util');
Expand Down
15 changes: 3 additions & 12 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
'use strict';
const l10nFile = __dirname + '/../l10n/commands/help.yml';
const l10n = require('../src/l10n')(l10nFile);
const util = require('util');
const HelpFiles = require('../src/help_files').HelpFiles;
const wrap = require('wrap-ansi');
const _ = require('../src/helpers');
const sprintf = require('sprintf').sprintf;

/*
NEW: {
title: 'Welcome to Ranvier',
body: 'Important topics include:',
related: 'levels','attributes','mutants','mental','physical','energy','combat','social',
},
*/
// TODO: Rewrite

exports.command = (rooms, items, players, npcs, Commands) => {
return (args, player) => {
Expand Down Expand Up @@ -55,9 +47,8 @@ exports.command = (rooms, items, players, npcs, Commands) => {
function displayHelpFile(topic) {
const file = HelpFiles[topic];
if ( !file) {
return args in Commands.player_commands ?
player.writeL10n(l10n, 'NO_HELP_FILE') :
player.writeL10n(l10n, 'NOT_FOUND');
util.log(`(admin help) Help page requested for '${topic}' by '${player.getName()}'`);
return player.say(`No help pages found for ${topic}.`);
}

// --- Helpers for printing out the help files. Help helpers.
Expand Down
25 changes: 12 additions & 13 deletions commands/inventory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
const l10nFile = __dirname + '/../l10n/commands/inventory.yml';
const l10n = require('../src/l10n')(l10nFile);
const _ = require('../src/helpers');
const util = require('util');

// TODO: Rewrite

exports.command = (rooms, items, players, npcs, Commands) => {
return (args, player) => {
const inventory = player.getInventory();
Expand All @@ -16,29 +16,29 @@ exports.command = (rooms, items, players, npcs, Commands) => {
const equipment = new Map();
const longestSlot = Object.keys(equipped)
.reduce((longest, key) => longest > key.length ? longest : key.length, 0);

let longest = 0;

for (let slot in equipped) {
const item = items.get(equipped[slot]);
const name = item.getShortDesc();
const weight = item.getWeight(items);
const contents = item.isContainer() ? item.getInventory() : false;
const capacity = item.isContainer() ?
const capacity = item.isContainer() ?
getContainerCapacity(item) :
null;
equipment.set(slot, { name, weight, contents, capacity });

longest = name.length > longest ?
name.length :
longest = name.length > longest ?
name.length :
longest;
}

player.say(
`<bold>Your inventory:</bold>
<cyan>Encumbrance: ${player.getCarriedWeight(items)}/${player.getMaxCarryWeight()} gravets</cyan>
`);

const displayListItem = (name, nestingLevel) => player.say(`<cyan>${_.leftPad(nestingLevel)} - ${name}</cyan>`);

for (let [slot, details] of equipment) {
Expand All @@ -54,8 +54,8 @@ exports.command = (rooms, items, players, npcs, Commands) => {
function displayContainerContents(contents, nestingLevel) {
contents
.map(items.get)
.forEach(item => item.isContainer() ?
displayNestedContainer(item, nestingLevel) :
.forEach(item => item.isContainer() ?
displayNestedContainer(item, nestingLevel) :
displayListItem(item.getShortDesc(), nestingLevel));
}

Expand All @@ -65,9 +65,9 @@ exports.command = (rooms, items, players, npcs, Commands) => {
}

function getContainerCapacity(item) {
return {
max: item.getAttribute('maxSizeCapacity'),
current: item.getSizeOfContents(items)
return {
max: item.getAttribute('maxSizeCapacity'),
current: item.getSizeOfContents(items)
};
}

Expand All @@ -76,6 +76,5 @@ exports.command = (rooms, items, players, npcs, Commands) => {
const { current, max } = capacity;
return ` <green>${current}/${max} aums</green>`;
}

};
};
4 changes: 0 additions & 4 deletions commands/kill.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict';
const CommandUtil = require('../src/command_util').CommandUtil;
const l10nFile = __dirname + '/../l10n/commands/kill.yml';
const _ = require('../src/helpers');
const l10n = require('../src/l10n')(l10nFile);
const util = require('util');

exports.command = (rooms, items, players, npcs, Commands) => {
return (args, player) => {
Expand Down
Loading

0 comments on commit ca16dda

Please sign in to comment.