kakaroto / Beyond20

D&D Beyond Character Sheet Integration in Roll20
GNU General Public License v3.0
492 stars 144 forks source link

Add support for hit-dice/saving throws in native rolls for FVTT #218

Open kakaroto opened 4 years ago

kakaroto commented 4 years ago

Create a fake item assigned to actor and roll from there, would allow FVTT modules to intercept the calls and do things their own ways.

Roll types

Features

Bugs/Missing content :

kakaroto commented 3 years ago

Basic code for a temporary actor with an item (spell type).

  const actorData = duplicate(game.system.template.Actor['character']);
  let templates = game.system.template.Actor['character'].templates || [];
  templates.forEach(template => mergeObject(actorData, game.system.template.Actor.templates[template])) 
  delete actorData.templates;
  const spellData = duplicate(game.system.template.Item['spell']);
  templates  = game.system.template.Item['spell'].templates || [];
  templates .forEach(template => mergeObject(actorData, game.system.template.Item.templates[template])) 
  delete spellData.templates;

a = new CONFIG.Actor.entityClass({name: "Foo", items: [{name: "bar", flags: {}, data: spellData}], flags: {}, data: actorData})
a.items.entries[0].rollAttack()

Need to check for dnd5e system, add a similar "template" option for fvtt like the roll20 one, override the actor's name and abilities from the beyond20 data, and the item type/description/attacks/damages based on the request, then roll the attack and damages. Might have to use some tricks for renderer rolls where results are pre-rolled on DNDB.

kakaroto commented 3 years ago

Moving this to using a hook instead and letting the native rolls be handled by a module instead. Start of implementation...


function createActorData(request) {
    const type = request.character.type == "Character" ? "character" : "npc";
    // get default actor template
    const actorData = duplicate(game.system.template.Actor[type]);
    const templates = game.system.template.Actor[type].templates || [];
    templates.forEach(template => mergeObject(actorData, game.system.template.Actor.templates[template])) 
    delete actorData.templates;

    for (let ability of request.character.abilities) {
        const [name, abbr, score, mod] = ability;
        actorData.abilities[abbr.toLowerCase()] = {value: score, mod}
    }
    if (type === "npc") {
        const cr = request.character.cr;
        const parseCR = (cr) => {
            const match = cr.match(/([0-9]+)\/([0-9]+)/);
            return (parseInt(match[1]) || 0) / (parseInt(match[2] || 1);
        }
        actorData.details.cr = parseFloat(cr.includes("/") ? parseCR(cr) : parseInt(cr));
    }

    return {name: request.character.name, flags: {}, img: request.character.avatar, data: actorData, items: []}
}
venom986 commented 3 years ago

Just to clarify - the hook made it in 2.2? And is in the Beyond20 companion module? I'm interested in exploring how to leverage this but just wanting to make sure I understand how to leverage it properly (and that I wouldn't be duplicating work you've already got lined up).

kakaroto commented 3 years ago

The hook is in 2.2, but the beyond20 companion module was not updated to implement that functionality. The good news is that I can now implement it and release a module update instead of having to do a full Beyond20 extension update for this feature to become available. The hook would also allow other modules to implement it their own way if they wanted for example (hopefully someone would contribute that feature to the beyond20 module instead of doing their own module just for this though).

kakaroto commented 3 years ago

Much hype, such wow! Latest module from git is able to do attacks now and seems to work with midi-qol, but to-hit value is wrong and I couldn't get it to show proper roll flavor text, which I was counting on for specifying "sneak attack" and things like that.

This https://foundryvtt.com/article/dice/#describing was a failure as it only allows it on dice (i.e: 1d6[hex] but not 1d6 + 6[hex] or even just 2[rage] wouldn't work) and you can't have special character (Hex's blade or anything) in there, and it will often mess up the formula and say it's invalid, etc... See https://gitlab.com/foundrynet/foundryvtt/-/issues/3487

hypergig commented 3 years ago

Pardon my naivety, but if you were to engineer a whole game system specifically for DnD Beyond, would that open up more of the API and allow for easier or greater control over the native roll system?

Like the 'Dnd Beyond game system'? That does have a nice ring to it. Dnd beyond native character sheets, compendium linking to Dnd Beyond, native status effects, deeper integration in general?

I mean if you think of it, hardcore dndb users need to install half a dozen modules just to leverage is much value as they can from their already purchased content in dndb. Maybe that should just be its own game system?

kakaroto commented 3 years ago

Pardon my naivety, but if you were to engineer a whole game system specifically for DnD Beyond, would that open up more of the API and allow for easier or greater control over the native roll system?

Like the 'Dnd Beyond game system'? That does have a nice ring to it. Dnd beyond native character sheets, compendium linking to Dnd Beyond, native status effects, deeper integration in general?

I mean if you think of it, hardcore dndb users need to install half a dozen modules just to leverage is much value as they can from their already purchased content in dndb. Maybe that should just be its own game system?

not really, we do get the same control over the API, and if it was a new system, not only would it be a huge undertaking, but also, it would simply not be compatible with other modules like better rolls, or automatic spell animations, or any other dnd5e specific modules, while the point of doing native rolls is to integrate with existing modules.

Also, you can't change the world in foundry from one system to another, so you'd be stuck to use it only on new worlds.

hypergig commented 3 years ago

ahhh, that all makes sense. thanks for laying it out for me.

DesktopMan commented 3 years ago

Foundry VTT has now closed https://gitlab.com/foundrynet/foundryvtt/-/issues/3487 , is there anything more blocking this feature?

kakaroto commented 3 years ago

Foundry VTT has now closed https://gitlab.com/foundrynet/foundryvtt/-/issues/3487 , is there anything more blocking this feature?

The issue being closed just means the current development of Foundry has that fixed (if you look at the milestone, you'll see it was fixed in the 0.8.1 release, which is still a "ALPHA, ONLY FOR DEVELOPERS!!!!" release). That being said. The current git version of the module does support this and some people have been testing it. It's not perfect, a little clunky, but the feature is, for the most part, done. Just needs a good polish.

AndreScaffidi commented 3 years ago

So real silly question: How does one functionally do all this with Beyond20 as it stands right now?

kakaroto commented 3 years ago

So real silly question: How does one functionally do all this with Beyond20 as it stands right now?

Not a silly question actually. I don't think I ever explained it properly.

I think that's all there is to it 🤔 Let me know if you have issues.

foxreinhold commented 3 years ago

Tried using this. With minimal roll enhancements module, it fails will console errors. With minimal roll enhancements off, the attack card comes up, but pressing attack makes it say the item no longer exists on actor. Currently on 0.7.9. Any advice?

Aeristoka commented 3 years ago

I have a problem using Foundry v0.8.8, where the attack card does not come up, and shows this error message:

FoundryVTT 0.8.8 (or in the 0.8.x series?) Need more info here.

Also, leaking your IP out there, not a great plan.

Aeristoka commented 3 years ago

I'm using FoundryVTT 0.8.8.

kép

Also, that is a local IP address that is unreachable from outside, so I don't worry about it.

Doesn't look internal.
Aeristoka commented 3 years ago

Also, 0.8.8 isn't supported yet, the feature isn't 100% ready even on 0.7.9/10

Mechrior commented 2 years ago

any news or updates on this please?! would add a whole new aspect to my remote players using D&D Beyond! Your module is one of the things that made me cast the wand on Foundry in the first place.

Aeristoka commented 2 years ago

any news or updates on this please?! would add a whole new aspect to my remote players using D&D Beyond! Your module is one of the things that made me cast the wand on Foundry in the first place.

Based on the stability of Beyond20 otherwise, and in discussions with @kakaroto I've had recently, this is slated to be the next major thing that is worked on, so keep holdin' tight!

kakaroto commented 2 years ago

It was slated to be worked on this week, but oh my god, the week that I've had 🤮 😭. I expect next week I'll work on it 🤞

LorduFreeman commented 2 years ago

Checking in on this before opening a separate issue:

Is rolling with Advantage on Weapon/Spell Attacks supported using Native Rolls? I cannot get it to work, while Ability Checks or Saves with Advantage work fine. (Have not tried Disadvantage)

kakaroto commented 2 years ago

Checking in on this before opening a separate issue:

Is rolling with Advantage on Weapon/Spell Attacks supported using Native Rolls? I cannot get it to work, while Ability Checks or Saves with Advantage work fine. (Have not tried Disadvantage)

That's just how native rolls work for attacks, it would prompt this card in the chat, and you click the Attack button to roll : image which then prompts you to choose if it's adv/disadv...

image

If it's rolling automatically for you for weapon attacks, it's probably better rolls module, but we don't have a way (that I know) to provide it with the information, since we're just doing the attack roll, and it picks it up to automate it. There might be a way to do it, but I'm not sure how that would be, since Foundry doesn't have a native way to do an attack and say make it adv/disadv, other than the attack itself (rather than rolling the item), but if we do that, then we're already side stepping better rolls and other automation modules... it can get dicey...

Aeristoka commented 2 years ago

Checking in on this before opening a separate issue: Is rolling with Advantage on Weapon/Spell Attacks supported using Native Rolls? I cannot get it to work, while Ability Checks or Saves with Advantage work fine. (Have not tried Disadvantage)

That's just how native rolls work for attacks, it would prompt this card in the chat, and you click the Attack button to roll : image which then prompts you to choose if it's adv/disadv...

image

If it's rolling automatically for you for weapon attacks, it's probably better rolls module, but we don't have a way (that I know) to provide it with the information, since we're just doing the attack roll, and it picks it up to automate it. There might be a way to do it, but I'm not sure how that would be, since Foundry doesn't have a native way to do an attack and say make it adv/disadv, other than the attack itself (rather than rolling the item), but if we do that, then we're already side stepping better rolls and other automation modules... it can get dicey...

MidiQOL Fast-forwards rolls too, check on that one.

LorduFreeman commented 2 years ago

Ooh I see, my bad. I tried vanilla, MRE and Better Rolls and assumed that the roll data passed along can contain data for rolling with (Dis)Advantage which gets picked up when the standard roll dialogue is skipped. Sorry!

kakaroto commented 1 year ago

Native rolls is pretty much implemented now. There's just a few small things missing (like hit dice or death saving throws). I'm not sure if I'll bother implementing those. I'd be happy to merge if there's a pull request that adds them, but for now I'm mostly done with native rolls support for a while. Keeping this issue open since it's not 100% complete, but moving it to a different milestone