Fix Title update AND bought_at_rank...

This commit is contained in:
Vlyan
2021-06-03 23:17:51 +02:00
parent 8094511d38
commit 29ba2549b9

View File

@@ -170,7 +170,7 @@ export class BaseSheetL5r5e extends ActorSheet {
} }
// Check item type and subtype // Check item type and subtype
let item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event); const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || item.documentName !== "Item" || item.data.type === "property") { if (!item || item.documentName !== "Item" || item.data.type === "property") {
return; return;
} }
@@ -201,8 +201,16 @@ export class BaseSheetL5r5e extends ActorSheet {
} }
} }
// Can add the item - Foundry override cause props
const allowed = Hooks.call("dropActorSheetData", this.actor, this, item);
if (allowed === false) {
return;
}
let itemData = item.data.toObject(true);
// Item subtype specific // Item subtype specific
switch (item.data.type) { switch (itemData.type) {
case "advancement": case "advancement":
// Specific advancements, remove 1 to selected ring/skill // Specific advancements, remove 1 to selected ring/skill
await this.actor.addBonus(item); await this.actor.addBonus(item);
@@ -218,15 +226,18 @@ export class BaseSheetL5r5e extends ActorSheet {
await this.actor.addBonus(embedItem); await this.actor.addBonus(embedItem);
} }
} }
// refresh data
itemData = item.data.toObject(true);
break; break;
case "technique": case "technique":
// School_ability and mastery_ability, allow only 1 per type // School_ability and mastery_ability, allow only 1 per type
if (CONFIG.l5r5e.techniques.get(item.data.data.technique_type)?.type === "school") { if (CONFIG.l5r5e.techniques.get(itemData.data.technique_type)?.type === "school") {
if ( if (
Array.from(this.actor.items).some((e) => { Array.from(this.actor.items).some((e) => {
return ( return (
e.type === "technique" && e.data.data.technique_type === item.data.data.technique_type e.type === "technique" && e.data.data.technique_type === itemData.data.technique_type
); );
}) })
) { ) {
@@ -235,36 +246,31 @@ export class BaseSheetL5r5e extends ActorSheet {
} }
// No cost for schools // No cost for schools
item.data.data.xp_cost = 0; itemData.data.xp_cost = 0;
item.data.data.xp_used = 0; itemData.data.xp_used = 0;
item.data.data.in_curriculum = true; itemData.data.in_curriculum = true;
} else { } else {
// Check if technique is allowed for this character // Check if technique is allowed for this character
if (!game.user.isGM && !this.actor.data.data.techniques[item.data.data.technique_type]) { if (!game.user.isGM && !this.actor.data.data.techniques[itemData.data.technique_type]) {
ui.notifications.info(game.i18n.localize("l5r5e.techniques.not_allowed")); ui.notifications.info(game.i18n.localize("l5r5e.techniques.not_allowed"));
return; return;
} }
// Verify cost // Verify cost
item.data.data.xp_cost = itemData.data.xp_cost =
item.data.data.xp_cost > 0 ? item.data.data.xp_cost : CONFIG.l5r5e.xp.techniqueCost; itemData.data.xp_cost > 0 ? itemData.data.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
item.data.data.xp_used = item.data.data.xp_cost; itemData.data.xp_used = itemData.data.xp_cost;
} }
break; break;
} }
// Modify the bought at rank to the current actor rank // Modify the bought at rank to the current actor rank
if (item.data.data.bought_at_rank !== undefined && this.actor.data.data.identity?.school_rank) { if (itemData.data.bought_at_rank !== undefined && this.actor.data.data.identity?.school_rank) {
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank; itemData.data.bought_at_rank = this.actor.data.data.identity.school_rank;
} }
// Ok add item - Foundry override cause props // Finally create the embed
const allowed = Hooks.call("dropActorSheetData", this.actor, this, item); return this.actor.createEmbeddedDocuments("Item", [itemData]);
if (allowed === false) {
return;
}
return this._onDropItemCreate(item.data.toObject(false));
} }
/** /**