Bläddra i källkod

modding[#1581]: Added the 'beforeGatherResource' event that fires before gathering a node and renamed the current 'beforeGatherResource' event to 'beforeGatherResourceComplete'

tags/v0.8.1^2
Shaun 3 år sedan
förälder
incheckning
a0da49cfd5
2 ändrade filer med 25 tillägg och 18 borttagningar
  1. +22
    -15
      src/server/components/gatherer.js
  2. +3
    -3
      src/server/config/factions/anglers.js

+ 22
- 15
src/server/components/gatherer.js Visa fil

@@ -16,27 +16,33 @@ module.exports = {
},

gather: function () {
if (this.gathering)
return;
const { gathering, nodes, defaultTtlMax, gatheringTtlMax, obj } = this;
const { equipment, stats, instance: { eventEmitter } } = obj;

let nodes = this.nodes;
if (nodes.length === 0)
if (gathering)
return;
else if (!nodes.length)
return;

const { obj: { equipment, stats } } = this;

let firstNode = nodes[0];
const [ node ] = nodes;

if (!this.hasSpace(firstNode)) {
if (!this.hasSpace(node)) {
this.sendAnnouncement('Your bags are too full to gather any more resources.');
return;
}

this.gathering = firstNode;
const eGather = {
node,
obj: this
};
eventEmitter.emitNoSticky('beforeGatherResource', eGather);
obj.fireEvent('beforeGatherResource', eGather);

this.gathering = node;

let ttlMax = firstNode.resourceNode.ttl || this.defaultTtlMax;
let ttlMax = node.resourceNode.ttl || defaultTtlMax;

if (firstNode.resourceNode.nodeType === 'fish') {
if (node.resourceNode.nodeType === 'fish') {
if (equipment.isSlotEmpty('tool')) {
this.sendAnnouncement('You need a fishing rod to fish');
this.gathering = null;
@@ -49,7 +55,7 @@ module.exports = {
}

this.gatheringTtlMax = ttlMax;
this.gatheringTtl = this.gatheringTtlMax;
this.gatheringTtl = gatheringTtlMax;
},

update: function () {
@@ -101,10 +107,11 @@ module.exports = {
nodeType: resourceNode.nodeType,
blueprint: resourceNode.blueprint,
xp: resourceNode.xp,
items: gathering.inventory.items
items: gathering.inventory.items,
source: this.obj
});
this.obj.instance.eventEmitter.emitNoSticky('beforeGatherResource', gatherResult, this.obj);
this.obj.fireEvent('beforeGatherResource', gatherResult, this.obj);
this.obj.instance.eventEmitter.emitNoSticky('beforeGatherResourceComplete', gatherResult);
this.obj.fireEvent('beforeGatherResourceComplete', gatherResult);

this.obj.syncer.set(false, 'gatherer', 'progress', 100);



+ 3
- 3
src/server/config/factions/anglers.js Visa fil

@@ -41,15 +41,15 @@ module.exports = {
},

events: {
beforeGatherResource: function (item, gatherResult, source) {
beforeGatherResourceComplete: function (item, { items }) {
let effect = item.effects.find(e => (e.factionId === 'anglers'));

let roll = Math.random() * 100;
if (roll >= effect.chance)
return;

let pick = gatherResult.items[~~(Math.random() * gatherResult.items.length)];
gatherResult.items.push(extend({}, pick));
let pick = items[~~(Math.random() * items.length)];
items.push(extend({}, pick));
}
}
},


Laddar…
Avbryt
Spara