Merge branch 'master' into 10-implement-money

This commit is contained in:
Johannes Loher 2021-01-18 19:48:07 +01:00
commit e89c87f0c1
46 changed files with 1651 additions and 505 deletions

View file

@ -1,39 +1,19 @@
export interface DS4ActorDataType {
import { ModifiableData, ResourceData, UsableResource } from "../common/common-data";
export type DS4ActorDataType = DS4ActorDataCharacter | DS4ActorDataCreature;
interface DS4ActorDataBase {
attributes: DS4ActorDataAttributes;
traits: DS4ActorDataTraits;
combatValues: DS4ActorDataCombatValues;
baseInfo: DS4ActorDataBaseInfo;
progression: DS4ActorDataProgression;
language: DS4ActorDataLanguage;
profile: DS4ActorDataProfile;
currency: DS4ActorDataCurrency;
}
interface DS4ActorDataAttributes {
body: BodyAttribute;
body: ModifiableData<number>;
mobility: ModifiableData<number>;
mind: ModifiableData<number>;
}
export interface ModifiableData<T> {
base: T;
mod: T;
total?: T;
}
interface UsableResource<T> {
total: T;
used: T;
}
interface ResourceData<T> extends ModifiableData<T> {
value: T;
max?: T;
}
// Blueprint in case we need more detailed differentiation
type BodyAttribute = ModifiableData<number>;
interface DS4ActorDataTraits {
strength: ModifiableData<number>;
constitution: ModifiableData<number>;
@ -54,26 +34,35 @@ interface DS4ActorDataCombatValues {
targetedSpellcasting: ModifiableData<number>;
}
interface DS4ActorDataBaseInfo {
interface DS4ActorDataCharacter extends DS4ActorDataBase {
baseInfo: DS4ActorDataCharacterBaseInfo;
progression: DS4ActorDataCharacterProgression;
language: DS4ActorDataCharacterLanguage;
profile: DS4ActorDataCharacterProfile;
currency: DS4ActorDataCharacterCurrency;
}
interface DS4ActorDataCharacterBaseInfo {
race: string;
class: string;
heroClass: string;
culture: string;
}
interface DS4ActorDataProgression {
interface DS4ActorDataCharacterProgression {
level: number;
experiencePoints: number;
talentPoints: UsableResource<number>;
progressPoints: UsableResource<number>;
}
interface DS4ActorDataLanguage {
interface DS4ActorDataCharacterLanguage {
languages: string;
alphabets: string;
}
interface DS4ActorDataProfile {
interface DS4ActorDataCharacterProfile {
biography: string;
gender: string;
birthday: string;
birthplace: string;
@ -85,8 +74,25 @@ interface DS4ActorDataProfile {
specialCharacteristics: string;
}
interface DS4ActorDataCurrency {
interface DS4ActorDataCharacterCurrency {
gold: number;
silver: number;
copper: number;
}
interface DS4ActorDataCreature extends DS4ActorDataBase {
baseInfo: DS4ActorDataCreatureBaseInfo;
}
type CreatureType = "animal" | "construct" | "humanoid" | "magicalEntity" | "plantBeing" | "undead";
type SizeCategory = "tiny" | "small" | "normal" | "large" | "huge" | "colossal";
interface DS4ActorDataCreatureBaseInfo {
loot: string;
foeFactor: number;
creatureType: CreatureType;
sizeCategory: SizeCategory;
experiencePoints: number;
description: string;
}

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",
"trinket",
"equipment",
"spell",
"talent",
"racialAbility",
"language",
"alphabet",
];
case "creature":
return ["weapon", "armor", "shield", "trinket", "equipment", "spell", "specialCreatureAbility"];
default:
return [];
}
}
/**
* 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

@ -1,12 +1,30 @@
import { DS4ItemDataType } from "../item/item-data";
import { DS4Actor } from "./actor";
import { DS4ActorDataType } from "./actor-data";
import { DS4Item } from "../../item/item";
import { DS4ItemDataType, ItemType } from "../../item/item-data";
import { DS4Actor } from "../actor";
import { DS4ActorDataType } from "../actor-data";
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4ItemDataType> {
/** @override */
static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, {
classes: ["ds4", "sheet", "actor"],
width: 745,
height: 600,
});
}
/** @override */
get template(): string {
const path = "systems/ds4/templates/actor";
return `${path}/${this.actor.data.type}-sheet.hbs`;
}
/* -------------------------------------------- */
/**
* This method returns the data for the template of the actor sheet.
* It explicitly adds the items of the object sorted by type in the
@ -21,21 +39,9 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor, DS4Ite
// Add the items explicitly sorted by type to the data:
itemsByType: this.actor.itemTypes,
};
console.log("Data:", data);
return data;
}
/** @override */
static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, {
classes: ["ds4", "sheet", "actor"],
template: "systems/ds4/templates/actor/actor-sheet.hbs",
width: 745,
height: 600,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description" }],
});
}
/* -------------------------------------------- */
/** @override */
@ -200,4 +206,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;
}
}
return super._onDrop(event);
}
}

View file

@ -0,0 +1,11 @@
import { DS4ActorSheet } from "./actor-sheet";
export class DS4CharacterActorSheet extends DS4ActorSheet {
/** @override */
static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, {
classes: ["ds4", "sheet", "actor", "character"],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "inventory" }],
});
}
}

View file

@ -0,0 +1,11 @@
import { DS4ActorSheet } from "./actor-sheet";
export class DS4CreatureActorSheet extends DS4ActorSheet {
/** @override */
static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, {
classes: ["ds4", "sheet", "actor", "creature"],
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "inventory" }],
});
}
}