Skip to content

Commit

Permalink
Merge pull request #192 from soltysek/bump_v9_support
Browse files Browse the repository at this point in the history
WIP: v9 support
  • Loading branch information
AnthonyMonette authored Dec 29, 2021
2 parents 8226f03 + 1cbd8d4 commit 9489125
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 82 deletions.
6 changes: 3 additions & 3 deletions module/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export async function buttonDialog(data)
});
}

function onCritRoll(event) {
async function onCritRoll(event) {
let current = event.currentTarget.parentElement.parentElement.parentElement.getElementsByClassName("dice-total")
if(!current.length){
current = event.currentTarget.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("dice-total")
}
let isSuccess = event.currentTarget.getElementsByClassName("dice-sucess")
let totalValue = Number(current[0].innerText)
let rollResult = new Roll("1d10x10").roll()
let rollResult = await new Roll("1d10x10").roll()
if (isSuccess.length){
totalValue += Number(rollResult.total)
}else {
Expand Down Expand Up @@ -141,7 +141,7 @@ export async function rollDamage(img, name, damageFormula, location, locationFor
messageData.flavor += `</div>`;
});
}
new Roll(damageFormula).roll().toMessage(messageData)
(await new Roll(damageFormula).roll()).toMessage(messageData)
}

export function addChatMessageContextOptions(html, options){
Expand Down
4 changes: 2 additions & 2 deletions module/sheets/MonsterSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ async function exportLoot(actor) {
"type" : "loot"
});

newLoot.items.forEach((item)=>{
newLoot.items.forEach(async item=>{
if (typeof(item.data.data.quantity) === 'string' && item.data.data.quantity.includes("d")){
let roll = new Roll(item.data.data.quantity).roll()
let roll = await new Roll(item.data.data.quantity).roll()
item.update({ 'data.quantity': Math.ceil(roll.total)})
}
});
Expand Down
48 changes: 24 additions & 24 deletions module/sheets/WitcherActorSheet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buttonDialog, rollDamage } from "../chat.js";
import { witcher } from "../config.js";
import { getRandomInt, updateDerived, rollSkillCheck, genId, calc_currency_weight } from "../witcher.js";
import { exportLoot, onChangeSkillList } from "./MonsterSheet.js"
import { exportLoot, onChangeSkillList } from "./MonsterSheet.js";

import { ExecuteDefense } from "../../scripts/actions.js";

Expand Down Expand Up @@ -324,10 +324,10 @@ export default class WitcherActorSheet extends ActorSheet {
flavor: `<h1>Quantity of ${dragData.item.name}</h1>`,
}

let roll = await new Roll(dragData.item.data.quantity).roll().toMessage(messageData)
let roll = (await new Roll(dragData.item.data.quantity).roll()).toMessage(messageData)
this._addItem(this.actor, dragData.item, Math.floor(roll.roll.total))
if (previousActor) {
previousActor.deleteOwnedItem(dragData.item._id)
await previousActor.items.get(dragData.item._id).delete()
}
return
}
Expand Down Expand Up @@ -363,7 +363,7 @@ export default class WitcherActorSheet extends ActorSheet {
}else {
this._addItem(this.actor, dragData.item)
if (previousActor) {
previousActor.deleteOwnedItem(dragData.item._id)
await previousActor.items.get(dragData.item._id).delete()
}
}
}
Expand All @@ -376,7 +376,7 @@ export default class WitcherActorSheet extends ActorSheet {
let foundItem = actor.items.get(itemId)
let newQuantity = foundItem.data.data.quantity - quantityToRemove
if (newQuantity <= 0 ){
await actor.deleteOwnedItem(itemId)
await actor.items.get(itemId).delete()
}else {
await foundItem.update({'data.quantity': newQuantity < 0 ? 0 : newQuantity})
}
Expand Down Expand Up @@ -896,15 +896,15 @@ export default class WitcherActorSheet extends ActorSheet {
}
}

this.actor.createOwnedItem(itemData)
await Item.create(itemData, {parent: this.actor})
}

async _onAddActiveEffect(){
let itemData = {
name: `new effect`,
type: "effect"
}
this.actor.createOwnedItem(itemData)
await Item.create(itemData, {parent: this.actor})
}

async _alchemyCraft(event) {
Expand Down Expand Up @@ -1014,7 +1014,7 @@ export default class WitcherActorSheet extends ActorSheet {
buttons: {
Craft: {
label: `${game.i18n.localize("WITCHER.Dialog.ButtonCraft")}`,
callback: (html) => {
callback: async html => {
let stat = this.actor.data.data.stats.cra.current;
let statName = game.i18n.localize(this.actor.data.data.stats.cra.label);
let skill = this.actor.data.data.skills.cra.alchemy.value;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ export default class WitcherActorSheet extends ActorSheet {
rollFormula += !displayRollDetails ? `+${totalModifiers}`: `+${totalModifiers}[${game.i18n.localize("WITCHER.Settings.modifiers")}]`
}

let roll = new Roll(rollFormula).roll()
let roll = await new Roll(rollFormula).roll()
if (roll.dice[0].results[0].result == 10){
messageData.flavor += `<a class="crit-roll"><div class="dice-sucess"><i class="fas fa-dice-d6"></i>${game.i18n.localize("WITCHER.Crit")}</div></a>`;
};
Expand Down Expand Up @@ -1169,7 +1169,7 @@ export default class WitcherActorSheet extends ActorSheet {

if (customModifier < 0){formula += !displayRollDetails ? `${customModifier}`: `${customModifier}[${game.i18n.localize("WITCHER.Settings.Custom")}]`}
if (customModifier > 0){formula += !displayRollDetails ? `+${customModifier}` : `+${customModifier}[${game.i18n.localize("WITCHER.Settings.Custom")}]`}
let rollResult = new Roll(formula).roll()
let rollResult = await new Roll(formula).roll()
let messageData = {flavor:`<h2><img src="${spellItem.img}" class="item-img" />${spellItem.name}</h2>
<div><b>${game.i18n.localize("WITCHER.Spell.StaCost")}: </b>${staCostdisplay}</div>
<div><b>${game.i18n.localize("WITCHER.Spell.Effect")}: </b>${spellItem.data.data.effect}</div>`}
Expand Down Expand Up @@ -1297,15 +1297,15 @@ export default class WitcherActorSheet extends ActorSheet {
buttons: {
continue: {
label: game.i18n.localize("WITCHER.Button.Continue"),
callback: (html) => {
callback: async html => {
let customAtt = html.find("[name=customModifiers]")[0].value;
if (customAtt < 0){
rollFormula += !displayRollDetails ? `${customAtt}`: `${customAtt}[${game.i18n.localize("WITCHER.Settings.Custom")}]`
}
if (customAtt > 0){
rollFormula += !displayRollDetails ? `+${customAtt}` : `+${customAtt}[${game.i18n.localize("WITCHER.Settings.Custom")}]`
}
let rollResult = new Roll(rollFormula).roll()
let rollResult = await new Roll(rollFormula).roll()
let messageData = {flavor: `<h2>${name}</h2>${effet}`}
if (rollResult.dice[0].results[0].result == 10){
messageData.flavor += `<a class="crit-roll"><div class="dice-sucess"><i class="fas fa-dice-d6"></i>${game.i18n.localize("WITCHER.Crit")}</div></a>`;
Expand All @@ -1323,12 +1323,12 @@ export default class WitcherActorSheet extends ActorSheet {
}

async _onCritRoll(event) {
let rollResult = new Roll("1d10x10").roll()
let rollResult = await new Roll("1d10x10").roll()
rollResult.toMessage()
}

async _onDeathSaveRoll(event) {
let rollResult = new Roll("1d10").roll()
let rollResult = await new Roll("1d10").roll()
let stunBase = Math.floor((this.actor.data.data.stats.body.max + this.actor.data.data.stats.will.max)/2);
if (this.actor.data.data.derivedStats.hp.value != 0) {
stunBase = this.actor.data.data.coreStats.stun.current
Expand Down Expand Up @@ -1370,7 +1370,7 @@ export default class WitcherActorSheet extends ActorSheet {
buttons: {
t1: {
label:`${game.i18n.localize("WITCHER.ReputationButton.Save")}`,
callback:(html =>{
callback:( async html =>{
let statValue = this.actor.data.data.reputation.max

this.actor.data.data.reputation.modifiers.forEach(mod => {
Expand All @@ -1379,7 +1379,7 @@ export default class WitcherActorSheet extends ActorSheet {
}
});

let rollResult = new Roll("1d10").roll()
let rollResult = await new Roll("1d10").roll()
let messageData = {}
messageData.flavor = `
<h2>${game.i18n.localize("WITCHER.Reputation")}</h2>
Expand All @@ -1398,7 +1398,7 @@ export default class WitcherActorSheet extends ActorSheet {
},
t2: {
label:`${game.i18n.localize("WITCHER.ReputationButton.FaceDown")}`,
callback:(html =>{
callback:(async html =>{
let repValue = this.actor.data.data.reputation.max

this.actor.data.data.reputation.modifiers.forEach(mod => {
Expand All @@ -1407,7 +1407,7 @@ export default class WitcherActorSheet extends ActorSheet {
}
});

let rollResult = new Roll("1d10").roll()
let rollResult = await new Roll("1d10").roll()
let messageData = {}

let faceDownValue = rollResult.total + Number(repValue) + Number(this.actor.data.data.stats.will.current)
Expand Down Expand Up @@ -1550,7 +1550,7 @@ export default class WitcherActorSheet extends ActorSheet {
break;
}

let rollResult = new Roll("1d10").roll()
let rollResult = await new Roll("1d10").roll()
let messageData = {}
messageData.flavor = `
<h2>${game.i18n.localize(statName)}</h2>
Expand Down Expand Up @@ -1597,10 +1597,10 @@ export default class WitcherActorSheet extends ActorSheet {
item.sheet.render(true)
}

_onItemDelete(event) {
async _onItemDelete(event) {
event.preventDefault();
let itemId = event.currentTarget.closest(".item").dataset.itemId;
return this.actor.deleteOwnedItem(itemId);
return await this.actor.items.get(itemId).delete();
}

async _onItemBuy(event) {
Expand Down Expand Up @@ -1747,7 +1747,7 @@ export default class WitcherActorSheet extends ActorSheet {
event.currentTarget.select();
}

_onItemRoll(event, itemId = null) {
async _onItemRoll(event, itemId = null) {

let displayRollDetails = game.settings.get("TheWitcherTRPG", "displayRollsDetails")

Expand Down Expand Up @@ -1884,7 +1884,7 @@ export default class WitcherActorSheet extends ActorSheet {
buttons: {
Roll: {
label: `${game.i18n.localize("WITCHER.Dialog.ButtonRoll")}`,
callback: (html) => {
callback: async html => {
let isExtraAttack = html.find("[name=isExtraAttack]").prop("checked");

let location = html.find("[name=location]")[0].value;
Expand Down Expand Up @@ -2154,7 +2154,7 @@ export default class WitcherActorSheet extends ActorSheet {
messageData.flavor = `<div class="attack-message"><h1><img src="${item.img}" class="item-img" />Attack: ${item.name}</h1>`;
messageData.flavor += `<span> ${game.i18n.localize("WITCHER.Armor.Location")}: ${touchedLocation} = ${LocationFormula} </span>`;
messageData.flavor += `<button class="damage" data-img="${item.img}" data-dmg-type="${damageType}" data-name="${item.name}" data-dmg="${damageFormula}" data-location="${touchedLocation}" data-location-formula="${LocationFormula}" data-strike="${strike}" data-effects='${effects}'>${game.i18n.localize("WITCHER.table.Damage")}</button>`;
let roll = new Roll(attFormula).roll()
let roll = await new Roll(attFormula).roll()
if (roll.dice[0].results[0].result == 10){
messageData.flavor += `<a class="crit-roll"><div class="dice-sucess"><i class="fas fa-dice-d6"></i>${game.i18n.localize("WITCHER.Crit")}</div></a>`;
};
Expand Down
4 changes: 2 additions & 2 deletions module/witcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function rollSkillCheck(thisActor, statNum, skillNum){
buttons: {
LocationRandom: {
label: game.i18n.localize("WITCHER.Button.Continue"),
callback: (html) => {
callback: async html => {
let customAtt = html.find("[name=customModifiers]")[0].value;
if (customAtt < 0){
rollFormula += !displayRollDetails ? `${customAtt}`: `${customAtt}[${game.i18n.localize("WITCHER.Settings.Custom")}]`
Expand All @@ -366,7 +366,7 @@ function rollSkillCheck(thisActor, statNum, skillNum){
rollFormula += !displayRollDetails ? `+${customAtt}` : `+${customAtt}[${game.i18n.localize("WITCHER.Settings.Custom")}]`
}

let roll = new Roll(rollFormula).roll()
let roll = await new Roll(rollFormula).roll()
if (roll.dice[0].results[0].result == 10){
messageData.flavor += `<a class="crit-roll"><div class="dice-sucess"><i class="fas fa-dice-d6"></i>${game.i18n.localize("WITCHER.Crit")}</div></a>`;
};
Expand Down
32 changes: 16 additions & 16 deletions scripts/TheWitcherTRPG.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Hooks.once("init", function () {
console.log("TheWItcherTRPG | init system");

CONFIG.witcher = witcher
CONFIG.Item.entityClass = WitcherItem;
CONFIG.Actor.entityClass = WitcherActor;
CONFIG.Item.documentClass = WitcherItem;
CONFIG.Actor.documentClass = WitcherActor;

Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("witcher", WitcherItemSheet, {makeDefault: true});
Expand Down Expand Up @@ -169,11 +169,11 @@ async function createBoilerplateMacro(data, slot) {
return ui.notifications.warn("You can only create macro buttons for owned Items");
}
else if(data.item.type == 'weapon'){
const item = data.item;
const weapon = data.item;
let foundActor = null
game.actors.forEach(actor => {
actor.items.forEach(item => {
if(data.item._id == item._id) {
if(weapon._id == item.id) {
foundActor = actor
}
});
Expand All @@ -182,14 +182,14 @@ async function createBoilerplateMacro(data, slot) {
return ui.notifications.warn("You can only create macro buttons with the original character");
}
const command =
`let actor = game.actors.get('${foundActor._id}');
actor.rollItem("${item._id}")`;
let macro = game.macros.entities.find(m => (m.name === item.name) && (m.command === command));
`let actor = game.actors.get('${foundActor.id}');
actor.rollItem("${weapon._id}")`;
let macro = game.macros.find(m => (m.name === weapon.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: item.name,
name: weapon.name,
type: "script",
img: item.img,
img: weapon.img,
command: command,
flags: { "boilerplate.itemMacro": true }
});
Expand All @@ -198,11 +198,11 @@ actor.rollItem("${item._id}")`;
return false;
}
else if(data.item.type == 'spell'){
const item = data.item;
const spell = data.item;
let foundActor = null
game.actors.forEach(actor => {
actor.items.forEach(item => {
if(data.item._id == item._id) {
if(spell._id == item.id) {
foundActor = actor
}
});
Expand All @@ -211,14 +211,14 @@ actor.rollItem("${item._id}")`;
return ui.notifications.warn("You can only create macro buttons with the original character");
}
const command =
`let actor = game.actors.get('${foundActor._id}');
actor.rollSpell("${item._id}")`;
let macro = game.macros.entities.find(m => (m.name === item.name) && (m.command === command));
`let actor = game.actors.get('${foundActor.id}');
actor.rollSpell("${spell._id}")`;
let macro = game.macros.find(m => (m.name === spell.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: item.name,
name: spell.name,
type: "script",
img: item.img,
img: spell.img,
command: command,
flags: { "boilerplate.itemMacro": true }
});
Expand Down
Loading

0 comments on commit 9489125

Please sign in to comment.