Fix NTU warning flag having the wrong data type (#224)

Fix LowNtuWarning having the wrong data type
This commit is contained in:
Mazo 2018-07-18 13:41:28 +01:00 committed by Fate-JH
parent b81ff2bbf4
commit fc78d53ecb
4 changed files with 35 additions and 34 deletions

View file

@ -9,8 +9,9 @@ import net.psforever.packet.game.UseItemMessage
class ResourceSilo extends Amenity {
private var chargeLevel : Int = 0
private val maximumCharge : Int = 1000
// For the flashing red light on top of the NTU silo on
private var lowNtuWarningOn : Int = 0
// For the flashing red light on top of the NTU silo on.
// Default to true until charge level can be persisted across restarts as default charge level is 0
private var lowNtuWarningOn : Boolean = true
// For the NTU display bar
private var capacitorDisplay : Long = 0
@ -31,8 +32,8 @@ class ResourceSilo extends Amenity {
def MaximumCharge : Int = maximumCharge
def LowNtuWarningOn : Int = lowNtuWarningOn
def LowNtuWarningOn_=(enabled: Int) : Int = {
def LowNtuWarningOn : Boolean = lowNtuWarningOn
def LowNtuWarningOn_=(enabled: Boolean) : Boolean = {
lowNtuWarningOn = enabled
LowNtuWarningOn
}
@ -55,7 +56,7 @@ object ResourceSilo {
final case class Use(player: Player, msg : UseItemMessage)
final case class UpdateChargeLevel(amount: Int)
final case class LowNtuWarning(enabled: Int)
final case class LowNtuWarning(enabled: Boolean)
sealed trait Exchange
final case class ChargeEvent() extends Exchange
final case class ResourceSiloMessage(player: Player, msg : UseItemMessage, response : Exchange)

View file

@ -40,10 +40,10 @@ class ResourceSiloControl(resourceSilo : ResourceSilo) extends Actor with Factio
def Processing : Receive = checkBehavior.orElse {
case ResourceSilo.Use(player, msg) =>
sender ! ResourceSilo.ResourceSiloMessage(player, msg, resourceSilo.Use(player, msg))
case ResourceSilo.LowNtuWarning(enabled: Int) =>
case ResourceSilo.LowNtuWarning(enabled: Boolean) =>
resourceSilo.LowNtuWarningOn = enabled
log.trace(s"LowNtuWarning: Silo ${resourceSilo.GUID} low ntu warning set to ${enabled}")
avatarService ! AvatarServiceMessage(resourceSilo.Owner.asInstanceOf[Building].Zone.Id, AvatarAction.PlanetsideAttribute(PlanetSideGUID(resourceSilo.Owner.asInstanceOf[Building].ModelId), 47, resourceSilo.LowNtuWarningOn))
avatarService ! AvatarServiceMessage(resourceSilo.Owner.asInstanceOf[Building].Zone.Id, AvatarAction.PlanetsideAttribute(PlanetSideGUID(resourceSilo.Owner.asInstanceOf[Building].ModelId), 47, if(resourceSilo.LowNtuWarningOn) 1 else 0))
case ResourceSilo.UpdateChargeLevel(amount: Int) =>
val siloChargeBeforeChange = resourceSilo.ChargeLevel
@ -65,10 +65,10 @@ class ResourceSiloControl(resourceSilo : ResourceSilo) extends Actor with Factio
}
val ntuIsLow = resourceSilo.ChargeLevel.toFloat / resourceSilo.MaximumCharge.toFloat < 0.2f
if(resourceSilo.LowNtuWarningOn == 1 && !ntuIsLow){
self ! ResourceSilo.LowNtuWarning(0)
} else if (resourceSilo.LowNtuWarningOn == 0 && ntuIsLow) {
self ! ResourceSilo.LowNtuWarning(1)
if(resourceSilo.LowNtuWarningOn && !ntuIsLow){
self ! ResourceSilo.LowNtuWarning(enabled = false)
} else if (!resourceSilo.LowNtuWarningOn && ntuIsLow) {
self ! ResourceSilo.LowNtuWarning(enabled = true)
}
@ -76,7 +76,7 @@ class ResourceSiloControl(resourceSilo : ResourceSilo) extends Actor with Factio
// Oops, someone let the base run out of power. Shut it all down.
//todo: Make base neutral if silo hits zero NTU
// temporarily disabled until warpgates can bring ANTs from sanctuary, otherwise we'd be stuck in a situation with an unpowered base and no way to get an ANT to refill it.
//todo: temporarily disabled until warpgates can bring ANTs from sanctuary, otherwise we'd be stuck in a situation with an unpowered base and no way to get an ANT to refill it.
// avatarService ! AvatarServiceMessage(resourceSilo.Owner.asInstanceOf[Building].Zone.Id, AvatarAction.PlanetsideAttribute(PlanetSideGUID(resourceSilo.Owner.asInstanceOf[Building].ModelId), 48, 1))
} else if (siloChargeBeforeChange == 0 && resourceSilo.ChargeLevel > 0) {
// Power restored. Reactor Online. Sensors Online. Weapons Online. All systems nominal.

View file

@ -30,14 +30,14 @@ class ResourceSiloTest extends Specification {
obj.Definition mustEqual GlobalDefinitions.resource_silo
obj.MaximumCharge mustEqual 1000
obj.ChargeLevel mustEqual 0
obj.LowNtuWarningOn mustEqual 0
obj.LowNtuWarningOn mustEqual true
obj.CapacitorDisplay mustEqual 0
//
obj.ChargeLevel = 50
obj.LowNtuWarningOn = 25
obj.LowNtuWarningOn = false
obj.CapacitorDisplay = 75
obj.ChargeLevel mustEqual 50
obj.LowNtuWarningOn mustEqual 25
obj.LowNtuWarningOn mustEqual false
obj.CapacitorDisplay mustEqual 75
}
@ -116,13 +116,13 @@ class ResourceSiloControlNtuWarningTest extends ActorTest {
}
"Resource silo" should {
"announce low ntu" in {
"announce high ntu" in {
expectNoMsg(1 seconds)
assert(obj.LowNtuWarningOn == 0)
obj.Actor ! ResourceSilo.LowNtuWarning(10)
assert(obj.LowNtuWarningOn == true)
obj.Actor ! ResourceSilo.LowNtuWarning(false)
val reply = probe.receiveOne(500 milliseconds)
assert(obj.LowNtuWarningOn == 10)
assert(obj.LowNtuWarningOn == false)
assert(reply.isInstanceOf[AvatarServiceMessage])
assert(reply.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
assert(reply.asInstanceOf[AvatarServiceMessage]
@ -132,7 +132,7 @@ class ResourceSiloControlNtuWarningTest extends ActorTest {
assert(reply.asInstanceOf[AvatarServiceMessage]
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 47)
assert(reply.asInstanceOf[AvatarServiceMessage]
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 10)
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
}
}
}
@ -154,17 +154,17 @@ class ResourceSiloControlUpdate1Test extends ActorTest {
obj.Owner = bldg
"Resource silo" should {
"update the charge level and capacitor display (report low ntu, power restored)" in {
"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(105)
obj.Actor ! ResourceSilo.UpdateChargeLevel(305)
val reply1 = probe1.receiveOne(500 milliseconds)
val reply2 = probe2.receiveOne(500 milliseconds)
assert(obj.ChargeLevel == 105)
assert(obj.CapacitorDisplay == 1)
assert(obj.ChargeLevel == 305)
assert(obj.CapacitorDisplay == 3)
assert(reply1.isInstanceOf[AvatarServiceMessage])
assert(reply1.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
assert(reply1.asInstanceOf[AvatarServiceMessage]
@ -174,7 +174,7 @@ class ResourceSiloControlUpdate1Test extends ActorTest {
assert(reply1.asInstanceOf[AvatarServiceMessage]
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 45)
assert(reply1.asInstanceOf[AvatarServiceMessage]
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 1)
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 3)
assert(reply2.isInstanceOf[Building.SendMapUpdateToAllClients])
@ -191,7 +191,7 @@ class ResourceSiloControlUpdate1Test extends ActorTest {
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
val reply4 = probe1.receiveOne(500 milliseconds)
assert(obj.LowNtuWarningOn == 1)
assert(obj.LowNtuWarningOn == false)
assert(reply4.isInstanceOf[AvatarServiceMessage])
assert(reply4.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
assert(reply4.asInstanceOf[AvatarServiceMessage]
@ -201,7 +201,7 @@ class ResourceSiloControlUpdate1Test extends ActorTest {
assert(reply4.asInstanceOf[AvatarServiceMessage]
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_type == 47)
assert(reply4.asInstanceOf[AvatarServiceMessage]
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 1)
.actionMessage.asInstanceOf[AvatarAction.PlanetsideAttribute].attribute_value == 0)
}
}
}
@ -228,10 +228,10 @@ class ResourceSiloControlUpdate2Test extends ActorTest {
obj.ChargeLevel = 100
obj.CapacitorDisplay = 1
obj.LowNtuWarningOn = 1
obj.LowNtuWarningOn = true
assert(obj.ChargeLevel == 100)
assert(obj.CapacitorDisplay == 1)
assert(obj.LowNtuWarningOn == 1)
assert(obj.LowNtuWarningOn == true)
obj.Actor ! ResourceSilo.UpdateChargeLevel(105)
val reply1 = probe1.receiveOne(500 milliseconds)
@ -252,7 +252,7 @@ class ResourceSiloControlUpdate2Test extends ActorTest {
assert(reply2.isInstanceOf[Building.SendMapUpdateToAllClients])
val reply3 = probe1.receiveOne(500 milliseconds)
assert(obj.LowNtuWarningOn == 0)
assert(obj.LowNtuWarningOn == false)
assert(reply3.isInstanceOf[AvatarServiceMessage])
assert(reply3.asInstanceOf[AvatarServiceMessage].forChannel == "nowhere")
assert(reply3.asInstanceOf[AvatarServiceMessage]
@ -289,10 +289,10 @@ class ResourceSiloControlNoUpdateTest extends ActorTest {
obj.ChargeLevel = 250
obj.CapacitorDisplay = 3
obj.LowNtuWarningOn = 0
obj.LowNtuWarningOn = false
assert(obj.ChargeLevel == 250)
assert(obj.CapacitorDisplay == 3)
assert(obj.LowNtuWarningOn == 0)
assert(obj.LowNtuWarningOn == false)
obj.Actor ! ResourceSilo.UpdateChargeLevel(50)
expectNoMsg(500 milliseconds)
@ -300,7 +300,7 @@ class ResourceSiloControlNoUpdateTest extends ActorTest {
probe2.expectNoMsg(500 milliseconds)
assert(obj.ChargeLevel == 300)
assert(obj.CapacitorDisplay == 3)
assert(obj.LowNtuWarningOn == 0)
assert(obj.LowNtuWarningOn == false)
}
}
}

View file

@ -4856,7 +4856,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
// Synchronise warning light & silo capacity
var silo = amenity.asInstanceOf[ResourceSilo]
sendResponse(PlanetsideAttributeMessage(amenityId, 45, silo.CapacitorDisplay))
sendResponse(PlanetsideAttributeMessage(amenityId, 47, silo.LowNtuWarningOn))
sendResponse(PlanetsideAttributeMessage(amenityId, 47, if(silo.LowNtuWarningOn) 1 else 0))
if(silo.ChargeLevel == 0) {
// temporarily disabled until warpgates can bring ANTs from sanctuary, otherwise we'd be stuck in a situation with an unpowered base and no way to get an ANT to refill it.