mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-01-19 18:44:45 +00:00
Merge pull request #113 from Fate-JH/zipline-update
Update: ZipLineMessage
This commit is contained in:
commit
e84e9d47e6
|
|
@ -1,11 +1,10 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package net.psforever.packet.game
|
||||
|
||||
import net.psforever.newcodecs.newcodecs
|
||||
import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket}
|
||||
import net.psforever.types.Vector3
|
||||
import scodec.Codec
|
||||
import scodec.codecs._
|
||||
import shapeless.{::, HNil}
|
||||
|
||||
/**
|
||||
* Dispatched by the client when the player is interacting with a zip line.
|
||||
|
|
@ -20,17 +19,14 @@ import shapeless.{::, HNil}
|
|||
* @param origin_side whether this corresponds with the "entry" or the "exit" of the zip line, as per the direction of the light pulse visuals
|
||||
* @param action how the player interacts with the zip line
|
||||
* @param guid a number that is consistent to a terminus
|
||||
* @param x the x-coordinate of the point where the player is interacting with the zip line
|
||||
* @param y the y-coordinate of the point where the player is interacting with the zip line
|
||||
* @param z the z-coordinate of the point where the player is interacting with the zip line
|
||||
* @param pos the coordinates of the point where the player is interacting with the zip line;
|
||||
* "optional," in theory
|
||||
*/
|
||||
final case class ZipLineMessage(player_guid : PlanetSideGUID,
|
||||
origin_side : Boolean,
|
||||
action : Int,
|
||||
guid : Long,
|
||||
x : Float,
|
||||
y : Float,
|
||||
z : Float)
|
||||
pos : Option[Vector3] = None)
|
||||
extends PlanetSideGamePacket {
|
||||
type Packet = ZipLineMessage
|
||||
def opcode = GamePacketOpcode.ZipLineMessage
|
||||
|
|
@ -38,37 +34,25 @@ final case class ZipLineMessage(player_guid : PlanetSideGUID,
|
|||
}
|
||||
|
||||
object ZipLineMessage extends Marshallable[ZipLineMessage] {
|
||||
type threeFloatsPattern = Float :: Float :: Float :: HNil
|
||||
|
||||
/**
|
||||
* A `Codec` for when three `Float` values are to be read or written.
|
||||
* Alternate constructor for `ZipLineMessage` that requirement for the last field.
|
||||
* @param player_guid the player
|
||||
* @param origin_side whether this corresponds with the "entry" or the "exit" of the zip line, as per the direction of the light pulse visuals
|
||||
* @param action how the player interacts with the zip line
|
||||
* @param guid a number that is consistent to a terminus
|
||||
* @param pos the coordinates of the point where the player is interacting with the zip line
|
||||
* @return a `ZipLineMessage` object
|
||||
*/
|
||||
val threeFloatValues : Codec[threeFloatsPattern] = (
|
||||
("x" | floatL) ::
|
||||
("y" | floatL) ::
|
||||
("z" | floatL)
|
||||
).as[threeFloatsPattern]
|
||||
|
||||
/**
|
||||
* A `Codec` for when there are no extra `Float` values present.
|
||||
*/
|
||||
val noFloatValues : Codec[threeFloatsPattern] = ignore(0).xmap[threeFloatsPattern] (
|
||||
{
|
||||
case () =>
|
||||
0f :: 0f :: 0f :: HNil
|
||||
},
|
||||
{
|
||||
case _ =>
|
||||
()
|
||||
}
|
||||
)
|
||||
def apply(player_guid : PlanetSideGUID, origin_side : Boolean, action : Int, guid : Long, pos : Vector3) : ZipLineMessage = {
|
||||
ZipLineMessage(player_guid, origin_side, action, guid, Some(pos))
|
||||
}
|
||||
|
||||
implicit val codec : Codec[ZipLineMessage] = (
|
||||
("player_guid" | PlanetSideGUID.codec) >>:~ { player =>
|
||||
("origin_side" | bool) ::
|
||||
("action" | uint2) ::
|
||||
("id" | uint32L) ::
|
||||
newcodecs.binary_choice(player.guid > 0, threeFloatValues, noFloatValues) // !(player.guid == 0)
|
||||
conditional(player.guid > 0, Vector3.codec_float) // !(player.guid == 0)
|
||||
}
|
||||
).as[ZipLineMessage]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package game
|
|||
import org.specs2.mutable._
|
||||
import net.psforever.packet._
|
||||
import net.psforever.packet.game._
|
||||
import net.psforever.types.Vector3
|
||||
import scodec.bits._
|
||||
|
||||
class ZipLineMessageTest extends Specification {
|
||||
|
|
@ -11,21 +12,22 @@ class ZipLineMessageTest extends Specification {
|
|||
|
||||
"decode" in {
|
||||
PacketCoding.DecodePacket(string).require match {
|
||||
case ZipLineMessage(player_guid, origin_side, action, uid, x, y, z) =>
|
||||
case ZipLineMessage(player_guid, origin_side, action, uid, pos) =>
|
||||
player_guid mustEqual PlanetSideGUID(75)
|
||||
origin_side mustEqual false
|
||||
action mustEqual 0
|
||||
uid mustEqual 204
|
||||
x mustEqual 1286.9221f
|
||||
y mustEqual 1116.5276f
|
||||
z mustEqual 91.74034f
|
||||
pos.isDefined mustEqual true
|
||||
pos.get.x mustEqual 1286.9221f
|
||||
pos.get.y mustEqual 1116.5276f
|
||||
pos.get.z mustEqual 91.74034f
|
||||
case _ =>
|
||||
ko
|
||||
}
|
||||
}
|
||||
|
||||
"encode" in {
|
||||
val msg = ZipLineMessage(PlanetSideGUID(75), false, 0, 204, 1286.9221f, 1116.5276f, 91.74034f)
|
||||
val msg = ZipLineMessage(PlanetSideGUID(75), false, 0, 204, Vector3(1286.9221f, 1116.5276f, 91.74034f))
|
||||
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||
|
||||
pkt mustEqual string
|
||||
|
|
|
|||
|
|
@ -291,11 +291,11 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
case msg @ AvatarJumpMessage(state) =>
|
||||
//log.info("AvatarJump: " + msg)
|
||||
|
||||
case msg @ ZipLineMessage(player_guid,origin_side,action,id,x,y,z) =>
|
||||
case msg @ ZipLineMessage(player_guid,origin_side,action,id,pos) =>
|
||||
log.info("ZipLineMessage: " + msg)
|
||||
if(action == 0) {
|
||||
//doing this lets you use the zip line, but you can't get off
|
||||
//sendResponse(PacketCoding.CreateGamePacket(0,ZipLineMessage(player_guid, origin_side, action, id, x,y,z)))
|
||||
//sendResponse(PacketCoding.CreateGamePacket(0,ZipLineMessage(player_guid, origin_side, action, id, pos)))
|
||||
}
|
||||
else if(action == 1) {
|
||||
//disembark from zipline at destination?
|
||||
|
|
|
|||
Loading…
Reference in a new issue