dice-roller / rpg-dice-roller

An advanced JS based dice roller that can roll various types of dice and modifiers, along with mathematical equations.
https://dice-roller.github.io/documentation
MIT License
240 stars 57 forks source link

Allow both `dh` and `dl` on a single roll #129

Closed sigfriedmcwild closed 4 years ago

sigfriedmcwild commented 4 years ago

The sentinel comics rpg (https://www.kickstarter.com/projects/gtgames/sentinel-comics-the-roleplaying-game) uses a system where the player rolls 3 dice of different sizes and usually keeps the middle 1.

This could be expressed as {d4+d6+d8}dh1dl1 once roll groups (#88) are implemented but currently only the last d modifier is kept.

Some examples from the test site (using a 3d6 roll as a place holder):

As I played around with this I noticed that k and d modifiers can both be present but their stacking is not obvious

Anyway, I feel that being able to use both dh and dl would make writing formulas trimming some amount of max and min dice more intuitive than using a combo of k and d especially in hypothetical scenarios where the pool size is unknown.

And I see no reason not to allow this for kh and kl, but I'm not sure I can provide any actual examples of games that would use the functionality.

This does introduce a difference of behaviour from roll20, so I can understand if you think full compatibility is more important (but I wonder how many people would actually notice)

GreenImp commented 4 years ago

Yeah, I think the best way of handling rolling three different dice and only keeping specific ones is with the roll groups, as you mentioned. Once the roll group functionality is complete, the notation will likely look something like:

{d4, d6, d8}kh2dh1

Or (If the modifier uniqueness is changed as described below):

{d4, d6, d8}dl1dh1

Modifier uniqueness

Your example above; 3d6dh1dl1: [6, 4d, 6] = 12 is actually correct at the moment. Only one modifier of each type can be applied to a roll set, and only the last one will be kept. So the dh1 gets ignored.

As you thought though, a combination of d and k can (Or should be able to) be used to work around it. This is because they both function in the same way, by flagging rolls to drop - the keep modifier works out what it wants to keep and flags others as dropped.

The modifier name is used as a reference throughout, so it has to be unique. I will look into making the drop and keep modifier names also be pre-pended by h or l as relevant, so they can be used together, but I'm not sure how easy that would be without re-looking at that part of the code.

However, I can't see a way of it working properly with the keep modifier. I think you'll just end up with everything being dropped:

3d6kh1kl1: [6d, 4d, 2d] = 0

kh1 flags the lower two as dropped, then the kl1 flags the highest two as dropped, levaing none remaining.

Modifier order

Modifiers do indeed run in a particular order. Each modifier has an order property, and it runs from lowest to highest. This is generally to esure that they run in the correct order, regardless of which order they've been specified in.

The "Keep" modifier has an order of 3, and the "Drop" modifier has an order of 4. However, the order of these two shouldn't really matter here, as the result shoud be the same. I'd only expect different results if the values were modified.

So these two are, and should be, equivalent:

3d6kh2dh1: [5d, 3, 1d] = 3  // `k` first
3d6dh1kh2: [3, 1d, 5d] = 3  // `d` first

Bare in mind that, by default, all dice are "kept" unless explicitely flagged as dropped. The keep modifier works by blacklisting dice to drop. It doesn't flag any as "kept". So even if it ran after the drop modifier, it wouldn't "keep" a roll that has been dropped. I'm also unsure as to whether it should or not. If one modifier explicitely drops a dice, should another be able to "un-drop" it?

Issues

There do seem to be some issues with using both keep and drop together though.

I wouldn't expect to get either of these results, that you found (And I've replicated):

GreenImp commented 4 years ago

I've raised tickets #130 and #131 to cover the issues with too many rolls being dropped, and a roll being dropped twice. Thought it best to sort them out seperately.

I'll leave this one open for looking into the modifier uniqueness.

sigfriedmcwild commented 4 years ago

Thanks for the details. I think it would be nice to have the specific interactions of k and d documented in the docs: I could see 3d6kh2dl1 always dropping 2 dice, since keep is executed first. But then again maybe order is not really a thing since the both operate on the full pool, ignoring what the previous modifier did.

And I agree given the definitions of k as "drop all but n highest/lowest dice" having both kh and kl will not make sense.

I don't know if "undropping dice" is a concept that makes sense and it's definitely something that can be dealt with at a later time.

GreenImp commented 4 years ago

I've made it so that you can use dl and dh together like:

// roll a d10 4 times and drop the highest and lowest rolls
4d10dh1dl2: [5, 3d, 7, 8d] = 12

I've also updated the readme to explain using Keep and Drop together.

These changes are on the develop branch, and will be going out in version 4.2.0.

GreenImp commented 4 years ago

I've just pushed this out in v4.1.1, rather than wait for the v4.2.0 release.