fvtt-crucible-rpg/modules/crucible-actor.js

702 lines
24 KiB
JavaScript
Raw Normal View History

2022-07-19 23:16:03 +02:00
/* -------------------------------------------- */
import { CrucibleUtility } from "./crucible-utility.js";
import { CrucibleRollDialog } from "./crucible-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"
}
/* -------------------------------------------- */
/* -------------------------------------------- */
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class CrucibleActor extends Actor {
/* -------------------------------------------- */
/**
* Override the create() function to provide additional SoS functionality.
*
* This overrided create() function adds initial items
* Namely: Basic skills, money,
*
* @param {Object} data Barebones actor data which this function adds onto.
* @param {Object} options (Unused) Additional options which customize the creation workflow.
*
*/
static async create(data, options) {
// Case of compendium global import
if (data instanceof Array) {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
let actor = super.create(data, options);
return actor;
}
if (data.type == 'character') {
const skills = await CrucibleUtility.loadCompendium("fvtt-crucible-rpg.skills");
2022-07-31 09:16:17 +02:00
data.items = skills.map(i => i.toObject())
2022-07-19 23:16:03 +02:00
}
if (data.type == 'npc') {
}
return super.create(data, options);
}
/* -------------------------------------------- */
prepareBaseData() {
}
/* -------------------------------------------- */
async prepareData() {
super.prepareData();
}
2022-08-03 09:34:33 +02:00
/* -------------------------------------------- */
2022-08-04 10:25:40 +02:00
computeHitPoints() {
2022-08-03 09:34:33 +02:00
let hp = duplicate(this.data.data.secondary.hp)
let max = (this.data.data.abilities.str.value + this.data.data.abilities.con.value) * 6
2022-08-04 10:25:40 +02:00
if (max != hp.max || hp.value > max) {
2022-08-03 09:34:33 +02:00
hp.max = max
hp.value = max // Init case
2022-08-04 10:25:40 +02:00
this.update({ 'data.secondary.hp': hp })
2022-08-03 09:34:33 +02:00
}
}
/* -------------------------------------------- */
2022-08-04 10:25:40 +02:00
computeEffortPoints() {
2022-08-03 09:34:33 +02:00
let effort = duplicate(this.data.data.secondary.effort)
let max = (this.data.data.abilities.con.value + this.data.data.abilities.int.value) * 6
2022-08-04 10:25:40 +02:00
if (max != effort.max || effort.value > max) {
2022-08-03 09:34:33 +02:00
effort.max = max
effort.value = max // Init case
2022-08-04 10:25:40 +02:00
this.update({ 'data.secondary.effort': effort })
2022-08-03 09:34:33 +02:00
}
}
2022-07-19 23:16:03 +02:00
/* -------------------------------------------- */
prepareDerivedData() {
2022-08-03 09:34:33 +02:00
if (this.type == 'character' || game.user.isGM) {
2022-07-19 23:16:03 +02:00
this.data.data.encCapacity = this.getEncumbranceCapacity()
this.buildContainerTree()
2022-08-03 09:34:33 +02:00
this.computeHitPoints()
this.computeEffortPoints()
2022-07-19 23:16:03 +02:00
}
super.prepareDerivedData();
}
/* -------------------------------------------- */
_preUpdate(changed, options, user) {
super._preUpdate(changed, options, user);
}
/* -------------------------------------------- */
getEncumbranceCapacity() {
2022-07-25 19:13:52 +02:00
return 1;
2022-07-19 23:16:03 +02:00
}
/* -------------------------------------------- */
getMoneys() {
let comp = this.data.items.filter(item => item.type == 'money');
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-19 23:16:03 +02:00
return comp;
}
/* -------------------------------------------- */
2022-07-30 22:54:08 +02:00
getFeats() {
let comp = duplicate(this.data.items.filter(item => item.type == 'feat') || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-30 22:54:08 +02:00
return comp;
}
/* -------------------------------------------- */
getFeatsWithDie() {
let comp = duplicate(this.data.items.filter(item => item.type == 'feat' && item.data.data.isfeatdie) || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-30 22:54:08 +02:00
return comp;
}
getFeatsWithSL() {
let comp = duplicate(this.data.items.filter(item => item.type == 'feat' && item.data.data.issl) || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-30 22:54:08 +02:00
return comp;
}
/* -------------------------------------------- */
getLore() {
let comp = duplicate(this.data.items.filter(item => item.type == 'spell') || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-30 22:54:08 +02:00
return comp;
}
getEquippedWeapons() {
let comp = duplicate(this.data.items.filter(item => item.type == 'weapon' && item.data.data.equipped) || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-30 22:54:08 +02:00
return comp;
}
/* -------------------------------------------- */
2022-07-19 23:16:03 +02:00
getArmors() {
let comp = duplicate(this.data.items.filter(item => item.type == 'armor') || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-19 23:16:03 +02:00
return comp;
}
2022-08-04 10:25:40 +02:00
getEquippedArmor() {
let comp = this.data.items.find(item => item.type == 'armor' && item.data.data.equipped)
if (comp) {
return duplicate(comp)
}
return undefined
}
2022-07-30 22:54:08 +02:00
/* -------------------------------------------- */
getShields() {
let comp = duplicate(this.data.items.filter(item => item.type == 'shield') || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-30 22:54:08 +02:00
return comp;
}
2022-08-04 10:25:40 +02:00
getEquippedShield() {
let comp = this.data.items.find(item => item.type == 'shield' && item.data.data.equipped)
if (comp) {
return duplicate(comp)
}
return undefined
}
/* -------------------------------------------- */
2022-07-19 23:16:03 +02:00
getRace() {
let race = this.data.items.filter(item => item.type == 'race')
return race[0] ?? [];
}
/* -------------------------------------------- */
checkAndPrepareEquipment(item) {
}
/* -------------------------------------------- */
checkAndPrepareEquipments(listItem) {
for (let item of listItem) {
this.checkAndPrepareEquipment(item)
}
return listItem
}
/* -------------------------------------------- */
getWeapons() {
let comp = duplicate(this.data.items.filter(item => item.type == 'weapon') || []);
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
2022-07-19 23:16:03 +02:00
return comp;
}
/* -------------------------------------------- */
getItemById(id) {
let item = this.data.items.find(item => item.id == id);
if (item) {
item = duplicate(item)
if (item.type == 'specialisation') {
item.data.dice = CrucibleUtility.getDiceFromLevel(item.data.level);
}
}
return item;
}
/* -------------------------------------------- */
getSkills() {
2022-07-31 19:32:54 +02:00
let comp = duplicate(this.data.items.filter(item => item.type == 'skill') || [])
2022-08-01 21:39:17 +02:00
for (let skill of comp) {
CrucibleUtility.updateSkill(skill)
}
2022-07-31 19:32:54 +02:00
CrucibleUtility.sortArrayObjectsByName(comp)
return comp
2022-07-19 23:16:03 +02:00
}
/* -------------------------------------------- */
getRelevantAbility(statKey) {
let comp = duplicate(this.data.items.filter(item => item.type == 'skill' && item.data.data.ability == ability) || []);
return comp;
}
/* -------------------------------------------- */
async equipItem(itemId) {
2022-08-04 10:25:40 +02:00
let item = this.data.items.find(item => item.id == itemId)
2022-07-19 23:16:03 +02:00
if (item && item.data.data) {
2022-08-04 10:25:40 +02:00
if (item.type == "armor") {
let armor = this.data.items.find(item => item.id != itemId && item.type == "armor" && item.data.data.equipped)
if (armor) {
ui.notifications.warn("You already have an armor equipped!")
return
}
}
if (item.type == "shield") {
let shield = this.data.items.find(item => item.id != itemId && item.type == "shield" && item.data.data.equipped)
if (shield) {
ui.notifications.warn("You already have a shield equipped!")
return
}
}
2022-07-19 23:16:03 +02:00
let update = { _id: item.id, "data.equipped": !item.data.data.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
compareName(a, b) {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
}
/* ------------------------------------------- */
getEquipments() {
return this.data.items.filter(item => item.type == 'shield' || item.type == 'armor' || item.type == "weapon" || item.type == "equipment");
}
/* ------------------------------------------- */
getEquipmentsOnly() {
return duplicate(this.data.items.filter(item => item.type == "equipment") || [])
}
2022-07-26 10:03:23 +02:00
/* ------------------------------------------- */
2022-07-30 22:54:08 +02:00
getSaveRoll() {
2022-07-26 10:03:23 +02:00
return {
reflex: {
2022-08-04 10:25:40 +02:00
"label": "Reflex Save",
"img": "systems/fvtt-crucible-rpg/images/icons/saves/reflex_save.webp",
2022-07-26 10:03:23 +02:00
"value": this.data.data.abilities.agi.value + this.data.data.abilities.wit.value
},
fortitude: {
2022-08-04 10:25:40 +02:00
"label": "Fortitude Save",
"img": "systems/fvtt-crucible-rpg/images/icons/saves/fortitude_save.webp",
2022-07-26 10:03:23 +02:00
"value": this.data.data.abilities.str.value + this.data.data.abilities.con.value
},
willpower: {
2022-08-04 10:25:40 +02:00
"label": "Willpower Save",
"img": "systems/fvtt-crucible-rpg/images/icons/saves/will_save.webp",
2022-07-26 10:03:23 +02:00
"value": this.data.data.abilities.int.value + this.data.data.abilities.cha.value
}
2022-07-30 22:54:08 +02:00
}
2022-07-26 10:03:23 +02:00
}
2022-07-19 23:16:03 +02:00
/* ------------------------------------------- */
async buildContainerTree() {
let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || [])
for (let equip1 of equipments) {
if (equip1.data.iscontainer) {
equip1.data.contents = []
equip1.data.contentsEnc = 0
for (let equip2 of equipments) {
if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) {
equip1.data.contents.push(equip2)
let q = equip2.data.quantity ?? 1
equip1.data.contentsEnc += q * equip2.data.weight
}
}
}
}
// Compute whole enc
let enc = 0
for (let item of equipments) {
2022-08-05 10:04:42 +02:00
//item.data.idrDice = CrucibleUtility.getDiceFromLevel(Number(item.data.idr))
2022-07-19 23:16:03 +02:00
if (item.data.equipped) {
if (item.data.iscontainer) {
enc += item.data.contentsEnc
} else if (item.data.containerid == "") {
let q = item.data.quantity ?? 1
enc += q * item.data.weight
}
}
}
for (let item of this.data.items) { // Process items/shields/armors
if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.data.data.equipped) {
let q = item.data.data.quantity ?? 1
enc += q * item.data.data.weight
}
}
// Store local values
this.encCurrent = enc
this.containersTree = equipments.filter(item => item.data.containerid == "") // Returns the root of equipements without container
}
2022-08-14 10:10:26 +02:00
/* -------------------------------------------- */
async rollArmor( rollData) {
let armor = this.getEquippedArmor()
if (armor) {
}
return { armor: "none"}
}
/* -------------------------------------------- */
async incDecHP( formula ) {
let dmgRoll = new Roll(formula).roll( {async: false})
await CrucibleUtility.showDiceSoNice(dmgRoll, game.settings.get("core", "rollMode"))
let hp = duplicate(this.data.data.secondary.hp)
hp.value = Number(hp.value) + Number(dmgRoll.total)
this.update( {'data.secondary.hp': hp })
return Number(dmgRoll.total)
}
2022-07-19 23:16:03 +02:00
/* -------------------------------------------- */
getAbility(abilKey) {
return this.data.data.abilities[abilKey];
}
/* -------------------------------------------- */
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)
if (container) {
if (object.data.data.iscontainer) {
ui.notifications.warn("Only 1 level of container allowed")
return
}
let alreadyInside = this.data.items.filter(item => item.data.data.containerid && item.data.data.containerid == containerId);
if (alreadyInside.length >= container.data.data.containercapacity) {
ui.notifications.warn("Container is already full !")
return
} else {
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': containerId }])
}
} else if (object && object.data.data.containerid) { // remove from container
console.log("Removeing: ", object)
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': "" }]);
}
}
/* -------------------------------------------- */
async preprocessItem(event, item, onDrop = 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
}
/* -------------------------------------------- */
async equipGear(equipmentId) {
let item = this.data.items.find(item => item.id == equipmentId);
if (item && item.data.data) {
let update = { _id: item.id, "data.equipped": !item.data.data.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
getInitiativeScore(combatId, combatantId) {
if (this.type == 'character') {
this.rollMR(true, combatId, combatantId)
}
console.log("Init required !!!!")
return -1;
}
/* -------------------------------------------- */
getSubActors() {
let subActors = [];
for (let id of this.data.data.subactors) {
subActors.push(duplicate(game.actors.get(id)))
}
return subActors;
}
/* -------------------------------------------- */
async addSubActor(subActorId) {
let subActors = duplicate(this.data.data.subactors);
subActors.push(subActorId);
await this.update({ 'data.subactors': subActors });
}
/* -------------------------------------------- */
async delSubActor(subActorId) {
let newArray = [];
for (let id of this.data.data.subactors) {
if (id != subActorId) {
newArray.push(id);
}
}
await this.update({ 'data.subactors': newArray });
}
/* -------------------------------------------- */
syncRoll(rollData) {
this.lastRollId = rollData.rollId;
CrucibleUtility.saveRollData(rollData);
}
/* -------------------------------------------- */
getOneSkill(skillId) {
let skill = this.data.items.find(item => item.type == 'skill' && item.id == skillId)
if (skill) {
skill = duplicate(skill);
}
return skill;
}
/* -------------------------------------------- */
async deleteAllItemsByType(itemType) {
let items = this.data.items.filter(item => item.type == itemType);
await this.deleteEmbeddedDocuments('Item', items);
}
/* -------------------------------------------- */
async addItemWithoutDuplicate(newItem) {
let item = this.data.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
if (!item) {
await this.createEmbeddedDocuments('Item', [newItem]);
}
}
2022-07-30 23:29:55 +02:00
/* -------------------------------------------- */
async incrementSkillExp(skillId, inc) {
let skill = this.data.items.get(skillId)
if (skill) {
await this.updateEmbeddedDocuments('Item', [{ _id: skill.id, 'data.exp': skill.data.data.exp + inc }])
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
2022-07-31 19:32:54 +02:00
content: `<div>${this.name} has gained 1 exp in the skill ${skill.name} (exp = ${skill.data.data.exp})</div`
2022-07-30 23:29:55 +02:00
}
ChatMessage.create(chatData)
if (skill.data.data.exp >= 25) {
2022-08-01 21:39:17 +02:00
await this.updateEmbeddedDocuments('Item', [{ _id: skill.id, 'data.exp': 0, 'data.explevel': skill.data.data.explevel + 1 }])
2022-07-30 23:29:55 +02:00
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
2022-08-01 21:39:17 +02:00
content: `<div>${this.name} has gained 1 exp SL in the skill ${skill.name} (new exp SL : ${skill.data.data.explevel}) !</div`
2022-07-30 23:29:55 +02:00
}
ChatMessage.create(chatData)
}
}
}
2022-07-19 23:16:03 +02:00
/* -------------------------------------------- */
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.data.items.get(objetId)
if (objetQ) {
let newQ = objetQ.data.data.quantity + incDec
if (newQ >= 0) {
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]) // pdates one EmbeddedEntity
}
}
}
/* -------------------------------------------- */
async incDecAmmo(objetId, incDec = 0) {
let objetQ = this.data.items.get(objetId)
if (objetQ) {
let newQ = objetQ.data.data.ammocurrent + incDec;
if (newQ >= 0 && newQ <= objetQ.data.data.ammomax) {
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.ammocurrent': newQ }]); // pdates one EmbeddedEntity
}
}
}
/* -------------------------------------------- */
2022-07-25 21:33:00 +02:00
getCommonRollData(abilityKey = undefined) {
2022-07-19 23:16:03 +02:00
let rollData = CrucibleUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
2022-07-30 22:54:08 +02:00
rollData.featsDie = this.getFeatsWithDie()
rollData.featsSL = this.getFeatsWithSL()
2022-08-01 21:39:17 +02:00
rollData.armors = this.getArmors()
2022-07-30 22:54:08 +02:00
rollData.featDieName = "none"
2022-07-30 23:29:55 +02:00
rollData.featSLName = "none"
2022-07-31 19:32:54 +02:00
rollData.rollAdvantage = "none"
rollData.advantage = "none"
2022-08-01 21:39:17 +02:00
rollData.disadvantage = "none"
2022-07-30 23:29:55 +02:00
2022-07-25 21:33:00 +02:00
if (abilityKey) {
rollData.ability = this.getAbility(abilityKey)
//rollData.skillList = this.getRelevantSkill(abilityKey)
rollData.selectedKill = undefined
2022-07-19 23:16:03 +02:00
}
console.log("ROLLDATA", rollData)
return rollData
}
2022-07-25 21:33:00 +02:00
/* -------------------------------------------- */
rollAbility(abilityKey) {
let rollData = this.getCommonRollData(abilityKey)
rollData.mode = "ability"
CrucibleUtility.rollCrucible(rollData)
}
/* -------------------------------------------- */
rollSkill(skillId) {
let skill = this.data.items.get(skillId)
if (skill) {
2022-07-31 19:48:23 +02:00
if (skill.data.islore && skill.data.level == 0) {
ui.notifications.warn("You can't use Lore Skills with a SL of 0.")
return
}
2022-07-25 21:33:00 +02:00
skill = duplicate(skill)
2022-08-01 21:39:17 +02:00
CrucibleUtility.updateSkill(skill)
2022-07-25 21:33:00 +02:00
let abilityKey = skill.data.ability
let rollData = this.getCommonRollData(abilityKey)
rollData.mode = "skill"
rollData.skill = skill
2022-07-31 19:32:54 +02:00
rollData.img = skill.img
2022-07-26 21:40:42 +02:00
this.startRoll(rollData)
2022-07-25 21:33:00 +02:00
}
}
2022-07-19 23:16:03 +02:00
2022-08-01 21:39:17 +02:00
/* -------------------------------------------- */
rollWeapon(weaponId) {
let weapon = this.data.items.get(weaponId)
if (weapon) {
weapon = duplicate(weapon)
2022-08-04 10:25:40 +02:00
let skill = this.data.items.find(item => item.name.toLowerCase() == weapon.data.skill.toLowerCase())
2022-08-01 21:39:17 +02:00
if (skill) {
skill = duplicate(skill)
CrucibleUtility.updateSkill(skill)
let abilityKey = skill.data.ability
let rollData = this.getCommonRollData(abilityKey)
rollData.mode = "weapon"
rollData.skill = skill
rollData.weapon = weapon
rollData.img = weapon.img
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
}
}
}
2022-08-04 16:28:10 +02:00
2022-08-06 17:06:05 +02:00
/* -------------------------------------------- */
rollDefenseMelee(attackRollData) {
let weapon = this.data.items.get(attackRollData.defenseWeaponId)
if (weapon) {
weapon = duplicate(weapon)
let skill = this.data.items.find(item => item.name.toLowerCase() == weapon.data.skill.toLowerCase())
if (skill) {
skill = duplicate(skill)
CrucibleUtility.updateSkill(skill)
let abilityKey = skill.data.ability
let rollData = this.getCommonRollData(abilityKey)
rollData.defenderTokenId = undefined // Cleanup
rollData.mode = "weapondefense"
rollData.shield = this.getEquippedShield()
rollData.attackRollData = duplicate(attackRollData)
rollData.skill = skill
rollData.weapon = weapon
rollData.img = weapon.img
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
}
} else {
ui.notifications.warn("Weapon not found ! ")
}
}
2022-08-04 16:28:10 +02:00
/* -------------------------------------------- */
rollShieldDie() {
let shield = this.getEquippedShield()
if (shield) {
shield = duplicate(shield)
let rollData = this.getCommonRollData()
rollData.mode = "shield"
rollData.shield = shield
2022-08-14 10:10:26 +02:00
rollData.useshield = true
2022-08-04 16:28:10 +02:00
rollData.img = shield.img
this.startRoll(rollData)
}
}
/* -------------------------------------------- */
2022-08-14 10:10:26 +02:00
async rollArmorDie(rollData = undefined) {
2022-08-04 16:28:10 +02:00
let armor = this.getEquippedArmor()
if (armor) {
armor = duplicate(armor)
2022-08-14 10:10:26 +02:00
let reduce = 0
let multiply = 1
let disadvantage = false
let advantage = false
let messages = ["Armor applied"]
if (rollData) {
if (CrucibleUtility.isArmorLight(armor) && CrucibleUtility.isWeaponPenetrating(rollData.attackRollData.weapon) ) {
return { armorIgnored: true, nbSuccess: 0, messages: ["Armor ignored : Penetrating weapons ignore Light Armors."] }
}
if (CrucibleUtility.isWeaponPenetrating(rollData.attackRollData.weapon) ) {
messages.push("Armor reduced by 1 (Penetrating weapon)")
reduce = 1
}
if (CrucibleUtility.isWeaponLight(rollData.attackRollData.weapon) ) {
messages.push("Armor with advantage (Light weapon)")
advantage = true
}
if (CrucibleUtility.isWeaponHeavy(rollData.attackRollData.weapon) ) {
messages.push("Armor with disadvantage (Heavy weapon)")
disadvantage = true
}
if (CrucibleUtility.isWeaponHack(rollData.attackRollData.weapon) ) {
messages.push("Armor reduced by 1 (Hack weapon)")
reduce = 1
}
if (CrucibleUtility.isWeaponUndamaging(rollData.attackRollData.weapon) ) {
messages.push("Armor multiplied by 2 (Undamaging weapon)")
multiply = 2
}
}
2022-08-05 10:04:42 +02:00
let diceColor = armor.data.absorprionroll
2022-08-14 10:10:26 +02:00
let armorResult = await CrucibleUtility.getRollTableFromDiceColor( diceColor, false )
let armorValue = (Number(armorResult.data.text) - reduce) * multiply
if ( advantage || disadvantage) {
let armorResult2 = await CrucibleUtility.getRollTableFromDiceColor( diceColor, false )
let armorValue2 = (Number(armorResult2.data.text) - reduce) * multiply
if ( advantage) {
armorValue = (armorValue2 > armorValue) ? armorValue2 : armorValue
messages.push(`Armor advantage - Roll 1 = ${armorValue} - Roll 2 = ${armorValue2}`)
}
if ( disadvantage) {
armorValue = (armorValue2 < armorValue) ? armorValue2 : armorValue
messages.push(`Armor disadvantage - Roll 1 = ${armorValue} - Roll 2 = ${armorValue2}`)
}
}
armorResult.armorValue = armorValue
if ( !rollData) {
ChatMessage.create( { content: "Armor result : " + armorValue } )
}
messages.push( "Armor result : " + armorValue)
return { armorIgnored: false, nbSuccess: armorValue, messages: messages }
2022-08-04 16:28:10 +02:00
}
2022-08-14 10:10:26 +02:00
return { armorIgnored: true, nbSuccess: 0, messages: ["No armor equipped."] }
2022-08-04 16:28:10 +02:00
}
2022-08-03 09:34:33 +02:00
/* -------------------------------------------- */
2022-08-04 10:25:40 +02:00
rollSave(saveKey) {
2022-08-03 09:34:33 +02:00
let saves = this.getSaveRoll()
let save = saves[saveKey]
if (save) {
save = duplicate(save)
let rollData = this.getCommonRollData()
rollData.mode = "save"
rollData.save = save
//rollData.img = skill.img
this.startRoll(rollData)
}
2022-08-01 21:39:17 +02:00
2022-08-03 09:34:33 +02:00
}
2022-07-19 23:16:03 +02:00
/* -------------------------------------------- */
async startRoll(rollData) {
2022-07-26 21:40:42 +02:00
this.syncRoll(rollData)
2022-07-19 23:16:03 +02:00
let rollDialog = await CrucibleRollDialog.create(this, rollData)
2022-07-26 21:40:42 +02:00
rollDialog.render(true)
2022-07-19 23:16:03 +02:00
}
}