mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-27 10:13:36 +00:00
splitting too big ammo boxes upon changing ammo; also, properly dropping too much ammo after same action
This commit is contained in:
parent
2aabf9abe7
commit
c838ff3168
2 changed files with 82 additions and 19 deletions
|
|
@ -40,6 +40,8 @@ object AmmoBox {
|
|||
* Accepting an `AmmoBox` object that has an uncertain amount of ammunition in it,
|
||||
* create multiple `AmmoBox` objects where none contain more than the maximum capacity for that ammunition type,
|
||||
* and the sum of all objects' capacities is the original object's capacity.
|
||||
* The first element in the returned value is always the same object as the input object.
|
||||
* Even if the original ammo object is not split, a list comprised of that same original object is returned.
|
||||
* @param box an `AmmoBox` object of unspecified capacity
|
||||
* @return a `List` of `AmmoBox` objects with correct capacities
|
||||
*/
|
||||
|
|
@ -48,7 +50,8 @@ object AmmoBox {
|
|||
val boxCap : Int = box.Capacity
|
||||
val maxCap : Int = ammoDef.Capacity
|
||||
val splitCap : Int = boxCap / maxCap
|
||||
val list : List[AmmoBox] = List.fill(splitCap)(new AmmoBox(ammoDef))
|
||||
box.Capacity = math.min(box.Capacity, maxCap)
|
||||
val list : List[AmmoBox] = if(splitCap == 0) { Nil } else { box +: List.fill(splitCap - 1)(new AmmoBox(ammoDef)) }
|
||||
val leftover = boxCap - maxCap * splitCap
|
||||
if(leftover > 0) {
|
||||
list :+ AmmoBox(ammoDef, leftover)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue