add special creature ability as item type
This commit is contained in:
parent
85defa7e44
commit
c422635d66
12 changed files with 121 additions and 24 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
15
src/module/common/common-data.ts
Normal file
15
src/module/common/common-data.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
export interface ModifiableData<T> {
|
||||
base: T;
|
||||
mod: T;
|
||||
total?: T;
|
||||
}
|
||||
|
||||
export interface ResourceData<T> extends ModifiableData<T> {
|
||||
value: T;
|
||||
max?: T;
|
||||
}
|
||||
|
||||
export interface UsableResource<T> {
|
||||
total: T;
|
||||
used: T;
|
||||
}
|
|
@ -61,6 +61,7 @@ export const DS4 = {
|
|||
racialAbility: "DS4.ItemTypeRacialAbility",
|
||||
language: "DS4.ItemTypeLanguage",
|
||||
alphabet: "DS4.ItemTypeAlphabet",
|
||||
specialCreatureAbility: "DS4.ItemTypeSpecialCreatureAbility",
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { ModifiableData } from "../actor/actor-data";
|
||||
import { ModifiableData } from "../common/common-data";
|
||||
import { DS4 } from "../config";
|
||||
|
||||
export type ItemType = keyof typeof DS4.itemTypes;
|
||||
|
||||
export type DS4ItemDataType =
|
||||
| DS4Weapon
|
||||
|
@ -10,7 +13,8 @@ export type DS4ItemDataType =
|
|||
| DS4Talent
|
||||
| DS4RacialAbility
|
||||
| DS4Language
|
||||
| DS4Alphabet;
|
||||
| DS4Alphabet
|
||||
| DS4SpecialCreatureAbility;
|
||||
|
||||
// types
|
||||
|
||||
|
@ -59,6 +63,9 @@ interface DS4Equipment extends DS4ItemBase, DS4ItemPhysical {}
|
|||
type DS4RacialAbility = DS4ItemBase;
|
||||
type DS4Language = DS4ItemBase;
|
||||
type DS4Alphabet = DS4ItemBase;
|
||||
interface DS4SpecialCreatureAbility extends DS4ItemBase {
|
||||
experiencePoints: number;
|
||||
}
|
||||
|
||||
// templates
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue