From c9ad65bb9e59505e16dc395d157831522a4002d4 Mon Sep 17 00:00:00 2001 From: FateJH Date: Mon, 6 Mar 2017 23:05:53 -0500 Subject: [PATCH] wrapping the three trailing Floats into a Vector3 object --- .../packet/game/ZipLineMessage.scala | 46 ++++++------------- .../test/scala/game/ZipLineMessageTest.scala | 12 +++-- .../src/main/scala/WorldSessionActor.scala | 4 +- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/common/src/main/scala/net/psforever/packet/game/ZipLineMessage.scala b/common/src/main/scala/net/psforever/packet/game/ZipLineMessage.scala index 447fa400..31ba3ffd 100644 --- a/common/src/main/scala/net/psforever/packet/game/ZipLineMessage.scala +++ b/common/src/main/scala/net/psforever/packet/game/ZipLineMessage.scala @@ -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] } diff --git a/common/src/test/scala/game/ZipLineMessageTest.scala b/common/src/test/scala/game/ZipLineMessageTest.scala index 290a9f24..9dfacd90 100644 --- a/common/src/test/scala/game/ZipLineMessageTest.scala +++ b/common/src/test/scala/game/ZipLineMessageTest.scala @@ -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 diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index 5dc6479e..044739d7 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -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?