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
This commit is contained in:
Mazo 2018-06-11 18:27:28 +01:00
parent 9707e88924
commit ca8d72cc4c
10 changed files with 38 additions and 48 deletions

View file

@ -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
}
}

View file

@ -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."<br>
@ -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 {

View file

@ -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

View file

@ -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 {

View file

@ -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 _ => ;

View file

@ -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 _ => ;

View file

@ -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

View file

@ -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

View file

@ -16,8 +16,8 @@ object TriggeredSound extends Enumeration {
val
SpawnInTube,
Unknown1,
Hack,
HackTerminal,
HackVehicle,
HackDoor,
Unknown4,
LockedOut,

View file

@ -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))
}