forked from Z3nner/lancer-weapon-fx
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flow): add effect-guessing heuristic for unknown weapons
If we do not have a defined effect for a weapon, allow the module to pick one which should be appropriate. This helps to bridge the gap for homebrew items in the absence of a customization option. As this may not always be desirable, gate the heuristic behind a config option (enabled by default). All credit to @dodgepong for the idea and algorithm.
- Loading branch information
Showing
5 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"lancer-weapon-fx.Sound Volume": "Sound Volume", | ||
"lancer-weapon-fx.Sound Volume Hint": "Set a base volume level for all sound effects. Note that for each user, this value is combined with the user's \"Global: Interface\" volume setting (see the \"Playlists\" sidebar tab) to produce their final volume level.", | ||
"lancer-weapon-fx.Debug: Play Miss Animations by Default": "Debug: Play Miss Animations by Default" | ||
"lancer-weapon-fx": { | ||
"Sound Volume": "Sound Volume", | ||
"Sound Volume Hint": "Set a base volume level for all sound effects. Note that for each user, this value is combined with the user's \"Global: Interface\" volume setting (see the \"Playlists\" sidebar tab) to produce their final volume level.", | ||
"Use Weapon Heuristic": "Use Weapon Heuristic", | ||
"Use Weapon Heuristic Hint": "Use a heuristic to determine a suitable effect to play when using an unknown (homebrew/custom) weapon.", | ||
"Debug: Play Miss Animations by Default": "Debug: Play Miss Animations by Default" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { MODULE_ID } from "../../consts.js"; | ||
import { SETTING_IS_WEAPON_HEURISTIC_ACTIVE } from "../../settings.js"; | ||
|
||
const getPrimaryDamageType = ({ activeProfile }) => { | ||
return activeProfile.all_damage?.[0]?.type; | ||
}; | ||
|
||
const getPrimaryRange = ({ activeProfile }) => { | ||
return activeProfile.all_range?.[0]?.type; | ||
}; | ||
|
||
const isShotgun = ({ name, activeProfile }) => { | ||
if (getPrimaryRange({ activeProfile }) === "Cone") return true; | ||
return /\bshotgun\b/i.test(name); | ||
}; | ||
|
||
const isMachineGun = ({ name }) => { | ||
return /\b(?:assault|lmg|hmg|machine gun|minigun)\b/i.test(name); | ||
}; | ||
|
||
export const fallbackActionIdentifier = flow => { | ||
if (!game.settings.get(MODULE_ID, SETTING_IS_WEAPON_HEURISTIC_ACTIVE)) return null; | ||
|
||
const activeProfile = flow.state.item?.system?.active_profile; | ||
if (!activeProfile) return null; | ||
|
||
const { | ||
name, | ||
system: { size }, | ||
} = flow.state.item; | ||
|
||
switch (flow.state.item.system.active_profile.type) { | ||
case "Melee": { | ||
return "lwfx_heuristic_melee"; | ||
} | ||
|
||
case "CQB": { | ||
if (getPrimaryDamageType({ activeProfile }) === "Energy") return "lwfx_heuristic_cqb_energy"; | ||
if (isShotgun({ name, activeProfile })) return "lwfx_heuristic_cqb_shotgun"; | ||
return "lwfx_heuristic_cqb_other"; | ||
} | ||
|
||
case "Rifle": { | ||
if (getPrimaryDamageType({ activeProfile }) === "Energy") return "lwfx_heuristic_rifle_energy"; | ||
if (isMachineGun({ name })) { | ||
if (["Heavy", "Superheavy"].includes(size)) return "lwfx_heuristic_rifle_mg"; | ||
return "lwfx_heuristic_rifle_ar"; | ||
} | ||
return "lwfx_heuristic_rifle_other"; | ||
} | ||
|
||
case "Launcher": { | ||
return "lwfx_heuristic_launcher"; | ||
} | ||
|
||
case "Cannon": { | ||
if (getPrimaryDamageType({ activeProfile }) === "Energy") return "lwfx_heuristic_cannon_energy"; | ||
if (isMachineGun({ name })) return "lwfx_heuristic_cannon_mg"; | ||
return "lwfx_heuristic_cannon_other"; | ||
} | ||
|
||
case "Nexus": { | ||
return "lwfx_heuristic_nexus"; | ||
} | ||
} | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters