Add Hackable trait to all terminals / IFF locks / lockers

This commit is contained in:
Mazo 2018-06-05 19:43:44 +01:00
parent fdf05337fd
commit c6eff22df7
7 changed files with 68 additions and 76 deletions

View file

@ -0,0 +1,41 @@
package net.psforever.objects.serverobject.hackable
import net.psforever.objects.Player
import net.psforever.packet.game.PlanetSideGUID
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
def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy
def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent))
/**
* Set the hack state of this object by recording important information about the player that caused it.
* Set the hack state if there is no current hack state.
* Override the hack state with a new hack state if the new user has different faction affiliation.
* @param agent a `Player`, or no player
* @return the player hack entry
*/
def HackedBy_=(agent : Option[Player]) : Option[(Player, PlanetSideGUID, Vector3)] = {
hackedBy match {
case None =>
//set the hack state if there is no current hack state
if(agent.isDefined) {
hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position)
}
case Some(_) =>
//clear the hack state
if(agent.isEmpty) {
hackedBy = None
}
//override the hack state with a new hack state if the new user has different faction affiliation
else if(agent.get.Faction != hackedBy.get._1.Faction) {
hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position)
}
}
HackedBy
}
}

View file

@ -1,10 +1,8 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.serverobject.locks
import net.psforever.objects.Player
import net.psforever.objects.serverobject.hackable.Hackable
import net.psforever.objects.serverobject.structures.Amenity
import net.psforever.packet.game.PlanetSideGUID
import net.psforever.types.Vector3
/**
* A structure-owned server object that is a "door lock."<br>
@ -15,43 +13,7 @@ import net.psforever.types.Vector3
* The `IFFLock` is ideally associated with a server map object - a `Door` - to which it acts as a gatekeeper.
* @param idef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields
*/
class IFFLock(private val idef : IFFLockDefinition) extends Amenity {
/**
* 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
def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy
def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent))
/**
* Set the hack state of this object by recording important information about the player that caused it.
* Set the hack state if there is no current hack state.
* Override the hack state with a new hack state if the new user has different faction affiliation.
* @param agent a `Player`, or no player
* @return the player hack entry
*/
def HackedBy_=(agent : Option[Player]) : Option[(Player, PlanetSideGUID, Vector3)] = {
hackedBy match {
case None =>
//set the hack state if there is no current hack state
if(agent.isDefined) {
hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position)
}
case Some(_) =>
//clear the hack state
if(agent.isEmpty) {
hackedBy = None
}
//override the hack state with a new hack state if the new user has different faction affiliation
else if(agent.get.Faction != hackedBy.get._1.Faction) {
hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position)
}
}
HackedBy
}
class IFFLock(private val idef : IFFLockDefinition) extends Amenity with Hackable {
def Definition : IFFLockDefinition = idef
}

View file

@ -3,9 +3,10 @@ package net.psforever.objects.serverobject.mblocker
import akka.actor.{ActorContext, Props}
import net.psforever.objects.GlobalDefinitions
import net.psforever.objects.serverobject.hackable.Hackable
import net.psforever.objects.serverobject.structures.Amenity
class Locker extends Amenity {
class Locker extends Amenity with Hackable {
def Definition : LockerDefinition = GlobalDefinitions.mb_locker
}

View file

@ -2,6 +2,7 @@
package net.psforever.objects.serverobject.mblocker
import akka.actor.Actor
import net.psforever.objects.serverobject.CommonMessages
import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior}
/**
@ -12,6 +13,11 @@ class LockerControl(locker : Locker) extends Actor with FactionAffinityBehavior.
def FactionObject : FactionAffinity = locker
def receive : Receive = checkBehavior.orElse {
case CommonMessages.Hack(player) =>
locker.HackedBy = player
case CommonMessages.ClearHack() =>
locker.HackedBy = None
case _ => ;
}
}

View file

@ -2,6 +2,7 @@
package net.psforever.objects.serverobject.terminals
import akka.actor.Actor
import net.psforever.objects.serverobject.CommonMessages
import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior}
/**
@ -18,6 +19,11 @@ class ProximityTerminalControl(term : Terminal with ProximityUnit) extends Actor
def receive : Receive = checkBehavior
.orElse(proximityBehavior)
.orElse {
case CommonMessages.Hack(player) =>
term.HackedBy = player
case CommonMessages.ClearHack() =>
term.HackedBy = None
case _ => ;
}

View file

@ -3,48 +3,17 @@ package net.psforever.objects.serverobject.terminals
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, PlanetSideGUID}
import net.psforever.types.{TransactionType, Vector3}
import net.psforever.packet.game.{ItemTransactionMessage}
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 {
/** 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
class Terminal(tdef : TerminalDefinition) extends Amenity with Hackable {
def HackedBy : Option[(Player, PlanetSideGUID, Vector3)] = hackedBy
def HackedBy_=(agent : Player) : Option[(Player, PlanetSideGUID, Vector3)] = HackedBy_=(Some(agent))
/**
* Set the hack state of this object by recording important information about the player that caused it.
* Set the hack state if there is no current hack state.
* Override the hack state with a new hack state if the new user has different faction affiliation.
* @param agent a `Player`, or no player
* @return the player hack entry
*/
def HackedBy_=(agent : Option[Player]) : Option[(Player, PlanetSideGUID, Vector3)] = {
hackedBy match {
case None =>
//set the hack state if there is no current hack state
if(agent.isDefined) {
hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position)
}
case Some(_) =>
//clear the hack state
if(agent.isEmpty) {
hackedBy = None
}
//override the hack state with a new hack state if the new user has different faction affiliation
else if(agent.get.Faction != hackedBy.get._1.Faction) {
hackedBy = Some(agent.get, agent.get.GUID, agent.get.Position)
}
}
HackedBy
}
//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

@ -2,6 +2,7 @@
package net.psforever.objects.serverobject.terminals
import akka.actor.Actor
import net.psforever.objects.serverobject.CommonMessages
import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior}
/**
@ -15,6 +16,12 @@ class TerminalControl(term : Terminal) extends Actor with FactionAffinityBehavio
case Terminal.Request(player, msg) =>
sender ! Terminal.TerminalMessage(player, msg, term.Request(player, msg))
case CommonMessages.Hack(player) =>
term.HackedBy = player
case CommonMessages.ClearHack() =>
term.HackedBy = None
case _ => ;
}