2017-11-29 22:30:25 -05:00
|
|
|
// Copyright (c) 2017 PSForever
|
|
|
|
|
package objects
|
|
|
|
|
|
2017-12-11 18:17:05 -05:00
|
|
|
import akka.actor.{Actor, ActorRef, Props}
|
2018-07-14 21:25:44 -04:00
|
|
|
import base.ActorTest
|
2018-03-19 20:13:39 -04:00
|
|
|
import net.psforever.objects.{Avatar, Player}
|
2017-11-29 22:30:25 -05:00
|
|
|
import net.psforever.objects.definition.{ObjectDefinition, SeatDefinition}
|
2018-01-26 15:32:08 -05:00
|
|
|
import net.psforever.objects.serverobject.mount.{Mountable, MountableBehavior}
|
2017-11-29 22:30:25 -05:00
|
|
|
import net.psforever.objects.serverobject.PlanetSideServerObject
|
|
|
|
|
import net.psforever.objects.vehicles.Seat
|
2020-01-06 08:45:55 -05:00
|
|
|
import net.psforever.types.{CharacterGender, CharacterVoice, PlanetSideEmpire, PlanetSideGUID}
|
2017-11-29 22:30:25 -05:00
|
|
|
|
|
|
|
|
import scala.concurrent.duration.Duration
|
|
|
|
|
|
2018-07-14 21:25:44 -04:00
|
|
|
class MountableControl1Test extends ActorTest {
|
2017-11-29 22:30:25 -05:00
|
|
|
"MountableControl" should {
|
|
|
|
|
"construct" in {
|
|
|
|
|
val obj = new MountableTest.MountableTestObject
|
|
|
|
|
obj.Actor = system.actorOf(Props(classOf[MountableTest.MountableTestControl], obj), "mech")
|
|
|
|
|
assert(obj.Actor != ActorRef.noSender)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-14 21:25:44 -04:00
|
|
|
class MountableControl2Test extends ActorTest {
|
2017-11-29 22:30:25 -05:00
|
|
|
"MountableControl" should {
|
|
|
|
|
"let a player mount" in {
|
2018-06-08 21:07:47 -04:00
|
|
|
val player = Player(Avatar("test", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
|
2020-07-14 05:54:05 +02:00
|
|
|
val obj = new MountableTest.MountableTestObject
|
2017-11-29 22:30:25 -05:00
|
|
|
obj.Actor = system.actorOf(Props(classOf[MountableTest.MountableTestControl], obj), "mountable")
|
|
|
|
|
val msg = Mountable.TryMount(player, 0)
|
|
|
|
|
|
|
|
|
|
obj.Actor ! msg
|
|
|
|
|
val reply = receiveOne(Duration.create(100, "ms"))
|
|
|
|
|
assert(reply.isInstanceOf[Mountable.MountMessages])
|
|
|
|
|
val reply2 = reply.asInstanceOf[Mountable.MountMessages]
|
|
|
|
|
assert(reply2.player == player)
|
|
|
|
|
assert(reply2.response.isInstanceOf[Mountable.CanMount])
|
|
|
|
|
val reply3 = reply2.response.asInstanceOf[Mountable.CanMount]
|
|
|
|
|
assert(reply3.obj == obj)
|
|
|
|
|
assert(reply3.seat_num == 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-14 21:25:44 -04:00
|
|
|
class MountableControl3Test extends ActorTest {
|
2017-11-29 22:30:25 -05:00
|
|
|
"MountableControl" should {
|
|
|
|
|
"block a player from mounting" in {
|
2018-06-08 21:07:47 -04:00
|
|
|
val player1 = Player(Avatar("test1", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
|
|
|
|
|
val player2 = Player(Avatar("test2", PlanetSideEmpire.TR, CharacterGender.Male, 0, CharacterVoice.Mute))
|
2020-07-14 05:54:05 +02:00
|
|
|
val obj = new MountableTest.MountableTestObject
|
2017-11-29 22:30:25 -05:00
|
|
|
obj.Actor = system.actorOf(Props(classOf[MountableTest.MountableTestControl], obj), "mountable")
|
|
|
|
|
obj.Actor ! Mountable.TryMount(player1, 0)
|
|
|
|
|
receiveOne(Duration.create(100, "ms")) //consume reply
|
|
|
|
|
|
|
|
|
|
obj.Actor ! Mountable.TryMount(player2, 0)
|
|
|
|
|
val reply = receiveOne(Duration.create(100, "ms"))
|
|
|
|
|
assert(reply.isInstanceOf[Mountable.MountMessages])
|
|
|
|
|
val reply2 = reply.asInstanceOf[Mountable.MountMessages]
|
|
|
|
|
assert(reply2.player == player2)
|
|
|
|
|
assert(reply2.response.isInstanceOf[Mountable.CanNotMount])
|
|
|
|
|
val reply3 = reply2.response.asInstanceOf[Mountable.CanNotMount]
|
|
|
|
|
assert(reply3.obj == obj)
|
|
|
|
|
assert(reply3.seat_num == 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object MountableTest {
|
|
|
|
|
class MountableTestObject extends PlanetSideServerObject with Mountable {
|
2020-07-14 05:54:05 +02:00
|
|
|
private val seats: Map[Int, Seat] = Map(0 -> new Seat(new SeatDefinition()))
|
|
|
|
|
def Seats: Map[Int, Seat] = seats
|
|
|
|
|
def Seat(seatNum: Int): Option[Seat] = seats.get(seatNum)
|
|
|
|
|
def MountPoints: Map[Int, Int] = Map(1 -> 0)
|
|
|
|
|
def GetSeatFromMountPoint(mount: Int): Option[Int] = MountPoints.get(mount)
|
|
|
|
|
def PassengerInSeat(user: Player): Option[Int] = {
|
|
|
|
|
if (seats(0).Occupant.contains(user)) {
|
2017-11-29 22:30:25 -05:00
|
|
|
Some(0)
|
2020-07-14 05:54:05 +02:00
|
|
|
} else {
|
2017-11-29 22:30:25 -05:00
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-26 15:32:08 -05:00
|
|
|
GUID = PlanetSideGUID(1)
|
|
|
|
|
//eh whatever
|
2020-07-14 05:54:05 +02:00
|
|
|
def Faction = PlanetSideEmpire.TR
|
|
|
|
|
def Definition: ObjectDefinition = null
|
2017-11-29 22:30:25 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-14 05:54:05 +02:00
|
|
|
class MountableTestControl(obj: PlanetSideServerObject with Mountable)
|
|
|
|
|
extends Actor
|
|
|
|
|
with MountableBehavior.Mount
|
|
|
|
|
with MountableBehavior.Dismount {
|
2017-12-11 18:17:05 -05:00
|
|
|
override def MountableObject = obj
|
|
|
|
|
|
2020-07-14 05:54:05 +02:00
|
|
|
def receive: Receive = mountBehavior.orElse(dismountBehavior)
|
2017-12-11 18:17:05 -05:00
|
|
|
}
|
2017-11-29 22:30:25 -05:00
|
|
|
}
|