foundryvtt / pf2e

A community contributed game system for Pathfinder Second Edition.
https://foundryvtt.com/packages/pf2e
Apache License 2.0
420 stars 349 forks source link

How Calculating Bulk For Stacks Should Work #347

Closed cswendrowski closed 2 years ago

cswendrowski commented 4 years ago

In GitLab by @putt1 on May 11, 2020, 11:20

There are several items that stack to 1 light bulk:

The following stack to 1 normal bulk (and don't produce light bulk ever):

These are groups of items meaning that 9 normal arrows and 1 magical arrow still end up creating 1 light bulk.

Also items of one group don't stack with others: 9 arrows and 1 bullet are still 0 bulk.

Implementation

What I'm advocating is to hard code these groups for now and make them configurable later at some point:

const stacks = {
  bolts: {
    size: 10,
    bulk: {
      type:'L',
      value: 1,
    }
  },
  arrows: {
    size: 10,
    bulk: {
      type:'L',
      value: 1,
    }
  },
  slingBullets: {
    size: 10,
    bulk: {
      type:'L',
      value: 1,
    }
  },
  blowgunDarts: {
    size: 10,
    bulk: {
      type:'L',
      value: 1,
    }
  },
  rations: {
    size: 7,
    bulk: {
      type:'L',
      value: 1,
    }
  },
  sacks: {
    size: 5,
    bulk: {
      type:'L',
      value: 1,
    }
  },
  coins: {
    size: 1000,
    bulk: {
      type:'normal',
      value: 1,
    }
  }
}

Each item would have a drop down that lets you select the stack group, Label: "stacks with". If empty (aka null), there is no stacking rule applied.

Calculating stacks

All items are summed up except stacks: these are summed up separately by the chosen group and then added to the whole stuff.

Implications

Grouping Items in Inventory

This implementation needs no special handling since stacks don't have to exist as a separate entry. It's fine to have 2 items:

They will all be added up just fine.

Containers

Since you can have two items with different quantities in your inventory nothing is preventing you from moving one into a container like a backpack.

The only thing that has to be adjusted is to know:

Then you just need to group by container and add up the bulk if it the container counts towards your limits.

Things That Aren't Stacks

Why Not Go For Floats

Technically light bulk counts as 0.1 bulk so we could make an arrow way 0.1 light bulk. Not everything stacks that well, e.g. rations have 7 per light bulk and that would make 0.14285714285714285 light bulk.

You'll end up with rounding errors, hard to edit weights and are going to bull out your hair. All the possible fixes for this might be impacted by future releases and have no clear way how rounding should be applied. You can't really define a margin of error as well because technically any size that adds up to 1 bulk can be specified.

cswendrowski commented 4 years ago

In GitLab by @tecknojock on May 11, 2020, 15:24

https://gitlab.com/hooking/foundry-vtt---pathfinder-2e/-/issues/208

I'm not sure I agree with any implementation that leaves out the ability to set custom stack items and bulk amounts.

While I agree that that floats are not the way to go, we'd be remiss in not accounting for items that may crop up either through homebrew needed by a GM, random artifacts cropping up in official campaigns, and future items that may be added. Even if we insist on hard coding some categories, the ability to apply weights to a particular stack in terms of X units / l should be included lest it get thrown by the wayside for this patch being good enough.

cswendrowski commented 4 years ago

In GitLab by @putt1 on May 11, 2020, 15:53

@tecknojock you will be able to set custom amounts once a GUI is built for that. It's hard coded for now to ship the PoC

cswendrowski commented 4 years ago

In GitLab by @hooking on May 14, 2020, 02:04

closed via merge request !227

cswendrowski commented 4 years ago

In GitLab by @hooking on May 14, 2020, 02:04

mentioned in commit 3455baccee523a2752ab73ef412503e97be2863e