Browse Source

moved recipe stuff to mod

1460-move-crafting-to-mod
Shaun 4 years ago
parent
commit
9cf622a1e8
3 changed files with 12 additions and 62 deletions
  1. +0
    -50
      src/server/components/inventory/learnRecipe.js
  2. +4
    -9
      src/server/components/inventory/useItem.js
  3. +8
    -3
      src/server/db/tableNames.js

+ 0
- 50
src/server/components/inventory/learnRecipe.js View File

@@ -1,50 +0,0 @@
module.exports = async ({ serverId, name }, { recipe: { profession, teaches } }) => {
const recipes = await io.getAsync({
key: name,
table: 'recipes',
isArray: true
});

const known = recipes.some(r => r.profession === profession && r.teaches === teaches);
if (known) {
process.send({
method: 'events',
data: {
onGetAnnouncement: [{
obj: {
msg: 'You already know that recipe'
},
to: [serverId]
}]
}
});

return false;
}

recipes.push({
profession,
teaches
});

await io.setAsync({
key: name,
table: 'recipes',
value: recipes,
serialize: true
});

process.send({
method: 'events',
data: {
onGetAnnouncement: [{
obj: {
msg: 'The recipe imprints itself in your mind, then vanishes'
},
to: [serverId]
}]
}
});

return true;
};

+ 4
- 9
src/server/components/inventory/useItem.js View File

@@ -1,5 +1,3 @@
const learnRecipe = require('./learnRecipe');

const isOnCooldown = (obj, cpnInv, item) => {
if (item.cdMax) {
if (item.cd) {
@@ -38,17 +36,14 @@ module.exports = async (cpnInv, itemId) => {
if (isOnCooldown(obj, cpnInv, item))
return;

let result = {};
let result = {
ignore: false
};
obj.instance.eventEmitter.emit('onBeforeUseItem', obj, item, result);
obj.fireEvent('onBeforeUseItem', item, result);

if (item.recipe) {
const didLearn = await learnRecipe(obj, item);
if (didLearn)
cpnInv.destroyItem(itemId, 1);

if (result.ignore)
return;
}

let effects = (item.effects || []);
let eLen = effects.length;


+ 8
- 3
src/server/db/tableNames.js View File

@@ -1,4 +1,6 @@
module.exports = [
const events = require('../misc/events');

const tableNames = [
'character',
'characterList',
'stash',
@@ -11,6 +13,9 @@ module.exports = [
'error',
'modLog',
'accountInfo',
'mtxStash',
'recipes'
'mtxStash'
];

events.emit('onBeforeGetTableNames', tableNames);

module.exports = tableNames;

Loading…
Cancel
Save