kgar / foundry-vtt-tidy-5e-sheets

D&D 5e sheet layouts for Foundry VTT, focused on a clean UI, user ergonomics, and extensibility.
https://kgar.github.io/foundry-vtt-tidy-5e-sheets/
MIT License
35 stars 12 forks source link

Calculate Max Prepared Spells? #20

Closed kgar closed 8 months ago

kgar commented 9 months ago

Is there a way to provide an option which calculates max prepared spells on the spellbook tab for player characters? This calculation differs between spellcasting classes. How would we represent this difference? Use a client / world setting or provide a max prepared spells formula box in the Class/Subclass item?

p4535992 commented 9 months ago

A setting is not good for the individual actor, at the time I had used Sdenec's solution with the DAE module, but I think that giving the option on the actor's spell tab to enter a formula such as @classes.druid.levels + @abilities.wis.mod as DAE use (in a flag probably) should be sufficient for any use case, homebrew subclass or not.

An automated solution is impossible too many use cases to account for if one really wants one can create a separate module to update the flag in question.

p4535992 commented 9 months ago

Add a piece of code as reference:

function calculateMaxPreparedSpells(ability, className, additionalBonus = 0) {
  const levels = actor.itemTypes.class.find(e => e.name === className)?.system.levels;
  const typeOfCaster = // add some code for this for say 2 == fullCaster, 1 == Half Caster, 0 === No Caster
  if(!levels) {
     return 0;
  }
  let maxPreparedSpells = 0;
  if(typeOfCaster == 2) {
     maxPreparedSpells = levels + Math.max(actor.system.abilities[ability].mod, 0) +additionalBonus; 
  } else if(typeOfCaster == 1) {
     maxPreparedSpells = (levels/2) + Math.max(actor.system.abilities[ability].mod, 0) + additionalBonus; 
  }
  return maxPreparedSpells;
}
const maxPreparedSpells = calculateMaxPreparedSpells("int", "Wizard");
cs96and commented 9 months ago
const typeOfCaster = // add some code for this for say 2 == fullCaster, 1 == Half Caster, 0 === No Caster

Don't forget that Artificers are like half casters, but have spell slots at character level 1.

Also, Eldritch Knights and Arcane Trickers (and possibly some other sub-classes that I'm forgetting) are quarter(?) casters.

kgar commented 8 months ago

Here's what I'm thinking... The existing flag is fine to keep using, but we do this:

kgar commented 8 months ago

Functionally, it works as intended:

image

image

image

As the TODO text states, I would like some buttons there with starter formulas for the core classes so the user can click one and get the basic formula applied to the input box.

kgar commented 8 months ago

It also recalculates as your actor updates. So if you change Akra's wisdom or level up, it does exactly what is expected.

kgar commented 8 months ago

Coming soon,

image

image

cs96and commented 8 months ago

Excellent work. What about Eldritch Knight and Arcane Tricksters?

kgar commented 8 months ago

Excellent work. What about Eldritch Knight and Arcane Tricksters?

If someone can supply me with a formula, I will add a button. I asked around on TPosney's server and got these, but I can definitely add more as I receive them.

cs96and commented 8 months ago

I found this Google sheet that has lots of handy formulae. These are for Dice Cloud though, so a simple cut n paste might not work for foundry. The Eldritch Knight and Arcane Trickster spells known formulae are insane though.

kgar commented 8 months ago

I found this Google sheet that has lots of handy formulae. These are for Dice Cloud though, so a simple cut n paste might not work for foundry. The Eldritch Knight and Arcane Trickster spells known formulae are insane though.

They do look pretty complex. I wonder if those if statements work in Foundry's roll code. Thinking about this and various other edge cases, maybe I can provide an external link to a Tidy 5e sheet github repo readme with a fuller list of sample formulas 🤔

Especially because of all the subclasses out there and those that haven't been invented yet.

I can take user-submitted formulas, too.

kgar commented 8 months ago

I started looking for how to do conditional selection (if/else logic) within rolls. So, at least with my current understanding of Foundry formulas, a port of some of those formulas is not really feasible. I will still add an external link to the community-submitted formulas readme. Hopefully some folks with a lot more knowledge on it can submit something. In the meantime, a hard number is also accepted in the formula field, as before.

kgar commented 8 months ago

Building it up here: https://github.com/kgar/foundry-vtt-tidy-5e-sheets/wiki/Max-Prepared-Spells-Formulas

kgar commented 8 months ago

This is now released in 0.1.17

kgar commented 8 months ago

Closing. Will handle any additional work in other issues.