feat: item usage cooldowns
This commit is contained in:
parent
0315ea3409
commit
a8d89f17ce
|
@ -1,4 +1,4 @@
|
|||
import {behaviorItemFromJSON} from '@avocado/behavior';
|
||||
import {behaviorItemFromJSON, buildInvoke} from '@avocado/behavior';
|
||||
import {compose, Property, TickingPromise} from '@avocado/core';
|
||||
import {StateProperty, Trait} from '@avocado/entity';
|
||||
import {Image} from '@avocado/graphics';
|
||||
|
@ -19,6 +19,7 @@ export class Item extends decorate(Trait) {
|
|||
|
||||
static defaultParams() {
|
||||
return {
|
||||
cooldown: 0,
|
||||
itemActions: {
|
||||
type: 'actions',
|
||||
traversals: [],
|
||||
|
@ -41,7 +42,39 @@ export class Item extends decorate(Trait) {
|
|||
|
||||
constructor(entity, params, state) {
|
||||
super(entity, params, state);
|
||||
this._itemActions = behaviorItemFromJSON(this.params.itemActions);
|
||||
let actionsSpec = this.params.itemActions;
|
||||
if (this.params.cooldown > 0) {
|
||||
// Rewrite the actions spec to run a wait in parallel to the normal
|
||||
// serial actions.
|
||||
actionsSpec = {
|
||||
type: 'actions',
|
||||
traversals: [
|
||||
buildInvoke(
|
||||
['global', 'parallel'],
|
||||
[
|
||||
{
|
||||
type: 'actions',
|
||||
traversals: [
|
||||
buildInvoke(
|
||||
['global', 'wait'],
|
||||
[
|
||||
this.params.cooldown
|
||||
]
|
||||
),
|
||||
buildInvoke(
|
||||
['global', 'serial'],
|
||||
[
|
||||
actionsSpec,
|
||||
],
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
),
|
||||
],
|
||||
}
|
||||
}
|
||||
this._itemActions = behaviorItemFromJSON(actionsSpec);
|
||||
this._slotImages = {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user