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

2
package-lock.json generated
View file

@ -2717,7 +2717,7 @@
}
},
"foundry-pc-types": {
"version": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#f84074f63d1aeeb9229e441e8c3ccaa9cba64142",
"version": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#5fcca4e4327b558d5eeeb962f05470c994a394be",
"from": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#f3l-fixes",
"dev": true,
"requires": {

View file

@ -56,6 +56,8 @@
"DS4.ItemTypeLanguagePlural": "Sprachen",
"DS4.ItemTypeAlphabet": "Schriftzeichen",
"DS4.ItemTypeAlphabetPlural": "Schriftzeichen",
"DS4.ItemTypeSpecialCreatureAbility": "Besondere Kreaturefähigkeit",
"DS4.ItemTypeSpecialCreatureAbilityPlural": "Besondere Kreaturefähigkeiten",
"DS4.ArmorType": "Panzerungstyp",
"DS4.ArmorTypeAbbr": "PAT",
"DS4.ArmorMaterialType": "Material Typ",
@ -133,6 +135,7 @@
"DS4.TalentRankTotal": "Gesamter Rang",
"DS4.CharacterLanguageLanguages": "Sprachen",
"DS4.CharacterLanguageAlphabets": "Schriftzeichen",
"DS4.SpecialCreatureAbilityExperiencePoints": "Erfahrungspunkte",
"DS4.CharacterProfileBiography": "Biographie",
"DS4.CharacterProfileGender": "Geschlecht",
"DS4.CharacterProfileBirthday": "Geburtstag",
@ -162,6 +165,7 @@
"DS4.CreatureBaseInfoExperiencePoints": "Erfahrungspunkte",
"DS4.CreatureBaseInfoDescription": "Beschreibung",
"DS4.WarningManageActiveEffectOnOwnedItem": "Das Verwalten von aktiven Effekten innerhalb eines besessen Items wird derzeit nicht unterstützt und wird in einem nachfolgenden Update hinzugefügt.",
"DS4.WarningActorCannotOwnItem": "Der Aktor '{actorName}' vom Typ '{actorType}' kann das Item '{itemName}' vom Typ '{itemType}' nicht besitzen.",
"DS4.ErrorDiceCritOverlap": "Es gibt eine Überlappung zwischen Patzern und Immersiegen.",
"DS4.ErrorExplodingRecursionLimitExceeded": "Die maximale Rekursionstiefe für slayende Würfelwürfe wurde überschritten.",
"DS4.UnitRounds": "Runden",

View file

@ -56,6 +56,8 @@
"DS4.ItemTypeLanguagePlural": "Languages",
"DS4.ItemTypeAlphabet": "Alphabet",
"DS4.ItemTypeAlphabetPlural": "Alphabets",
"DS4.ItemTypeSpecialCreatureAbility": "Special Creature Ability",
"DS4.ItemTypeSpecialCreatureAbilityPlural": "Special Creature Abilities",
"DS4.ArmorType": "Armor Type",
"DS4.ArmorTypeAbbr": "AT",
"DS4.ArmorMaterialType": "Material Type",
@ -133,6 +135,7 @@
"DS4.TalentRankTotal": "Total Ranks",
"DS4.CharacterLanguageLanguages": "Languages",
"DS4.CharacterLanguageAlphabets": "Alphabets",
"DS4.SpecialCreatureAbilityExperiencePoints": "Experience Points",
"DS4.CharacterProfileBiography": "Biography",
"DS4.CharacterProfileGender": "Gender",
"DS4.CharacterProfileBirthday": "Birthday",
@ -162,6 +165,7 @@
"DS4.CreatureBaseInfoExperiencePoints": "Experience Points",
"DS4.CreatureBaseInfoDescription": "Description",
"DS4.WarningManageActiveEffectOnOwnedItem": "Managing Active Effects within an Owned Item is not currently supported and will be added in a subsequent update.",
"DS4.WarningActorCannotOwnItem": "The actor '{actorName}' of type '{actorType}' cannot own the item '{itemName}' of type '{itemType}'.",
"DS4.ErrorDiceCritOverlap": "There's an overlap between Fumbles and Coups",
"DS4.ErrorExplodingRecursionLimitExceeded": "Maximum recursion depth for exploding dice roll exceeded",
"DS4.UnitRounds": "Rounds",

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);
}
}

View 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;
}

View file

@ -61,6 +61,7 @@ export const DS4 = {
racialAbility: "DS4.ItemTypeRacialAbility",
language: "DS4.ItemTypeLanguage",
alphabet: "DS4.ItemTypeAlphabet",
specialCreatureAbility: "DS4.ItemTypeSpecialCreatureAbility",
},
/**

View file

@ -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

View file

@ -136,7 +136,8 @@
"talent",
"racialAbility",
"language",
"alphabet"
"alphabet",
"specialCreatureAbility"
],
"templates": {
"base": {
@ -214,6 +215,10 @@
"unit": "custom"
},
"scrollPrice": 0
},
"specialCreatureAbility": {
"templates": ["base"],
"experiencePoints": 0
}
}
}

View file

@ -1,7 +1,7 @@
<div class="tab profile" data-group="primary" data-tab="profile">
<div class="grid grid-2col">
{{#each data.profile as |profile-data-value profile-data-key|}}
{{#if (neq profile-data-key 'biography')}}
{{#if (ne profile-data-key 'biography')}}
<div class="profile-entry">
<label for="data.profile.{{profile-data-key}}">
{{lookup ../config.characterProfile profile-data-key}}

View file

@ -0,0 +1,15 @@
<form class="{{cssClass}}" autocomplete="off">
{{#> systems/ds4/templates/item/partials/sheet-header.hbs}}
<div class="grid grid-3col basic-properties">
<div class="basic-property">
<label>{{localize "DS4.SpecialCreatureAbilityExperiencePoints"}}</label>
<input type="number" name="data.experiencePoints" value="{{data.experiencePoints}}" placeholder="0"
data-dtype="Number" />
</div>
</div>
{{/systems/ds4/templates/item/partials/sheet-header.hbs}}
{{!-- Common Item body --}}
{{#> systems/ds4/templates/item/partials/body.hbs}}{{/systems/ds4/templates/item/partials/body.hbs}}
</form>