[#5192, #5489] Allow configuration of initiative grouping#6910
Conversation
Fyorl
left a comment
There was a problem hiding this comment.
Implementation looks correct. One additional requirement that I would propose is that when you roll initiative separately for a creature, with the 'roll once' setting enabled, that we check the existing combatants for a getGroupingKey match, and use that initiative so it gets added to the existing group automatically.
I suppose we would only do this if combat hasn't started or if it's the first round of combat.
- take initiative value of existing combatant when applicable; - changed default for "roll once" to true.
| if ( !updates.length ) return this; | ||
| await this.updateEmbeddedDocuments("Combatant", updates, { turnEvents: false }); |
There was a problem hiding this comment.
Still want to _recoverUses I think
| if ( !updates.length ) return this; | |
| await this.updateEmbeddedDocuments("Combatant", updates, { turnEvents: false }); | |
| if ( updates.length ) await this.updateEmbeddedDocuments("Combatant", updates, { turnEvents: false }); |
Can even remove the guard entirely since updateEmbeddedDocuments will no-op on an empty array.
| if ( this.group ) return this.group.id; | ||
| if ( this.token?.actorLink || !this.token?.baseActor | ||
| || !dnd5e.settings.initiativeGroupRoll ) return null; | ||
| return `${this.getInitiativeRoll().formula}:${this.token.disposition}:${this.token.baseActor.id}`; |
There was a problem hiding this comment.
I guess the desire is to match getGroupingKey's use of this.initiative, but that is solely for keeping combatants grouped in the tracker so long as they share initiative.
For this method we just want to detect 'is this creature identical to some other creature that has already rolled initiative', where 'identical' is from the wording in the PHB:
For a group of identical creatures, the DM makes a single roll, so each member of the group has the same Initiative.
Let me know if there's some other reason we are using this, otherwise I think it's safe to remove.
There was a problem hiding this comment.
Could we use something like this to share some more of the logic:
/**
* Key for the group to which this combatant should belong, or `null` if it can't be grouped.
* @returns {string|null}
*/
getGroupingKey() {
if ( this.group ) return this.group.id;
const uniqueKey = this.getUniqueKey();
return (uniqueKey === null) || (this.initiative === null) ? null : `${Math.floor(this.initiative)}:${uniqueKey}`;
}
/* -------------------------------------------- */
/**
* Key used to group unique sets of actors in the combat, or `null` if they shouldn't be grouped.
* @returns {string|null}
*/
getUniqueKey() {
if ( this.token?.actorLink || !this.token?.baseActor ) return null;
return `${this.token.disposition}:${this.token.baseActor.id}`;
}There was a problem hiding this comment.
I opted to use the initiative roll formula in the grouping key because it seemed like a reasonable interpretation of the rule. I might have a group of identical enemies where half of them are surprised at the start of combat, so I would expect two groups to roll (one normal, one with disadvantage); or I dragged four unlinked Mage tokens, changed Dex to -2 for one of them and called it Clumsy Mage, and similarly expect it to roll separately.
Let me know if that seems reasonable. To me, it seems that "having the same kind of initiative" has to be a prerequisite part of "identical creatures" in this context.
There was a problem hiding this comment.
It's a reasonable interpretation. The rules are very much underspecified in this regard. I don't feel strongly, so I have approved the PR. If there's anything to be done with regards to sharing code like Jeff's suggestion, feel free to make those changes. Otherwise I will merge in due course.
There was a problem hiding this comment.
Since it is a method, I suppose we can just pass in an initiative parameter that falls back to this.initiative if not present.
There was a problem hiding this comment.
Yeah, I think it can go back to being a single method (except the parameter will need to tell if it's for rolling or just for final grouping, since we need to check the appropriate setting). I'll do that and the other final fixes (probably on Monday though)
There was a problem hiding this comment.
I added a canonical getUniqueKey, but I think we still need separate methods since they check different settings. If I've done something silly, feel free to just amend it.
This change adds two settings to the Initiative section of the combat configuration:
Closes #5192
Closes #5489