Skip to content

Commit

Permalink
expose all functions for other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Stexinator committed Aug 21, 2024
1 parent 2ac25a8 commit fe32908
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/get-includes.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var fs = require('fs');
console.log(JSON.parse(fs.readFileSync('src/module.json', 'utf8')).includes.join(" "));
console.log(JSON.parse(fs.readFileSync('src/build.json', 'utf8')).includes.join(" "));
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/src/node_modules/
/.idea/
/src/package-lock.json
37 changes: 0 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,3 @@

- Adds buttons to weapons, equipment and abilities with damage
- When targeted the output can apply the damage to the target via a button

## Changelog

0.0.19
- output heat check when maximum heat due to usage

0.0.17
- added handling for pilots with SP
- skip heat spikes for npc mechs
- (heat spikes for player mechs are working since 0.0.16)

0.0.16
- add ability to add custom buttons for combat
- you can find this option under settings
- you need to separate each entry with , oder ;


0.0.15
- do not inform player that items without uses do not have any uses left

0.0.12
- support uses
- fix npc-mech heat check

0.0.10
- add modules to automation

0.0.8
- added automatic deduction for ep and ap
- when costs of X the chat output will replace x with actual value

0.0.7
- added automatic heat increase
- when Hot(X) the player is queried for a number
- when usage would increase heat over maximum, the roll is aborted and error is shown
- when usage increases to maximum a heat check message is put into chat (WIP)
- added message when damage is applied to target
14 changes: 14 additions & 0 deletions src/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"trailingComma": "none",
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "consistent",
"bracketSpacing": true,
"arrowParens": "avoid",
"printWidth": 120,
"endOfLine": "crlf",

"bracketSameLine": true
}
12 changes: 12 additions & 0 deletions src/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"includes": [
"./assets/**",
"./packs/**",
"./languages/**",
"./scripts/**",
"./styles/**",
"./templates/**",
"./module.json",
"./README.md"
]
}
14 changes: 2 additions & 12 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"flags": {}
}
],
"version": "0.0.21",
"version": "0.0.22",
"compatibility": {
"minimum": "11",
"verified": "12"
},
"title": "Salvage Union Combat Automation Module",
"description": "A Salvage Union module to help with some combat automation",
"download": "https://github.com/Stexinator/salvage-union-combat-automation/releases/download/0.0.15/module.zip",
"download": "https://github.com/Stexinator/salvage-union-combat-automation/releases/download/0.0.21/module.zip",
"esmodules": [
"scripts/hooks.js"
],
Expand All @@ -39,16 +39,6 @@
}
]
},
"includes": [
"./assets/**",
"./packs/**",
"./languages/**",
"./scripts/**",
"./styles/**",
"./templates/**",
"./module.json",
"./README.md"
],
"styles": [
"styles/module.css"
],
Expand Down
7 changes: 7 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"devDependencies": {
"prettier": "^3.3.3"
},
"scripts": {
}
}
57 changes: 25 additions & 32 deletions src/scripts/applyDamage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
export default class SalvageUnionCombatAutomationDamage {

static async clickDamageButton(message) {
let damage = message.getFlag('salvage-union-combat-automation', 'damage');
let target = await fromUuid(message.getFlag('salvage-union-combat-automation', 'target'));

let damage = message.getFlag('salvage-union-combat-automation', 'damage')
let target = await fromUuid(message.getFlag('salvage-union-combat-automation', 'target'))

this.applyDamage(target, damage)
this.applyDamage(target, damage);
}

static async clickCustomDamageButton(message, button) {

let damage = message.getFlag('salvage-union-combat-automation', 'damage')
let target = await fromUuid(message.getFlag('salvage-union-combat-automation', 'target'))
let damage = message.getFlag('salvage-union-combat-automation', 'damage');
let target = await fromUuid(message.getFlag('salvage-union-combat-automation', 'target'));

let modifier = button.dataset.value;

Expand All @@ -25,18 +22,20 @@ export default class SalvageUnionCombatAutomationDamage {

let damageNumber;

if (target.system.healthType?.includes("sp") || target.system.sp?.value) {
damageNumber = await this.applyDamageToSp(target, damage, modifier)
}
else {
damageNumber = await this.applyDamageToHp(target, damage, modifier)
if (target.system.healthType?.includes('sp') || target.system.sp?.value) {
damageNumber = await this.applyDamageToSp(target, damage, modifier);
} else {
damageNumber = await this.applyDamageToHp(target, damage, modifier);
}

const msgData = {
content: game.i18n.format("salvage-union-combat-automation.apply-damage", { damage: damage + (modifier ? ' ' + modifier + ' (' + damageNumber + ')' : ''), name: target.name }),
type: CONST.CHAT_MESSAGE_STYLES.ROLL,
content: game.i18n.format('salvage-union-combat-automation.apply-damage', {
damage: damage + (modifier ? ' ' + modifier + ' (' + damageNumber + ')' : ''),
name: target.name
}),
type: CONST.CHAT_MESSAGE_STYLES.ROLL
};
ChatMessage.applyRollMode(msgData, game.settings.get("core", "rollMode"));
ChatMessage.applyRollMode(msgData, game.settings.get('core', 'rollMode'));
ChatMessage.create(msgData);
}

Expand All @@ -46,32 +45,28 @@ export default class SalvageUnionCombatAutomationDamage {
if (modifier) {
if (modifier.includes('*') || modifier.includes('x')) {
damageNumber *= parseInt(modifier.match(/\d+/).pop());
}
else if (modifier.includes('/')) {
} else if (modifier.includes('/')) {
damageNumber = Math.floor(damageNumber / parseInt(modifier.match(/\d+/).pop()));
}
else {
} else {
damageNumber += parseInt(modifier);
}
}

if (damage.includes("HP")) {
if (damage.includes('HP')) {
damageNumber = Math.floor(damageNumber * 0.5);
}

let newSp;
if (target.system.sp?.value) {
newSp = target.system.sp.value - damageNumber;
target.update({ 'system.sp.value': newSp });
}
else {
} else {
newSp = target.system.hp.value - damageNumber;
target.update({ 'system.hp.value': newSp });
}


if (newSp <= 0) {
this.markDefeated(target)
this.markDefeated(target);
}

return damageNumber;
Expand All @@ -83,29 +78,27 @@ export default class SalvageUnionCombatAutomationDamage {
if (modifier) {
if (modifier.includes('*')) {
damageNumber *= parseInt(modifier.match(/\d+/).pop());
}
else if (modifier.includes('/')) {
} else if (modifier.includes('/')) {
damageNumber /= Math.floor(parseInt(modifier.match(/\d+/).pop()));
}
else {
} else {
damageNumber += parseInt(modifier);
}
}

if (damage.includes("SP") && target.system.healthType !== 'sp') {
if (damage.includes('SP') && target.system.healthType !== 'sp') {
damageNumber = damageNumber * 2;
}

let newHp = target.system.hp.value - damageNumber;
target.update({ 'system.hp.value': newHp });

if (newHp <= 0) {
this.markDefeated(target)
this.markDefeated(target);
}
}

static async markDefeated(target) {
let token = target.token
let token = target.token;
await token?.combatant?.update({ defeated: true });
const status = CONFIG.statusEffects.find(e => e.id === CONFIG.specialStatusEffects.DEFEATED);

Expand Down
39 changes: 19 additions & 20 deletions src/scripts/heat.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
export default class SalvageUnionCombatAutomationHeat{
export default class SalvageUnionCombatAutomationHeat {
static async handleHeat(hot, actor) {

if(hot == undefined || actor.type !== "mech") {
if (hot == undefined || actor.type !== 'mech') {
return true;
}

let heat = parseInt(actor.system.heat.value)
let max_heat = parseInt(actor.system.heat.max)

let heat = parseInt(actor.system.heat.value);
let max_heat = parseInt(actor.system.heat.max);

let heatValue = hot.match(/\d+|X/).pop()
let heatValue = hot.match(/\d+|X/).pop();

if(heatValue == 'X') {
if (heatValue == 'X') {
heatValue = await Dialog.prompt({
title: game.i18n.format("salvage-union-combat-automation.heat-dialog.title"),
content: game.i18n.format("salvage-union-combat-automation.heat-dialog.heat-produced") + '<input type="number">',
callback: (html) => html.find('input').val()
title: game.i18n.format('salvage-union-combat-automation.heat-dialog.title'),
content:
game.i18n.format('salvage-union-combat-automation.heat-dialog.heat-produced') +
'<input type="number">',
callback: html => html.find('input').val()
});

}

heatValue = parseInt(heatValue);

if((heat + heatValue) > max_heat) {
ui.notifications.error(game.i18n.format("salvage-union-combat-automation.too-much-heat"))
if (heat + heatValue > max_heat) {
ui.notifications.error(game.i18n.format('salvage-union-combat-automation.too-much-heat'));
return false;
}

if((heat + heatValue) == max_heat) {
this.handleHeatspike(actor)
if (heat + heatValue == max_heat) {
this.handleHeatspike(actor);
}

actor.update({ 'system.heat.value': heat + heatValue });

return true;
}

static async handleHeatspike(actor) {
if(actor.system.heat?.value) {
game.salvage.heatRoll(actor.system.heat.value)
if (actor.system.heat?.value) {
game.salvage.heatRoll(actor.system.heat.value);
}
return true;
}
}
}
46 changes: 26 additions & 20 deletions src/scripts/hooks.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
import SalvageUnionCombatAutomationWeapons from "./weapons.js"
import SalvageUnionCombatAutomationDamage from "./applyDamage.js"
import SalvageUnionCombatAutomationResources from "./resources.js"
import Settings from "./settings.js";
import SalvageUnionCombatAutomationWeapons from './weapons.js';
import SalvageUnionCombatAutomationDamage from './applyDamage.js';
import SalvageUnionCombatAutomationResources from './resources.js';
import Settings from './settings.js';

Hooks.on("ready", () => {
Hooks.on('ready', () => {
Settings.addAllSettings();
});
});

Hooks.on('renderSalvageUnionActorSheet', async function(actor, html) {
Hooks.once('init', function () {
game.salvage = {
...game.salvage,
salvageUnionCombatAutomationWeapons: SalvageUnionCombatAutomationWeapons
};
});

SalvageUnionCombatAutomationWeapons.addAutomationToWeapons(actor, html)
SalvageUnionCombatAutomationResources.addAutomationToEnergyItems(actor, html)
Hooks.on('renderSalvageUnionActorSheet', async function (actor, html) {
SalvageUnionCombatAutomationWeapons.addAutomationToWeapons(actor, html);
SalvageUnionCombatAutomationResources.addAutomationToEnergyItems(actor, html);

html.find('.su-combatautomation-combatdicebutton').on('click', ev => {
SalvageUnionCombatAutomationWeapons.handleAttackRollButton(ev);
})
});

html.find('.su-combatautomation-resourcedicebutton').on('click', ev => {
SalvageUnionCombatAutomationResources.handleResource(ev);
})
});
});

Hooks.on('renderChatMessage', async function(message, html){
Hooks.on('renderChatMessage', async function (message, html) {
html.find('.su-combatautomation-damagebutton').on('click', _ => {
SalvageUnionCombatAutomationDamage.clickDamageButton(message);
})
});
html.find('.su-combatautomation-customdamagebutton').on('click', event => {
SalvageUnionCombatAutomationDamage.clickCustomDamageButton(message, event.currentTarget);
})
});
});

Hooks.on('renderChatMessage', async function(message, html){
Hooks.on('renderChatMessage', async function (message, html) {
html.find('.su-combatautomation-heatcheckbutton').on('click', _ => {
ChatMessage.create({
content: 'Work in Progress -> Use the actor sheet',
speaker: { alias: game.user.name }
ChatMessage.create({
content: 'Work in Progress -> Use the actor sheet',
speaker: { alias: game.user.name }
});
})
});
});
});
Loading

0 comments on commit fe32908

Please sign in to comment.