converting advancement to dynamic list skills

This commit is contained in:
Vlyan
2023-03-15 17:44:06 +01:00
parent a24e775001
commit 1b68d33bd2
8 changed files with 209 additions and 191 deletions

View File

@@ -133,146 +133,151 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
* @param {DragEvent} event
*/
async _onDrop(event) {
// *** Everything below here is only needed if the sheet is editable ***
if (!this.isEditable || this.actor.system.soft_locked) {
console.log("L5R5E | This sheet is not editable");
return;
}
// Check item type and subtype
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || !["Item", "JournalEntry"].includes(item.documentName) || item.type === "property") {
console.log(`L5R5E | Wrong subtype ${item?.type}`, item);
return;
}
// Specific curriculum journal drop
if (item.documentName === "JournalEntry") {
// npc does not have this
if (!this.actor.system.identity?.school_curriculum_journal) {
console.log("L5R5E | NPC won't go to school :'(");
return;
}
this.actor.system.identity.school_curriculum_journal = {
id: item._id,
name: item.name,
pack: item.pack || null,
};
await this.actor.update({
system: {
identity: {
school_curriculum_journal: this.actor.system.identity.school_curriculum_journal,
},
},
});
return;
}
// Dropped an item with same "id" as one owned
if (this.actor.items) {
// Exit if we already owned exactly this id (drag a personal item on our own sheet)
if (
this.actor.items.some((embedItem) => {
// Search in children
if (embedItem.items instanceof Map && embedItem.items.has(item._id)) {
return true;
}
return embedItem._id === item._id;
})
) {
console.log("L5R5E | This element has been ignored because it already exists in this actor", item.uuid);
try {
// *** Everything below here is only needed if the sheet is editable ***
if (!this.isEditable || this.actor.system.soft_locked) {
console.log("L5R5E | This sheet is not editable");
return;
}
// Add quantity instead if they have (id is different so use type and name)
if (item.system.quantity) {
const tmpItem = this.actor.items.find(
(embedItem) => embedItem.name === item.name && embedItem.type === item.type
);
if (tmpItem && this._modifyQuantity(tmpItem.id, 1)) {
// Check item type and subtype
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
if (!item || !["Item", "JournalEntry"].includes(item.documentName) || item.type === "property") {
console.log(`L5R5E | Wrong subtype ${item?.type}`, item);
return;
}
// Specific curriculum journal drop
if (item.documentName === "JournalEntry") {
// npc does not have this
if (!this.actor.system.identity?.school_curriculum_journal) {
console.log("L5R5E | NPC won't go to school :'(");
return;
}
}
}
// Can add the item - Foundry override cause props
const allowed = Hooks.call("dropActorSheetData", this.actor, this, item);
if (allowed === false) {
return;
}
let itemData = item.toObject(true);
// Item subtype specific
switch (itemData.type) {
case "army_cohort":
case "army_fortification":
console.warn("L5R5E | Army items are not allowed", item?.type, item);
this.actor.system.identity.school_curriculum_journal = {
id: item._id,
name: item.name,
pack: item.pack || null,
};
await this.actor.update({
system: {
identity: {
school_curriculum_journal: this.actor.system.identity.school_curriculum_journal,
},
},
});
return;
}
case "advancement":
// Specific advancements, remove 1 to selected ring/skill
await this.actor.addBonus(item);
break;
case "title":
// Generate new Ids for the embed items
await item.generateNewIdsForAllEmbedItems();
// Add embed advancements bonus
for (let [embedId, embedItem] of item.system.items) {
if (embedItem.type === "advancement") {
await this.actor.addBonus(embedItem);
}
// Dropped an item with same "id" as one owned
if (this.actor.items) {
// Exit if we already owned exactly this id (drag a personal item on our own sheet)
if (
this.actor.items.some((embedItem) => {
// Search in children
if (embedItem.items instanceof Map && embedItem.items.has(item._id)) {
return true;
}
return embedItem._id === item._id;
})
) {
console.log("L5R5E | This element has been ignored because it already exists in this actor", item.uuid);
return;
}
// refresh data
itemData = item.toObject(true);
break;
case "skill":
itemData.system.rank = 0;
itemData.system.modifier = 0;
break;
case "technique":
// School_ability and mastery_ability, allow only 1 per type
if (CONFIG.l5r5e.techniques.get(itemData.system.technique_type)?.type === "school") {
if (
Array.from(this.actor.items).some((e) => {
return e.type === "technique" && e.system.technique_type === itemData.system.technique_type;
})
) {
ui.notifications.info(game.i18n.localize("l5r5e.techniques.only_one"));
// Add quantity instead if they have (id is different so use type and name)
if (item.system.quantity) {
const tmpItem = this.actor.items.find(
(embedItem) => embedItem.name === item.name && embedItem.type === item.type
);
if (tmpItem && this._modifyQuantity(tmpItem.id, 1)) {
return;
}
// No cost for schools
itemData.system.xp_cost = 0;
itemData.system.xp_used = 0;
itemData.system.in_curriculum = true;
} else {
// Check if technique is allowed for this character
// if (!game.user.isGM && !this.actor.system.techniques[itemData.system.technique_type]) {
// ui.notifications.info(game.i18n.localize("l5r5e.techniques.not_allowed"));
// return;
// }
// Verify cost
itemData.system.xp_cost =
itemData.system.xp_cost > 0 ? itemData.system.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
itemData.system.xp_used = itemData.system.xp_cost;
}
break;
}
}
// Modify the bought at rank to the current actor rank
if (itemData.system.bought_at_rank !== undefined && this.actor.system.identity?.school_rank) {
itemData.system.bought_at_rank = this.actor.system.identity.school_rank;
}
// Can add the item - Foundry override cause props
const allowed = Hooks.call("dropActorSheetData", this.actor, this, item);
if (allowed === false) {
return;
}
// Finally create the embed
return this.actor.createEmbeddedDocuments("Item", [itemData]);
let itemData = item.toObject(true);
// Item subtype specific
switch (itemData.type) {
case "army_cohort":
case "army_fortification":
console.warn("L5R5E | Army items are not allowed", item?.type, item);
return;
case "advancement":
// Specific advancements, add x to selected ring/skill
await this.actor.addBonus(item);
break;
case "title":
// Generate new Ids for the embed items
await item.generateNewIdsForAllEmbedItems();
// Add embed advancements bonus
for (let [embedId, embedItem] of item.system.items) {
if (embedItem.type === "advancement") {
await this.actor.addBonus(embedItem);
}
}
// refresh data
itemData = item.toObject(true);
break;
case "skill":
itemData.system.rank = 0;
itemData.system.modifier = 0;
break;
case "technique":
// School_ability and mastery_ability, allow only 1 per type
if (CONFIG.l5r5e.techniques.get(itemData.system.technique_type)?.type === "school") {
if (
Array.from(this.actor.items).some((e) => {
return e.type === "technique" && e.system.technique_type === itemData.system.technique_type;
})
) {
ui.notifications.info(game.i18n.localize("l5r5e.techniques.only_one"));
return;
}
// No cost for schools
itemData.system.xp_cost = 0;
itemData.system.xp_used = 0;
itemData.system.in_curriculum = true;
} else {
// Check if technique is allowed for this character
// if (!game.user.isGM && !this.actor.system.techniques[itemData.system.technique_type]) {
// ui.notifications.info(game.i18n.localize("l5r5e.techniques.not_allowed"));
// return;
// }
// Verify cost
itemData.system.xp_cost =
itemData.system.xp_cost > 0 ? itemData.system.xp_cost : CONFIG.l5r5e.xp.techniqueCost;
itemData.system.xp_used = itemData.system.xp_cost;
}
break;
}
// Modify the bought at rank to the current actor rank
if (itemData.system.bought_at_rank !== undefined && this.actor.system.identity?.school_rank) {
itemData.system.bought_at_rank = this.actor.system.identity.school_rank;
}
// Finally create the embed
return this.actor.createEmbeddedDocuments("Item", [itemData]);
} catch (ex) {
console.warn("L5R5E |", ex.message);
}
}
/** @inheritdoc */