mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-12 15:04:39 +00:00
synchronizing change ammo
This commit is contained in:
parent
b292739b54
commit
9e51e33246
10 changed files with 407 additions and 68 deletions
|
|
@ -36,17 +36,26 @@ object AmmoBox {
|
|||
new AmmoBox(ammoDef, Some(capacity))
|
||||
}
|
||||
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
def apply(guid : PlanetSideGUID, ammoDef : AmmoBoxDefinition) : AmmoBox = {
|
||||
val obj = new AmmoBox(ammoDef)
|
||||
obj.GUID = guid
|
||||
obj
|
||||
}
|
||||
|
||||
def apply(guid : PlanetSideGUID, ammoDef : AmmoBoxDefinition, capacity : Int) : AmmoBox = {
|
||||
val obj = new AmmoBox(ammoDef, Some(capacity))
|
||||
obj.GUID = guid
|
||||
obj
|
||||
/**
|
||||
* 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.
|
||||
* @param box an `AmmoBox` object of unspecified capacity
|
||||
* @return a `List` of `AmmoBox` objects with correct capacities
|
||||
*/
|
||||
def Split(box : AmmoBox) : List[AmmoBox] = {
|
||||
val ammoDef = box.Definition
|
||||
var boxCap : Int = box.Capacity
|
||||
val maxCap : Int = ammoDef.Capacity
|
||||
val splitCap : Int = boxCap / maxCap
|
||||
val list : List[AmmoBox] = List.fill(splitCap)(new AmmoBox(ammoDef))
|
||||
val leftover = boxCap - maxCap * splitCap
|
||||
if(leftover > 0) {
|
||||
list :+ AmmoBox(ammoDef, leftover)
|
||||
}
|
||||
else {
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
def limitCapacity(count : Int, min : Int = 0) : Int = math.min(math.max(min, count), 65535)
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ import scodec.codecs._
|
|||
/**
|
||||
* Dispatched by the server to cause two associated objects to disentangle from one another.<br>
|
||||
* <br>
|
||||
* `ObjectDetachMessage` is the opposite to `ObjectAttachMessage`.
|
||||
* When detached, the resulting freed object will be placed at the given coordinates.
|
||||
* For some container objects, most often static ones, a default placement point does exist.
|
||||
* `ObjectDetachMessage` is the opposite of `ObjectAttachMessage`.
|
||||
* When detached, the resulting freed object will be placed at the given coordinates in the game world.
|
||||
* For detachment from some container objects, a default placement point may exist.
|
||||
* This usually matches the position where the original mounting occurred, or is relative to the current position of the container.
|
||||
* Using a position that is not the mounting one, in this case, counts as a temporary teleport of the character.
|
||||
* As soon as available, e.g., the end of an animation, the character will rw-appear at the mounting point.
|
||||
* The object may also have its orientation aspect changed.<br>
|
||||
* This mounting position overrides the input one, but other temporary side-effects may occur.
|
||||
* For example, if a player detaches from a vehicle with coordinates for "somewhere else,"
|
||||
* the camera will temporarily be moved to that location "somewhere else" for the duration of the animation
|
||||
* but it will soon regain the player who appeared where expected.<br>
|
||||
* <br>
|
||||
* This packet is considered proper response to:<br>
|
||||
* - `DismountVehicleMsg`<br>
|
||||
* - `DropItemMessage`
|
||||
* An object that is already dropped is a special case where the parent (container) does not technically exist.
|
||||
* The parent also does not need to exist as the object will still be transported to the specified coordinates.
|
||||
* @param parent_guid the container/connector object
|
||||
* @param child_guid the contained/connected object
|
||||
* @param pos where the contained/connected object will be placed after it has detached
|
||||
|
|
|
|||
|
|
@ -277,7 +277,8 @@ class ConverterTest extends Specification {
|
|||
fury_def.TrunkSize = InventoryTile(11, 11)
|
||||
fury_def.TrunkOffset = 30
|
||||
|
||||
val hellfire_ammo_box = AmmoBox(PlanetSideGUID(432), hellfire_ammo)
|
||||
val hellfire_ammo_box = AmmoBox(hellfire_ammo)
|
||||
hellfire_ammo_box.GUID = PlanetSideGUID(432)
|
||||
|
||||
val fury = Vehicle(fury_def)
|
||||
fury.GUID = PlanetSideGUID(413)
|
||||
|
|
|
|||
|
|
@ -65,6 +65,41 @@ class EquipmentTest extends Specification {
|
|||
obj.Capacity = 65536
|
||||
obj.Capacity mustEqual 65535
|
||||
}
|
||||
|
||||
"split (0)" in {
|
||||
val obj = AmmoBox(bullet_9mm)
|
||||
obj.Capacity = 0
|
||||
val list = AmmoBox.Split(obj)
|
||||
list.size mustEqual 0
|
||||
}
|
||||
|
||||
"split (1)" in {
|
||||
val obj = AmmoBox(bullet_9mm)
|
||||
obj.Capacity = 50
|
||||
val list = AmmoBox.Split(obj)
|
||||
list.size mustEqual 1
|
||||
list.head.Capacity mustEqual 50
|
||||
}
|
||||
|
||||
"split (2)" in {
|
||||
val obj = AmmoBox(bullet_9mm)
|
||||
obj.Capacity = 75
|
||||
val list = AmmoBox.Split(obj)
|
||||
list.size mustEqual 2
|
||||
list.head.Capacity mustEqual 50
|
||||
list(1).Capacity mustEqual 25
|
||||
}
|
||||
|
||||
"split (4)" in {
|
||||
val obj = AmmoBox(bullet_9mm)
|
||||
obj.Capacity = 165
|
||||
val list = AmmoBox.Split(obj)
|
||||
list.size mustEqual 4
|
||||
list.head.Capacity mustEqual 50
|
||||
list(1).Capacity mustEqual 50
|
||||
list(2).Capacity mustEqual 50
|
||||
list(3).Capacity mustEqual 15
|
||||
}
|
||||
}
|
||||
|
||||
"Tool" should {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@ import scala.collection.mutable.ListBuffer
|
|||
import scala.util.Success
|
||||
|
||||
class InventoryTest extends Specification {
|
||||
val bullet9mmBox1 = AmmoBox(PlanetSideGUID(1), bullet_9mm)
|
||||
val bullet9mmBox2 = AmmoBox(PlanetSideGUID(2), bullet_9mm)
|
||||
val
|
||||
bullet9mmBox1 = AmmoBox(bullet_9mm)
|
||||
bullet9mmBox1.GUID = PlanetSideGUID(1)
|
||||
val
|
||||
bullet9mmBox2 = AmmoBox(bullet_9mm)
|
||||
bullet9mmBox2.GUID = PlanetSideGUID(2)
|
||||
|
||||
"GridInventory" should {
|
||||
"construct" in {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue