humus-old/server/fixtures/rock-projectile.entity.js
2019-10-02 00:48:44 -05:00

213 lines
4.5 KiB
JavaScript

import {buildInvoke, buildTraversal} from '@avocado/behavior';
import {AFFINITY_NONE} from '../../common/combat/constants';
// Projectile rock.
export function rockProjectileJSON() {
// Set as not damaging to user.
const setDoesNotCollideWith = buildInvoke(
['entity', 'setDoesNotCollideWith'],
[
buildTraversal(['wielder']),
],
);
// Set visible.
const setVisible = buildTraversal(
['entity', 'isVisible'],
true,
);
// Set item to user position.
const setToUserPosition = buildInvoke(
['entity', 'setPosition'],
[
buildTraversal(['wielder', 'position']),
],
);
// Turn and move in direction user is facing for half a second.
const turn = buildTraversal(
['entity', 'direction'],
buildTraversal(['wielder', 'direction']),
);
const move = buildInvoke(
['entity', 'moveFor'],
[
buildInvoke(
['Math', 'Vector', 'fromDirection'],
[
buildTraversal(['entity', 'direction']),
],
),
0.5,
],
);
const setIsNotColliding = buildTraversal(
['entity', 'isColliding'],
false,
);
const setIsNotDamaging = buildTraversal(
['entity', 'isDamaging'],
false,
);
const fadeOutAndSlowDown = buildInvoke(
['entity', 'transition'],
[
{
opacity: 0,
speed: 0,
},
0.2,
],
);
const reflect = buildInvoke(
['entity', 'moveFor'],
[
buildInvoke(
['Math', 'Vector', 'sub'],
[
buildTraversal(['entity', 'position']),
buildTraversal(['obstacle', 'position']),
],
),
0.2,
],
);
const afterImpact = buildInvoke(
['Flow', 'parallel'],
[
{
type: 'actions',
traversals: [
fadeOutAndSlowDown,
reflect,
],
},
],
);
// Destroy.
const destroy = buildInvoke(
['entity', 'destroy'],
);
return {
traits: {
behaved: {
params: {
routines: {
type: 'routines',
routines: {
initial: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
setDoesNotCollideWith,
setToUserPosition,
setVisible,
turn,
move,
destroy,
],
},
},
reflect: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
setIsNotColliding,
setIsNotDamaging,
afterImpact,
destroy,
],
},
},
},
},
},
state: {
isBehaving: false,
},
},
collider: {
params: {
collisionGroup: 'projectile',
collisionStartActions: {
type: 'actions',
traversals: [
buildInvoke(
['entity', 'context', 'add'],
[
'obstacle',
buildTraversal(['other']),
],
),
buildTraversal(
['entity', 'currentRoutine'],
'reflect',
),
],
},
isSensor: true,
},
},
damaging: {
params: {
damageSpecs: [
{
affinity: AFFINITY_NONE,
knockback: 500,
lock: 1,
power: 50,
variance: 0.1,
},
],
},
},
directional: {
params: {
directionCount: 4,
},
},
existent: {
state: {
name: 'Rock (projectile)',
},
},
layered: {},
listed: {},
mobile: {
state: {
speed: 200,
},
},
physical: {},
pictured: {
params: {
images: {
initial: {
offset: [0, 0],
size: [12, 12], // Derive?
uri: '/rock.png',
},
}
},
},
positioned: {},
roomed: {},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [12, 12],
},
},
},
visible: {
state: {
isVisible: false,
},
},
},
};
}