working medical terminal and stubs for other proximity-based terminal operations

This commit is contained in:
FateJH 2018-04-18 11:56:26 -04:00
parent d8fe6bab28
commit 29cf59775a
10 changed files with 253 additions and 3 deletions

View file

@ -515,6 +515,14 @@ object GlobalDefinitions {
val respawn_tube_tower = new SpawnTubeDefinition(733)
val adv_med_terminal = new MedicalTerminalDefinition(38)
val crystals_health_a = new MedicalTerminalDefinition(225)
val crystals_health_b = new MedicalTerminalDefinition(226)
val medical_terminal = new MedicalTerminalDefinition(529)
val spawn_pad = new VehicleSpawnPadDefinition
val mb_locker = new LockerDefinition

View file

@ -0,0 +1,28 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.serverobject.terminals
import net.psforever.objects.Player
import net.psforever.packet.game.ItemTransactionMessage
class MedicalTerminalDefinition(objectId : Int) extends TerminalDefinition(objectId) {
Name = if(objectId == 38) {
"adv_med_terminal"
}
else if(objectId == 225) {
"crystals_health_a"
}
else if(objectId == 226) {
"crystals_health_b"
}
else if(objectId == 529) {
"medical_terminal"
}
else if(objectId == 689) {
"portable_med_terminal"
}
else {
throw new IllegalArgumentException("terminal must be either object id 38, object id 529, or object id 689")
}
def Buy(player : Player, msg : ItemTransactionMessage) : Terminal.Exchange = Terminal.NoDeal()
}

View file

@ -0,0 +1,50 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.serverobject.terminals
import net.psforever.objects.Player
import net.psforever.packet.game.PlanetSideGUID
class ProximityTerminal(tdef : TerminalDefinition) extends Terminal(tdef) {
private var users : Set[PlanetSideGUID] = Set.empty
def NumberUsers : Int = users.size
def AddUser(player_guid : PlanetSideGUID) : Int = {
users += player_guid
NumberUsers
}
def RemoveUser(player_guid : PlanetSideGUID) : Int = {
users -= player_guid
NumberUsers
}
}
object ProximityTerminal {
final case class Use(player : Player)
final case class Unuse(player : Player)
/**
* Overloaded constructor.
* @param tdef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields
*/
def apply(tdef : TerminalDefinition) : ProximityTerminal = {
new ProximityTerminal(tdef)
}
import akka.actor.ActorContext
/**
* Instantiate an configure a `Terminal` object
* @param tdef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields
* @param id the unique id that will be assigned to this entity
* @param context a context to allow the object to properly set up `ActorSystem` functionality
* @return the `Terminal` object
*/
def Constructor(tdef : TerminalDefinition)(id : Int, context : ActorContext) : Terminal = {
import akka.actor.Props
val obj = ProximityTerminal(tdef)
obj.Actor = context.actorOf(Props(classOf[ProximityTerminalControl], obj), s"${tdef.Name}_$id")
obj
}
}

View file

@ -0,0 +1,29 @@
// Copyright (c) 2017 PSForever
package net.psforever.objects.serverobject.terminals
import akka.actor.Actor
import net.psforever.objects.serverobject.affinity.{FactionAffinity, FactionAffinityBehavior}
import net.psforever.objects.serverobject.terminals.Terminal.TerminalMessage
class ProximityTerminalControl(term : ProximityTerminal) extends Actor with FactionAffinityBehavior.Check {
def FactionObject : FactionAffinity = term
def receive : Receive = checkBehavior.orElse {
case ProximityTerminal.Use(player) =>
val hadNoUsers = term.NumberUsers == 0
if(term.AddUser(player.GUID) == 1 && hadNoUsers) {
sender ! TerminalMessage(player, null, Terminal.StartProximityEffect(term))
}
case ProximityTerminal.Unuse(player) =>
val hadUsers = term.NumberUsers > 0
if(term.RemoveUser(player.GUID) == 0 && hadUsers) {
sender ! TerminalMessage(player, null, Terminal.StopProximityEffect(term))
}
case _ =>
sender ! Terminal.NoDeal()
}
override def toString : String = term.Definition.Name
}

View file

@ -190,6 +190,10 @@ object Terminal {
*/
final case class InfantryLoadout(exosuit : ExoSuitType.Value, subtype : Int = 0, holsters : List[InventoryItem], inventory : List[InventoryItem]) extends Exchange
final case class StartProximityEffect(terminal : ProximityTerminal) extends Exchange
final case class StopProximityEffect(terminal : ProximityTerminal) extends Exchange
/**
* Overloaded constructor.
* @param tdef the `ObjectDefinition` that constructs this object and maintains some of its immutable fields