From ca8d72cc4cfec4f8ad3f242055145622dc08a9ae Mon Sep 17 00:00:00 2001 From: Mazo Date: Mon, 11 Jun 2018 18:27:28 +0100 Subject: [PATCH] Added correct sounds for hacking terminals/lockers & consolidated FinishHacking function Wait for target actor to set HackedBy property before sending LocalAction.HackTemporarily to fix crash when run in the wrong order --- .../serverobject/hackable/Hackable.scala | 10 +++- .../objects/serverobject/locks/IFFLock.scala | 2 + .../serverobject/locks/IFFLockControl.scala | 2 +- .../serverobject/mblocker/Locker.scala | 2 + .../serverobject/mblocker/LockerControl.scala | 2 +- .../terminals/ProximityTerminalControl.scala | 2 +- .../serverobject/terminals/Terminal.scala | 6 +-- .../terminals/TerminalControl.scala | 2 +- .../packet/game/TriggerSoundMessage.scala | 4 +- .../src/main/scala/WorldSessionActor.scala | 54 ++++++------------- 10 files changed, 38 insertions(+), 48 deletions(-) diff --git a/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala b/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala index 1ffb34f6f..ef5bbd3f3 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/hackable/Hackable.scala @@ -1,13 +1,15 @@ package net.psforever.objects.serverobject.hackable import net.psforever.objects.Player -import net.psforever.packet.game.PlanetSideGUID +import net.psforever.packet.game.{PlanetSideGUID, TriggeredSound} import net.psforever.types.Vector3 trait Hackable { /** An entry that maintains a reference to the `Player`, and the player's GUID and location when the message was received. */ private var hackedBy : Option[(Player, PlanetSideGUID, Vector3)] = None + private var hackSound : TriggeredSound.Value = TriggeredSound.HackDoor + def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent)) @@ -38,4 +40,10 @@ trait Hackable { } HackedBy } + + def HackSound : TriggeredSound.Value = hackSound + def HackSound_=(sound : TriggeredSound.Value) : TriggeredSound.Value = { + hackSound = sound + hackSound + } } diff --git a/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala b/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala index b22ae76db..6c21bdc41 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLock.scala @@ -3,6 +3,7 @@ package net.psforever.objects.serverobject.locks import net.psforever.objects.serverobject.hackable.Hackable import net.psforever.objects.serverobject.structures.Amenity +import net.psforever.packet.game.TriggeredSound /** * A structure-owned server object that is a "door lock."
@@ -15,6 +16,7 @@ import net.psforever.objects.serverobject.structures.Amenity */ class IFFLock(private val idef : IFFLockDefinition) extends Amenity with Hackable { def Definition : IFFLockDefinition = idef + HackSound = TriggeredSound.HackDoor } object IFFLock { diff --git a/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLockControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLockControl.scala index 0af058115..960a1c3c5 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLockControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/locks/IFFLockControl.scala @@ -16,7 +16,7 @@ class IFFLockControl(lock : IFFLock) extends Actor with FactionAffinityBehavior. def receive : Receive = checkBehavior.orElse { case CommonMessages.Hack(player) => lock.HackedBy = player - + sender ! true case CommonMessages.ClearHack() => lock.HackedBy = None diff --git a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala index 39906ac74..c91c787d3 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/Locker.scala @@ -5,9 +5,11 @@ import akka.actor.{ActorContext, Props} import net.psforever.objects.GlobalDefinitions import net.psforever.objects.serverobject.hackable.Hackable import net.psforever.objects.serverobject.structures.Amenity +import net.psforever.packet.game.TriggeredSound class Locker extends Amenity with Hackable { def Definition : LockerDefinition = GlobalDefinitions.mb_locker + HackSound = TriggeredSound.HackTerminal } object Locker { diff --git a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala index 75df57309..7bced8d81 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/mblocker/LockerControl.scala @@ -15,7 +15,7 @@ class LockerControl(locker : Locker) extends Actor with FactionAffinityBehavior. def receive : Receive = checkBehavior.orElse { case CommonMessages.Hack(player) => locker.HackedBy = player - + sender ! true case CommonMessages.ClearHack() => locker.HackedBy = None case _ => ; diff --git a/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala index 540da72b1..fcc8c073a 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/terminals/ProximityTerminalControl.scala @@ -21,7 +21,7 @@ class ProximityTerminalControl(term : Terminal with ProximityUnit) extends Actor .orElse { case CommonMessages.Hack(player) => term.HackedBy = player - + sender ! true case CommonMessages.ClearHack() => term.HackedBy = None case _ => ; diff --git a/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala b/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala index 03323cc50..61f587e79 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/terminals/Terminal.scala @@ -5,15 +5,15 @@ import net.psforever.objects.Player import net.psforever.objects.definition.VehicleDefinition import net.psforever.objects.serverobject.hackable.Hackable import net.psforever.objects.serverobject.structures.Amenity -import net.psforever.packet.game.{ItemTransactionMessage} -import net.psforever.types.{TransactionType} +import net.psforever.packet.game.{ItemTransactionMessage, TriggeredSound} +import net.psforever.types.TransactionType /** * A structure-owned server object that is a "terminal" that can be accessed for amenities and services. * @param tdef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields */ class Terminal(tdef : TerminalDefinition) extends Amenity with Hackable { - + HackSound = TriggeredSound.HackTerminal //the following fields and related methods are neither finalized nor integrated; GOTO Request private var health : Int = 100 //TODO not real health value diff --git a/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala b/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala index e226fad6b..7474706c9 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/terminals/TerminalControl.scala @@ -18,7 +18,7 @@ class TerminalControl(term : Terminal) extends Actor with FactionAffinityBehavio case CommonMessages.Hack(player) => term.HackedBy = player - + sender ! true case CommonMessages.ClearHack() => term.HackedBy = None diff --git a/common/src/main/scala/net/psforever/packet/game/TriggerSoundMessage.scala b/common/src/main/scala/net/psforever/packet/game/TriggerSoundMessage.scala index 24cc5fa92..68bda057f 100644 --- a/common/src/main/scala/net/psforever/packet/game/TriggerSoundMessage.scala +++ b/common/src/main/scala/net/psforever/packet/game/TriggerSoundMessage.scala @@ -16,8 +16,8 @@ object TriggeredSound extends Enumeration { val SpawnInTube, - Unknown1, - Hack, + HackTerminal, + HackVehicle, HackDoor, Unknown4, LockedOut, diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index 1372b856b..5ecd81c67 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -45,8 +45,10 @@ import services.vehicle.VehicleAction.UnstowEquipment import services.vehicle.{VehicleAction, VehicleResponse, VehicleServiceMessage, VehicleServiceResponse} import scala.annotation.tailrec +import scala.concurrent.Future import scala.concurrent.duration._ import scala.util.Success +import akka.pattern.ask class WorldSessionActor extends Actor with MDCContextAware { import WorldSessionActor._ @@ -2469,7 +2471,7 @@ class WorldSessionActor extends Actor with MDCContextAware { case Some(tool : SimpleItem) => if(tool.Definition == GlobalDefinitions.remote_electronics_kit) { progressBarValue = Some(-GetPlayerHackSpeed()) - self ! WorldSessionActor.ItemHacking(player, panel, tool.GUID, GetPlayerHackSpeed(), FinishHackingDoor(panel, 1114636288L)) + self ! WorldSessionActor.ItemHacking(player, panel, tool.GUID, GetPlayerHackSpeed(), FinishHacking(panel, 1114636288L)) log.info("Hacking a door~") } case _ => ; @@ -2531,7 +2533,7 @@ class WorldSessionActor extends Actor with MDCContextAware { case Some(tool: SimpleItem) => if (tool.Definition == GlobalDefinitions.remote_electronics_kit) { progressBarValue = Some(-GetPlayerHackSpeed()) - self ! WorldSessionActor.ItemHacking(player, obj, tool.GUID, GetPlayerHackSpeed(), FinishHackingLocker(obj, 3212836864L)) + self ! WorldSessionActor.ItemHacking(player, obj, tool.GUID, GetPlayerHackSpeed(), FinishHacking(obj, 3212836864L)) log.info("Hacking a locker") } case _ => ; @@ -2607,7 +2609,7 @@ class WorldSessionActor extends Actor with MDCContextAware { case Some(tool: SimpleItem) => if (tool.Definition == GlobalDefinitions.remote_electronics_kit) { progressBarValue = Some(-GetPlayerHackSpeed()) - self ! WorldSessionActor.ItemHacking(player, obj, tool.GUID, GetPlayerHackSpeed(), FinishHackingTerminal(obj, 3212836864L)) + self ! WorldSessionActor.ItemHacking(player, obj, tool.GUID, GetPlayerHackSpeed(), FinishHacking(obj, 3212836864L)) log.info("Hacking a terminal") } case _ => ; @@ -3433,47 +3435,23 @@ class WorldSessionActor extends Actor with MDCContextAware { } /** - * The process of hacking the `Door` `IFFLock` is completed. - * Pass the message onto the lock and onto the local events system. - * @param target the `IFFLock` belonging to the door that is being hacked + * The process of hacking an object is completed + * Pass the message onto the hackable object and onto the local events system. + * @param target the `Hackable` object that has been hacked * @param unk na; - * used by `HackingMessage` as `unk5` + * used by `HackMessage` as `unk5` * @see `HackMessage` */ //TODO add params here depending on which params in HackMessage are important - private def FinishHackingDoor(target : IFFLock, unk : Long)() : Unit = { - target.Actor ! CommonMessages.Hack(player) - localService ! LocalServiceMessage(continent.Id, LocalAction.TriggerSound(player.GUID, TriggeredSound.HackDoor, player.Position, 30, 0.49803925f)) + private def FinishHacking(target : PlanetSideServerObject with Hackable, unk : Long)() : Unit = { + // Wait for the target actor to set the HackedBy property, otherwise LocalAction.HackTemporarily will not complete properly + import scala.concurrent.ExecutionContext.Implicits.global + ask(target.Actor, CommonMessages.Hack(player))(1 second).mapTo[Boolean].onComplete { + case Success(_) => + localService ! LocalServiceMessage(continent.Id, LocalAction.TriggerSound(player.GUID, target.HackSound, player.Position, 30, 0.49803925f)) localService ! LocalServiceMessage(continent.Id, LocalAction.HackTemporarily(player.GUID, continent, target, unk)) + case scala.util.Failure(_) => log.warn(s"Hack message failed on target guid: ${target.GUID}") } - - /** - * The process of hacking a terminal - * Pass the message onto the terminal and onto the local events system. - * @param target the `terminal` being hacked - * @param unk na; - * used by `HackingMessage` as `unk5` - * @see `HackMessage` - */ - //TODO add params here depending on which params in HackMessage are important - private def FinishHackingTerminal(target : Terminal, unk : Long)() : Unit = { - target.Actor ! CommonMessages.Hack(player) - localService ! LocalServiceMessage(continent.Id, LocalAction.TriggerSound(player.GUID, TriggeredSound.HackDoor, player.Position, 30, 0.49803925f)) - localService ! LocalServiceMessage(continent.Id, LocalAction.HackTemporarily(player.GUID, continent, target, unk)) - } - - /** - * The process of hacking a locker - * Pass the message onto the locker and onto the local events system. - * @param target the `locker` being hacked - * @param unk na; - * used by `HackingMessage` as `unk5` - * @see `HackMessage` - */ - private def FinishHackingLocker(target : Locker, unk : Long)() : Unit = { - target.Actor ! CommonMessages.Hack(player) - localService ! LocalServiceMessage(continent.Id, LocalAction.TriggerSound(player.GUID, TriggeredSound.HackDoor, player.Position, 30, 0.49803925f)) - localService ! LocalServiceMessage(continent.Id, LocalAction.HackTemporarily(player.GUID, continent, target, unk)) }