+
+
⚒️ ${weaponName}
+
Enhancements are applied via Arcane Pool buff items and stay in sync with any toggle source.
+
+
-
+
-
+
-
+
-
+
-
Enhancement Bonus Used: 0 / ${level}
+
Enhancement Bonus Used: 0 / ${enhancementCap}
Arcane Pool Cost: 1 point(s)
+
Weapon Enhancement Applied: ${enhancementCap}
`;
-
- new Dialog({
- title: "Arcane Pool - Weapon Enhancement",
- content: dialogContent,
- buttons: {
- confirm: {
- label: "Apply Enhancements",
- callback: async (html) => {
- // Read all selections
- let checkboxes = html.find('input[type="checkbox"]:checked');
- let radios = html.find('input[type="radio"]:checked');
- let enhancementUsed = parseInt(html.find("#enhancement-used").text()) || 0;
- let poolCost = parseInt(html.find("#pool-cost").text()) || 1;
-
- // Collect all selected buffs
- let selectedBuffs = [];
- checkboxes.each(function() {
- // Skip the arcana checkboxes (enduring-blade and ghost-blade)
- if (this.id !== "enduring-blade" && this.id !== "ghost-blade") {
- console.log(this.id);
- selectedBuffs.push(this.id);
- }
- });
- radios.each(function() {
- let value = $(this).val();
- if (value !== "0") {
- selectedBuffs.push(this.id);
- }
- });
- console.log(actor);
-
- // Check if Enduring Blade is selected
- if (html.find("#enduring-blade").is(":checked")) {
- var bubb = actor.items.find(o => o.name === "Enduring Blade" && o.type ==="buff");
- selectedBuffs.push("Enduring Blade");
- }
-
- // Check if Ghost Blade is selected
- if (html.find("#ghost-blade").is(":checked")) {
- var bubb = actor.items.find(o => o.name === "Ghost Blade" && o.type ==="buff");
- selectedBuffs.push("Ghost Blade");
- }
-
- // Get all required macros upfront
- const setBuffStatusMacro = game.macros.getName("_callSetBuffStatus");
- const changePoolBonusMacro = game.macros.getName("_callChangeArcanePoolBonus");
- const changePoolMacro = game.macros.getName("_callChangeArcanePool");
-
- // Validate all macros exist
- if (!setBuffStatusMacro || !changePoolBonusMacro || !changePoolMacro) {
- ui.notifications.error("Required helper macros not found!");
- console.error("Missing macros:", {
- setBuffStatus: !!setBuffStatusMacro,
- changePoolBonus: !!changePoolBonusMacro,
- changePool: !!changePoolMacro
- });
- return;
- }
-
- // Activate all selected buffs
- // NOTE: Each buff toggle triggers its own macro that must complete before
- // attack rolls can see the buff effects. The 150ms delay allows those
- // buff macros to finish processing and apply effects to the character.
- for (const buffName of selectedBuffs) {
- await setBuffStatusMacro.execute({
- name: buffName,
- status: true
- });
- // Allow buff's triggered macro to complete and apply effects
- await new Promise(resolve => setTimeout(resolve, 150));
- }
-
- // Activate Arcane Pool buff
- await setBuffStatusMacro.execute({
- name: "Arcane Pool",
- status: true
- });
- // Allow Arcane Pool buff macro to complete
- await new Promise(resolve => setTimeout(resolve, 150));
-
- // Update enhancement bonus
- await changePoolBonusMacro.execute({value: enhancementUsed});
-
- // Deduct pool points
- await changePoolMacro.execute({value: -poolCost});
-
- ui.notifications.info(`Arcane Pool activated! Enhancements: ${selectedBuffs.join(', ')} | Pool Cost: ${poolCost} points`);
- },
- disabled: true
- },
- cancel: {
- label: "Cancel"
- }
- },
- default: "confirm",
- render: (html) => {
- const confirmButton = html.closest('.dialog').find('button[data-button="confirm"]');
-
- // Handle Ghost Blade checkbox to enable/disable dependent options
- html.find('#ghost-blade').on('change', function() {
- const isChecked = $(this).is(':checked');
- html.find('.enhancement-option[data-requires="ghost-blade"]').prop('disabled', !isChecked);
- if (!isChecked) {
- // Uncheck Ghost Touch and Brilliant Energy if Ghost Blade is unchecked
- html.find('.enhancement-option[data-requires="ghost-blade"]').prop('checked', false);
- }
- calculateSum();
- });
-
- // Attach the calculateSum function to inputs after the dialog is rendered
- html.find('.action, .arcana-checkbox, #input-value').on('change', calculateSum);
-
- function calculateSum() {
- let enhancementSum = 0;
- let inputValue = parseInt(html.find('#input-value').val()) || 0;
- let rows = html.find('[name="InputTable"] tbody tr');
-
- // Calculate enhancement bonus used
- rows.each(function() {
- let actionCell = $(this).find('.action:checked');
- let valueCell = $(this).find('.value');
- let value = 0;
-
- if (actionCell.length) {
- value = parseInt(actionCell.val());
- enhancementSum += value;
- // Color code the cost
- valueCell.removeClass('cost-high cost-medium cost-low');
- if (value >= 4) valueCell.addClass('cost-high');
- else if (value >= 2) valueCell.addClass('cost-medium');
- else if (value > 0) valueCell.addClass('cost-low');
- } else {
- valueCell.removeClass('cost-high cost-medium cost-low');
- }
-
- valueCell.text(value);
- });
-
- // Calculate arcane pool cost (base 1 + arcana costs)
- let poolCost = 1;
- html.find('.arcana-checkbox:checked').each(function() {
- poolCost += parseInt($(this).val()) || 0;
- });
-
- html.find('#enhancement-used').text(enhancementSum);
- html.find('#pool-cost').text(poolCost);
-
- // Check constraints
- let availablePool = parseInt(html.find('#arcane-pool-value').val()) || 0;
- let enhancementExceeded = enhancementSum > inputValue;
- let poolInsufficient = poolCost > availablePool;
-
- // Update display warnings
- if (enhancementExceeded) {
- html.find('#enhancement-used').addClass('warning');
- } else {
- html.find('#enhancement-used').removeClass('warning');
- }
-
- if (poolInsufficient) {
- html.find('#pool-cost').addClass('warning');
- } else {
- html.find('#pool-cost').removeClass('warning');
- }
-
- // Enable/disable confirm button
- if (enhancementExceeded || poolInsufficient) {
- confirmButton.prop('disabled', true).css('background-color', 'red');
- } else {
- confirmButton.prop('disabled', false).css('background-color', '');
- }
- }
-
- // Initial calculation on render
- calculateSum();
- }
- }).render(true);
}
- // Call the function to open the dialog
- openDialog();
-})();
\ No newline at end of file
+ function gatherSelections(html) {
+ const selections = [];
+
+ html.find('input[type="checkbox"]:checked').each(function () {
+ if (this.id && this.id !== "enduring-blade" && this.id !== "ghost-blade") {
+ const value = parseInt(this.value) || 0;
+ selections.push({ id: this.id, cost: value, damage: $(this).data("damage") || "" });
+ }
+ });
+
+ html.find('input[type="radio"]:checked').each(function () {
+ const value = parseInt(this.value) || 0;
+ if (value > 0 && this.id) {
+ selections.push({ id: this.id, cost: value, damage: $(this).data("damage") || "" });
+ }
+ });
+
+ return selections;
+ }
+
+ new Dialog({
+ title: `Arcane Pool - ${currentWeapon.name}`,
+ content: buildDialog(currentWeapon.name),
+ buttons: {
+ confirm: {
+ label: "Apply Enhancements",
+ icon: '