Skip to content

Commit

Permalink
0.0.93
Browse files Browse the repository at this point in the history
  • Loading branch information
gambit07 committed Mar 8, 2024
1 parent b0c2938 commit de4862d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 50 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ jobs:
- name: Set Release Notes for Github
id: set-release-notes-github
run: |
echo "- Updates:" >> release_notes.txt
echo " - Silvery Barbs: Now compatible with the Counterspell automation, Silvery Barbs will be cancelled if counterspelled." >> release_notes.txt
echo "- Bugfixes:" >> release_notes.txt
echo " - Silvery Barbs: Fix for attack silvery barbs not calling the correct token doc" >> release_notes.txt
echo " - Silvery Barbs: Fix advantage targets not displaying if only one target was present." >> release_notes.txt
echo "release-notes-github<<EOF" >> $GITHUB_ENV
cat release_notes.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Gambit"
}
],
"version": "0.0.92",
"version": "0.0.93",
"compatibility": {
"minimum": "11",
"verified": "11",
Expand Down
95 changes: 48 additions & 47 deletions scripts/macros/silveryBarbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,51 +166,50 @@ export async function silveryBarbs({workflowData,workflowType}) {
const {silveryBarbsDecision, returnedTokenUuid} = await socket.executeAsUser("showSilveryBarbsDialog", browserUser.id, originTokenUuidPrimary, actorUuidPrimary, validTokenPrimary.document.uuid, dialogTitlePrimary, originTokenUuidPrimary, "attack");
if (silveryBarbsDecision === false || !silveryBarbsDecision) continue;
if (silveryBarbsDecision === true) {

let rerollAddition = workflow.attackRoll.total - workflow.attackRoll.dice[0].total
let targetAC = workflow.hitTargets.first().actor.system.attributes.ac.value;
const saveSetting = workflow.options.noOnUseMacro;
workflow.options.noOnUseMacro = true;
await workflow.setAttackRoll(await new Roll(`1d20 + ${rerollAddition}`).roll({async: true}));
workflow.options.noOnUseMacro = saveSetting;

if(workflow.attackTotal < targetAC) {
let chatList = [];

chatList = `The creature was silvery barbed, and failed their attack. <img src="${workflow.token.actor.img}" width="30" height="30" style="border:0px">`;

let msgHistory = [];
game.messages.reduce((list, message) => {
if (message.flags["midi-qol"]?.itemId === spellData._id && message.speaker.token === validTokenPrimary.id) msgHistory.push(message.id);
}, msgHistory);
let itemCard = msgHistory[msgHistory.length - 1];
let chatMessage = await game.messages.get(itemCard);
let content = await duplicate(chatMessage.content);
let insertPosition = content.indexOf('<div class="end-midi-qol-attack-roll"></div>');
if (insertPosition !== -1) {
content = content.slice(0, insertPosition) + chatList + content.slice(insertPosition);
let rerollAddition = workflow.attackRoll.total - workflow.attackRoll.dice[0].total
let targetAC = workflow.hitTargets.first().actor.system.attributes.ac.value;
const saveSetting = workflow.options.noOnUseMacro;
workflow.options.noOnUseMacro = true;
await workflow.setAttackRoll(await new Roll(`1d20 + ${rerollAddition}`).roll({async: true}));
workflow.options.noOnUseMacro = saveSetting;

if(workflow.attackTotal < targetAC) {
let chatList = [];

chatList = `The creature was silvery barbed, and failed their attack. <img src="${workflow.token.actor.img}" width="30" height="30" style="border:0px">`;

let msgHistory = [];
game.messages.reduce((list, message) => {
if (message.flags["midi-qol"]?.itemId === spellData._id && message.speaker.token === validTokenPrimary.id) msgHistory.push(message.id);
}, msgHistory);
let itemCard = msgHistory[msgHistory.length - 1];
let chatMessage = await game.messages.get(itemCard);
let content = await duplicate(chatMessage.content);
let insertPosition = content.indexOf('<div class="end-midi-qol-attack-roll"></div>');
if (insertPosition !== -1) {
content = content.slice(0, insertPosition) + chatList + content.slice(insertPosition);
}
await chatMessage.update({ content: content });
}
await chatMessage.update({ content: content });
}

else {
let chatList = [];

chatList = `The creature was silvery barbed, but were still able to hit their target. <img src="${workflow.token.actor.img}" width="30" height="30" style="border:0px">`;

let msgHistory = [];
game.messages.reduce((list, message) => {
if (message.flags["midi-qol"]?.itemId === spellData._id && message.speaker.token === validTokenPrimary.id) msgHistory.push(message.id);
}, msgHistory);
let itemCard = msgHistory[msgHistory.length - 1];
let chatMessage = await game.messages.get(itemCard);
let content = await duplicate(chatMessage.content);
let insertPosition = content.indexOf('<div class="end-midi-qol-attack-roll"></div>');
if (insertPosition !== -1) {
content = content.slice(0, insertPosition) + chatList + content.slice(insertPosition);
else {
let chatList = [];

chatList = `The creature was silvery barbed, but were still able to hit their target. <img src="${workflow.token.actor.img}" width="30" height="30" style="border:0px">`;

let msgHistory = [];
game.messages.reduce((list, message) => {
if (message.flags["midi-qol"]?.itemId === spellData._id && message.speaker.token === validTokenPrimary.id) msgHistory.push(message.id);
}, msgHistory);
let itemCard = msgHistory[msgHistory.length - 1];
let chatMessage = await game.messages.get(itemCard);
let content = await duplicate(chatMessage.content);
let insertPosition = content.indexOf('<div class="end-midi-qol-attack-roll"></div>');
if (insertPosition !== -1) {
content = content.slice(0, insertPosition) + chatList + content.slice(insertPosition);
}
await chatMessage.update({ content: content });
}
await chatMessage.update({ content: content });
}
}
}
}
Expand All @@ -234,7 +233,7 @@ export async function showSilveryBarbsDialog(tokenUuids, actorUuid, tokenUuid, d
<div style='display: flex; width: 100%; gap: 20px;'>
<div style='flex-grow: 1; display: flex; flex-direction: column;'>
<p style='margin: 0 0 10px 0;'>Choose who is advantaged:</p>
${validFriendlies.length > 1 ?
${validFriendlies.length >= 1 ?
`<select id="advantagedSelection" style="padding: 4px; width: 100%; box-sizing: border-box; border-radius: 4px; border: 1px solid #ccc;">
${validFriendlies.map(friendly => `<option value="${friendly.actor.uuid}">${friendly.actor.name}</option>`).join('')}
</select>` : '<p>No valid friendlies in range.</p>'
Expand Down Expand Up @@ -270,7 +269,7 @@ export async function showSilveryBarbsDialog(tokenUuids, actorUuid, tokenUuid, d
<div style='flex-grow: 1; display: flex; flex-direction: column; border-left: 1px solid #ccc; padding-left: 20px;'>
<p style='margin: 0 0 10px 0;'>Choose who is advantaged:</p>
${validFriendlies.length > 1 ?
${validFriendlies.length >= 1 ?
`<select id="advantagedSelection" style="padding: 4px; width: 100%; box-sizing: border-box; border-radius: 4px; border: 1px solid #ccc;">
${validFriendlies.map(friendly => `<option value="${friendly.actor.uuid}">${friendly.actor.name}</option>`).join('')}
</select>` : '<p>No valid friendlies in range.</p>'
Expand Down Expand Up @@ -318,16 +317,18 @@ export async function showSilveryBarbsDialog(tokenUuids, actorUuid, tokenUuid, d
};

const itemRoll = await MidiQOL.completeItemUse(chosenSpell, {}, options);

let silveryBarbsDecision = true;
let returnedTokenUuid = originToken.document.uuid;

const hasEffectApplied = await game.dfreds.effectInterface.hasEffectApplied('Reaction', uuid);

if (!hasEffectApplied) {
game.dfreds.effectInterface.addEffect({ effectName: 'Reaction', uuid });
}

if(itemRoll.aborted === true) return resolve({ silveryBarbsDecision: false, returnedTokenUuid: null });

let silveryBarbsDecision = true;
let returnedTokenUuid = originToken.document.uuid;

let effectData = [
{
"icon": "icons/magic/control/control-influence-puppet.webp",
Expand Down
2 changes: 1 addition & 1 deletion scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function registerSettings() {

game.settings.register('gambits-premades', 'Silvery Barbs Timeout', {
name: "Silvery Barbs Timeout",
hint: "Enter custom number (in seconds). Default timeout value is 15 seconds.",
hint: "Enter custom number (in seconds). Default timeout value is 30 seconds.",
scope: 'world',
config: true,
type: String,
Expand Down

0 comments on commit de4862d

Please sign in to comment.