Skip to content

Dependency checks can come up with wrong result if the object that has the dependency also modifies the dependency #6

Description

@spuxx-dev

If an object that has both a dependency and a modifier targeting the same value, the dependency check will behave differently depending on whether the object has already been added to the owner that will be checked.

An example:

  {
    name: 'character.ability.reflexes-1',
    category: 'character.ability-category.general',
    usageType: 'character.ability-usage-type.passive',
    cost: 300,
    dependencies: [
      {
        name: 'character.primary-attribute.intuition',
        key: 'current',
        value: 12,
      } as Dependency<PrimaryAttribute>,
      {
        name: 'character.secondary-attribute.reaction',
        key: 'total',
        value: 10,
      } as Dependency<SecondaryAttribute>,
    ],
    modifiers: [
      {
        targetName: 'character.secondary-attribute.reaction',
        keys: 'total',
        amount: 4,
      } as Modifier<SecondaryAttribute>,
    ],
  },

Assuming that the new owner is a character that has the object character.secondary-attribute.reaction with a value of 9, the dependency check for the object character.ability.reflexes-1 will fail when the object has not yet been added (9 < 10), but will pass after the object has been added (13 > 10). This doesn't matter if the dependency check prevents the object from being added, but in general, dependency checks should be agnostic to whether they are ran before or after an object has been added to an owner.

We could solve this by making sure that dependency checks ignore modifiers modifying the very same object, but this could pose some engineering challenges I'm not seeing yet. This is where such a check could be implemented: https://github.com/satellite-games/orbit/blob/main/lib/modifier/modifier.ts#L66

I'll leave this open until I know whether this becomes an actual issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions