Update with minor fixes/updates

This commit is contained in:
2022-07-19 20:51:48 +02:00
parent 2ab1cbe24c
commit a2e0eb213f
11 changed files with 214 additions and 105 deletions

View File

@ -5,6 +5,11 @@ import { PegasusRollDialog } from "./pegasus-roll-dialog.js";
/* -------------------------------------------- */
const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entrenchedcover": 6 };
const statThreatLevel = ["agi", "str", "phy", "com", "def", "per"]
const __subkey2title = {
"melee-dmg": "Melee Damage", "melee-atk": "Melee Attack", "ranged-atk": "Ranged Attack",
"ranged-dmg": "Ranged Damage", "dmg-res": "Damare Resistance"
}
/* -------------------------------------------- */
/* -------------------------------------------- */
/**
@ -516,7 +521,6 @@ export class PegasusActor extends Actor {
async addObjectToContainer(itemId, containerId) {
let container = this.data.items.find(item => item.id == containerId && item.data.data.iscontainer)
let object = this.data.items.find(item => item.id == itemId)
console.log("Found", container, object)
if (container) {
if (object.data.data.iscontainer) {
ui.notifications.warn("Only 1 level of container allowed")
@ -534,10 +538,35 @@ export class PegasusActor extends Actor {
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': "" }]);
}
}
/* -------------------------------------------- */
checkVirtue( virtue) {
let vices = this.getVices()
for (let vice of vices) {
let nonVirtues = vice.data.data.unavailablevirtue
for (let blockedVirtue of nonVirtues) {
if (blockedVirtue.name.toLowerCase() == virtue.name.toLowerCase()) {
return false
}
}
}
return true
}
/* -------------------------------------------- */
checkVice( vice) {
let virtues = this.getVirtues()
for (let virtue of virtues) {
let nonVices = virtue.data.data.unavailablevice
for (let blockedVice of nonVices) {
if (blockedVice.name.toLowerCase() == vice.name.toLowerCase()) {
return false
}
}
}
return true
}
/* -------------------------------------------- */
async preprocessItem(event, item, onDrop = false) {
console.log("Pre-process !!!", item)
if (item.data.type == 'race') {
this.applyRace(item.data)
} else if (item.data.type == 'role') {
@ -546,18 +575,30 @@ export class PegasusActor extends Actor {
this.applyAbility(item.data, [], true)
if (!onDrop) {
await this.createEmbeddedDocuments('Item', [item.data])
return
}
} else {
if (!onDrop) {
await this.createEmbeddedDocuments('Item', [item.data])
return
}
}
// Check virtue/vice validity
if ( item.data.type == "virtue") {
if ( !this.checkVirtue(item) ) {
ui.notifications.info("Virtue is not allowed due to Vice.")
return false
}
}
if ( item.data.type == "vice") {
if ( !this.checkVice(item) ) {
ui.notifications.info("Vice is not allowed due to Virtue.")
return false
}
}
let dropID = $(event.target).parents(".item").attr("data-item-id") // Only relevant if container drop
let objectID = item.id || item._id
this.addObjectToContainer(objectID, dropID)
return true
}
/* -------------------------------------------- */
@ -890,11 +931,12 @@ export class PegasusActor extends Actor {
/* -------------------------------------------- */
getTraumaState() {
this.traumaState = "none"
let negDelirium = -Math.floor((this.data.data.secondary.delirium.max + 1) / 2)
if (this.type == "character") {
if (this.data.data.secondary.delirium.value >= 0 && this.data.data.secondary.delirium.value <= Math.floor((this.data.data.secondary.delirium.max + 1) / 2)) {
if (this.data.data.secondary.delirium.value <= 0 && this.data.data.secondary.delirium.value >= negDelirium) {
this.traumaState = "trauma"
}
if (this.data.data.secondary.delirium.value < 0) {
if (this.data.data.secondary.delirium.value < negDelirium) {
this.traumaState = "severetrauma"
}
}
@ -1174,7 +1216,7 @@ export class PegasusActor extends Actor {
effectsList.push({ label: "Stun Hindrance", type: "hindrance", applied: false, value: this.data.data.combat.stunlevel })
}
if (this.data.data.combat.hindrancedice > 0) {
effectsList.push({ label: "Health/Delirium Hindrance", type: "hindrance", applied: false, value: this.data.data.combat.hindrancedice })
effectsList.push({ label: "Wounds Hindrance", type: "hindrance", applied: false, value: this.data.data.combat.hindrancedice })
}
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
if (overCapacity > 0) {
@ -1220,13 +1262,13 @@ export class PegasusActor extends Actor {
if (statKey == 'phy') {
let armors = this.getArmors()
for (let armor of armors) {
rollData.armorsList.push({ label: `Armor ${armor.name}`, type: "other", applied: false, value: armor.data.resistance })
rollData.armorsList.push({ label: `Armor ${armor.name}`, type: "armor", applied: false, value: armor.data.resistance })
}
}
if (useShield) {
let shields = this.data.items.filter(item => item.type == "shield" && item.data.data.equipped)
for (let sh of shields) {
rollData.armorsList.push({ label: `Shield ${sh.name}`, type: "other", applied: false, value: sh.data.data.level })
rollData.armorsList.push({ label: `Shield ${sh.name}`, type: "shield", applied: false, value: sh.data.data.level })
}
}
}
@ -1234,13 +1276,13 @@ export class PegasusActor extends Actor {
let weapons = this.getWeapons()
for (let weapon of weapons) {
if (weapon.data.equipped && weapon.data.statistic == statKey) {
rollData.weaponsList.push({ label: `Attack ${weapon.name}`, type: "attack", applied: false, weapon: weapon, value: 0 })
rollData.weaponsList.push({ label: `Attack ${weapon.name}`, type: "attack", applied: false, weapon: weapon, value: 0, damageDice: PegasusUtility.getDiceFromLevel(0) })
}
if (weapon.data.equipped && weapon.data.enhanced && weapon.data.enhancedstat == statKey) {
rollData.weaponsList.push({ label: `Enhanced Attack ${weapon.name}`, type: "enhanced", applied: false, weapon: weapon, value: weapon.data.enhancedlevel })
rollData.weaponsList.push({ label: `Enhanced Attack ${weapon.name}`, type: "enhanced", applied: false, weapon: weapon, value: weapon.data.enhancedlevel, damageDice: PegasusUtility.getDiceFromLevel(weapon.data.enhancedlevel) })
}
if (weapon.data.equipped && weapon.data.damagestatistic == statKey) {
rollData.weaponsList.push({ label: `Damage ${weapon.name}`, type: "damage", applied: false, weapon: weapon, value: weapon.data.damage })
rollData.weaponsList.push({ label: `Damage ${weapon.name}`, type: "damage", applied: false, weapon: weapon, value: weapon.data.damage, damageDice: PegasusUtility.getDiceFromLevel(weapon.data.damage) })
}
}
}
@ -1328,7 +1370,11 @@ export class PegasusActor extends Actor {
let rollData = this.getCommonRollData(statKey, useShield)
rollData.mode = "stat"
rollData.subKey = subKey
rollData.title = `Roll : ${stat.label} `
let def = stat.label
if (subKey) {
def = __subkey2title[subKey]
}
rollData.title = `Roll : ${def} `
rollData.img = "icons/dice/d12black.svg"
if (subKey == "melee-dmg" || subKey == "ranged-dmg" || subKey == "power-dmg") {
rollData.isDamage = true