PSF-LoginServer/common/src/test/scala/objects/ContainerTest.scala

60 lines
1.8 KiB
Scala
Raw Normal View History

// Copyright (c) 2017 PSForever
package objects
ObjectCreateMessage Alterations, Class Object Adjustments (#243) * power outage failure resulting in the destruction of the original ocm-fixes branch; the git branch refs were corrupted during commit, but the up-to-date changed files remained intact * eliminating the need for CommonFieldData2 and CommonFieldData2WithPlacement * in the middle of integrating CommonFieldData into DetailedLockerContainerData (but not standard LockerContainerData); added field for final boolean in WeaponData * adding faction affinity to Equipment (to match functionality; not becuase I know what ends ...) * in the middle of integrating CommonFieldData into DetailedCommandDetonaterData * applying faction affinity to objects at time of terminal production (but to what ends?); required BoomerTrigger and AmmoBox to always report as NEUTRAL internally * completed the transition from using the old class-based order terminal system to the page-based order terminal system; unused terminal classes have been eliminated * more closely aligned TelepadDeployableData and InternalTelepadDeployableData * modifying TelepadDeployableData make it generic and eliminate the need for InternalTelepadDeployableData after fixing a packet converter to utilize DroppedItemData * modified Terminal operation to branch further outwards from Terminal.Request to the TerminalDefinition's Request method; modified tests to reflect update * loosening up matrix terminal definition limitations * modified ProximityTerminal to support a custom defintition class * rendered the message passing system for Terminals general (Any) in the full scale so it can be specific in instance cases * refactored and moved both EquipmentSlot and ExoSuitDefinition * (re)load Favorites each time player (re)spawns
2019-03-03 08:23:30 -05:00
import net.psforever.objects.equipment.{EquipmentSize, EquipmentSlot}
import net.psforever.objects.inventory.{Container, GridInventory, InventoryEquipmentSlot}
ObjectCreateMessage Alterations, Class Object Adjustments (#243) * power outage failure resulting in the destruction of the original ocm-fixes branch; the git branch refs were corrupted during commit, but the up-to-date changed files remained intact * eliminating the need for CommonFieldData2 and CommonFieldData2WithPlacement * in the middle of integrating CommonFieldData into DetailedLockerContainerData (but not standard LockerContainerData); added field for final boolean in WeaponData * adding faction affinity to Equipment (to match functionality; not becuase I know what ends ...) * in the middle of integrating CommonFieldData into DetailedCommandDetonaterData * applying faction affinity to objects at time of terminal production (but to what ends?); required BoomerTrigger and AmmoBox to always report as NEUTRAL internally * completed the transition from using the old class-based order terminal system to the page-based order terminal system; unused terminal classes have been eliminated * more closely aligned TelepadDeployableData and InternalTelepadDeployableData * modifying TelepadDeployableData make it generic and eliminate the need for InternalTelepadDeployableData after fixing a packet converter to utilize DroppedItemData * modified Terminal operation to branch further outwards from Terminal.Request to the TerminalDefinition's Request method; modified tests to reflect update * loosening up matrix terminal definition limitations * modified ProximityTerminal to support a custom defintition class * rendered the message passing system for Terminals general (Any) in the full scale so it can be specific in instance cases * refactored and moved both EquipmentSlot and ExoSuitDefinition * (re)load Favorites each time player (re)spawns
2019-03-03 08:23:30 -05:00
import net.psforever.objects.{GlobalDefinitions, OffhandEquipmentSlot, Tool}
import net.psforever.types.PlanetSideGUID
import org.specs2.mutable._
import scala.util.Success
class ContainerTest extends Specification {
"Container" should {
"construct" in {
val obj = new ContainerTest.CObject
obj.VisibleSlots mustEqual (0 until 9).toSet
obj.Inventory.Size mustEqual 0
obj.Inventory.Capacity mustEqual 9
obj.Find(PlanetSideGUID(0)) mustEqual None
obj.Slot(0).isInstanceOf[OffhandEquipmentSlot] mustEqual true
obj.Slot(0).isInstanceOf[InventoryEquipmentSlot] mustEqual true
obj.Slot(0).isInstanceOf[EquipmentSlot] mustEqual true
obj.Slot(0).Size mustEqual EquipmentSize.Inventory
obj.Slot(0).Equipment mustEqual None
obj.Collisions(0, 2, 2) mustEqual Success(List())
}
"Collisions can Find items in Inventory (default behavior)" in {
val obj = new ContainerTest.CObject
val weapon = Tool(GlobalDefinitions.beamer)
weapon.GUID = PlanetSideGUID(1)
obj.Inventory += 0 -> weapon
obj.Find(PlanetSideGUID(1)) match {
case Some(index) =>
obj.Inventory.Items(index).obj mustEqual weapon
case None =>
ko
}
obj.Collisions(1,1,1) match {
case Success(items) =>
items.length mustEqual 1
items.head.obj mustEqual weapon
case _ =>;
ko
}
}
}
}
object ContainerTest {
class CObject extends Container {
private val inv = GridInventory(3, 3)
def Inventory : GridInventory = inv
def VisibleSlots :Set[Int] = Set[Int](0,1,2, 3,4,5, 6,7,8)
}
}