Skip to content

Commit

Permalink
support to vehicle and other improves
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcomac committed Feb 18, 2024
1 parent 80fe802 commit f143cd2
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 50 deletions.
84 changes: 53 additions & 31 deletions scripts/action-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
const actor = this.actor;
if (!actor) return;

this._getAttributes({ id: 'attributes', type: 'system' });
this._getSkills({ id: 'skills', type: 'system' });
["powers", "weapons", 'consumables', 'gears', 'actions'].forEach(element => {
if(["npc", "character"].includes(actor.type)) {

this._getItems({ id: element, type: 'system' }, element.slice(0, -1))
})
this._getArmorShield();
this._getAttributes({ id: 'attributes', type: 'system' });
this._getSkills({ id: 'skills', type: 'system' });
["powers", "weapons", 'consumables', 'gears', 'actions'].forEach(element => {

this._getItems({ id: element, type: 'system' }, element.slice(0, -1))
})
this._getArmorShield();

this._getUtilities({ id: "utility", type: 'system'})
this._powerpoints({ id: 'powerpoints', type: 'system' })
let default_statuses = [
coreModule.api.Utils.i18n('SWADE.Shaken'),
coreModule.api.Utils.i18n('SWADE.Distr'),
coreModule.api.Utils.i18n('SWADE.Vuln'),
coreModule.api.Utils.i18n('SWADE.Stunned'),
coreModule.api.Utils.i18n('SWADE.Entangled'),
coreModule.api.Utils.i18n('SWADE.Bound'),
coreModule.api.Utils.i18n('SWADE.Incap'),
coreModule.api.Utils.i18n('SWADE.Prone')
]
this._effects(default_statuses)
this._getUtilities({ id: "utility", type: 'system'})
this._powerpoints({ id: 'powerpoints', type: 'system' })
let default_statuses = []
CONFIG.statusEffects.forEach(item => {
default_statuses.push(item.id)
})
this._effects(default_statuses)
} else if (actor.type == "vehicle") {
["weapons"].forEach(element => {
this._getSkills({ id: 'skills', type: 'system' });
this._getItems({ id: element, type: 'system' }, element.slice(0, -1))
})
}
}
_activeEffects(parent, category) {
const items = Array.from(this.actor.items.filter(it => [category].includes(it.type)))
Expand Down Expand Up @@ -193,21 +195,41 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
this._activeEffects(item_ae, itemType)
})
}
_getSkills(parent) {
async _getSkills(parent) {
const tokenType = this.actor.type;

let skills = this.actor.items.filter(i => i.type === "skill")
let actions = skills.map(element => {
return {
id: element.id,
name: element.name,
img: element.img,
description: element.system.description,
encodedValue: ['skills', element.id].join(this.delimiter),
info1: { text: SavageActionHandler._buildDieString(element.system.die) }
if(tokenType == "vehicle") {
const driver = await fromUuid(this.actor.system.driver.id)
let skill = driver.items.filter(item => item.name === this.actor.system.driver.skill)
if(skill.length === 0) {
skill = driver.items.filter(item=>item.type==="skill" && item.system.die.sides === 4 && item.system.die.modifier === -2)[0]
} else {
skill = skill[0]
}
this.addActions([{
id: this.actor.id,
name: coreModule.api.Utils.i18n("ManCheck"),
img: "systems/swade/assets/icons/skills/steering-wheel.svg",
description: "",
encodedValue: ['maneuver', skill.id].join(this.delimiter),
info1: { text: SavageActionHandler._buildDieString(skill.system.die) }
}], parent)

});
this.addActions(actions, parent)
} else {
let skills = this.actor.items.filter(i => i.type === "skill")
let actions = skills.map(element => {
return {
id: element.id,
name: element.name,
img: element.img,
description: element.system.description,
encodedValue: ['skills', element.id].join(this.delimiter),
info1: { text: SavageActionHandler._buildDieString(element.system.die) }
}

});
this.addActions(actions, parent)
}
}
_getAttributes(parent) {
//this.addGroup( { id: 'derivedstats', name: coreModule.api.Utils.i18n('SWADE.Derived'), type: 'system' },{id :'attributes', type: 'custom'})
Expand Down
10 changes: 5 additions & 5 deletions scripts/br2-rollhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@ Hooks.on('tokenActionHudCoreApiReady', async (coreModule) => {
}

/** @override */
_rollSkill(event, actionId) {
_rollSkill(event, actionId, actor) {
const behavior = this._get_behaviour(event);

if (behavior === "trait" || behavior === "trait_damage") {
game.brsw
.create_skill_card(this.token, actionId)
.create_skill_card(actor, actionId)
.then((message) => {
game.brsw.roll_skill(message, false);
});
} else if (behavior === "system") {
game.swade.rollItemMacro(this.token.actor.items.get(actionId).name);
game.swade.rollItemMacro(actor.items.get(actionId).name);
} else if(behavior == 'dialog'){
game.brsw.create_skill_card(this.token, actionId).then(br_card => {
game.brsw.create_skill_card(actor, actionId).then(br_card => {
game.brsw.dialog.show_card(br_card);
})

} else {
game.brsw.create_skill_card(this.token, actionId);
game.brsw.create_skill_card(actor, actionId);
}
}

Expand Down
26 changes: 20 additions & 6 deletions scripts/core-rollhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
case "gears":
case "consumables":
case "powers":
this._rollItem(event, actionId);
const tokenType = this.actor.type;
if(tokenType == "vehicle" && macroType === "weapons") {
const driver = await fromUuid(this.actor.system.driver.id)
const weaponToCopy = this.actor.items.filter(item => item.id === actionId)[0]
let itemData = duplicate(weaponToCopy);
const item = await driver.createEmbeddedDocuments("Item", [itemData]);
this._rollItem(event, item[0].id, driver)
driver.deleteEmbeddedDocuments("Item", [item[0].id]);
} else {
this._rollItem(event, actionId,this.token.actor);
}
break;
case "effects":
case "statuses":
Expand All @@ -55,7 +65,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
this._run();
break;
case "skills":
this._rollSkill(event, actionId);
this._rollSkill(event, actionId, this.token.actor);
break;
case "utility":
if (actionId === "endTurn") {
Expand All @@ -68,6 +78,10 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
if(actionId != "NONE")
this._wounds(macroType,actor,actionId)
break;
case "maneuver":
const driver = await fromUuid(this.actor.system.driver.id)
this._rollSkill(event, actionId, driver);
break;
}
}

Expand Down Expand Up @@ -110,8 +124,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
}

/** @private */
_rollItem(event, actionId) {
const item = this.token.actor.items.filter(el => el.id === actionId)[0];
_rollItem(event, actionId, actor) {
const item = actor.actor.items.filter(el => el.id === actionId)[0];
item.show();
}

Expand Down Expand Up @@ -171,8 +185,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
}

/** @private */
_rollSkill(event, actionId) {
this.token.actor.rollSkill(actionId, { event: event });
_rollSkill(event, actionId, actor) {
actor.rollSkill(actionId, { event: event });
}

/** @private */
Expand Down
13 changes: 11 additions & 2 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Hooks.on('tokenActionHudCoreApiReady', async (coreModule) => {

async registerDefaults() {
const GROUP = {
utility: { id: 'utility', name: coreModule.api.Utils.i18n('SWADE.General'), type: 'system' },
//utility: { id: 'utility', name: coreModule.api.Utils.i18n('SWADE.General'), type: 'system' },
vehicledriver: { id: 'vehicledriver', name: coreModule.api.Utils.i18n('SWADE.Operator'), type: 'system' },
attributes: { id: 'attributes', name: coreModule.api.Utils.i18n('SWADE.Attributes'), type: 'system' },
derivedstats: { id: 'derivedstats', name: coreModule.api.Utils.i18n('SWADE.Derived'), type: 'system' },
skills: { id: 'skills', name: coreModule.api.Utils.i18n('SWADE.Skills'), type: 'system' },
Expand Down Expand Up @@ -103,12 +104,20 @@ Hooks.on('tokenActionHudCoreApiReady', async (coreModule) => {
const groupsArray = Object.values(groups)
DEFAULTS = {
layout: [
/*{
nestId: 'vehicle',
id: 'vehicle',
name: coreModule.api.Utils.i18n('SWADE.TYPES.Actor.vehicle'),
groups: [
{ ...groups.vehicledriver, nestId: 'vehicledriver' },
]
},*/
{
nestId: 'utility',
id: 'utility',
name: coreModule.api.Utils.i18n('SWADE.General'),
groups: [
{ ...groups.utility, nestId: 'utility_utility' },
//{ ...groups.utility, nestId: 'utility_utility' },
{ ...groups.benny, nestId: 'utility_benny' }
]
},
Expand Down
2 changes: 0 additions & 2 deletions scripts/settings.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { MODULE } from './constants.js'

export function register (updateFunc) {
console.log("REGISTER SETTING2")
const targetModule = game.modules.get("betterrolls-swade2");
if (targetModule && targetModule.active) {
console.log("REGISTER SETTING22")
game.settings.register(MODULE.ID, 'br2RollsBehaviour', {
name: "Select HUD's behavour when using Better Rolls module",
hint: "By selecting one of the options from the dropdown menu, you can tailor the behavior of the HUD module to simulate ctrl and alt keys pressed.This customization enhances your experience with the Better Rolls module.",
Expand Down
8 changes: 4 additions & 4 deletions scripts/swadetools-rollhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
SwadeToolsRollHandler = class SwadeToolsRollHandler extends SavageRollHandler {

/** @override */
_rollItem(event, actionId) {
game.swadetools.item(this.token.actor,actionId)
_rollItem(event, actionId, actor) {
game.swadetools.item(actor,actionId)
}

/** @override */
Expand All @@ -16,8 +16,8 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
}

/** @override */
async _rollSkill(event, actionId) {
await game.swadetools.skill(this.token.actor,actionId)
async _rollSkill(event, actionId, actor) {
await game.swadetools.skill(actor,actionId)
}

/** @override */
Expand Down

0 comments on commit f143cd2

Please sign in to comment.