mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-04-26 14:25:21 +00:00
Merge pull request #113 from Fate-JH/zipline-update
Update: ZipLineMessage
This commit is contained in:
commit
e84e9d47e6
3 changed files with 24 additions and 38 deletions
|
|
@ -1,11 +1,10 @@
|
||||||
// Copyright (c) 2017 PSForever
|
// Copyright (c) 2017 PSForever
|
||||||
package net.psforever.packet.game
|
package net.psforever.packet.game
|
||||||
|
|
||||||
import net.psforever.newcodecs.newcodecs
|
|
||||||
import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket}
|
import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket}
|
||||||
|
import net.psforever.types.Vector3
|
||||||
import scodec.Codec
|
import scodec.Codec
|
||||||
import scodec.codecs._
|
import scodec.codecs._
|
||||||
import shapeless.{::, HNil}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatched by the client when the player is interacting with a zip line.
|
* 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 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 action how the player interacts with the zip line
|
||||||
* @param guid a number that is consistent to a terminus
|
* @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 pos the coordinates 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
|
* "optional," in theory
|
||||||
* @param z the z-coordinate of the point where the player is interacting with the zip line
|
|
||||||
*/
|
*/
|
||||||
final case class ZipLineMessage(player_guid : PlanetSideGUID,
|
final case class ZipLineMessage(player_guid : PlanetSideGUID,
|
||||||
origin_side : Boolean,
|
origin_side : Boolean,
|
||||||
action : Int,
|
action : Int,
|
||||||
guid : Long,
|
guid : Long,
|
||||||
x : Float,
|
pos : Option[Vector3] = None)
|
||||||
y : Float,
|
|
||||||
z : Float)
|
|
||||||
extends PlanetSideGamePacket {
|
extends PlanetSideGamePacket {
|
||||||
type Packet = ZipLineMessage
|
type Packet = ZipLineMessage
|
||||||
def opcode = GamePacketOpcode.ZipLineMessage
|
def opcode = GamePacketOpcode.ZipLineMessage
|
||||||
|
|
@ -38,37 +34,25 @@ final case class ZipLineMessage(player_guid : PlanetSideGUID,
|
||||||
}
|
}
|
||||||
|
|
||||||
object ZipLineMessage extends Marshallable[ZipLineMessage] {
|
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] = (
|
def apply(player_guid : PlanetSideGUID, origin_side : Boolean, action : Int, guid : Long, pos : Vector3) : ZipLineMessage = {
|
||||||
("x" | floatL) ::
|
ZipLineMessage(player_guid, origin_side, action, guid, Some(pos))
|
||||||
("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 _ =>
|
|
||||||
()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
implicit val codec : Codec[ZipLineMessage] = (
|
implicit val codec : Codec[ZipLineMessage] = (
|
||||||
("player_guid" | PlanetSideGUID.codec) >>:~ { player =>
|
("player_guid" | PlanetSideGUID.codec) >>:~ { player =>
|
||||||
("origin_side" | bool) ::
|
("origin_side" | bool) ::
|
||||||
("action" | uint2) ::
|
("action" | uint2) ::
|
||||||
("id" | uint32L) ::
|
("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]
|
).as[ZipLineMessage]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ package game
|
||||||
import org.specs2.mutable._
|
import org.specs2.mutable._
|
||||||
import net.psforever.packet._
|
import net.psforever.packet._
|
||||||
import net.psforever.packet.game._
|
import net.psforever.packet.game._
|
||||||
|
import net.psforever.types.Vector3
|
||||||
import scodec.bits._
|
import scodec.bits._
|
||||||
|
|
||||||
class ZipLineMessageTest extends Specification {
|
class ZipLineMessageTest extends Specification {
|
||||||
|
|
@ -11,21 +12,22 @@ class ZipLineMessageTest extends Specification {
|
||||||
|
|
||||||
"decode" in {
|
"decode" in {
|
||||||
PacketCoding.DecodePacket(string).require match {
|
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)
|
player_guid mustEqual PlanetSideGUID(75)
|
||||||
origin_side mustEqual false
|
origin_side mustEqual false
|
||||||
action mustEqual 0
|
action mustEqual 0
|
||||||
uid mustEqual 204
|
uid mustEqual 204
|
||||||
x mustEqual 1286.9221f
|
pos.isDefined mustEqual true
|
||||||
y mustEqual 1116.5276f
|
pos.get.x mustEqual 1286.9221f
|
||||||
z mustEqual 91.74034f
|
pos.get.y mustEqual 1116.5276f
|
||||||
|
pos.get.z mustEqual 91.74034f
|
||||||
case _ =>
|
case _ =>
|
||||||
ko
|
ko
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"encode" in {
|
"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
|
val pkt = PacketCoding.EncodePacket(msg).require.toByteVector
|
||||||
|
|
||||||
pkt mustEqual string
|
pkt mustEqual string
|
||||||
|
|
|
||||||
|
|
@ -291,11 +291,11 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
||||||
case msg @ AvatarJumpMessage(state) =>
|
case msg @ AvatarJumpMessage(state) =>
|
||||||
//log.info("AvatarJump: " + msg)
|
//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)
|
log.info("ZipLineMessage: " + msg)
|
||||||
if(action == 0) {
|
if(action == 0) {
|
||||||
//doing this lets you use the zip line, but you can't get off
|
//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) {
|
else if(action == 1) {
|
||||||
//disembark from zipline at destination?
|
//disembark from zipline at destination?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue