PSF-LoginServer/src/test/scala/game/PlayerStateShiftMessageTest.scala
Fate-JH 93a544c07c
Collisions (#932)
* pattern for applying damage to player avatar and player-controlled vehicle collisions

* pattern for applying damage to targets due to collisions, falling damage and crashing damage individually; fields to support these calculations are provided

* modifiers to translate 'small step velocity' to real game velocity, as reported by the HUD; corrections for velocity; corrections for velocity in other packets

* fall damage calculations moved to function

* basic two-body collisions between GUID-identified game entities and a ward against too many collisions in a short amount of time

* bailing mechanics

* vssm for non-driven vehicles

* comment about vehicle state message field

* comments and minor refactoring for current collision damage calc; tank_traps modifier; potential fix for blockmap indexing issue

* fixed cargo/carrier vehicle ops

* corrections to initialization of ce construction items; adjustments to handling of modifiers for collision damage

* modifier change, protection against flight speed and spectator crashes; submerged status is once again known only to the actor

* appeasing the automated tests

* hopefully paced collisions better; re-did how Infantry collisions are calculated, incorporating mass and exo-suit data; kill feed reporting should be better

* adjusted damage values again, focusing on the lesser of or middling results; collision killfeed attribution attempt

* kicking offers bail protection; lowered the artificial modifier for one kind of collision damage calculation

* correction to the local reference map functions

* fixed tests; attempt to zero fall damage distance based on velocity; attempt to block mine damage when spectating
2021-10-05 09:59:49 -04:00

83 lines
2.6 KiB
Scala

// Copyright (c) 2017 PSForever
package game
import org.specs2.mutable._
import net.psforever.packet._
import net.psforever.packet.game.{PlayerStateShiftMessage, ShiftState}
import net.psforever.types.Vector3
import scodec.bits._
class PlayerStateShiftMessageTest extends Specification {
val string_short = hex"BE 68"
val string_pos = hex"BE 95 A0 89 13 91 B8 B0 B7 F0" //orig: ... B0 BF F0
val string_posAndVel = hex"BE AE 01 29 CD 59 B9 40 C0 EA D4 00 0F 86 40"
"decode (short)" in {
PacketCoding.decodePacket(string_short).require match {
case PlayerStateShiftMessage(state, unk) =>
state.isDefined mustEqual false
unk.isDefined mustEqual true
unk.get mustEqual 5
case _ =>
ko
}
}
"decode (pos)" in {
PacketCoding.decodePacket(string_pos).require match {
case PlayerStateShiftMessage(state, unk) =>
state.isDefined mustEqual true
state.get.unk mustEqual 1
state.get.pos.x mustEqual 4624.703f
state.get.pos.y mustEqual 5922.1484f
state.get.pos.z mustEqual 46.171875f
state.get.viewYawLim mustEqual 92.8125f
state.get.vel.isDefined mustEqual false
unk.isDefined mustEqual false
case _ =>
ko
}
}
"decode (pos and vel)" in {
PacketCoding.decodePacket(string_posAndVel).require match {
case PlayerStateShiftMessage(state, unk) =>
state.isDefined mustEqual true
state.get.unk mustEqual 2
state.get.pos.x mustEqual 4645.75f
state.get.pos.y mustEqual 5811.6016f
state.get.pos.z mustEqual 50.3125f
state.get.viewYawLim mustEqual 50.625f
state.get.vel.isDefined mustEqual true
state.get.vel.get.x mustEqual 10.125f
state.get.vel.get.y mustEqual -28.8f
state.get.vel.get.z mustEqual 1.3499999f
unk.isDefined mustEqual false
case _ =>
ko
}
}
"encode (short)" in {
val msg = PlayerStateShiftMessage(5)
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
pkt mustEqual string_short
}
"encode (pos)" in {
val msg = PlayerStateShiftMessage(ShiftState(1, Vector3(4624.703f, 5922.1484f, 46.171875f), 92.8125f))
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
pkt mustEqual string_pos
}
"encode (pos and vel)" in {
val msg = PlayerStateShiftMessage(
ShiftState(2, Vector3(4645.75f, 5811.6016f, 50.3125f), 50.625f, Vector3(10.125f, -28.8f, 1.3499999f))
)
val pkt = PacketCoding.encodePacket(msg).require.toByteVector
pkt mustEqual string_posAndVel
}
}