Add drag & drop support for effects between different sheets
Also refactor some effect related functionality into the DS4ActiveEffect class
This commit is contained in:
parent
b1d0810100
commit
1e7368875c
5 changed files with 60 additions and 29 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
import { DS4Actor } from "./actor/actor";
|
||||
import { getGame } from "./helpers";
|
||||
import { DS4Item } from "./item/item";
|
||||
|
||||
declare global {
|
||||
interface DocumentClassConfig {
|
||||
|
@ -12,6 +13,7 @@ declare global {
|
|||
}
|
||||
|
||||
type PromisedType<T> = T extends Promise<infer U> ? U : T;
|
||||
|
||||
export class DS4ActiveEffect extends ActiveEffect {
|
||||
/**
|
||||
* A fallback icon that can be used if no icon is defined for the effect.
|
||||
|
@ -23,6 +25,38 @@ export class DS4ActiveEffect extends ActiveEffect {
|
|||
*/
|
||||
protected source: PromisedType<ReturnType<typeof fromUuid>> | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Whether or not this effect is currently surpressed.
|
||||
*/
|
||||
get isSurpressed(): boolean {
|
||||
const originatingItem = this.originatingItem;
|
||||
if (!originatingItem) {
|
||||
return false;
|
||||
}
|
||||
return originatingItem.isNonEquippedEuipable();
|
||||
}
|
||||
|
||||
/**
|
||||
* The item which this effect originates from if it has been transferred from an item to an actor.
|
||||
*/
|
||||
get originatingItem(): DS4Item | undefined {
|
||||
if (!(this.parent instanceof DS4Actor)) {
|
||||
return;
|
||||
}
|
||||
const [, , , itemId] = this.data.origin?.split(".") ?? [];
|
||||
if (!itemId) {
|
||||
return;
|
||||
}
|
||||
return this.parent.items.get(itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of times this effect should be applied.
|
||||
*/
|
||||
get factor(): number {
|
||||
return this.originatingItem?.activeEffectFactor ?? 1;
|
||||
}
|
||||
|
||||
/** @override */
|
||||
apply(actor: DS4Actor, change: foundry.data.ActiveEffectData["changes"][number]): unknown {
|
||||
change.value = Roll.replaceFormulaData(change.value, actor.data);
|
||||
|
@ -54,4 +88,21 @@ export class DS4ActiveEffect extends ActiveEffect {
|
|||
}
|
||||
return this.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link DS4ActiveEffect} using default data.
|
||||
*
|
||||
* @param context The context for the creation of the effect, requiring a parent {@link DS4Actor} or {@link DS4Item}.
|
||||
* @returns A promise that resolved to the created effect or udifined of the creation was prevented.
|
||||
*/
|
||||
static async createDefault(
|
||||
context: DocumentModificationContext & { parent: DS4Actor | DS4Item },
|
||||
): Promise<DS4ActiveEffect | undefined> {
|
||||
const createData = {
|
||||
label: getGame().i18n.localize(`DS4.NewEffectLabel`),
|
||||
icon: this.FALLBACK_ICON,
|
||||
};
|
||||
|
||||
return this.create(createData, context);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue