From 976c31da2bbd4e1662aad6692813292d0b1bc536 Mon Sep 17 00:00:00 2001 From: FateJH Date: Wed, 6 Sep 2017 19:40:52 -0400 Subject: [PATCH] set up rudimentary certification and implant list-building calls in AvatarConverter, as supported by (existing) data structures in Player --- .../net/psforever/objects/ImplantSlot.scala | 2 +- .../scala/net/psforever/objects/Player.scala | 20 ++++++++++ .../converter/AvatarConverter.scala | 40 ++++++++++++++----- .../objectcreate/DetailedCharacterData.scala | 2 +- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/common/src/main/scala/net/psforever/objects/ImplantSlot.scala b/common/src/main/scala/net/psforever/objects/ImplantSlot.scala index 00951f503..bf6d0b01a 100644 --- a/common/src/main/scala/net/psforever/objects/ImplantSlot.scala +++ b/common/src/main/scala/net/psforever/objects/ImplantSlot.scala @@ -54,7 +54,7 @@ class ImplantSlot { } object ImplantSlot { - private val default = new Implant(ImplantDefinition(ImplantType.RangeMagnifier)) + private val default = new Implant(ImplantDefinition(ImplantType.None)) def apply() : ImplantSlot = { new ImplantSlot() diff --git a/common/src/main/scala/net/psforever/objects/Player.scala b/common/src/main/scala/net/psforever/objects/Player.scala index c2300965f..0873c1c9b 100644 --- a/common/src/main/scala/net/psforever/objects/Player.scala +++ b/common/src/main/scala/net/psforever/objects/Player.scala @@ -8,6 +8,7 @@ import net.psforever.packet.game.PlanetSideGUID import net.psforever.types._ import scala.annotation.tailrec +import scala.collection.mutable class Player(private val name : String, private val faction : PlanetSideEmpire.Value, @@ -33,6 +34,9 @@ class Player(private val name : String, private val loadouts : Array[Option[InfantryLoadout]] = Array.fill[Option[InfantryLoadout]](10)(None) + private var bep : Long = 0 + private var cep : Long = 0 + private val certifications : mutable.Set[CertificationType.Value] = mutable.Set[CertificationType.Value]() private val implants : Array[ImplantSlot] = Array.fill[ImplantSlot](3)(new ImplantSlot) // private var tosRibbon : MeritCommendation.Value = MeritCommendation.None @@ -312,6 +316,22 @@ class Player(private val name : String, exosuit = suit } + def BEP : Long = bep + + def BEP_=(battleExperiencePoints : Long) : Long = { + bep = math.max(0L, math.min(battleExperiencePoints, 4294967295L)) + BEP + } + + def CEP : Long = cep + + def CEP_=(commandExperiencePoints : Long) : Long = { + cep = math.max(0L, math.min(commandExperiencePoints, 4294967295L)) + CEP + } + + def Certifications : mutable.Set[CertificationType.Value] = certifications + def Implants : Array[ImplantSlot] = implants def Implant(slot : Int) : Option[ImplantType.Value] = { diff --git a/common/src/main/scala/net/psforever/objects/definition/converter/AvatarConverter.scala b/common/src/main/scala/net/psforever/objects/definition/converter/AvatarConverter.scala index 6c97c17cf..12e5ee29a 100644 --- a/common/src/main/scala/net/psforever/objects/definition/converter/AvatarConverter.scala +++ b/common/src/main/scala/net/psforever/objects/definition/converter/AvatarConverter.scala @@ -3,8 +3,8 @@ package net.psforever.objects.definition.converter import net.psforever.objects.{EquipmentSlot, Player} import net.psforever.objects.equipment.Equipment -import net.psforever.packet.game.objectcreate.{BasicCharacterData, CharacterAppearanceData, CharacterData, DetailedCharacterData, DrawnSlot, InternalSlot, InventoryData, PlacementData, RibbonBars, UniformStyle} -import net.psforever.types.GrenadeState +import net.psforever.packet.game.objectcreate.{BasicCharacterData, CharacterAppearanceData, CharacterData, DetailedCharacterData, DrawnSlot, ImplantEntry, InternalSlot, InventoryData, PlacementData, RibbonBars, UniformStyle} +import net.psforever.types.{GrenadeState, ImplantType} import scala.annotation.tailrec import scala.util.{Success, Try} @@ -28,26 +28,24 @@ class AvatarConverter extends ObjectCreateConverter[Player]() { } override def DetailedConstructorData(obj : Player) : Try[DetailedCharacterData] = { - import net.psforever.types.CertificationType._ Success( DetailedCharacterData( MakeAppearanceData(obj), - 0L, - 0L, + obj.BEP, + obj.CEP, obj.MaxHealth, obj.Health, obj.Armor, obj.MaxStamina, obj.Stamina, - List(StandardAssault, MediumAssault, ATV, Harasser, StandardExoSuit, AgileExoSuit, ReinforcedExoSuit), //TODO certification list - List(), //TODO implant list + obj.Certifications.toList.sortBy(_.id), + MakeImplantEntries(obj), List.empty[String], //TODO fte list List.empty[String], //TODO tutorial list InventoryData((MakeHolsters(obj, BuildDetailedEquipment) ++ MakeFifthSlot(obj) ++ MakeInventory(obj)).sortBy(_.parentSlot)), GetDrawnSlot(obj) ) ) - //TODO tidy this mess up } /** @@ -66,8 +64,8 @@ class AvatarConverter extends ObjectCreateConverter[Player]() { "", 0, obj.isBackpack, - obj.Orientation.y.toInt, - obj.FacingYawUpper.toInt, + obj.Orientation.y, + obj.FacingYawUpper, true, GrenadeState.None, false, @@ -77,6 +75,28 @@ class AvatarConverter extends ObjectCreateConverter[Player]() { ) } + /** + * Transform an `Array` of `Implant` objects into a `List` of `ImplantEntry` objects suitable as packet data. + * @param obj the `Player` game object + * @return the resulting implant `List` + * @see `ImplantEntry` in `DetailedCharacterData` + */ + private def MakeImplantEntries(obj : Player) : List[ImplantEntry] = { + obj.Implants.map(impl => { + impl.Installed match { + case Some(module) => + if(impl.Implant.get.Ready) { + ImplantEntry(module, None) + } + else { + ImplantEntry(module, Some(impl.Implant.get.Timer.toInt)) + } + case None => + ImplantEntry(ImplantType.None, None) + } + }).toList + } + /** * Given a player with an inventory, convert the contents of that inventory into converted-decoded packet data. * The inventory is not represented in a `0x17` `Player`, so the conversion is only valid for `0x18` avatars. diff --git a/common/src/main/scala/net/psforever/packet/game/objectcreate/DetailedCharacterData.scala b/common/src/main/scala/net/psforever/packet/game/objectcreate/DetailedCharacterData.scala index e678c3f10..cc3663a96 100644 --- a/common/src/main/scala/net/psforever/packet/game/objectcreate/DetailedCharacterData.scala +++ b/common/src/main/scala/net/psforever/packet/game/objectcreate/DetailedCharacterData.scala @@ -12,7 +12,7 @@ import scala.annotation.tailrec /** * An entry in the `List` of valid implant slots in `DetailedCharacterData`. - * `activation`, if defined, indicates the time remaining (in seconds?) before an implant can be activated. + * `activation`, if defined, indicates the time remaining (in seconds?) before an implant becomes usable. * @param implant the type of implant * @param activation the activation timer * @see `ImplantType`