mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-25 09:33:33 +00:00
* functions for certifcation ui updates (that don't work) * initialization of combat engineering deployables ui on load and certification change * representation classes for ACE and FDU; ability to pull ACE and FDU from equipment terminals * ammo change functionality and fire mode change functionality for ConstructionItems refactored from Tool operations and supported properly (switch between deployable options) * zone-specific structure for keeping track of deployables; abaility to dismiss deployables from the map screen (previous functionality); local client creation of explosive-type deployables * refactored MannedTurret into FacilityTurret and lesser traits to be used in the deployable spitfires and the OMFT's; all ACE deployables are available for placement; partial management of the construction items after the deployable is placed; boomers create boomer triggers * Avatar-specific storage for deployables and for updating UI elements * refactored quite a bit of code in WSA for the benefit of deployable management; refinements to deployable creation; server messages about deployable quantities; corrected the FDU encoding pattern; lots of work dedicated just to synchronizing BoomerTrigger objects * added RemoverActor for deployables and redistributed deconstruction functionality away from WSA to new DeployableRemover; added events to facilitate activities not inheritable with this model * refactored and distributed Deployables classes; copious amounts of testing and document-writing * boomers now explode from trigger; support for deployables being destroyed by weapon discharge, including individual health, soure identification, and damage model; shuffled deployable classes to build different hierarchy * sensor_shield was skipped by accident * identified stray object in Hanish, Ishundar, and added Irkalla, Ishundar's capture console; fixed issue with Warp command and 'Irkalla'; modified building amenity setup and setup testing in Zone; players load and die properly when seated in an omft; reserve ammunition in omft properly registered * added local service channel, capture consoles, fixed tests as much as posible * fixed LocalService tests by booting the ServiceManager; added avatar and local tests * a simple attempt to refactor Actor messages in a way that is acceptable to Travis CI * making the explosive deployables vanish upon explosion; sensor health bars are now supported
332 lines
14 KiB
Scala
332 lines
14 KiB
Scala
// Copyright (c) 2017 PSForever
|
|
package objects
|
|
|
|
import akka.actor.{Actor, Props}
|
|
import akka.routing.RandomPool
|
|
import akka.testkit.TestProbe
|
|
import base.ActorTest
|
|
import net.psforever.objects.guid.TaskResolver
|
|
import net.psforever.objects.{Avatar, GlobalDefinitions, Player}
|
|
import net.psforever.objects.serverobject.resourcesilo.{ResourceSilo, ResourceSiloControl, ResourceSiloDefinition}
|
|
import net.psforever.objects.serverobject.structures.{Building, StructureType}
|
|
import net.psforever.objects.zones.Zone
|
|
import net.psforever.packet.game.{PlanetSideGUID, UseItemMessage}
|
|
import net.psforever.types.{CharacterGender, CharacterVoice, PlanetSideEmpire, Vector3}
|
|
import org.specs2.mutable.Specification
|
|
import services.ServiceManager
|
|
import services.avatar.{AvatarAction, AvatarService, AvatarServiceMessage}
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
class ResourceSiloTest extends Specification {
|
|
"Resource Silo" should {
|
|
"define" in {
|
|
val obj = new ResourceSiloDefinition
|
|
obj.ObjectId mustEqual 731
|
|
}
|
|
|
|
"construct" in {
|
|
val obj = ResourceSilo()
|
|
obj.Definition mustEqual GlobalDefinitions.resource_silo
|
|
obj.MaximumCharge mustEqual 1000
|
|
obj.ChargeLevel mustEqual 0
|
|
obj.LowNtuWarningOn mustEqual true
|
|
obj.CapacitorDisplay mustEqual 0
|
|
//
|
|
obj.ChargeLevel = 50
|
|
obj.LowNtuWarningOn = false
|
|
obj.CapacitorDisplay = 75
|
|
obj.ChargeLevel mustEqual 50
|
|
obj.LowNtuWarningOn mustEqual false
|
|
obj.CapacitorDisplay mustEqual 75
|
|
}
|
|
|
|
"charge level can not exceed limits(0 to maximum)" in {
|
|
val obj = ResourceSilo()
|
|
obj.ChargeLevel mustEqual 0
|
|
obj.ChargeLevel = -5
|
|
obj.ChargeLevel mustEqual 0
|
|
|
|
obj.ChargeLevel = 1250
|
|
obj.ChargeLevel mustEqual 1000
|
|
obj.ChargeLevel mustEqual obj.MaximumCharge
|
|
}
|
|
|
|
"using the silo generates a charge event" in {
|
|
val msg = UseItemMessage(PlanetSideGUID(1), PlanetSideGUID(0), PlanetSideGUID(2), 0L, false, Vector3(0f,0f,0f),Vector3(0f,0f,0f),0,0,0,0L) //faked
|
|
ResourceSilo().Use(ResourceSiloTest.player, msg) mustEqual ResourceSilo.ChargeEvent()
|
|
}
|
|
}
|
|
}
|
|
|
|
class ResourceSiloControlStartupTest extends ActorTest {
|
|
val serviceManager = ServiceManager.boot(system)
|
|
serviceManager ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
|
val obj = ResourceSilo()
|
|
obj.GUID = PlanetSideGUID(1)
|
|
val probe = TestProbe()
|
|
serviceManager ! ServiceManager.Register(Props(classOf[ResourceSiloTest.ProbedAvatarService], probe), "avatar")
|
|
|
|
"Resource silo" should {
|
|
"startup properly" in {
|
|
expectNoMsg(500 milliseconds)
|
|
system.actorOf(Props(classOf[ResourceSiloControl], obj), "test-silo")
|
|
expectNoMsg(1 seconds)
|
|
assert(true)
|
|
}
|
|
}
|
|
}
|
|
|
|
class ResourceSiloControlUseTest extends ActorTest {
|
|
val serviceManager = ServiceManager.boot(system)
|
|
serviceManager ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
|
val probe = TestProbe()
|
|
serviceManager ! ServiceManager.Register(Props(classOf[ResourceSiloTest.ProbedAvatarService], probe), "avatar")
|
|
val msg = UseItemMessage(PlanetSideGUID(1), PlanetSideGUID(0), PlanetSideGUID(2), 0L, false, Vector3(0f,0f,0f),Vector3(0f,0f,0f),0,0,0,0L) //faked
|
|
val obj = ResourceSilo()
|
|
obj.GUID = PlanetSideGUID(1)
|
|
obj.Actor = system.actorOf(Props(classOf[ResourceSiloControl], obj), "test-silo")
|
|
obj.Actor ! "startup"
|
|
|
|
"Resource silo" should {
|
|
"respond when being used" in {
|
|
expectNoMsg(1 seconds)
|
|
obj.Actor ! ResourceSilo.Use(ResourceSiloTest.player, msg)
|
|
|
|
val reply = receiveOne(500 milliseconds)
|
|
assert(reply.isInstanceOf[ResourceSilo.ResourceSiloMessage])
|
|
assert(reply.asInstanceOf[ResourceSilo.ResourceSiloMessage].player == ResourceSiloTest.player)
|
|
assert(reply.asInstanceOf[ResourceSilo.ResourceSiloMessage].msg == msg)
|
|
assert(reply.asInstanceOf[ResourceSilo.ResourceSiloMessage].response == ResourceSilo.ChargeEvent())
|
|
}
|
|
}
|
|
}
|
|
|
|
class ResourceSiloControlNtuWarningTest extends ActorTest {
|
|
val serviceManager = ServiceManager.boot(system)
|
|
serviceManager ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
|
val probe = TestProbe()
|
|
serviceManager ! ServiceManager.Register(Props(classOf[ResourceSiloTest.ProbedAvatarService], probe), "avatar")
|
|
val obj = ResourceSilo()
|
|
obj.GUID = PlanetSideGUID(1)
|
|
obj.Actor = system.actorOf(Props(classOf[ResourceSiloControl], obj), "test-silo")
|
|
obj.Actor ! "startup"
|
|
obj.Owner = new Building(0, Zone.Nowhere, StructureType.Building) {
|
|
ModelId = 6
|
|
}
|
|
|
|
"Resource silo" should {
|
|
"announce high ntu" in {
|
|
expectNoMsg(1 seconds)
|
|
assert(obj.LowNtuWarningOn == true)
|
|
obj.Actor ! ResourceSilo.LowNtuWarning(false)
|
|
|
|
val reply = probe.receiveOne(500 milliseconds)
|
|
assert(obj.LowNtuWarningOn == false)
|
|
assert(reply.isInstanceOf[AvatarServiceMessage])
|
|
assert(reply.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
|
|
assert(reply.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.isInstanceOf[AvatarAction.PlanetsideAttribute])
|
|
assert(reply.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].player_guid == PlanetSideGUID(6))
|
|
assert(reply.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 47)
|
|
assert(reply.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
class ResourceSiloControlUpdate1Test extends ActorTest {
|
|
val serviceManager = ServiceManager.boot(system)
|
|
serviceManager ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
|
val probe1 = TestProbe()
|
|
serviceManager ! ServiceManager.Register(Props(classOf[ResourceSiloTest.ProbedAvatarService], probe1), "avatar")
|
|
val obj = ResourceSilo()
|
|
obj.GUID = PlanetSideGUID(1)
|
|
obj.Actor = system.actorOf(Props(classOf[ResourceSiloControl], obj), "test-silo")
|
|
obj.Actor ! "startup"
|
|
val bldg = new Building(0, Zone.Nowhere, StructureType.Building) {
|
|
ModelId = 6
|
|
}
|
|
val probe2 = TestProbe()
|
|
bldg.Actor = system.actorOf(Props(classOf[ResourceSiloTest.ProbedBuildingControl], probe2), "test-bldg")
|
|
obj.Owner = bldg
|
|
|
|
"Resource silo" should {
|
|
"update the charge level and capacitor display (report high ntu, power restored)" in {
|
|
expectNoMsg(1 seconds)
|
|
|
|
assert(obj.ChargeLevel == 0)
|
|
assert(obj.CapacitorDisplay == 0)
|
|
obj.Actor ! ResourceSilo.UpdateChargeLevel(305)
|
|
|
|
val reply1 = probe1.receiveOne(500 milliseconds)
|
|
val reply2 = probe2.receiveOne(500 milliseconds)
|
|
assert(obj.ChargeLevel == 305)
|
|
assert(obj.CapacitorDisplay == 3)
|
|
assert(reply1.isInstanceOf[AvatarServiceMessage])
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.isInstanceOf[AvatarAction.PlanetsideAttribute])
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].player_guid == PlanetSideGUID(1))
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 45)
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 3)
|
|
|
|
assert(reply2.isInstanceOf[Building.SendMapUpdate])
|
|
|
|
val reply3 = probe1.receiveOne(500 milliseconds)
|
|
assert(reply3.isInstanceOf[AvatarServiceMessage])
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.isInstanceOf[AvatarAction.PlanetsideAttribute])
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].player_guid == PlanetSideGUID(6))
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 48)
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
|
|
|
|
val reply4 = probe1.receiveOne(500 milliseconds)
|
|
assert(!obj.LowNtuWarningOn)
|
|
assert(reply4.isInstanceOf[AvatarServiceMessage])
|
|
assert(reply4.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
|
|
assert(reply4.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.isInstanceOf[AvatarAction.PlanetsideAttribute])
|
|
assert(reply4.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].player_guid == PlanetSideGUID(6))
|
|
assert(reply4.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 47)
|
|
assert(reply4.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
class ResourceSiloControlUpdate2Test extends ActorTest {
|
|
val serviceManager = ServiceManager.boot(system)
|
|
serviceManager ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
|
val probe1 = TestProbe()
|
|
serviceManager ! ServiceManager.Register(Props(classOf[ResourceSiloTest.ProbedAvatarService], probe1), "avatar")
|
|
val obj = ResourceSilo()
|
|
obj.GUID = PlanetSideGUID(1)
|
|
obj.Actor = system.actorOf(Props(classOf[ResourceSiloControl], obj), "test-silo")
|
|
obj.Actor ! "startup"
|
|
val bldg = new Building(0, Zone.Nowhere, StructureType.Building) {
|
|
ModelId = 6
|
|
}
|
|
val probe2 = TestProbe()
|
|
bldg.Actor = system.actorOf(Props(classOf[ResourceSiloTest.ProbedBuildingControl], probe2), "test-bldg")
|
|
obj.Owner = bldg
|
|
|
|
"Resource silo" should {
|
|
"update the charge level and capacitor display (report good ntu)" in {
|
|
expectNoMsg(1 seconds)
|
|
|
|
obj.ChargeLevel = 100
|
|
obj.CapacitorDisplay = 1
|
|
obj.LowNtuWarningOn = true
|
|
assert(obj.ChargeLevel == 100)
|
|
assert(obj.CapacitorDisplay == 1)
|
|
assert(obj.LowNtuWarningOn == true)
|
|
obj.Actor ! ResourceSilo.UpdateChargeLevel(105)
|
|
|
|
val reply1 = probe1.receiveOne(500 milliseconds)
|
|
val reply2 = probe2.receiveOne(500 milliseconds)
|
|
assert(obj.ChargeLevel == 205)
|
|
assert(obj.CapacitorDisplay == 2)
|
|
assert(reply1.isInstanceOf[AvatarServiceMessage])
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.isInstanceOf[AvatarAction.PlanetsideAttribute])
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].player_guid == PlanetSideGUID(1))
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 45)
|
|
assert(reply1.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 2)
|
|
|
|
assert(reply2.isInstanceOf[Building.SendMapUpdate])
|
|
|
|
val reply3 = probe1.receiveOne(500 milliseconds)
|
|
assert(obj.LowNtuWarningOn == false)
|
|
assert(reply3.isInstanceOf[AvatarServiceMessage])
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.isInstanceOf[AvatarAction.PlanetsideAttribute])
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].player_guid == PlanetSideGUID(6))
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 47)
|
|
assert(reply3.asInstanceOf[AvatarServiceMessage]
|
|
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
class ResourceSiloControlNoUpdateTest extends ActorTest {
|
|
val serviceManager = ServiceManager.boot(system)
|
|
serviceManager ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
|
val probe1 = TestProbe()
|
|
serviceManager ! ServiceManager.Register(Props(classOf[ResourceSiloTest.ProbedAvatarService], probe1), "avatar")
|
|
val obj = ResourceSilo()
|
|
obj.GUID = PlanetSideGUID(1)
|
|
obj.Actor = system.actorOf(Props(classOf[ResourceSiloControl], obj), "test-silo")
|
|
obj.Actor ! "startup"
|
|
val bldg = new Building(0, Zone.Nowhere, StructureType.Building) {
|
|
ModelId = 6
|
|
}
|
|
val probe2 = TestProbe()
|
|
bldg.Actor = system.actorOf(Props(classOf[ResourceSiloTest.ProbedBuildingControl], probe2), "test-bldg")
|
|
obj.Owner = bldg
|
|
|
|
"Resource silo" should {
|
|
"update, but not sufficiently to change the capacitor display" in {
|
|
expectNoMsg(1 seconds)
|
|
|
|
obj.ChargeLevel = 250
|
|
obj.CapacitorDisplay = 3
|
|
obj.LowNtuWarningOn = false
|
|
assert(obj.ChargeLevel == 250)
|
|
assert(obj.CapacitorDisplay == 3)
|
|
assert(obj.LowNtuWarningOn == false)
|
|
obj.Actor ! ResourceSilo.UpdateChargeLevel(50)
|
|
|
|
expectNoMsg(500 milliseconds)
|
|
probe1.expectNoMsg(500 milliseconds)
|
|
probe2.expectNoMsg(500 milliseconds)
|
|
assert(obj.ChargeLevel == 300)
|
|
assert(obj.CapacitorDisplay == 3)
|
|
assert(obj.LowNtuWarningOn == false)
|
|
}
|
|
}
|
|
}
|
|
|
|
object ResourceSiloTest {
|
|
val player = Player(Avatar("TestCharacter", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
|
|
|
|
class ProbedAvatarService(probe : TestProbe) extends Actor {
|
|
override def receive : Receive = {
|
|
case msg =>
|
|
probe.ref ! msg
|
|
}
|
|
}
|
|
|
|
class ProbedBuildingControl(probe : TestProbe) extends Actor {
|
|
override def receive : Receive = {
|
|
case msg =>
|
|
probe.ref ! msg
|
|
}
|
|
}
|
|
|
|
class ProbedResourceSiloControl(silo : ResourceSilo, probe : TestProbe) extends ResourceSiloControl(silo) {
|
|
override def receive : Receive = {
|
|
case msg =>
|
|
super.receive.apply(msg)
|
|
probe.ref ! msg
|
|
}
|
|
}
|
|
}
|