Proximity Terminal Fix (#241)

* modifications to ProximityUnit and related classes to internalize the effect control for the terminal, removing the flywheel functiuonality from WSA

* proximity operations for medical terminals (the one in the Anguta lobby, specifically) is functional; some entities besides Player now keep track of the continent they possess, a necessary compromise for proximity ops

* repair rearm silos (Anguta courtyard East) demonstrate operational behavior when lattice benefits are active

* proximity terminals may now juggle multiple targets that move in and out of range and change validity over time

* previous rebase; preparing for special location + offset calculations for utilities

* working location-based proximity repair terminals for the lodestar, utilizing new fields in the vehicle definition, new configuration method in the utilities, and new calculations for Vector3 entities; some comments and tests

* separated ProximityTarget; updated existing terminals; restored defaults; preparing to fix tests

* tests involving the proximity unit workflow

* dismantling a portion of the proximity terminal machinery that is no longer necessary and only poses risk to the system; removing temporary code used to quickly test vehicle silo repairs
This commit is contained in:
Fate-JH 2018-12-23 21:09:12 -05:00 committed by GitHub
parent c4c8609238
commit 961ae1b93b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1320 additions and 888 deletions

View file

@ -201,5 +201,44 @@ class Vector3Test extends Specification {
Vector3.VectorProjection(A, B) mustEqual Vector3(1.0384614f, 1.3846153f, 0.34615383f)
Vector3.VectorProjection(B, A) mustEqual Vector3(2.9999998f, 1.4999999f, -1.4999999f)
}
"rotate positive x-axis-vector 90-degrees around the z-axis" in {
val A : Vector3 = Vector3(1, 0, 0)
A.Rz(0) mustEqual A
A.Rz(90) mustEqual Vector3(0, 1, 0)
A.Rz(180) mustEqual Vector3(-1, 0, 0)
A.Rz(270) mustEqual Vector3(0, -1, 0)
A.Rz(360) mustEqual A
}
"rotate positive y-axis-vector 90-degrees around the x-axis" in {
val A : Vector3 = Vector3(0, 1, 0)
A.Rx(0) mustEqual A
A.Rx(90) mustEqual Vector3(0, 0, 1)
A.Rx(180) mustEqual Vector3(0, -1, 0)
A.Rx(270) mustEqual Vector3(0, 0, -1)
A.Rx(360) mustEqual A
}
"rotate positive x-axis-vector 90-degrees around the y-axis" in {
val A : Vector3 = Vector3(1, 0, 0)
A.Ry(0) mustEqual A
A.Ry(90) mustEqual Vector3(0, 0, -1)
A.Ry(180) mustEqual Vector3(-1, 0, 0)
A.Ry(270) mustEqual Vector3(0, 0, 1)
A.Ry(360) mustEqual A
}
"compound rotation" in {
val A : Vector3 = Vector3(1, 0, 0)
A.Rz(90)
.Rx(90)
.Ry(90) mustEqual A
}
"45-degree rotation" in {
val A : Vector3 = Vector3(1, 0, 0)
A.Rz(45) mustEqual Vector3(0.70710677f, 0.70710677f, 0)
}
}
}

View file

@ -1,90 +0,0 @@
// Copyright (c) 2017 PSForever
package objects.terminal
import akka.actor.ActorRef
import net.psforever.objects.serverobject.terminals.{MedicalTerminalDefinition, ProximityTerminal, Terminal}
import net.psforever.objects.{Avatar, GlobalDefinitions, Player}
import net.psforever.packet.game.{ItemTransactionMessage, PlanetSideGUID}
import net.psforever.types.{CharacterGender, CharacterVoice, PlanetSideEmpire, TransactionType}
import org.specs2.mutable.Specification
class MedicalTerminalTest extends Specification {
"MedicalTerminal" should {
"define (a)" in {
val a = new MedicalTerminalDefinition(38)
a.ObjectId mustEqual 38
a.Name mustEqual "adv_med_terminal"
}
"define (b)" in {
val b = new MedicalTerminalDefinition(225)
b.ObjectId mustEqual 225
b.Name mustEqual "crystals_health_a"
}
"define (c)" in {
val c = new MedicalTerminalDefinition(226)
c.ObjectId mustEqual 226
c.Name mustEqual "crystals_health_b"
}
"define (d)" in {
val d = new MedicalTerminalDefinition(529)
d.ObjectId mustEqual 529
d.Name mustEqual "medical_terminal"
}
"define (e)" in {
val e = new MedicalTerminalDefinition(689)
e.ObjectId mustEqual 689
e.Name mustEqual "portable_med_terminal"
}
"define (invalid)" in {
var id : Int = (math.random * Int.MaxValue).toInt
if(id == 224) {
id += 2
}
else if(id == 37) {
id += 1
}
else if(id == 528) {
id += 1
}
else if(id == 688) {
id += 1
}
new MedicalTerminalDefinition(id) must throwA[IllegalArgumentException]
}
}
"Medical_Terminal" should {
"construct" in {
ProximityTerminal(GlobalDefinitions.medical_terminal).Actor mustEqual ActorRef.noSender
}
"can add a player to a list of users" in {
val terminal = ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.NumberUsers mustEqual 0
terminal.AddUser(PlanetSideGUID(10))
terminal.NumberUsers mustEqual 1
}
"can remove a player from a list of users" in {
val terminal = ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.AddUser(PlanetSideGUID(10))
terminal.NumberUsers mustEqual 1
terminal.RemoveUser(PlanetSideGUID(10))
terminal.NumberUsers mustEqual 0
}
"player can not interact with the proximity terminal normally (buy)" in {
val terminal = ProximityTerminal(GlobalDefinitions.medical_terminal)
val player = Player(Avatar("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
val msg = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.Buy, 1, "lite_armor", 0, PlanetSideGUID(0))
terminal.Request(player, msg) mustEqual Terminal.NoDeal()
}
}
}

View file

@ -1,120 +0,0 @@
// Copyright (c) 2017 PSForever
package objects.terminal
import akka.actor.{ActorSystem, Props}
import base.ActorTest
import net.psforever.objects.serverobject.CommonMessages
import net.psforever.objects.{Avatar, GlobalDefinitions, Player}
import net.psforever.objects.serverobject.terminals._
import net.psforever.packet.game.PlanetSideGUID
import net.psforever.types.{CharacterGender, CharacterVoice, PlanetSideEmpire}
import scala.concurrent.duration.Duration
class ProximityTerminalControl1Test extends ActorTest {
"ProximityTerminalControl" should {
"construct (medical terminal)" in {
val terminal = ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], terminal), "test-term")
}
}
}
class ProximityTerminalControl2Test extends ActorTest {
"ProximityTerminalControl can not process wrong messages" in {
val (_, terminal) = TerminalControlTest.SetUpAgents(GlobalDefinitions.medical_terminal, PlanetSideEmpire.TR)
terminal.Actor !"hello"
expectNoMsg(Duration.create(500, "ms"))
}
}
//terminal control is mostly a pass-through actor for Terminal.Exchange messages, wrapped in Terminal.TerminalMessage protocol
class MedicalTerminalControl1Test extends ActorTest {
"ProximityTerminalControl sends a message to the first new user only" in {
val (player, terminal) = ProximityTerminalControlTest.SetUpAgents(GlobalDefinitions.medical_terminal, PlanetSideEmpire.TR)
player.GUID = PlanetSideGUID(10)
val player2 = Player(Avatar("someothertest", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player2.GUID = PlanetSideGUID(11)
terminal.Actor ! CommonMessages.Use(player)
val reply = receiveOne(Duration.create(500, "ms"))
assert(reply.isInstanceOf[Terminal.TerminalMessage])
val reply2 = reply.asInstanceOf[Terminal.TerminalMessage]
assert(reply2.player == player)
assert(reply2.msg == null)
assert(reply2.response.isInstanceOf[Terminal.StartProximityEffect])
assert(reply2.response.asInstanceOf[Terminal.StartProximityEffect].terminal == terminal)
assert(terminal.NumberUsers == 1)
terminal.Actor ! CommonMessages.Use(player2)
expectNoMsg(Duration.create(500, "ms"))
assert(terminal.NumberUsers == 2)
}
}
class MedicalTerminalControl2Test extends ActorTest {
"ProximityTerminalControl sends a message to the last user only" in {
val (player, terminal) : (Player, ProximityTerminal) = ProximityTerminalControlTest.SetUpAgents(GlobalDefinitions.medical_terminal, PlanetSideEmpire.TR)
player.GUID = PlanetSideGUID(10)
val player2 = Player(Avatar("someothertest", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player2.GUID = PlanetSideGUID(11)
terminal.Actor ! CommonMessages.Use(player)
receiveOne(Duration.create(500, "ms"))
terminal.Actor ! CommonMessages.Use(player2)
expectNoMsg(Duration.create(500, "ms"))
assert(terminal.NumberUsers == 2)
terminal.Actor ! CommonMessages.Unuse(player)
expectNoMsg(Duration.create(500, "ms"))
assert(terminal.NumberUsers == 1)
terminal.Actor ! CommonMessages.Unuse(player2)
val reply = receiveOne(Duration.create(500, "ms"))
assert(reply.isInstanceOf[Terminal.TerminalMessage])
val reply2 = reply.asInstanceOf[Terminal.TerminalMessage]
assert(reply2.player == player2)
assert(reply2.msg == null)
assert(reply2.response.isInstanceOf[Terminal.StopProximityEffect])
assert(reply2.response.asInstanceOf[Terminal.StopProximityEffect].terminal == terminal)
assert(terminal.NumberUsers == 0)
}
}
class MedicalTerminalControl3Test extends ActorTest {
"ProximityTerminalControl sends a message to the last user only (confirmation of test #2)" in {
val (player, terminal) : (Player, ProximityTerminal) = ProximityTerminalControlTest.SetUpAgents(GlobalDefinitions.medical_terminal, PlanetSideEmpire.TR)
player.GUID = PlanetSideGUID(10)
val player2 = Player(Avatar("someothertest", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player2.GUID = PlanetSideGUID(11)
terminal.Actor ! CommonMessages.Use(player)
receiveOne(Duration.create(500, "ms"))
terminal.Actor ! CommonMessages.Use(player2)
expectNoMsg(Duration.create(500, "ms"))
assert(terminal.NumberUsers == 2)
terminal.Actor ! CommonMessages.Unuse(player2)
expectNoMsg(Duration.create(500, "ms"))
assert(terminal.NumberUsers == 1)
terminal.Actor ! CommonMessages.Unuse(player)
val reply = receiveOne(Duration.create(500, "ms"))
assert(reply.isInstanceOf[Terminal.TerminalMessage])
val reply2 = reply.asInstanceOf[Terminal.TerminalMessage]
assert(reply2.player == player) //important!
assert(reply2.msg == null)
assert(reply2.response.isInstanceOf[Terminal.StopProximityEffect])
assert(reply2.response.asInstanceOf[Terminal.StopProximityEffect].terminal == terminal)
assert(terminal.NumberUsers == 0)
}
}
object ProximityTerminalControlTest {
def SetUpAgents(tdef : MedicalTerminalDefinition, faction : PlanetSideEmpire.Value)(implicit system : ActorSystem) : (Player, ProximityTerminal) = {
val terminal = ProximityTerminal(tdef)
terminal.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], terminal), "test-term")
(Player(Avatar("test", faction, CharacterGender.Male, 0, CharacterVoice.Mute)), terminal)
}
}

View file

@ -2,14 +2,19 @@
package objects.terminal
import akka.actor.Props
import akka.testkit.TestProbe
import base.ActorTest
import net.psforever.objects.guid.TaskResolver
import net.psforever.objects.serverobject.CommonMessages
import net.psforever.objects.serverobject.terminals.Terminal.TerminalMessage
import net.psforever.objects.serverobject.structures.{Building, StructureType}
import net.psforever.objects.serverobject.terminals.{ProximityTerminal, ProximityTerminalControl, ProximityUnit, Terminal}
import net.psforever.objects.zones.{Zone, ZoneActor, ZoneMap}
import net.psforever.objects.{Avatar, GlobalDefinitions, Player}
import net.psforever.packet.game.PlanetSideGUID
import net.psforever.types.{CharacterGender, CharacterVoice, PlanetSideEmpire}
import org.specs2.mutable.Specification
import services.{Service, ServiceManager}
import services.local.{LocalResponse, LocalService, LocalServiceResponse}
import scala.concurrent.duration._
@ -21,39 +26,62 @@ class ProximityTest extends Specification {
}
"keep track of users (add)" in {
val obj = new ProximityTest.SampleTerminal()
val avatar1 = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar1.Spawn
avatar1.Health = 50
val avatar2 = Player(Avatar("TestCharacter2", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar2.Spawn
avatar2.Health = 50
val obj = new ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.NumberUsers mustEqual 0
obj.AddUser(PlanetSideGUID(10)) mustEqual obj.NumberUsers
obj.AddUser(avatar1) mustEqual true
obj.NumberUsers mustEqual 1
obj.AddUser(PlanetSideGUID(20)) mustEqual obj.NumberUsers
obj.AddUser(avatar2) mustEqual true
obj.NumberUsers mustEqual 2
}
"keep track of users (remove)" in {
val obj = new ProximityTest.SampleTerminal()
obj.AddUser(PlanetSideGUID(10))
obj.AddUser(PlanetSideGUID(20))
obj.NumberUsers mustEqual 2
obj.RemoveUser(PlanetSideGUID(10)) mustEqual obj.NumberUsers
val avatar1 = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar1.Spawn
avatar1.Health = 50
val avatar2 = Player(Avatar("TestCharacter2", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar2.Spawn
avatar2.Health = 50
val obj = new ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.NumberUsers mustEqual 0
obj.AddUser(avatar1) mustEqual true
obj.NumberUsers mustEqual 1
obj.RemoveUser(PlanetSideGUID(20)) mustEqual obj.NumberUsers
obj.AddUser(avatar2) mustEqual true
obj.NumberUsers mustEqual 2
obj.RemoveUser(avatar1) mustEqual true
obj.NumberUsers mustEqual 1
obj.RemoveUser(avatar2) mustEqual true
obj.NumberUsers mustEqual 0
}
"can not add a user twice" in {
val obj = new ProximityTest.SampleTerminal()
obj.AddUser(PlanetSideGUID(10))
val avatar = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar.Spawn
avatar.Health = 50
val obj = new ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.AddUser(avatar) mustEqual true
obj.NumberUsers mustEqual 1
obj.AddUser(PlanetSideGUID(10))
obj.AddUser(avatar)// mustEqual false
obj.NumberUsers mustEqual 1
}
"can not remove a user that was not added" in {
val avatar = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar.Spawn
avatar.Health = 50
val obj = new ProximityTest.SampleTerminal()
obj.AddUser(PlanetSideGUID(10))
obj.NumberUsers mustEqual 1
obj.RemoveUser(PlanetSideGUID(20))
obj.NumberUsers mustEqual 1
obj.RemoveUser(avatar) mustEqual false
obj.NumberUsers mustEqual 0
}
}
@ -65,106 +93,216 @@ class ProximityTest extends Specification {
}
}
class ProximityTerminalControl1bTest extends ActorTest {
class ProximityTerminalControlStartTest extends ActorTest {
"ProximityTerminalControl" should {
//setup
val probe = new TestProbe(system)
val service = ServiceManager.boot(system)
service ! ServiceManager.Register(Props(classOf[ProximityTest.ProbedLocalService], probe), "local")
service ! ServiceManager.Register(Props[TaskResolver], "taskResolver")
service ! ServiceManager.Register(Props[TaskResolver], "cluster")
val terminal = new ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], terminal), "test-prox")
val zone : Zone = new Zone("test", new ZoneMap("test-map"), 0) {
Actor = system.actorOf(Props(classOf[ZoneActor], this), "test-zone")
override def SetupNumberPools() = {
AddPool("dynamic", 1 to 10)
}
}
new Building(0, zone, StructureType.Facility) {
Amenities = terminal
Faction = PlanetSideEmpire.VS
}
val avatar = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar.Continent = "test"
avatar.Spawn
avatar.Health = 50
avatar.GUID = PlanetSideGUID(1)
terminal.GUID = PlanetSideGUID(2)
terminal.Actor ! Service.Startup()
expectNoMsg(500 milliseconds) //spacer
"send out a start message" in {
val obj = ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], obj), "prox-ctrl")
val player = Player(Avatar("TestCharacter", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player.GUID = PlanetSideGUID(10)
assert(terminal.NumberUsers == 0)
assert(terminal.Owner.Continent.equals("test"))
terminal.Actor ! CommonMessages.Use(avatar, Some(avatar))
assert(obj.NumberUsers == 0)
obj.Actor ! CommonMessages.Use(player)
val msg = receiveOne(200 milliseconds)
assert(obj.NumberUsers == 1)
assert(msg.isInstanceOf[TerminalMessage])
val msgout = msg.asInstanceOf[TerminalMessage]
assert(msgout.player == player)
assert(msgout.msg == null)
assert(msgout.response.isInstanceOf[Terminal.StartProximityEffect])
val msg = probe.receiveOne(500 milliseconds)
assert(terminal.NumberUsers == 1)
assert(msg.isInstanceOf[LocalServiceResponse])
val resp = msg.asInstanceOf[LocalServiceResponse]
assert(resp.replyMessage == LocalResponse.ProximityTerminalEffect(PlanetSideGUID(2), true))
}
}
}
class ProximityTerminalControl2bTest extends ActorTest {
class ProximityTerminalControlTwoUsersTest extends ActorTest {
"ProximityTerminalControl" should {
"will not send out one start message unless first user" in {
val obj = ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], obj), "prox-ctrl")
val player1 = Player(Avatar("TestCharacter1", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player1.GUID = PlanetSideGUID(10)
val player2 = Player(Avatar("TestCharacter2", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player2.GUID = PlanetSideGUID(11)
assert(obj.NumberUsers == 0)
//setup
val probe = new TestProbe(system)
val service = ServiceManager.boot(system)
service ! ServiceManager.Register(Props(classOf[ProximityTest.ProbedLocalService], probe), "local")
service ! ServiceManager.Register(Props[TaskResolver], "taskResolver")
service ! ServiceManager.Register(Props[TaskResolver], "cluster")
val terminal = new ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], terminal), "test-prox")
val zone : Zone = new Zone("test", new ZoneMap("test-map"), 0) {
Actor = system.actorOf(Props(classOf[ZoneActor], this), "test-zone")
override def SetupNumberPools() = {
AddPool("dynamic", 1 to 10)
}
}
new Building(0, zone, StructureType.Facility) {
Amenities = terminal
Faction = PlanetSideEmpire.VS
}
val avatar = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar.Continent = "test"
avatar.Spawn
avatar.Health = 50
obj.Actor ! CommonMessages.Use(player1)
val msg = receiveOne(200 milliseconds)
assert(obj.NumberUsers == 1)
assert(msg.isInstanceOf[TerminalMessage])
assert(msg.asInstanceOf[TerminalMessage].response.isInstanceOf[Terminal.StartProximityEffect])
obj.Actor ! CommonMessages.Use(player2)
expectNoMsg(500 milliseconds)
assert(obj.NumberUsers == 2)
avatar.GUID = PlanetSideGUID(1)
terminal.GUID = PlanetSideGUID(2)
terminal.Actor ! Service.Startup()
expectNoMsg(500 milliseconds) //spacer
"will not send out a start message if not the first user" in {
assert(terminal.NumberUsers == 0)
assert(terminal.Owner.Continent.equals("test"))
terminal.Actor ! CommonMessages.Use(avatar, Some(avatar))
val msg = probe.receiveOne(500 milliseconds)
assert(terminal.NumberUsers == 1)
assert(msg.isInstanceOf[LocalServiceResponse])
val resp = msg.asInstanceOf[LocalServiceResponse]
assert(resp.replyMessage == LocalResponse.ProximityTerminalEffect(PlanetSideGUID(2), true))
val avatar2 = Player(Avatar("TestCharacter2", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar2.Continent = "test"
avatar2.Spawn
avatar2.Health = 50
terminal.Actor ! CommonMessages.Use(avatar2, Some(avatar2))
probe.expectNoMsg(500 milliseconds)
assert(terminal.NumberUsers == 2)
}
}
}
class ProximityTerminalControl3bTest extends ActorTest {
class ProximityTerminalControlStopTest extends ActorTest {
"ProximityTerminalControl" should {
//setup
val probe = new TestProbe(system)
val service = ServiceManager.boot(system)
service ! ServiceManager.Register(Props(classOf[ProximityTest.ProbedLocalService], probe), "local")
service ! ServiceManager.Register(Props[TaskResolver], "taskResolver")
service ! ServiceManager.Register(Props[TaskResolver], "cluster")
val terminal = new ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], terminal), "test-prox")
val zone : Zone = new Zone("test", new ZoneMap("test-map"), 0) {
Actor = system.actorOf(Props(classOf[ZoneActor], this), "test-zone")
override def SetupNumberPools() = {
AddPool("dynamic", 1 to 10)
}
}
new Building(0, zone, StructureType.Facility) {
Amenities = terminal
Faction = PlanetSideEmpire.VS
}
val avatar = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar.Continent = "test"
avatar.Spawn
avatar.Health = 50
avatar.GUID = PlanetSideGUID(1)
terminal.GUID = PlanetSideGUID(2)
terminal.Actor ! Service.Startup()
expectNoMsg(500 milliseconds) //spacer
"send out a stop message" in {
val obj = ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], obj), "prox-ctrl")
val player = Player(Avatar("TestCharacter", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player.GUID = PlanetSideGUID(10)
assert(terminal.NumberUsers == 0)
assert(terminal.Owner.Continent.equals("test"))
assert(obj.NumberUsers == 0)
obj.Actor ! CommonMessages.Use(player)
receiveOne(200 milliseconds)
assert(obj.NumberUsers == 1)
obj.Actor ! CommonMessages.Unuse(player)
val msg = receiveOne(200 milliseconds)
assert(obj.NumberUsers == 0)
assert(msg.isInstanceOf[TerminalMessage])
val msgout = msg.asInstanceOf[TerminalMessage]
assert(msgout.player == player)
assert(msgout.msg == null)
assert(msgout.response.isInstanceOf[Terminal.StopProximityEffect])
terminal.Actor ! CommonMessages.Use(avatar, Some(avatar))
val msg1 = probe.receiveOne(500 milliseconds)
assert(terminal.NumberUsers == 1)
assert(msg1.isInstanceOf[LocalServiceResponse])
val resp1 = msg1.asInstanceOf[LocalServiceResponse]
assert(resp1.replyMessage == LocalResponse.ProximityTerminalEffect(PlanetSideGUID(2), true))
terminal.Actor ! CommonMessages.Unuse(avatar, Some(avatar))
val msg2 = probe.receiveWhile(500 milliseconds) {
case LocalServiceResponse(_, _, replyMessage) => replyMessage
}
assert(terminal.NumberUsers == 0)
assert(msg2.last == LocalResponse.ProximityTerminalEffect(PlanetSideGUID(2), false))
}
}
}
class ProximityTerminalControl4bTest extends ActorTest {
class ProximityTerminalControlNotStopTest extends ActorTest {
"ProximityTerminalControl" should {
"will not send out one stop message until last user" in {
val obj = ProximityTerminal(GlobalDefinitions.medical_terminal)
obj.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], obj), "prox-ctrl")
val player1 = Player(Avatar("TestCharacter1", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player1.GUID = PlanetSideGUID(10)
val player2 = Player(Avatar("TestCharacter2", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
player2.GUID = PlanetSideGUID(11)
assert(obj.NumberUsers == 0)
//setup
val probe = new TestProbe(system)
val service = ServiceManager.boot(system)
service ! ServiceManager.Register(Props(classOf[ProximityTest.ProbedLocalService], probe), "local")
service ! ServiceManager.Register(Props[TaskResolver], "taskResolver")
service ! ServiceManager.Register(Props[TaskResolver], "cluster")
val terminal = new ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.Actor = system.actorOf(Props(classOf[ProximityTerminalControl], terminal), "test-prox")
val zone : Zone = new Zone("test", new ZoneMap("test-map"), 0) {
Actor = system.actorOf(Props(classOf[ZoneActor], this), "test-zone")
override def SetupNumberPools() = {
AddPool("dynamic", 1 to 10)
}
}
new Building(0, zone, StructureType.Facility) {
Amenities = terminal
Faction = PlanetSideEmpire.VS
}
val avatar = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar.Continent = "test"
avatar.Spawn
avatar.Health = 50
obj.Actor ! CommonMessages.Use(player1)
receiveOne(200 milliseconds) //StartProximityEffect
assert(obj.NumberUsers == 1)
obj.Actor ! CommonMessages.Use(player2)
expectNoMsg(500 milliseconds)
assert(obj.NumberUsers == 2)
obj.Actor ! CommonMessages.Unuse(player1)
expectNoMsg(500 milliseconds)
assert(obj.NumberUsers == 1)
obj.Actor ! CommonMessages.Unuse(player2)
val msg = receiveOne(200 milliseconds)
assert(obj.NumberUsers == 0)
assert(msg.isInstanceOf[TerminalMessage])
val msgout = msg.asInstanceOf[TerminalMessage]
assert(msgout.player == player2)
assert(msgout.msg == null)
assert(msgout.response.isInstanceOf[Terminal.StopProximityEffect])
avatar.GUID = PlanetSideGUID(1)
terminal.GUID = PlanetSideGUID(2)
terminal.Actor ! Service.Startup()
expectNoMsg(500 milliseconds) //spacer
"will not send out one stop message until last user" in {
assert(terminal.NumberUsers == 0)
assert(terminal.Owner.Continent.equals("test"))
terminal.Actor ! CommonMessages.Use(avatar, Some(avatar))
val msg = probe.receiveOne(500 milliseconds)
assert(terminal.NumberUsers == 1)
assert(msg.isInstanceOf[LocalServiceResponse])
val resp = msg.asInstanceOf[LocalServiceResponse]
assert(resp.replyMessage == LocalResponse.ProximityTerminalEffect(PlanetSideGUID(2), true))
val avatar2 = Player(Avatar("TestCharacter2", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
avatar2.Continent = "test"
avatar2.Spawn
avatar2.Health = 50
terminal.Actor ! CommonMessages.Use(avatar2, Some(avatar2))
probe.expectNoMsg(500 milliseconds)
assert(terminal.NumberUsers == 2)
terminal.Actor ! CommonMessages.Unuse(avatar, Some(avatar))
val msg2 = probe.receiveWhile(500 milliseconds) {
case LocalServiceResponse(_, _, replyMessage) => replyMessage
}
assert(terminal.NumberUsers == 1)
assert(!msg2.contains(LocalResponse.ProximityTerminalEffect(PlanetSideGUID(2), false)))
}
}
}
object ProximityTest {
class SampleTerminal extends Terminal(GlobalDefinitions.dropship_vehicle_terminal) with ProximityUnit
class ProbedLocalService(probe : TestProbe) extends LocalService {
self.tell(Service.Join("test"), probe.ref)
}
}

View file

@ -1,91 +0,0 @@
// Copyright (c) 2017 PSForever
package objects.terminal
import akka.actor.ActorRef
import net.psforever.objects.serverobject.structures.{Building, StructureType}
import net.psforever.objects._
import net.psforever.objects.serverobject.terminals.Terminal
import net.psforever.objects.zones.Zone
import net.psforever.packet.game.{ItemTransactionMessage, PlanetSideGUID}
import net.psforever.types.{CharacterGender, CharacterVoice, PlanetSideEmpire, TransactionType}
import org.specs2.mutable.Specification
class RepairRearmSiloTest extends Specification {
"RepairRearmSilo" should {
val player = Player(Avatar("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
val silo = Terminal(GlobalDefinitions.repair_silo)
silo.Owner = new Building(0, Zone.Nowhere, StructureType.Building)
silo.Owner.Faction = PlanetSideEmpire.TR
"define" in {
GlobalDefinitions.repair_silo.ObjectId mustEqual 729
}
"construct" in {
val obj = Terminal(GlobalDefinitions.repair_silo)
obj.Actor mustEqual ActorRef.noSender
}
"player can buy a box of ammunition ('bullet_35mm')" in {
val msg = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.Buy, 3, "35mmbullet", 0, PlanetSideGUID(0))
val reply = silo.Request(player, msg)
reply.isInstanceOf[Terminal.BuyEquipment] mustEqual true
val reply2 = reply.asInstanceOf[Terminal.BuyEquipment]
reply2.item.isInstanceOf[AmmoBox] mustEqual true
reply2.item.asInstanceOf[AmmoBox].Definition mustEqual GlobalDefinitions.bullet_35mm
reply2.item.asInstanceOf[AmmoBox].Capacity mustEqual 100
}
"player can not buy fake equipment ('sabot')" in {
val msg = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.Buy, 3, "sabot", 0, PlanetSideGUID(0))
silo.Request(player, msg) mustEqual Terminal.NoDeal()
}
"player can not buy equipment from the wrong page ('35mmbullet', page 1)" in {
val msg = ItemTransactionMessage(PlanetSideGUID(1), TransactionType.Buy, 1, "35mmbullet", 0, PlanetSideGUID(0))
silo.Request(player, msg) mustEqual Terminal.NoDeal()
}
"player can retrieve a vehicle loadout" in {
val avatar = Avatar("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute)
val player2 = Player(avatar)
val vehicle = Vehicle(GlobalDefinitions.fury)
vehicle.Slot(30).Equipment = AmmoBox(GlobalDefinitions.bullet_9mm)
avatar.SaveLoadout(vehicle, "test", 10)
val msg = silo.Request(player2, ItemTransactionMessage(PlanetSideGUID(10), TransactionType.Loadout, 4, "", 0, PlanetSideGUID(0)))
msg.isInstanceOf[Terminal.VehicleLoadout] mustEqual true
val loadout = msg.asInstanceOf[Terminal.VehicleLoadout]
loadout.vehicle_definition mustEqual GlobalDefinitions.fury
loadout.weapons.size mustEqual 1
loadout.weapons.head.obj.Definition mustEqual GlobalDefinitions.fury_weapon_systema
loadout.weapons.head.start mustEqual 1
loadout.inventory.head.obj.Definition mustEqual GlobalDefinitions.bullet_9mm
loadout.inventory.head.start mustEqual 30
}
"player can not retrieve a vehicle loadout from the wrong line" in {
val avatar = Avatar("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute)
val player2 = Player(avatar)
val vehicle = Vehicle(GlobalDefinitions.fury)
vehicle.Slot(30).Equipment = AmmoBox(GlobalDefinitions.bullet_9mm)
avatar.SaveLoadout(vehicle, "test", 10)
val msg = silo.Request(player2, ItemTransactionMessage(PlanetSideGUID(10), TransactionType.Loadout, 3, "", 0, PlanetSideGUID(0))) //page 3
msg.isInstanceOf[Terminal.NoDeal] mustEqual true
}
"player can not retrieve a vehicle loadout from the wrong line" in {
val avatar = Avatar("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute)
val player2 = Player(avatar)
val vehicle = Vehicle(GlobalDefinitions.fury)
vehicle.Slot(30).Equipment = AmmoBox(GlobalDefinitions.bullet_9mm)
avatar.SaveLoadout(vehicle, "test", 10)
val msg = silo.Request(player2, ItemTransactionMessage(PlanetSideGUID(10), TransactionType.Loadout, 4, "", 1, PlanetSideGUID(0))) //line 11
msg.isInstanceOf[Terminal.NoDeal] mustEqual true
}
}
}

View file

@ -5,6 +5,7 @@ import akka.actor.Props
import base.ActorTest
import net.psforever.objects.{GlobalDefinitions, SensorDeployable, Vehicle}
import net.psforever.objects.serverobject.PlanetSideServerObject
import net.psforever.objects.serverobject.terminals.{ProximityTerminal, Terminal}
import net.psforever.packet.game._
import net.psforever.types.{PlanetSideEmpire, Vector3}
import services.{Service, ServiceManager}
@ -141,15 +142,32 @@ class HackClearTest extends ActorTest {
}
}
class ProximityTerminalEffectTest extends ActorTest {
class ProximityTerminalEffectOnTest extends ActorTest {
ServiceManager.boot(system)
val service = system.actorOf(Props[LocalService], "l_service")
val terminal = new ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.GUID = PlanetSideGUID(1)
"LocalService" should {
"pass ProximityTerminalEffect" in {
val service = system.actorOf(Props[LocalService], "l_service")
service ! Service.Join("test")
service ! LocalServiceMessage("test", LocalAction.ProximityTerminalEffect(PlanetSideGUID(10), PlanetSideGUID(40), true))
expectMsg(LocalServiceResponse("/test/Local", PlanetSideGUID(10), LocalResponse.ProximityTerminalEffect(PlanetSideGUID(40), true)))
"pass ProximityTerminalEffect (true)" in {
service ! Service.Join("nowhere")
service ! Terminal.StartProximityEffect(terminal)
expectMsg(LocalServiceResponse("/nowhere/Local", PlanetSideGUID(0), LocalResponse.ProximityTerminalEffect(PlanetSideGUID(1), true)))
}
}
}
class ProximityTerminalEffectOffTest extends ActorTest {
ServiceManager.boot(system)
val service = system.actorOf(Props[LocalService], "l_service")
val terminal = new ProximityTerminal(GlobalDefinitions.medical_terminal)
terminal.GUID = PlanetSideGUID(1)
"LocalService" should {
"pass ProximityTerminalEffect (false)" in {
service ! Service.Join("nowhere")
service ! Terminal.StopProximityEffect(terminal)
expectMsg(LocalServiceResponse("/nowhere/Local", PlanetSideGUID(0), LocalResponse.ProximityTerminalEffect(PlanetSideGUID(1), false)))
}
}
}