mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-25 09:33:33 +00:00
Removed duplicate code by moving the logic of Container around; removed duplicate code by producing a functional inventory search algorithm that handles both ammunition and weapon magazine options; corrected tests
This commit is contained in:
parent
ba49b5859e
commit
526ab7d5ec
8 changed files with 140 additions and 173 deletions
|
|
@ -1,8 +1,9 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects
|
||||
|
||||
import net.psforever.objects.inventory.{Container, GridInventory, InventoryItem}
|
||||
import net.psforever.objects.{GlobalDefinitions, OffhandEquipmentSlot, Tool}
|
||||
import net.psforever.objects.equipment.EquipmentSize
|
||||
import net.psforever.objects.inventory.{Container, GridInventory, InventoryEquipmentSlot}
|
||||
import net.psforever.objects.{EquipmentSlot, GlobalDefinitions, OffhandEquipmentSlot, Tool}
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import org.specs2.mutable._
|
||||
|
||||
|
|
@ -16,7 +17,11 @@ class ContainerTest extends Specification {
|
|||
obj.Inventory.Size mustEqual 0
|
||||
obj.Inventory.Capacity mustEqual 9
|
||||
obj.Find(PlanetSideGUID(0)) mustEqual None
|
||||
obj.Slot(0) mustEqual OffhandEquipmentSlot.BlockedSlot
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
@ -49,23 +54,6 @@ object ContainerTest {
|
|||
|
||||
def Inventory : GridInventory = inv
|
||||
|
||||
def Find(guid : PlanetSideGUID) : Option[Int] = {
|
||||
Inventory.Items.find({
|
||||
case((_, item)) =>
|
||||
if(item.obj.HasGUID) {
|
||||
item.obj.GUID == guid
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
}) match {
|
||||
case Some((index, _)) =>
|
||||
Some(index)
|
||||
case None =>
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
def VisibleSlots :Set[Int] = Set[Int](0,1,2, 3,4,5, 6,7,8)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ class PlayerTest extends Specification {
|
|||
obj.Find(PlanetSideGUID(1)) mustEqual Some(0) //holsters
|
||||
obj.Find(PlanetSideGUID(2)) mustEqual Some(4) //holsters, melee
|
||||
obj.Find(PlanetSideGUID(3)) mustEqual Some(6) //inventory
|
||||
obj.Find(PlanetSideGUID(4)) mustEqual Some(Player.LockerSlot) //locker-space
|
||||
obj.Find(PlanetSideGUID(4)) mustEqual None //can not find in locker-space
|
||||
obj.Find(PlanetSideGUID(5)) mustEqual Some(Player.FreeHandSlot) //free hand
|
||||
obj.Find(PlanetSideGUID(6)) mustEqual None //not here
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue