mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-13 19:53:38 +00:00
code documentation and tests
This commit is contained in:
parent
29cf59775a
commit
35ed000ccc
10 changed files with 452 additions and 37 deletions
|
|
@ -2199,7 +2199,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
continent.GUID(object_guid) match {
|
||||
case Some(obj : ProximityTerminal) =>
|
||||
if(usingProximityTerminal.contains(object_guid)) {
|
||||
SelectProximityTerminal(obj)
|
||||
SelectProximityUnit(obj)
|
||||
}
|
||||
else {
|
||||
//obj.Actor ! ProximityTerminal.Use(player)
|
||||
|
|
@ -3637,6 +3637,11 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start using a proximity-base service.
|
||||
* Special note is warranted in the case of a medical terminal or an advanced medical terminal.
|
||||
* @param terminal the proximity-based unit
|
||||
*/
|
||||
def StartUsingProximityUnit(terminal : ProximityTerminal) : Unit = {
|
||||
val term_guid = terminal.GUID
|
||||
if(!usingProximityTerminal.contains(term_guid)) {
|
||||
|
|
@ -3646,10 +3651,15 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
case _ => ;
|
||||
}
|
||||
usingProximityTerminal += term_guid
|
||||
terminal.Actor ! ProximityTerminal.Use(player)
|
||||
terminal.Actor ! CommonMessages.Use(player)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop using a proximity-base service.
|
||||
* Special note is warranted in the case of a medical terminal or an advanced medical terminal.
|
||||
* @param terminal the proximity-based unit
|
||||
*/
|
||||
def StopUsingProximityUnit(terminal : ProximityTerminal) : Unit = {
|
||||
val term_guid = terminal.GUID
|
||||
if(usingProximityTerminal.contains(term_guid)) {
|
||||
|
|
@ -3657,11 +3667,16 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
usingMedicalTerminal = None
|
||||
}
|
||||
usingProximityTerminal -= term_guid
|
||||
terminal.Actor ! ProximityTerminal.Unuse(player)
|
||||
terminal.Actor ! CommonMessages.Unuse(player)
|
||||
}
|
||||
}
|
||||
|
||||
def SelectProximityTerminal(terminal : ProximityTerminal) : Unit = {
|
||||
/**
|
||||
* Determine which functionality to pursue, by being given a generic proximity-functional unit
|
||||
* and determinig which kind of unit is being utilized.
|
||||
* @param terminal the proximity-based unit
|
||||
*/
|
||||
def SelectProximityUnit(terminal : ProximityTerminal) : Unit = {
|
||||
terminal.Definition match {
|
||||
case GlobalDefinitions.adv_med_terminal | GlobalDefinitions.medical_terminal =>
|
||||
ProximityMedicalTerminal(terminal)
|
||||
|
|
@ -3673,47 +3688,72 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When standing on the platform of a(n advanced) medical terminal,
|
||||
* resotre the player's health and armor points (when they need their health and armor points restored).
|
||||
* If the player is both fully healed and fully repaired, stop using the terminal.
|
||||
* @param unit the medical terminal
|
||||
*/
|
||||
def ProximityMedicalTerminal(terminal : ProximityTerminal) : Unit = {
|
||||
val object_guid : PlanetSideGUID = terminal.GUID
|
||||
val healthUp : Boolean = player.Health < player.MaxHealth
|
||||
val armorUp : Boolean = player.Armor < player.MaxArmor
|
||||
if(healthUp || armorUp) {
|
||||
val player_guid = player.GUID
|
||||
val fullHealth = ProximityHeal(player_guid, object_guid)
|
||||
val fullArmor = ProximityArmorRepair(player_guid, object_guid)
|
||||
val fullHealth = HealAction(player)
|
||||
val fullArmor = ArmorRepairAction(player)
|
||||
if(fullHealth && fullArmor) {
|
||||
log.info(s"ProximityTerminal: ${player.Name} is all healed up")
|
||||
log.info(s"${player.Name} is all healed up")
|
||||
StopUsingProximityUnit(terminal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def ProximityHealCrystal(terminal : ProximityTerminal) : Unit = {
|
||||
val object_guid : PlanetSideGUID = terminal.GUID
|
||||
/**
|
||||
* When near a red cavern crystal, resotre the player's health (when they need their health restored).
|
||||
* If the player is fully healed, stop using the crystal.
|
||||
* @param unit the healing crystal
|
||||
*/
|
||||
def ProximityHealCrystal(unit : ProximityTerminal) : Unit = {
|
||||
val healthUp : Boolean = player.Health < player.MaxHealth
|
||||
if(healthUp) {
|
||||
val player_guid = player.GUID
|
||||
if(ProximityHeal(object_guid, player.GUID)) {
|
||||
log.info(s"ProximityTerminal: ${player.Name} is all healed up")
|
||||
StopUsingProximityUnit(terminal)
|
||||
if(HealAction(player)) {
|
||||
log.info(s"${player.Name} is all healed up")
|
||||
StopUsingProximityUnit(unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def ProximityHeal(player_guid : PlanetSideGUID, object_guid : PlanetSideGUID, healValue : Int = 10) : Boolean = {
|
||||
log.info(s"ProximityTerminal: dispensing health to ${player.Name} - <3")
|
||||
player.Health = player.Health + healValue
|
||||
sendResponse(PlanetsideAttributeMessage(player_guid, 0, player.Health))
|
||||
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(player.GUID, 0, player.Health))
|
||||
player.Health == player.MaxHealth
|
||||
/**
|
||||
* Restore, at most, a specific amount of health points on a player.
|
||||
* Send messages to connected client and to events system.
|
||||
* @param tplayer the player
|
||||
* @param repairValue the amount to heal;
|
||||
* 10 by default
|
||||
* @return whether the player can be repaired for any more health points
|
||||
*/
|
||||
def HealAction(tplayer : Player, healValue : Int = 10) : Boolean = {
|
||||
log.info(s"Dispensing health to ${tplayer.Name} - <3")
|
||||
val player_guid = tplayer.GUID
|
||||
tplayer.Health = tplayer.Health + healValue
|
||||
sendResponse(PlanetsideAttributeMessage(player_guid, 0, tplayer.Health))
|
||||
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(player_guid, 0, tplayer.Health))
|
||||
tplayer.Health == tplayer.MaxHealth
|
||||
}
|
||||
|
||||
def ProximityArmorRepair(player_guid : PlanetSideGUID, object_guid : PlanetSideGUID, repairValue : Int = 10) : Boolean = {
|
||||
log.info(s"ProximityTerminal: dispensing armor to ${player.Name} - c[=")
|
||||
player.Armor = player.Armor + repairValue
|
||||
sendResponse(PlanetsideAttributeMessage(player_guid, 4, player.Armor))
|
||||
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(player.GUID, 4, player.Armor))
|
||||
player.Armor == player.MaxArmor
|
||||
/**
|
||||
* Restore, at most, a specific amount of personal armor points on a player.
|
||||
* Send messages to connected client and to events system.
|
||||
* @param tplayer the player
|
||||
* @param repairValue the amount to repair;
|
||||
* 10 by default
|
||||
* @return whether the player can be repaired for any more armor points
|
||||
*/
|
||||
def ArmorRepairAction(tplayer : Player, repairValue : Int = 10) : Boolean = {
|
||||
log.info(s"Dispensing armor to ${tplayer.Name} - c[=")
|
||||
val player_guid = tplayer.GUID
|
||||
tplayer.Armor = tplayer.Armor + repairValue
|
||||
sendResponse(PlanetsideAttributeMessage(player_guid, 4, tplayer.Armor))
|
||||
avatarService ! AvatarServiceMessage(continent.Id, AvatarAction.PlanetsideAttribute(player_guid, 4, tplayer.Armor))
|
||||
tplayer.Armor == tplayer.MaxArmor
|
||||
}
|
||||
|
||||
def failWithError(error : String) = {
|
||||
|
|
|
|||
115
pslogin/src/test/scala/LocalServiceTest.scala
Normal file
115
pslogin/src/test/scala/LocalServiceTest.scala
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
import akka.actor.Props
|
||||
import net.psforever.objects.serverobject.PlanetSideServerObject
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import net.psforever.types.{PlanetSideEmpire, Vector3}
|
||||
import services.Service
|
||||
import services.local._
|
||||
|
||||
class LocalService1Test extends ActorTest {
|
||||
"LocalService" should {
|
||||
"construct" in {
|
||||
system.actorOf(Props[LocalService], "service")
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocalService2Test extends ActorTest {
|
||||
"LocalService" should {
|
||||
"subscribe" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocalService3Test extends ActorTest {
|
||||
"LocalService" should {
|
||||
"subscribe to a specific channel" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! Service.Leave()
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocalService4Test extends ActorTest {
|
||||
"LocalService" should {
|
||||
"subscribe" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! Service.LeaveAll()
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocalService5Test extends ActorTest {
|
||||
"LocalService" should {
|
||||
"pass an unhandled message" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! "hello"
|
||||
expectNoMsg()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DoorClosesTest extends ActorTest {
|
||||
"LocalService" should {
|
||||
"pass DoorCloses" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! LocalServiceMessage("test", LocalAction.DoorCloses(PlanetSideGUID(10), PlanetSideGUID(40)))
|
||||
expectMsg(LocalServiceResponse("/test/Local", PlanetSideGUID(10), LocalResponse.DoorCloses(PlanetSideGUID(40))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HackClearTest extends ActorTest {
|
||||
val obj = new PlanetSideServerObject() {
|
||||
def Faction = PlanetSideEmpire.NEUTRAL
|
||||
def Definition = null
|
||||
GUID = PlanetSideGUID(40)
|
||||
}
|
||||
|
||||
"LocalService" should {
|
||||
"pass HackClear" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! LocalServiceMessage("test", LocalAction.HackClear(PlanetSideGUID(10), obj, 0L, 1000L))
|
||||
expectMsg(LocalServiceResponse("/test/Local", PlanetSideGUID(10), LocalResponse.HackClear(PlanetSideGUID(40), 0L, 1000L)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ProximityTerminalEffectTest extends ActorTest {
|
||||
"LocalService" should {
|
||||
"pass ProximityTerminalEffect" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! LocalServiceMessage("test", LocalAction.ProximityTerminalEffect(PlanetSideGUID(10), PlanetSideGUID(40), true))
|
||||
expectMsg(LocalServiceResponse("/test/Local", PlanetSideGUID(10), LocalResponse.ProximityTerminalEffect(PlanetSideGUID(40), true)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TriggerSoundTest extends ActorTest {
|
||||
import net.psforever.packet.game.TriggeredSound
|
||||
|
||||
"LocalService" should {
|
||||
"pass TriggerSound" in {
|
||||
val service = system.actorOf(Props[LocalService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! LocalServiceMessage("test", LocalAction.TriggerSound(PlanetSideGUID(10), TriggeredSound.LockedOut, Vector3(1.1f, 2.2f, 3.3f), 0, 0.75f))
|
||||
expectMsg(LocalServiceResponse("/test/Local", PlanetSideGUID(10), LocalResponse.TriggerSound(TriggeredSound.LockedOut, Vector3(1.1f, 2.2f, 3.3f), 0, 0.75f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object LocalServiceTest {
|
||||
//decoy
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue