Переглянути джерело

refactoring

tags/v0.3.3^2
Shaun Kichenbrand 4 роки тому
джерело
коміт
66a2c7360a
2 змінених файлів з 15 додано та 33 видалено
  1. +1
    -6
      src/server/components/dialogue.js
  2. +14
    -27
      src/server/components/trade.js

+ 1
- 6
src/server/components/dialogue.js Переглянути файл

@@ -54,12 +54,8 @@ module.exports = {
this.obj.syncer.set(true, 'dialogue', 'state', null);
},

getState: function (sourceObj, state) {
getState: function (sourceObj, state = 1) {
let result = null;

state = state || 1;

//Goto?
if ((state + '').indexOf('.') > -1) {
let config = this.states[(state + '').split('.')[0]];
if (!config)
@@ -89,7 +85,6 @@ module.exports = {
return null;

let useMsg = stateConfig.msg;

if (stateConfig.cpn) {
let cpn = sourceObj[stateConfig.cpn];
let newArgs = extend([], stateConfig.args);


+ 14
- 27
src/server/components/trade.js Переглянути файл

@@ -2,6 +2,17 @@ let generator = require('../items/generator');
let statGenerator = require('../items/generators/stats');
let skins = require('../config/skins');

const sendMessage = ({ instance, id, serverId }, color, message) => {
instance.syncer.queue('onGetMessages', {
id: id,
messages: [{
class: color,
message,
type: 'info'
}]
}, [serverId]);
};

module.exports = {
type: 'trade',

@@ -169,15 +180,7 @@ module.exports = {
canAfford = this.gold >= ~~(item.worth * markup);

if (!canAfford) {
this.obj.instance.syncer.queue('onGetMessages', {
id: this.obj.id,
messages: [{
class: 'color-redA',
message: 'you can\'t afford that item',
type: 'info'
}]
}, [this.obj.serverId]);

sendMessage(this.obj, 'color-redA', 'You can\'t afford that item.');
this.resolveCallback(msg);
return;
}
@@ -191,15 +194,7 @@ module.exports = {
let haveSkin = this.obj.auth.doesOwnSkin(item.skinId);

if (haveSkin) {
this.obj.instance.syncer.queue('onGetMessages', {
id: this.obj.id,
messages: [{
class: 'color-redA',
message: 'you have already unlocked that skin',
type: 'info'
}]
}, [this.obj.serverId]);

sendMessage(this.obj, 'color-redA', 'You have already unlocked that skin.');
this.resolveCallback(msg);
return;
}
@@ -240,15 +235,7 @@ module.exports = {
this.obj.syncer.setArray(true, 'trade', 'removeItems', item.id);
} else {
this.obj.auth.saveSkin(item.skinId);

this.obj.instance.syncer.queue('onGetMessages', {
id: this.obj.id,
messages: [{
class: 'color-greenB',
message: 'Unlocked skin: ' + item.name,
type: 'info'
}]
}, [this.obj.serverId]);
sendMessage(this.obj, 'color-greenB', `Unlocked skin: ${item.name}.`);
}

if (item.worth.currency) {


Завантаження…
Відмінити
Зберегти