add special creature ability as item type

This commit is contained in:
Johannes Loher 2021-01-11 00:55:49 +01:00
parent 85defa7e44
commit c422635d66
12 changed files with 121 additions and 24 deletions

View file

@ -1,21 +1,10 @@
import { ModifiableData, ResourceData, UsableResource } from "../common/common-data";
import { DS4 } from "../config";
export type ActorType = keyof typeof DS4.actorTypes;
export type DS4ActorDataType = DS4ActorDataCharacter | DS4ActorDataCreature;
export interface ModifiableData<T> {
base: T;
mod: T;
total?: T;
}
interface ResourceData<T> extends ModifiableData<T> {
value: T;
max?: T;
}
interface UsableResource<T> {
total: T;
used: T;
}
interface DS4ActorDataBase {
attributes: DS4ActorDataAttributes;
traits: DS4ActorDataTraits;

View file

@ -1,4 +1,5 @@
import { DS4ItemDataType } from "../item/item-data";
import { DS4Item } from "../item/item";
import { DS4ItemDataType, ItemType } from "../item/item-data";
import { DS4Actor } from "./actor";
import { DS4ActorDataType } from "./actor-data";
@ -207,4 +208,26 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
});
}
}
/**
* @override
*/
async _onDrop(event: DragEvent): Promise<boolean | unknown> {
const data = JSON.parse(event.dataTransfer?.getData("text/plain")) as { type?: string };
if (data.type === "Item") {
const item = await Item.fromDropData(data as Parameters<typeof DS4Item.fromDropData>[0]);
if (item && !this.actor.canOwnItemType(item.data.type as ItemType)) {
ui.notifications.warn(
game.i18n.format("DS4.WarningActorCannotOwnItem", {
actorName: this.actor.name,
actorType: this.actor.data.type,
itemName: item.name,
itemType: item.data.type,
}),
);
return false;
}
}
super._onDrop(event);
}
}

View file

@ -1,6 +1,7 @@
import { ModifiableData } from "../common/common-data";
import { DS4Item } from "../item/item";
import { DS4ItemDataType } from "../item/item-data";
import { DS4ActorDataType, ModifiableData } from "./actor-data";
import { DS4ItemDataType, ItemType } from "../item/item-data";
import { DS4ActorDataType } from "./actor-data";
export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item> {
/** @override */
@ -21,4 +22,37 @@ export class DS4Actor extends Actor<DS4ActorDataType, DS4ItemDataType, DS4Item>
combatValues.hitPoints.max = combatValues.hitPoints.total;
}
/**
* The list of item types that can be owned by this actor.
*/
get ownableItemTypes(): Array<ItemType> {
switch (this.data.type) {
case "character":
return [
"weapon",
"armor",
"shield",
"spell",
"trinket",
"equipment",
"talent",
"racialAbility",
"language",
"alphabet",
];
case "creature":
return ["weapon", "armor", "spell", "specialCreatureAbility"];
default:
[];
}
}
/**
* Checks whether or not the given item type can be owned by the actor.
* @param itemType the item type to check
*/
canOwnItemType(itemType: ItemType): boolean {
return this.ownableItemTypes.includes(itemType);
}
}