PAYDAY 2
评价数不足
Ammo Pickup Guide
由 dxdydzd 制作
A guide for calculating weapon ammo pickup.
   
奖励
收藏
已收藏
取消收藏
Introduction
This guide will explain how to calculate the amount of ammo you get whenever you pick up an ammo box from defeated enemies.

Since ammo pickup involves random variables, this guide will go through how to calculate both 1) the pickup in a single instance, assuming you (theoretically) know the value of the random variable that the game generated, and 2) the average pickup.

This guide is best viewed on desktop, as the short width of mobile devices may cause some diagrams to appear incorrectly.
Basic Mechanics
Min/max Pickup
Every weapon has a hidden min/max pickup stat, which is used when calculating how much ammo is picked up. These stats are not displayed in-game, but can be seen through the use of mods.

Note that mods may display the min/max pickup after Walk-in Closet/Fully Loaded has been applied (see next section), instead of the base min/max pickup.

Calculating Ammo Picked Up
Whenever you pick up an ammo box (or a teammate with Gambler does so, while her Ammo Give Out is not on cooldown), how much ammo you get is determined by performing the following steps, in sequence:
  1. Start with a multiplier of 1. Then if you have the Walk-in Closet card from your perk deck unlocked, use 1.35 instead. Then if you have the Fully Loaded skill aced, use 1.75 instead. (FL's 1.75 overrides WIC's 1.35; do not add/multiply them together if you have both.)
  2. If an AI teammate has the Sharpeyed crew ability, add 0.2*(number of AI teammates) to the multiplier.
  3. Multiply both the min and max pickup by the multiplier.
  4. Generate a uniformly distributed random variable, between the min and max pickup.
  5. Take the RV from the previous step and round it to the nearest integer.
  6. If the pickup was due to a Gambler teammate, take the result from the previous step, halve it, then round it down to the nearest integer.
  7. If the weapon is akimbo, and the amount of ammo picked up would cause its total ammo to become an odd integer, take the result from the previous step and add 1. (This has the effect of causing its ammo to become even again.)
The number at the end of all this is the amount of ammo that gets added to the weapon.

(If you want to read the game's code for this, it's located here[github.com], under the function
function RaycastWeaponBase:add_ammo(ratio, add_amount_override)
)

If both your weapons are capable of picking up ammo, the game does the calculation and increments ammo for each of them separately, using their respective min/max pickups.

If the amount of ammo picked up would cause the weapon to exceed its maximum ammo, clearly, that can't be allowed to happen, so you just get enough ammo to reach the max instead. This guide will assume that your ammo pickups are never cut short in this fashion.

It doesn't matter whether the Gambler teammate has WIC/FL, just you. When a Gambler teammate's Ammo Give Out triggers, it's treated as though you were the one who picked up the ammo box, so your multipliers are used.

Whether you get 1 extra ammo from the "akimbo correction" in step 7 depends on the parity of your ammo and the amount that would be picked up: if one is odd and the other even, then you get the bonus ammo. This guide will assume that for akimbo weapons, you always have an even amount of ammo before picking up ammo boxes, i.e. you only get 1 extra ammo if the amount that would be picked up prior to correction is odd.

(You may be wondering how it's possible to have an odd amount of ammo on akimbo weapons, since they all start with even amounts of ammo, each mouse click fires two shots, and the pickup always tries to make it even. One possibility, which I've seen occur in a real game: if you have 0 ammo consumption from Bulletstorm or Swan Song, and the effect happens to run out just after you've fired the gun in one of your hands, but before firing the gun in the other, you will have an odd amount of ammo remaining.)

If you somehow know the random value generated in step 4, then you would be able to find out exactly how much ammo you pick up, just by following the subsequent steps. Of course, you won't know, but the idea behind calculating the average pickup, which we'll see later, is to consider the entire range of possible values generated and how much ammo pickup they end up with.

Exceptions
Some weapons (bows, rocket launchers, saws) have ammo pickups disabled. This means that weapon cannot gain ammo from ammo boxes, though bows can still gain ammo by picking up arrows. If the weapon with pickups disabled is depleted, and the other weapon is full, walking over an ammo box will not cause you to pick it up.

Some weapons (assault rifles with DMR kits, and the Broomstick with the Precision Barrel) are unaffected by WIC, FL, or Sharpeyed. So they always use a min/max pickup multiplier of 1.
Pickup Intervals
You may notice that certain random values will result in the same amount of ammo being picked up. For example, assuming non-Gambler and non-akimbo, rolling a random value of 2.1 or 2.4 will result in a pickup of 2, since they both round to that number. We can draw out, on a number line, the intervals where the pickup is the same.

There are four cases: Gambler, akimbo, both, or neither. Let's start with the simplest, and most frequently encountered:

Neither
Let's start with a number line, with markings at every integer and half-integer:
--|---------|---------|---------|---------|---------|---------|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4
If we roll a number between 2 and 2.5 (exclusive), such as 2.1 or 2.4, we pick up 2 ammo. Let's mark that out in the 2-2.5 interval below the number line, with "Round" at the side to remind ourselves that it's because of the rounding in step 5 of the pickup calculation:
--|---------|---------|---------|---------|---------|---------|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Round 2
Repeating this for all the other intervals:
--|---------|---------|---------|---------|---------|---------|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Round 0 1 1 2 2 3 3 4
At this point it should be obvious that the rule for converting the random variable X, generated in step 4 of the pickup calculation, to the amount of ammo picked up can be summarized as:
  • 0 <= X < 0.5: pick up 0 ammo
  • 0.5 <= X < 1.5: pick up 1 ammo
  • 1.5 <= X < 2.5: pick up 2 ammo
  • 2.5 <= X < 3.5: pick up 3 ammo
and so on.

The other three cases will be presented without further explanation.

Akimbo
--|---------|---------|---------|---------|---------|---------|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Round 0 1 1 2 2 3 3 4 Odd+1 0 2 2 2 2 4 4 4
  • 0 <= X < 0.5: pick up 0 ammo
  • 0.5 <= X < 2.5: pick up 2 ammo
  • 2.5 <= X < 4.5: pick up 4 ammo
  • 4.5 <= X < 6.5: pick up 6 ammo
and so on.

Due to akimbo correction, each interval which has an odd-numbered pickup "fuses" with the one after it, taking on that interval's (higher) pickup.

Gambler
--|---------|---------|---------|---------|---------|---------|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Round 0 1 1 2 2 3 3 4 Halve 0 0.5 0.5 1 1 1.5 1.5 2 RoundD 0 0 0 1 1 1 1 2
  • 0 <= X < 1.5: pick up 0 ammo
  • 1.5 <= X < 3.5: pick up 1 ammo
  • 3.5 <= X < 5.5: pick up 2 ammo
  • 5.5 <= X < 7.5: pick up 3 ammo
and so on.

Rounding down is not kind to Gambler, as it means that it's longer (counting from 0) before you see a non-zero pickup. Halving also has the effect of doubling the interval length.

Gambler + Akimbo
--|---------|---------|---------|---------|---------|---------|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Round 0 1 1 2 2 3 3 4 Halve 0 0.5 0.5 1 1 1.5 1.5 2 RoundD 0 0 0 1 1 1 1 2 Odd+1 0 0 0 2 2 2 2 2
  • 0 <= X < 1.5: pick up 0 ammo
  • 1.5 <= X < 5.5: pick up 2 ammo
  • 5.5 <= X < 9.5: pick up 4 ammo
  • 9.5 <= X < 13.5: pick up 6 ammo
and so on.
Average Pickup
Before starting this section, you should know that the expected value of a random variable is the sum of each outcome multiplied by the probability of that outcome: E(X) = x_i * p_i, summed over all i's in the sample space.

The question we are interested in answering is, given the conditions for an ammo box pickup (weapon's min/max pickup, player has/doesn't have WIC/FL, Sharpeyed absent/present with 1/2/3 AIs, pickup was/was not from Gambler, weapon is/is not akimbo), what is the average amount of ammo picked up?

With the number line, it's easy to visualize the calculations for average pickup. Mark out the min/max pickup, after multipliers, on the line. Combine that with the pickup intervals to figure out the possible pickup values, and the probability of getting each pickup value. Then multiply each pickup value by its probability, and sum them all. That's the average pickup.

The following examples should prove instructive.

Worked Example 1
Assume the following conditions:
  • Weapon under consideration is the Deagle (secondary, non-akimbo), with base min/max pickup 1.5/2.1.
  • We have WIC, since we're using a 9/9 perk deck, but not FL.
  • Sharpeyed is absent.
  • We pick up an ammo box ourselves, not having a Gambler teammate pick one up.
What's the average pickup?

With WIC, the min pickup becomes 1.5*1.35 = 2.025, and the max pickup becomes 2.1*1.35 = 2.835.

We bust out the number line for the "neither" case, and mark off 2.025 and 2.835 on it. It looks slightly different below, because I combined intervals where the pickup value is identical:
2.025 2.835 --|---------|---------|---------|---------|+--------|-----+---|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Pickup [----0---)[---------1--------)[---------2--------)[---------3--------)[---------4-...
Let's clean that up by removing the intervals which lie outside the possible values for the random variable generated:
2.025 2.835 --|---------|---------|---------|---------|+--------|-----+---|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Pickup [---2---)[--3--]
So if we roll:
  • 2.025 <= X < 2.5: we pick up 2 ammo
  • 2.5 <= X <= 2.835: we pick up 3 ammo
X can only lie between 2.025 and 2.835, so this covers all possibilities.

What's the probability of each outcome? Since the random variable is uniformly distributed, it's just the length of each interval, divided by the length of the whole interval (max pickup-min pickup).
  • 2.025 <= X < 2.5: this happens with probability (2.5-2.025)/(2.835-2.025) = 0.586, and we pick up 2 ammo
  • 2.5 <= X <= 2.835: this happens with probability (2.835-2.5)/(2.835-2.025) = 0.414, and we pick up 3 ammo
Thus the average pickup is 0.586*2 + 0.414*3 = 2.414.

To ease the calculations, you can multiply each possible pickup outcome by the length of its interval, add them, then finally divide by the total interval length. So it would be (2.5-2.025)*2 + (2.835-2.5)*3 = 1.955 first, then divide that by (2.835-2.025), for 2.414.

Worked Example 2 - Akimbo
Let's find the average pickup for an akimbo weapon next.
  • Weapon under consideration is the akimbo Deagles, with base min/max pickup 0.6/2.1.
  • We have WIC, but not FL.
  • Sharpeyed is absent.
  • We pick up an ammo box ourselves.

New min pickup = 0.6*1.35 = 0.81
New max pickup = 2.1*1.35 = 2.835
0.81 2.835 --|---------|-----+---|---------|---------|---------|-----+---|---------|---------|---> 0 0.5 1 1.5 2 2.5 3 3.5 4 Pickup [----------------2---------------)[--4--]
Interval
Pickup
Length
p*l
0.81 <= X < 2.5
2
1.69
3.38
2.5 <= X <= 2.835
4
0.335
1.34
Total
2.025
4.72
Thus the average pickup is 4.72/2.025 = 2.331.
Some Observations
Some weapons always pick up the same amount of ammo because their min/max pickup is tight enough that they fit inside one interval. An example is the Platypus 70, with base min/max pickup of 0.7/1. This lies entirely within the 0.5 <= X < 1.5 interval, so it always picks up 1 ammo, no matter the random value rolled. Even adding WIC doesn't change that - the new min/max is 0.945/1.35, still within the interval. FL will alter its average pickup to be >1, though.

The average pickup with WIC is (generally) not simply the average pickup without it, multiplied by 1.35. (Mathematicians would state the pickup as "not homogeneous of degree 1": f(k*a, k*b) != k*f(a, b).) As we just saw in the Platypus 70 example, WIC does not change its average pickup at all. The same goes for FL not being *1.75, Sharpeyed not being *(1+0.2n), and Gambler not being *0.5.

The 480 base damage sniper rifles, along with the Thanatos, don't get any ammo from Gambler teammates with only WIC. So expect no supplementary pickups if attempting the Failed Assassination trophy with other Gambler players while using one of those sniper rifles. (Gambler is still a decent deck for the trophy - anything with health regeneration is, when playing on Overkill difficulty, suit only, no skills.)
Conclusion
If you understood all that, you should know how the game determines how much ammo you get from picking up an ammo box, and be able to calculate the average ammo picked up from an ammo box under any combination of factors that could influence it.

Thanks for reading this and I hope it's been helpful.

Special thanks to Unknown Knight for code tracing the pickup function.
Appendix A: Pickup Table
Zetnus has compiled the min, max, and average pickup of each weapon here[docs.google.com].
Appendix B: Pickup Script
A script to calculate the average pickup, implementing the number line method, written in Python 3.
def average_pickup(min_pickup, max_pickup, mod='wic', sharpeyed_ais=0, akimbo=False, gambler=False):
'''Function for calculating average pickup.

Parameters
----------
min_pickup : int or float
Min pickup. Non-negative.
max_pickup : int or float
Max pickup. Non-negative, greater than min_pickup.
mod : str, default 'wic'
Modifiers to the min/max pickup. 'wic' for Walk-in Closet, 'fl' for Fully Loaded, anything else for neither.
sharpeyed_ais : int, default 0
Number of AI teammates for the Sharpeyed crew ability. Min 0, max 3. If no AI has the ability, use 0.
akimbo : bool, default False
Whether the weapon is akimbo.
gambler : bool, default False
Whether the pickup was from a Gambler teammate.

Returns
-------
float
The average pickup.
'''
#Multiply min/max pickup if WIC/FL/Sharpeyed present
if mod == 'wic':
pickup_multiplier = 1.35
elif mod == 'fl':
pickup_multiplier = 1.75
else:
pickup_multiplier = 1
pickup_multiplier += 0.2*sharpeyed_ais
min_pickup, max_pickup = min_pickup*pickup_multiplier, max_pickup*pickup_multiplier
#Initialize parameters for number line
if not gambler and not akimbo:
lowest_x_with_nonzero_pickup = 0.5
interval_length = 1
pickup_increment = 1
elif not gambler and akimbo:
lowest_x_with_nonzero_pickup = 0.5
interval_length = 2
pickup_increment = 2
elif gambler and not akimbo:
lowest_x_with_nonzero_pickup = 1.5
interval_length = 2
pickup_increment = 1
elif gambler and akimbo:
lowest_x_with_nonzero_pickup = 1.5
interval_length = 4
pickup_increment = 2
#Generate number line with pickup intervals, until just above max_pickup
n = []
p = []
next_n = lowest_x_with_nonzero_pickup
i = 0
while True:
if min_pickup < next_n:
n.append(min_pickup)
break
else:
i += 1
next_n += interval_length
while True:
if next_n < max_pickup:
n.append(next_n)
p.append(i*pickup_increment)
i += 1
next_n += interval_length
else:
n.append(max_pickup)
p.append(i*pickup_increment)
break
#Calculate average pickup
x_i_p_i = 0
for i in range(len(n)-1):
length = n[i+1] - n[i]
pickup = p[i]
x_i_p_i += length*pickup
return x_i_p_i/(max_pickup - min_pickup)
Note: please only comment on this if it gives you a wrong answer. I don't need to hear if you managed to save 20 bytes file size or 0.000001s runtime by modifying it or any other trifling stuff like that.
4 条留言
dxdydzd  [作者] 2022 年 2 月 19 日 上午 1:51 
Alright, I updated the Deagle example with its new pickup (0.5-1.75 -> 1.5-2.1).
YellowMan95 2022 年 2 月 18 日 下午 2:09 
update the document pls
4rods 2021 年 12 月 13 日 上午 4:45 
cool but its not like anyone actually wants this or would use it so why make it
Ding 2021 年 3 月 2 日 下午 9:30 
Pleaae just use this [pd2mods.z77.fr]