Browse Source

first version

tags/v0.2.1^2
big bad waffle 5 years ago
parent
commit
8c84248b94
14 changed files with 343 additions and 169 deletions
  1. +1
    -1
      .eslintrc
  2. +1
    -1
      src/client/ui/templates/workbench/styles.less
  3. +2
    -6
      src/client/ui/templates/workbench/template.html
  4. +118
    -0
      src/client/ui/templates/workbench/workbench.js
  5. +0
    -53
      src/client/ui/templates/workbenchAlchemy/workbenchAlchemy.js
  6. +151
    -0
      src/server/components/workbench.js
  7. +0
    -106
      src/server/components/workbenchAlchemy.js
  8. +3
    -1
      src/server/config/maps/fjolarok/zone.js
  9. +19
    -0
      src/server/config/recipes/alchemy.js
  10. +19
    -0
      src/server/config/recipes/cooking.js
  11. +24
    -0
      src/server/config/recipes/recipes.js
  12. +2
    -0
      src/server/index.js
  13. +1
    -1
      src/server/security/router.js
  14. +2
    -0
      src/server/world/worker.js

+ 1
- 1
.eslintrc View File

@@ -88,7 +88,7 @@
"curly": [2,"multi-or-nest"],
"dot-notation": 2,
"dot-location": [2,"property"],
"eqeqeq": [2,"smart", {"null": "ignore"}],
"eqeqeq": [2,"always", {"null": "ignore"}],
"no-alert": 2,
"no-caller": 2,
"no-else-return": 2,


src/client/ui/templates/workbenchAlchemy/styles.less → src/client/ui/templates/workbench/styles.less View File

@@ -1,6 +1,6 @@
@import "../../../css/ui.less";

.uiWorkbenchAlchemy {
.uiWorkbench {
display: none;
width: 720px;
height: 385px;

src/client/ui/templates/workbenchAlchemy/template.html → src/client/ui/templates/workbench/template.html View File

@@ -1,4 +1,4 @@
<div class="uiWorkbenchAlchemy">
<div class="uiWorkbench">
<div class="heading">
<div class="heading-text">Alchemy Workbench</div>
</div>
@@ -6,11 +6,7 @@
<div class="left">
<div class="heading">Recipes</div>
<div class="list">
<div class="item">Minor Healing Potion</div>
<div class="item selected">Lesser Healing Potion</div>
<div class="item">Healing Potion</div>
<div class="item">Greater Healing Potion</div>
<div class="item">Ultimate Healing Potion</div>
</div>
</div>
<div class="right">

+ 118
- 0
src/client/ui/templates/workbench/workbench.js View File

@@ -0,0 +1,118 @@
define([
'js/system/events',
'js/system/client',
'html!ui/templates/workbench/template',
'css!ui/templates/workbench/styles'
], function (
events,
client,
template,
styles
) {
return {
tpl: template,

centered: true,

modal: true,

workbenchId: null,

recipes: null,

postRender: function () {
this.onEvent('onOpenWorkbench', this.onOpenWorkbench.bind(this));
this.onEvent('onCloseWorkbench', this.hide.bind(this));

this.on('.btnCraft', 'click', this.craft.bind(this));
this.on('.btnCancel', 'click', this.hide.bind(this));
},

onOpenWorkbench: function (msg) {
this.workbenchId = msg.workbenchId;
this.find('.heading-title').html(msg.name);

this.renderRecipes(msg.recipes);

this.show();
},

renderRecipes: function (recipes) {
this.recipes = recipes;

let container = this.find('.list').empty();

recipes.forEach(function (r) {
let el = $('<div class="item">' + r + '</div>')
.appendTo(container);

el.on('click', this.onSelectRecipe.bind(this, el, r));
}, this);
},

onSelectRecipe: function (el, name) {
el.parent().find('.selected').removeClass('selected');
el.addClass('selected');

client.request({
cpn: 'player',
method: 'performAction',
data: {
targetId: this.workbenchId,
cpn: 'workbench',
method: 'getRecipe',
data: {
name: name
}
},
callback: this.onGetRecipe.bind(this)
});
},

onGetRecipe: function (recipe) {
this.find('.title').html(recipe.item.name);
this.find('.description').html(recipe.item.description);

let container = this.find('.materialList .material')
.remove()
.parent();

let canCraft = true;

recipe.materials.forEach(function (m) {
let el = $('<div class="material">' + m.quantity + 'x ' + m.name + '</div>')
.appendTo(container);

if (m.need) {
canCraft = false;
el.addClass('need');
}
});

this.find('.btnCraft')
.removeClass('disabled');

if (canCraft) {
this.find('.btnCraft')
.addClass('disabled');
}
},

craft: function () {
let selectedRecipe = this.find('.list .item.selected').html();

client.request({
cpn: 'player',
method: 'performAction',
data: {
targetId: this.workbenchId,
cpn: 'workbench',
method: 'craft',
data: {
name: selectedRecipe
}
}
});
}
};
});

+ 0
- 53
src/client/ui/templates/workbenchAlchemy/workbenchAlchemy.js View File

@@ -1,53 +0,0 @@
define([
'js/system/events',
'js/system/client',
'html!ui/templates/workbenchAlchemy/template',
'css!ui/templates/workbenchAlchemy/styles'
], function (
events,
client,
template,
styles
) {
return {
tpl: template,

centered: true,

modal: true,

skin: null,
workbenchId: null,

postRender: function () {
this.onEvent('onOpenWorkbenchAlchemy', this.onOpenWorkbenchAlchemy.bind(this));
this.onEvent('onCloseWorkbenchAlchemy', this.hide.bind(this));

this.on('.btnCraft', 'click', this.craft.bind(this));
this.on('.btnCancel', 'click', this.hide.bind(this));
},

onOpenWorkbenchAlchemy: function (msg) {
this.workbenchId = msg.workbenchId;
console.log(msg);

this.show();
},

craft: function() {
client.request({
cpn: 'player',
method: 'performAction',
data: {
targetId: this.workbenchId,
cpn: 'workbenchAlchemy',
method: 'craft',
data: {
a: 10,
c: 'abc'
}
}
});
}
}
});

+ 151
- 0
src/server/components/workbench.js View File

@@ -0,0 +1,151 @@
const recipes = require('../config/recipes/recipes');

module.exports = {
type: 'workbench',

craftType: null,

init: function (blueprint) {
this.craftType = blueprint.type;

let o = this.obj.instance.objects.buildObjects([{
properties: {
x: this.obj.x - 1,
y: this.obj.y - 1,
width: 3,
height: 3,
cpnNotice: {
actions: {
enter: {
cpn: 'workbench',
method: 'enterArea',
targetId: this.obj.id,
args: []
},
exit: {
cpn: 'workbench',
method: 'exitArea',
targetId: this.obj.id,
args: []
}
}
}
}
}]);
},

exitArea: function (obj) {
if (!obj.player)
return;

obj.syncer.setArray(true, 'serverActions', 'removeActions', {
key: 'u',
action: {
targetId: this.obj.id,
cpn: 'workbench',
method: 'access'
}
});

this.obj.instance.syncer.queue('onCloseWorkbench', null, [obj.serverId]);
},

enterArea: function (obj) {
if (!obj.player)
return;

let msg = 'Press U to access the alchemy station';

obj.syncer.setArray(true, 'serverActions', 'addActions', {
key: 'u',
action: {
targetId: this.obj.id,
cpn: 'workbench',
method: 'open'
}
});

this.obj.instance.syncer.queue('onGetAnnouncement', {
src: this.obj.id,
msg: msg
}, [obj.serverId]);
},

open: function (msg) {
if (msg.sourceId == null)
return;

let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
if ((!obj) || (!obj.player))
return;

let thisObj = this.obj;
if ((Math.abs(thisObj.x - obj.x) > 1) || (Math.abs(thisObj.y - obj.y) > 1))
return;

this.obj.instance.syncer.queue('onOpenWorkbench', {
workbenchId: this.obj.id,
name: this.obj.name,
recipes: recipes.getList(this.craftType)
}, [obj.serverId]);
},

getRecipe: function (msg) {
let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
if ((!obj) || (!obj.player))
return;

let recipe = recipes.getRecipe(msg.data.name);
if (!recipe)
return;

const items = obj.inventory.items;

let sendRecipe = extend(true, {}, recipe);
(recipe.materials || []).forEach(function (m) {
m.need = items.some(i => (i.name === m.name && i.quantity >= m.quantity));
});

this.resolveCallback(msg, sendRecipe);
},

craft: function (msg) {
let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
if ((!obj) || (!obj.player))
return;

let recipe = recipes.getRecipe(msg.data.name);
if (!recipe)
return;

const items = obj.inventory.items;
let canCraft = recipe.materials.every(m => (items.some(i => i.name == m.name && i.quantity >= m.quantity)));

if (!canCraft)
return;

recipe.materials.forEach(m => obj.inventory.removeItem(m.name, m.quantity));

let item = extend(true, {}, recipe.item);
item.description += `<br /><br />(Crafted by ${obj.name})`;

obj.inventory.getItem(item);
},

resolveCallback: function (msg, result) {
let callbackId = (msg.callbackId != null) ? msg.callbackId : msg;
result = result || [];

if (callbackId == null)
return;

process.send({
module: 'atlas',
method: 'resolveCallback',
msg: {
id: callbackId,
result: result
}
});
}
};

+ 0
- 106
src/server/components/workbenchAlchemy.js View File

@@ -1,106 +0,0 @@
module.exports = {
type: 'workbenchAlchemy',

init: function (blueprint) {
let o = this.obj.instance.objects.buildObjects([{
properties: {
x: this.obj.x - 1,
y: this.obj.y - 1,
width: 3,
height: 3,
cpnNotice: {
actions: {
enter: {
cpn: 'workbenchAlchemy',
method: 'enterArea',
targetId: this.obj.id,
args: []
},
exit: {
cpn: 'workbenchAlchemy',
method: 'exitArea',
targetId: this.obj.id,
args: []
}
}
}
}
}]);
},

exitArea: function (obj) {
if (!obj.player)
return;

obj.syncer.setArray(true, 'serverActions', 'removeActions', {
key: 'u',
action: {
targetId: this.obj.id,
cpn: 'workbenchAlchemy',
method: 'access'
}
});

this.obj.instance.syncer.queue('onCloseWorkbenchAlchemy', null, [obj.serverId]);
},

enterArea: function (obj) {
if (!obj.player)
return;

let msg = 'Press U to access the alchemy station';

obj.syncer.setArray(true, 'serverActions', 'addActions', {
key: 'u',
action: {
targetId: this.obj.id,
cpn: 'workbenchAlchemy',
method: 'open'
}
});

this.obj.instance.syncer.queue('onGetAnnouncement', {
src: this.obj.id,
msg: msg
}, [obj.serverId]);
},

open: function (msg) {
if (msg.sourceId == null)
return;

let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
if ((!obj) || (!obj.player))
return;

let thisObj = this.obj;
if ((Math.abs(thisObj.x - obj.x) > 1) || (Math.abs(thisObj.y - obj.y) > 1))
return;

this.obj.instance.syncer.queue('onOpenWorkbenchAlchemy', {
workbenchId: this.obj.id
}, [obj.serverId]);
},

craft: function(msg) {
let potions = [{
name: 'Minor Healing Potion',
type: 'consumable',
sprite: [0, 1],
description: 'Does not affect emotional scars.',
worth: 0,
noSalvage: true,
noAugment: true,
uses: 1
}];

let obj = this.obj.instance.objects.objects.find(o => o.serverId === msg.sourceId);
if ((!obj) || (!obj.player))
return;

let item = extend(true, {}, potions[0]);
item.description += `<br /><br />(Crafted by ${obj.name})`;

obj.inventory.getItem(item);
}
};

+ 3
- 1
src/server/config/maps/fjolarok/zone.js View File

@@ -384,7 +384,9 @@ module.exports = {
};
}
},
cpnWorkbenchAlchemy: {}
cpnWorkbench: {
type: 'alchemy'
}
}
}
},


+ 19
- 0
src/server/config/recipes/alchemy.js View File

@@ -0,0 +1,19 @@
module.exports = [{
item: {
name: 'Minor Healing Potion',
type: 'consumable',
sprite: [0, 1],
description: 'Does not affect emotional scars.',
worth: 0,
noSalvage: true,
noAugment: true,
uses: 1
},
materials: [{
name: 'Skyblossom',
quantity: 3
}, {
name: 'Empty Vial',
quantity: 1
}]
}];

+ 19
- 0
src/server/config/recipes/cooking.js View File

@@ -0,0 +1,19 @@
module.exports = [{
item: {
name: 'Carp on a Stick',
type: 'consumable',
sprite: [0, 2],
description: 'It\'s a fish on a stick, what more do you want to know?',
worth: 0,
noSalvage: true,
noAugment: true,
uses: 1
},
materials: [{
name: 'Sun Carp',
quantity: 1
}, {
name: 'Stick',
quantity: 1
}]
}];

+ 24
- 0
src/server/config/recipes/recipes.js View File

@@ -0,0 +1,24 @@
let events = require('../../misc/events');

const recipesAlchemy = require('./alchemy');
const recipesCooking = require('./cooking');

let recipes = {
alchemy: [
...recipesAlchemy
],
cooking: [
...recipesCooking
]
};

module.exports = {
init: function () {
events.emit('onBeforeGetRecipes', recipes);
},

getList: function (type) {
return recipes[type]
.map(r => r.item.name);
}
};

+ 2
- 0
src/server/index.js View File

@@ -13,6 +13,7 @@ let classes = require('./config/spirits');
let spellsConfig = require('./config/spellsConfig');
let spells = require('./config/spells');
let itemTypes = require('./items/config/types');
let recipes = require('./config/recipes/recipes');
let sheets = require('./security/sheets');

let startup = {
@@ -36,6 +37,7 @@ let startup = {
classes.init();
spellsConfig.init();
spells.init();
recipes.init();
itemTypes.init();
components.init(this.onComponentsReady.bind(this));
},


+ 1
- 1
src/server/security/router.js View File

@@ -25,7 +25,7 @@ module.exports = {
wardrobe: ['open', 'apply'],
stats: ['respawn'],
passives: ['tickNode', 'untickNode'],
workbenchAlchemy: ['open', 'craft']
workbench: ['open', 'craft', 'getRecipe']
};

return ((secondaryAllowed[msg.data.cpn]) && (secondaryAllowed[msg.data.cpn].indexOf(msg.data.method) > -1));


+ 2
- 0
src/server/world/worker.js View File

@@ -12,6 +12,7 @@ let factions = require('../config/factions');
let classes = require('../config/spirits');
let spellsConfig = require('../config/spellsConfig');
let spells = require('../config/spells');
let recipes = require('../config/recipes/recipes');
let itemTypes = require('../items/config/types');
let sheets = require('../security/sheets');

@@ -24,6 +25,7 @@ let onCpnsReady = function () {
spellsConfig.init();
spells.init();
itemTypes.init();
recipes.init();
sheets.init();

process.send({


Loading…
Cancel
Save