Various enhancements

This commit is contained in:
2024-06-12 11:16:46 +02:00
parent dc4429f3e1
commit e92b2deacf
53 changed files with 207 additions and 151 deletions

View File

@@ -54,7 +54,7 @@ export class DarkStarsActorSheet extends ActorSheet {
subActors: foundry.utils.duplicate(this.actor.getSubActors()),
encCapacity: this.actor.getEncumbranceCapacity(),
conditions: this.actor.getConditions(),
tasks: this.actor.getCumulativeTasks(),
extendedTests: this.actor.getExtendedTests(),
config: game.system.darkstars.config,
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
notes: await TextEditor.enrichHTML(this.object.system.biodata.notes, {async: true}),
@@ -151,12 +151,17 @@ export class DarkStarsActorSheet extends ActorSheet {
const attrKey = $(event.currentTarget).data("attr-key")
this.actor.rollAttribute(attrKey)
})
html.find('.start-cumulative-task').click((event) => {
html.find('.start-extended-test').click((event) => {
const li = $(event.currentTarget).parents(".item")
const skillId = li.data("item-id")
this.actor.rollSkill(skillId, true)
})
html.find('.roll-extended-test').click((event) => {
const li = $(event.currentTarget).parents(".item")
const testId = li.data("item-id")
this.actor.continueExtendedTest(testId)
})
html.find('.roll-weapon').click((event) => {
const li = $(event.currentTarget).parents(".item");
const skillId = li.data("item-id")

View File

@@ -138,8 +138,8 @@ export class DarkStarsActor extends Actor {
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
getCumulativeTasks() {
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'cumulativetask') || []);
getExtendedTests() {
let comp = foundry.utils.duplicate(this.items.filter(item => item.type == 'extendedtest') || []);
DarkStarsUtility.sortArrayObjectsByName(comp)
return comp;
}
@@ -266,7 +266,7 @@ export class DarkStarsActor extends Actor {
/* -------------------------------------------- */
async equipItem(itemId) {
let item = this.items.find(item => item.id == itemId)
if (item && item.system) {
if (item?.system) {
if (item.type == "armor") {
let armor = this.items.find(item => item.id != itemId && item.type == "armor" && item.system.equipped)
if (armor) {
@@ -634,16 +634,44 @@ export class DarkStarsActor extends Actor {
rollData.title = "Attribute " + rollData.attr.label
this.startRoll(rollData)
}
/* -------------------------------------------- */
continueExtendedTest(testId) {
let test = this.items.get(testId)
if (test) {
let skill = this.items.find(it => it.type == "skill" && it.name.toLowerCase() == test.system.skill.toLowerCase())
if (skill) {
skill = foundry.utils.duplicate(skill)
this.updateSkill(skill)
let rollData = this.getCommonRollData()
rollData.mode = "extendedtest"
rollData.isExtended = true
rollData.extendedTest = test
rollData.title = "Extended test " + skill.name
rollData.skill = skill
rollData.img = skill.img
rollData.taskId = test.id
if (rollData.target) {
ui.notifications.warn("You are targetting a token with a skill : please use a Weapon instead.")
return
}
this.startRoll(rollData)
} else {
console.log("Unable to find the relevant skill for extended test " + test.system.skill)
}
} else {
console.log("Unable to find the extended test")
}
}
/* -------------------------------------------- */
async rollSkill(skillId, isCumulative = false, taskId = undefined) {
async rollSkill(skillId, isExtended = false, taskId = undefined) {
let skill = this.items.get(skillId)
if (skill) {
skill = foundry.utils.duplicate(skill)
this.updateSkill(skill)
let rollData = this.getCommonRollData()
rollData.mode = "skill"
rollData.isCumulative = isCumulative
rollData.isExtended = isExtended
rollData.title = "Skill " + skill.name
rollData.skill = skill
rollData.img = skill.img
@@ -651,15 +679,15 @@ export class DarkStarsActor extends Actor {
ui.notifications.warn("You are targetting a token with a skill : please use a Weapon instead.")
return
}
if (isCumulative) {
rollData.title = "Cumulative Task " + skill.name
if (isExtended) {
rollData.title = "Extended Test " + skill.name
if (!taskId) {
let cumulativeTask = await this.createEmbeddedDocuments("Item", [{name: "Cumulative task " + skill.name, type: "cumulativetask",
let extendedTest = await this.createEmbeddedDocuments("Item", [{name: "Extended test " + skill.name, type: "extendedtest",
'system.skill': skill.name}])
//console.log("Task", cumulativeTask)
rollData.taskId = cumulativeTask[0].id
rollData.taskId = extendedTest[0].id
}else {
rollData.taskId = cumulativeTask[0].id
rollData.taskId = extendedTest[0].id
}
}
this.startRoll(rollData)