Skip to content

Commit

Permalink
Merge pull request #2578 from Azmoria/QoL---add-option-to-roll-initia…
Browse files Browse the repository at this point in the history
…tive-with-adv/dis-automatically-when-adding-to-combat-tracker-

QoL - add option to roll initiative with adv/dis automatically when adding to combat tracker.
  • Loading branch information
Azmoria authored Oct 21, 2024
2 parents 21cb626 + 98031d1 commit 1c73735
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CombatTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ function ct_reorder(persist=true) {
}


function ct_add_token(token,persist=true,disablerolling=false){
function ct_add_token(token,persist=true,disablerolling=false, adv=false, dis=false){
if(token.options.name == "Not in the current map")
return;
if (token.isAoe()) {
Expand Down Expand Up @@ -766,7 +766,7 @@ function ct_add_token(token,persist=true,disablerolling=false){
window.TOKEN_OBJECTS[token.options.id].update_and_sync()
}
debounceCombatReorder();
}, token.options.itemId, token.options.id);
}, token.options.itemId, token.options.id, adv, dis);
}
}

Expand Down
3 changes: 1 addition & 2 deletions CoreFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ $(function() {
window.AVTT_VERSION = $("#avttversion").attr('data-version');
$("head").append('<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"></link>');
$("head").append('<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" />');
// WORKAROUND FOR ANNOYING DDB BUG WITH COOKIES AND UPVOTING STUFF
document.cookie="Ratings=;path=/;domain=.dndbeyond.com;expires=Thu, 01 Jan 1970 00:00:00 GMT";

if (is_encounters_page()) {
window.DM = true; // the DM plays from the encounters page
dmAvatarUrl = $('#site-bar').attr('user-avatar');
Expand Down
12 changes: 6 additions & 6 deletions StatHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class StatHandler {
}
}

rollInit(monsterid, callback, open5eSlug = undefined, tokenId = undefined) {

rollInit(monsterid, callback, open5eSlug = undefined, tokenId = undefined, adv=false, dis=false) {
let dice = adv ? '2d20kh1+' : dis ? '2d20kl1+' : '1d20+'
if(window.TOKEN_OBJECTS[tokenId].options.combatGroupToken){
let modArray = [];
let statArray = [];
Expand Down Expand Up @@ -86,7 +86,7 @@ class StatHandler {
const sumStat = statArray.reduce((a, b) => a + b, 0);
const stat = (sumStat / statArray.length) || 0;

let expression = "1d20+" + modifier;
let expression = dice + modifier;
let roll = new rpgDiceRoller.DiceRoll(expression);
console.log(expression + "->" + roll.total);
let total = parseFloat(Math.floor(roll.total) + stat/100).toFixed(2);
Expand All @@ -103,7 +103,7 @@ class StatHandler {
{
this.getStat(monsterid, function(data) {
let modifier = Math.floor((data.stats[1].value - 10) / 2.0);
let expression = "1d20+" + modifier;
let expression = dice + modifier;
let roll = new rpgDiceRoller.DiceRoll(expression);
console.log(expression + "->" + roll.total);
let total = parseFloat(roll.total + data.stats[1].value/100).toFixed(2);
Expand All @@ -116,7 +116,7 @@ class StatHandler {
}
else if(monsterid =='customStat'){
let modifier = (window.TOKEN_OBJECTS[tokenId]?.options?.customInit != undefined) ? parseInt(window.TOKEN_OBJECTS[tokenId].options.customInit) : (window.TOKEN_OBJECTS[tokenId]?.options?.customStat != undefined && window.TOKEN_OBJECTS[tokenId]?.options?.customStat[1]?.mod != undefined) ? parseInt(window.TOKEN_OBJECTS[tokenId].options.customStat[1].mod) : 0;
let expression = (!isNaN(modifier)) ? "1d20+" + modifier : '0';
let expression = (!isNaN(modifier)) ? dice + modifier : '0';
let roll = new rpgDiceRoller.DiceRoll(expression);
let decimalAdd = (window.TOKEN_OBJECTS[tokenId]?.options?.customInit != undefined || (window.TOKEN_OBJECTS[tokenId]?.options?.customStat != undefined && window.TOKEN_OBJECTS[tokenId]?.options?.customStat[1]?.mod != undefined)) ? ((modifier*2)+10)/100 : 0
console.log(expression + "->" + roll.total);
Expand All @@ -130,7 +130,7 @@ class StatHandler {
else{
this.getStat(monsterid, function(stat) {
let modifier = Math.floor((stat.data.stats[1].value - 10) / 2.0);
let expression = "1d20+" + modifier;
let expression = dice + modifier;
let roll = new rpgDiceRoller.DiceRoll(expression);
console.log(expression + "->" + roll.total);
let total = parseFloat(roll.total + stat.data.stats[1].value/100).toFixed(2);
Expand Down
35 changes: 31 additions & 4 deletions TokenMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,35 @@ function token_context_menu_expanded(tokenIds, e) {
groupCombatButton.addClass("add-to-ct");
groupCombatButton.html(addGroupButtonInternals);
}


let shiftClick = jQuery.Event("click");
shiftClick.shiftKey = true;
let ctrlClick = jQuery.Event("click");
ctrlClick.ctrlKey = true;

let roll_adv = $('<button title="Advantage to roll" id="adv" name="roll_mod" value="OFF" class="roll_mods_button icon-advantage markers-icon" />')
roll_adv.click(function(e){
e.stopPropagation();
$(this).parent().trigger(shiftClick);
});

roll_disadv = $('<button title="Disadvantage to roll" id="disadv" name="roll_mod" value="OFF" class="roll_mods_button icon-disadvantage markers-icon" />')

roll_disadv.click(function(e){
e.stopPropagation();
$(this).parent().trigger(ctrlClick);
});

combatButton.append(roll_adv, roll_disadv);


combatButton.on("click", function(clickEvent) {
let clickedButton = $(clickEvent.currentTarget);
if (clickedButton.hasClass("remove-from-ct")) {
clickedButton.removeClass("remove-from-ct").addClass("add-to-ct");
clickedButton.html(addButtonInternals);
clickedButton.append(roll_adv.clone(true, true), roll_disadv.clone(true, true));
tokens.forEach(t =>{
t.options.ct_show = undefined;
t.options.combatGroup = undefined;
Expand All @@ -722,7 +746,7 @@ function token_context_menu_expanded(tokenIds, e) {
clickedButton.html(removeButtonInternals);
tokens.forEach(t => {
t.options.combatGroup = undefined;
ct_add_token(t, false)
ct_add_token(t, false, undefined, clickEvent.shiftKey, clickEvent.ctrlKey)
t.update_and_sync();
});
}
Expand All @@ -736,6 +760,7 @@ function token_context_menu_expanded(tokenIds, e) {
combatButton.html(addButtonInternals);
clickedButton.removeClass("remove-from-ct").addClass("add-to-ct");
clickedButton.html(addGroupButtonInternals);
clickedButton.append(roll_adv.clone(true, true), roll_disadv.clone(true, true));
tokens.forEach(t =>{
if(t.options.combatGroup && window.TOKEN_OBJECTS[t.options.combatGroup]){
window.TOKEN_OBJECTS[t.options.combatGroup].delete()
Expand All @@ -760,7 +785,7 @@ function token_context_menu_expanded(tokenIds, e) {
allHidden = false
}
t.options.combatGroup = group;
ct_add_token(t, false);
ct_add_token(t, false, undefined, clickEvent.shiftKey, clickEvent.ctrlKey);
t.update_and_sync();
});
let t = new Token({
Expand All @@ -778,13 +803,15 @@ function token_context_menu_expanded(tokenIds, e) {
window.MB.sendMessage('custom/myVTT/token', t.options);
}, 10);
t.place_sync_persist();
ct_add_token(window.TOKEN_OBJECTS[group], false)
ct_add_token(window.TOKEN_OBJECTS[group], false, clickEvent.shiftKey, clickEvent.ctrlKey)
}
debounceCombatReorder();
});



body.append(combatButton);
if(tokens.length >1){
groupCombatButton.append(roll_adv.clone(true,true), roll_disadv.clone(true,true));
body.append(groupCombatButton);
}
}
Expand Down
35 changes: 35 additions & 0 deletions abovevtt.css
Original file line number Diff line number Diff line change
Expand Up @@ -6077,6 +6077,41 @@ div#selectedTokensBorderRotationGrabberConnector,
box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%);
}


div#tokenOptionsContainer button#adv{
filter: sepia(0.3) hue-rotate(63deg) saturate(8) drop-shadow(0px 0px 0px #0F0);
right:32px;
}

div#tokenOptionsContainer button#disadv{
filter: sepia(0.3) hue-rotate(312deg) saturate(14) drop-shadow(0px 0px 0px #F00);
right: 10px;
}

div#tokenOptionsContainer button#adv,
div#tokenOptionsContainer button#disadv{
width:20px;
background:none;
outline:none;
border:none;
height:20px;
position:absolute;
opacity:0.2;
padding:0px;
}
div#tokenOptionsContainer button#adv:hover,
div#tokenOptionsContainer button#disadv:hover{
opacity:1;
}
div#tokenOptionsContainer button#adv:before,
div#tokenOptionsContainer button#disadv:before{
width:100%;
height:100%;
}

div#tokenOptionsContainer .remove-from-ct>button{
display:none;
}
.context-menu-list{
border-radius: 10px !important;
}
Expand Down

0 comments on commit 1c73735

Please sign in to comment.