Skip to content

Commit

Permalink
Smith ore and turn to bar!
Browse files Browse the repository at this point in the history
  • Loading branch information
naknode committed May 29, 2020
1 parent 822b708 commit 77e85e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -9,6 +9,7 @@ module.exports = {
],
rules: {
'import/extensions': 0,
'no-restricted-syntax': 0,
'import/first': 0,
'import/no-cycle': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
Expand Down
35 changes: 25 additions & 10 deletions server/core/skills/smithing.js
Expand Up @@ -2,11 +2,14 @@ import world from '@server/core/world';
import Skill from './index';

export default class Smithing extends Skill {
constructor(playerIndex, ores) {
constructor(playerIndex, resourceId, type) {
super(playerIndex);
this.player = world.players[playerIndex];
this.ores = ores;
this.resourceId = resourceId;
this.type = type; // bar | ore
this.columnId = 'smithing';

this.inventory = this.player.inventory;
}

static ores() {
Expand All @@ -27,31 +30,43 @@ export default class Smithing extends Skill {
};
}

static smelt(inventory, bar) {
console.log('Smelting', bar);
smelt(inventory) {
console.log('Smelting', this.resourceId);

const barToSmelt = this.ores()[bar];
const barToSmelt = Smithing.ores()[this.resourceId];

const hasEnoughOre = () => {
// eslint-disable-next-line
for (const ore of Object.keys(barToSmelt.requires)) {
const oreFound = inventory.filter(inv => inv.id === ore);
if (barToSmelt.requires[ore] > oreFound.length) {
return false;
}
if (barToSmelt.requires[ore] > oreFound.length) { return false; }
}

return true;
};

if (hasEnoughOre) {
console.log('We have enough ore!');
// Let's take away the needed ores from inventory
for (const ore of Object.keys(barToSmelt.requires)) {
for (let i = 0; i < barToSmelt.requires[ore]; i + 1) {
// Going through every ore requirement, getting the value
// and filtering the ore needed one by one.
// There's probably a better way to do this...
const getIndexOfOre = this.inventory.findIndex(inv => inv.id === ore);
this.inventory.splice(getIndexOfOre, 1);
}
}

// Add bar to inventory
// WORLD PLAYER ADD BAR TO INVENTORY (inventory.add() from Player)
// AND RETURN THEIR NEW INVENTORY
} else {
console.log('Not enough ore.');
}
}

static bars() {
// The bars available to smith and their level needed.
// Is this better suited in a config file?
return {
'bronze-bar': 1,
'iron-bar': 19,
Expand Down

0 comments on commit 77e85e8

Please sign in to comment.