Initial commit: Fresh start with current state
This commit is contained in:
65
src/macro_haste.js
Normal file
65
src/macro_haste.js
Normal file
@@ -0,0 +1,65 @@
|
||||
// Improved Haste Auto-Enabler for Pathfinder 1e
|
||||
// Automatically enables the haste attack option when the Haste buff is active
|
||||
(async () => {
|
||||
// Ensure a token is selected
|
||||
if (!actor) {
|
||||
ui.notifications.warn("Please select a token!");
|
||||
return;
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// CONFIGURATION - Adjust these settings
|
||||
// ============================================
|
||||
const WEAPON_NAME = "YOUR WEAPON NAME HERE"; // Change to your weapon name
|
||||
const DEBUG = false; // Set to true for debugging console logs
|
||||
|
||||
// Find the weapon on the selected actor
|
||||
const weapon = actor.items.find(i =>
|
||||
i.type === "attack" &&
|
||||
i.name === WEAPON_NAME
|
||||
);
|
||||
|
||||
if (!weapon) {
|
||||
ui.notifications.warn(`Weapon "${WEAPON_NAME}" not found on ${actor.name}!`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if wrapper already applied to prevent double-wrapping
|
||||
if (weapon._hasteWrapperApplied) {
|
||||
ui.notifications.info("Haste auto-enabler already active for this weapon!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Store original use function
|
||||
const originalUse = weapon.use;
|
||||
|
||||
// Apply wrapper to intercept attack use
|
||||
weapon.use = async function(...args) {
|
||||
if (DEBUG) console.log("Attack use() intercepted!");
|
||||
|
||||
// Check if Haste buff is active on the actor
|
||||
const isHasteActive = this.actor.items.find(i =>
|
||||
i.name === "Haste" &&
|
||||
i.type === "buff" &&
|
||||
i.system.active
|
||||
);
|
||||
|
||||
if (isHasteActive) {
|
||||
// Auto-enable haste option in attack dialog
|
||||
args[0] = args[0] || {};
|
||||
args[0].options = args[0].options || {};
|
||||
args[0].options.haste = true;
|
||||
|
||||
if (DEBUG) console.log("Auto-enabled haste option!");
|
||||
ui.notifications.info("⚡ Haste attack enabled!");
|
||||
}
|
||||
|
||||
// Call original function with modified args
|
||||
return originalUse.apply(this, args);
|
||||
};
|
||||
|
||||
// Mark as wrapped to prevent duplicate wrappers
|
||||
weapon._hasteWrapperApplied = true;
|
||||
|
||||
ui.notifications.info(`✅ Haste auto-enabler activated for ${WEAPON_NAME}!`);
|
||||
})();
|
||||
Reference in New Issue
Block a user