refactor: item use context
This commit is contained in:
parent
dbd6091acc
commit
10289f4c06
|
@ -34,6 +34,7 @@ export default (latus) => class Item extends decorate(Trait) {
|
||||||
|
|
||||||
static dependencies() {
|
static dependencies() {
|
||||||
return [
|
return [
|
||||||
|
'Behaved',
|
||||||
'Pictured',
|
'Pictured',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -71,10 +72,10 @@ export default (latus) => class Item extends decorate(Trait) {
|
||||||
return this.entity.image(key);
|
return this.entity.image(key);
|
||||||
},
|
},
|
||||||
|
|
||||||
use: (context) => {
|
use: () => {
|
||||||
const {cooldown} = this.params;
|
const {cooldown} = this.params;
|
||||||
const {Script} = latus.get('%resources');
|
const {Script} = latus.get('%resources');
|
||||||
const promises = [Script.loadTickingPromise(this.params.useScript, context)];
|
const promises = [Script.loadTickingPromise(this.params.useScript, this.entity.context)];
|
||||||
if (cooldown > 0) {
|
if (cooldown > 0) {
|
||||||
promises.push(new Promise((resolve) => {
|
promises.push(new Promise((resolve) => {
|
||||||
setTimeout(resolve, 1000 * cooldown);
|
setTimeout(resolve, 1000 * cooldown);
|
||||||
|
|
|
@ -96,10 +96,8 @@ export default () => class Wielder extends decorate(Trait) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
// Defer until the item actions are finished.
|
// Defer until the item actions are finished.
|
||||||
this.#itemPromise = item.use({
|
item.context.wielder = this.entity;
|
||||||
entity: item,
|
this.#itemPromise = item.use();
|
||||||
wielder: this.entity,
|
|
||||||
});
|
|
||||||
this.#itemPromise.then(() => {
|
this.#itemPromise.then(() => {
|
||||||
this.#itemPromise = undefined;
|
this.#itemPromise = undefined;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user