Browse Source

fishing effect

tags/v0.1.5^2
Big Bad Waffle 6 years ago
parent
commit
5c2a207124
9 changed files with 298 additions and 22 deletions
  1. +36
    -3
      src/client/js/components/gatherer.js
  2. +12
    -4
      src/client/js/components/lightningEffect.js
  3. +9
    -4
      src/client/js/rendering/lightningBuilder.js
  4. +3
    -0
      src/server/components/extensions/socialCommands.js
  5. +8
    -0
      src/server/components/gatherer.js
  6. +2
    -2
      src/server/config/herbs.js
  7. +193
    -3
      src/server/config/maps/tutorial/map.json
  8. +2
    -3
      src/server/config/maps/tutorial/zone.js
  9. +33
    -3
      src/server/world/resourceSpawner.js

+ 36
- 3
src/client/js/components/gatherer.js View File

@@ -1,19 +1,52 @@
define([
'js/system/client',
'js/system/events'
'js/system/events',
'js/misc/physics'
], function(
client,
events
events,
physics
) {
return {
type: 'gatherer',
effect: null,

init: function() {
this.obj.on('onKeyDown', this.onKeyDown.bind(this));
},

extend: function(msg) {
events.emit('onShowProgress', (msg.action || 'Gathering') + '...', msg.progress);
if (msg.width) {
if (this.effect)
this.effect.destroyed = true;

var x = 0;
var y = 0;
while (true) {
x = msg.x + ~~(Math.random() * msg.width);
y = msg.y + ~~(Math.random() * msg.height);
if ((physics.isTileBlocking(x, y)) && (Math.max(Math.abs(x - this.obj.x), Math.abs(y - this.obj.y)) > 2))
break;
}

this.effect = this.obj.addComponent('lightningEffect', {
new: true,
toX: x,
toY: y,
ttl: -1,
divisions: 4,
cdMax: 12,
colors: [0xfafcfc, 0xc0c3cf, 0xc0c3cf],
maxDeviate: 5
});
} else {
if (msg.progress == 100) {
this.effect.destroyed = true;
this.effect = null;
}

events.emit('onShowProgress', (msg.action || 'Gathering') + '...', msg.progress);
}
},

onKeyDown: function(key) {


+ 12
- 4
src/client/js/components/lightningEffect.js View File

@@ -18,13 +18,16 @@ define([
init: function() {
effects.register(this);

var xOffset = (this.toX > this.obj.x) ? 1 : 0;
var xOffset = (this.toX >= this.obj.x) ? 1 : 0;

this.effect = lightningBuilder.build({
fromX: this.obj.x + xOffset,
fromY: this.obj.y + 0.5,
toX: this.toX + 0.5,
toY: this.toY + 0.5
toY: this.toY + 0.5,
divisions: this.divisions,
colors: this.colors,
maxDeviate: this.maxDeviate
});
},

@@ -37,6 +40,7 @@ define([
this.cd = this.cdMax;

lightningBuilder.destroy(this.effect);
this.effect = null;

this.ttl--;
if (this.ttl == 0) {
@@ -50,12 +54,16 @@ define([
fromX: this.obj.x + xOffset,
fromY: this.obj.y + 0.5,
toX: this.toX + 0.5,
toY: this.toY + 0.5
toY: this.toY + 0.5,
divisions: this.divisions,
colors: this.colors,
maxDeviate: this.maxDeviate
});
},

destroyManual: function() {
//lightningBuilder.destroy(this.effect);
if (this.effect)
lightningBuilder.destroy(this.effect);

effects.unregister(this);
}


+ 9
- 4
src/client/js/rendering/lightningBuilder.js View File

@@ -14,7 +14,7 @@ define([
lines: []
};

var maxDeviate = scale * 0.3;
var maxDeviate = config.maxDeviate || (scale * 0.3);

var fx = config.fromX * scale;
var fy = config.fromY * scale;
@@ -25,7 +25,7 @@ define([
var angle = Math.atan2(ty - fy, tx - fx);
var distance = Math.sqrt(Math.pow(tx - fx, 2) + Math.pow(ty - fy, 2));
var divDistance = Math.min(20, distance);
var divisions = Math.max(1, distance / divDistance);
var divisions = config.divisions || Math.max(1, distance / divDistance);

var x = fx;
var y = fy;
@@ -49,19 +49,24 @@ define([
var patches = {};

for (var j = 0; j < steps; j++) {
var c = [0xffeb38, 0xfaac45, 0xfafcfc][~~(Math.random() * 3)];
var alpha = 1;
if ((config.colors) && (i == divisions - 1) && (j > (steps * 0.75)))
alpha = 1 - (j / steps);

var c = (config.colors || [0xffeb38, 0xfaac45, 0xfafcfc])[~~(Math.random() * (config.colors ? config.colors.length : 3))];
line.sprites.push(renderer.buildRectangle({
x: ~~(x / scaleMult) * scaleMult,
y: ~~(y / scaleMult) * scaleMult,
w: scaleMult,
h: scaleMult,
alpha: alpha,
color: c,
layerName: 'effects'
}));

var xx = x;
var yy = y;
if (!patches[xx + '-' + yy]) {
if ((!patches[xx + '-' + yy]) && (!config.colors)) {
patches[xx + '-' + yy] = 1;

var lightPatch = renderer.buildObject({


+ 3
- 0
src/server/components/extensions/socialCommands.js View File

@@ -71,6 +71,9 @@ define([
if (config.stats)
config.stats = config.stats.split(',');

if (config.name)
config.name = config.name.split('_').join(' ');

this.obj.inventory.getItem(generator.generate(config));
},



+ 8
- 0
src/server/components/gatherer.js View File

@@ -36,6 +36,12 @@ define([

this.gatheringTtlMax = ttlMax;
this.gatheringTtl = this.gatheringTtlMax;

if (firstNode.width) {
['x', 'y', 'width', 'height'].forEach(function(p) {
this.obj.syncer.set(true, 'gatherer', p, firstNode[p]);
}, this);
}
},

update: function() {
@@ -55,6 +61,8 @@ define([
return;
}

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

var isFish = (gathering.resourceNode.nodeType == 'fish');

if (isFish) {


+ 2
- 2
src/server/config/herbs.js View File

@@ -21,9 +21,9 @@ define([
},
'Sun Carp': {
sheetName: 'objects',
cell: 45,
itemSprite: [11, 2],
baseWeight: 3
baseWeight: 3,
ttl: 30
}
};
});

+ 193
- 3
src/server/config/maps/tutorial/map.json View File

@@ -1376,7 +1376,7 @@
"name":"sun carp school",
"properties":
{
"resource":"sun carp"
"resource":"Sun Carp"
},
"propertytypes":
{
@@ -1395,7 +1395,7 @@
"name":"sun carp school",
"properties":
{
"resource":"sun carp"
"resource":"Sun Carp"
},
"propertytypes":
{
@@ -1407,6 +1407,196 @@
"width":56,
"x":776,
"y":336
},
{
"height":40,
"id":640,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":48,
"x":784,
"y":512
},
{
"height":24,
"id":641,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":48,
"x":776,
"y":600
},
{
"height":40,
"id":642,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":48,
"x":552,
"y":632
},
{
"height":32,
"id":643,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":40,
"x":528,
"y":528
},
{
"height":40,
"id":645,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":40,
"x":456,
"y":32
},
{
"height":40,
"id":646,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":32,
"x":328,
"y":40
},
{
"height":32,
"id":647,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":56,
"x":168,
"y":152
},
{
"height":40,
"id":648,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":64,
"x":72,
"y":320
},
{
"height":32,
"id":649,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":48,
"x":88,
"y":496
},
{
"height":32,
"id":651,
"name":"sun carp school",
"properties":
{
"resource":"Sun Carp"
},
"propertytypes":
{
"resource":"string"
},
"rotation":0,
"type":"",
"visible":true,
"width":24,
"x":288,
"y":488
}],
"opacity":1,
"type":"objectgroup",
@@ -1414,7 +1604,7 @@
"x":0,
"y":0
}],
"nextobjectid":640,
"nextobjectid":652,
"orientation":"orthogonal",
"properties":
{


+ 2
- 3
src/server/config/maps/tutorial/zone.js View File

@@ -16,10 +16,9 @@ module.exports = {
},
objects: {
'sun carp school': {
max: 1,
max: 4,
type: 'fish',
quanity: [2, 2],
ttl: 30
quanity: [3, 6]
},
shophermit: {
properties: {


+ 33
- 3
src/server/world/resourceSpawner.js View File

@@ -12,7 +12,7 @@ define([
physics: null,
map: null,

cdMax: 10,
cdMax: 200,

init: function(instance) {
this.objects = instance.objects;
@@ -23,6 +23,26 @@ define([
},

register: function(name, blueprint) {
var exists = this.nodes.find(n => (n.blueprint.name == name));
if (exists) {
if (!exists.blueprint.positions)
exists.blueprint.positions = [{
x: exists.blueprint.x,
y: exists.blueprint.y,
width: exists.blueprint.width,
height: exists.blueprint.height
}];

exists.blueprint.positions.push({
x: blueprint.x,
y: blueprint.y,
width: blueprint.width,
height: blueprint.height
});

return;
}

blueprint = extend(true, {}, blueprint, herbs[name], {
name: name
});
@@ -45,14 +65,17 @@ define([
var w = this.physics.width;
var h = this.physics.height;

var spawn = this.map.spawn[0];
var x = blueprint.x || ~~(Math.random() * w);
var y = blueprint.y || ~~(Math.random() * h);

var position = null;

if (blueprint.type == 'herb') {
if (this.physics.isTileBlocking(x, y))
return false;

var spawn = this.map.spawn[0];

var path = this.physics.getPath(spawn, {
x: x,
y: y
@@ -73,13 +96,20 @@ define([
blueprint.y = y;
}
}
} else if (blueprint.positions) {
//Find all possible positions in which a node hasn't spawned yet
position = blueprint.positions.filter(f => !node.spawns.some(s => ((s.x == f.x) && (s.y == f.y))));
if (position.length == 0)
return false;

position = position[~~(Math.random() * position.length)];
}

var quantity = 1;
if (blueprint.quantity)
quantity = blueprint.quantity[0] + ~~(Math.random() * (blueprint.quantity[1] - blueprint.quantity[0]));

var objBlueprint = extend(true, {}, blueprint);
var objBlueprint = extend(true, {}, blueprint, position);
objBlueprint.properties = {
cpnResourceNode: {
nodeType: blueprint.type,


Loading…
Cancel
Save