mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-03-02 19:50:21 +00:00
Utility:
A container class for vehicle-installed Amenity objects that are owned by the vehicle. It not only constructs the internalized Amenity but harbors logic that is required to setup the object at a more appropriate time (at start of VehicleControl). OrderTerminalABDefinition: Terminals built into the sides of the advanced mobile spawn, accessible when it deploys. OCM packet converters, GUID registrtaion, and setup code allows the code to wire into the vehicle.
This commit is contained in:
parent
fb1c365bc2
commit
860edf9a97
18 changed files with 494 additions and 229 deletions
|
|
@ -1,18 +1,20 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects
|
||||
|
||||
import net.psforever.objects.GlobalDefinitions.remote_electronics_kit
|
||||
import net.psforever.objects.definition.converter.{ACEConverter, CharacterSelectConverter, REKConverter}
|
||||
import net.psforever.objects._
|
||||
import net.psforever.objects.definition._
|
||||
import net.psforever.objects.equipment.CItem.{DeployedItem, Unit}
|
||||
import net.psforever.objects.equipment._
|
||||
import net.psforever.objects.inventory.InventoryTile
|
||||
import net.psforever.objects.serverobject.terminals.Terminal
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import net.psforever.packet.game.objectcreate._
|
||||
import net.psforever.types.{CharacterGender, PlanetSideEmpire, Vector3}
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
import scala.util.Success
|
||||
import scala.util.{Failure, Success}
|
||||
|
||||
class ConverterTest extends Specification {
|
||||
"AmmoBox" should {
|
||||
|
|
@ -275,6 +277,26 @@ class ConverterTest extends Specification {
|
|||
}
|
||||
}
|
||||
|
||||
"Terminal" should {
|
||||
"convert to packet" in {
|
||||
val obj = Terminal(GlobalDefinitions.order_terminala)
|
||||
|
||||
obj.Definition.Packet.DetailedConstructorData(obj) match {
|
||||
case Failure(err) =>
|
||||
err.isInstanceOf[NoSuchMethodException] mustEqual true
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
|
||||
obj.Definition.Packet.ConstructorData(obj) match {
|
||||
case Success(pkt) =>
|
||||
pkt mustEqual CommonTerminalData(PlanetSideEmpire.NEUTRAL, 0)
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"Vehicle" should {
|
||||
"convert to packet" in {
|
||||
val hellfire_ammo = AmmoBoxDefinition(Ammo.hellfire_ammo.id)
|
||||
|
|
|
|||
69
common/src/test/scala/objects/UtilityTest.scala
Normal file
69
common/src/test/scala/objects/UtilityTest.scala
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects
|
||||
|
||||
import akka.actor.{Actor, ActorRef, Props}
|
||||
import net.psforever.objects.{GlobalDefinitions, Vehicle}
|
||||
import net.psforever.objects.serverobject.terminals.Terminal
|
||||
import net.psforever.objects.vehicles._
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import org.specs2.mutable._
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
class UtilityTest extends Specification {
|
||||
"Utility" should {
|
||||
"create an order_terminala object" in {
|
||||
val obj = Utility(UtilityType.order_terminala, UtilityTest.vehicle)
|
||||
obj().isInstanceOf[Terminal] mustEqual true
|
||||
obj().asInstanceOf[Terminal].Definition.ObjectId mustEqual 613
|
||||
obj().asInstanceOf[Terminal].Actor == ActorRef.noSender
|
||||
}
|
||||
|
||||
"create an order_terminalb object" in {
|
||||
val obj = Utility(UtilityType.order_terminalb, UtilityTest.vehicle)
|
||||
obj().isInstanceOf[Terminal] mustEqual true
|
||||
obj().asInstanceOf[Terminal].Definition.ObjectId mustEqual 614
|
||||
obj().asInstanceOf[Terminal].Actor == ActorRef.noSender
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Utility1Test extends ActorTest() {
|
||||
"Utility" should {
|
||||
"wire an order_terminala Actor" in {
|
||||
val obj = Utility(UtilityType.order_terminala, UtilityTest.vehicle)
|
||||
obj().GUID = PlanetSideGUID(1)
|
||||
assert(obj().Actor == ActorRef.noSender)
|
||||
|
||||
system.actorOf(Props(classOf[UtilityTest.SetupControl], obj), "test") ! ""
|
||||
receiveOne(Duration.create(100, "ms")) //consume and discard
|
||||
assert(obj().Actor != ActorRef.noSender)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Utility2Test extends ActorTest() {
|
||||
"Utility" should {
|
||||
"wire an order_terminalb Actor" in {
|
||||
val obj = Utility(UtilityType.order_terminalb, UtilityTest.vehicle)
|
||||
obj().GUID = PlanetSideGUID(1)
|
||||
assert(obj().Actor == ActorRef.noSender)
|
||||
|
||||
system.actorOf(Props(classOf[UtilityTest.SetupControl], obj), "test") ! ""
|
||||
receiveOne(Duration.create(100, "ms")) //consume and discard
|
||||
assert(obj().Actor != ActorRef.noSender)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object UtilityTest {
|
||||
val vehicle = Vehicle(GlobalDefinitions.quadstealth)
|
||||
|
||||
class SetupControl(obj : Utility) extends Actor {
|
||||
def receive : Receive = {
|
||||
case _ =>
|
||||
obj.Setup(context)
|
||||
sender ! ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects.terminal
|
||||
|
||||
import akka.actor.ActorRef
|
||||
import net.psforever.objects.serverobject.structures.Building
|
||||
import net.psforever.objects.serverobject.terminals.{OrderTerminalABDefinition, Terminal}
|
||||
import net.psforever.objects.zones.Zone
|
||||
import net.psforever.objects.{GlobalDefinitions, Player}
|
||||
import net.psforever.packet.game.{ItemTransactionMessage, PlanetSideGUID}
|
||||
import net.psforever.types._
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
class OrderTerminalABTest extends Specification {
|
||||
"OrderTerminalAB" should {
|
||||
"define (a)" in {
|
||||
val a = new OrderTerminalABDefinition(613)
|
||||
a.ObjectId mustEqual 613
|
||||
a.Name mustEqual "order_terminala"
|
||||
}
|
||||
|
||||
"define (b)" in {
|
||||
val b = new OrderTerminalABDefinition(614)
|
||||
b.ObjectId mustEqual 614
|
||||
b.Name mustEqual "order_terminalb"
|
||||
}
|
||||
|
||||
"define (invalid)" in {
|
||||
var id : Int = (math.random * Int.MaxValue).toInt
|
||||
if(id == 613) {
|
||||
id += 2
|
||||
}
|
||||
else if(id == 614) {
|
||||
id += 1
|
||||
}
|
||||
|
||||
new OrderTerminalABDefinition(id) must throwA[IllegalArgumentException]
|
||||
}
|
||||
}
|
||||
|
||||
"Order_Terminal" should {
|
||||
val terminal = Terminal(GlobalDefinitions.order_terminala)
|
||||
terminal.Owner = new Building(0, Zone.Nowhere)
|
||||
terminal.Owner.Faction = PlanetSideEmpire.TR
|
||||
|
||||
"construct" in {
|
||||
terminal.Actor mustEqual ActorRef.noSender
|
||||
}
|
||||
|
||||
"player can buy different armor ('lite_armor')" in {
|
||||
val player = Player("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, 0)
|
||||
val msg = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.Buy, 1, "lite_armor", 0, PlanetSideGUID(0))
|
||||
|
||||
terminal.Request(player, msg) mustEqual Terminal.BuyExosuit(ExoSuitType.Agile)
|
||||
}
|
||||
|
||||
"player can buy max armor ('trhev_antiaircraft')" in {
|
||||
val player = Player("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, 0)
|
||||
val msg = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.Buy, 1, "trhev_antiaircraft", 0, PlanetSideGUID(0))
|
||||
|
||||
terminal.Request(player, msg) mustEqual Terminal.NoDeal()
|
||||
}
|
||||
//TODO loudout tests
|
||||
|
||||
"player can not load max loadout" in {
|
||||
val player = Player("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, 0)
|
||||
player.SaveLoadout("test1", 0)
|
||||
player.ExoSuit = ExoSuitType.MAX
|
||||
player.SaveLoadout("test2", 1)
|
||||
|
||||
val msg1 = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.InfantryLoadout, 4, "", 0, PlanetSideGUID(0))
|
||||
terminal.Request(player, msg1) mustEqual Terminal.InfantryLoadout(ExoSuitType.Standard, 0, Nil, Nil)
|
||||
|
||||
val msg2 = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.InfantryLoadout, 4, "", 1, PlanetSideGUID(0))
|
||||
terminal.Request(player, msg2) mustEqual Terminal.NoDeal()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue