set up rudimentary certification and implant list-building calls in AvatarConverter, as supported by (existing) data structures in Player

This commit is contained in:
FateJH 2017-09-06 19:40:52 -04:00
parent 69af5124ba
commit 976c31da2b
4 changed files with 52 additions and 12 deletions

View file

@ -54,7 +54,7 @@ class ImplantSlot {
} }
object ImplantSlot { object ImplantSlot {
private val default = new Implant(ImplantDefinition(ImplantType.RangeMagnifier)) private val default = new Implant(ImplantDefinition(ImplantType.None))
def apply() : ImplantSlot = { def apply() : ImplantSlot = {
new ImplantSlot() new ImplantSlot()

View file

@ -8,6 +8,7 @@ import net.psforever.packet.game.PlanetSideGUID
import net.psforever.types._ import net.psforever.types._
import scala.annotation.tailrec import scala.annotation.tailrec
import scala.collection.mutable
class Player(private val name : String, class Player(private val name : String,
private val faction : PlanetSideEmpire.Value, 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 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 val implants : Array[ImplantSlot] = Array.fill[ImplantSlot](3)(new ImplantSlot)
// private var tosRibbon : MeritCommendation.Value = MeritCommendation.None // private var tosRibbon : MeritCommendation.Value = MeritCommendation.None
@ -312,6 +316,22 @@ class Player(private val name : String,
exosuit = suit 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 Implants : Array[ImplantSlot] = implants
def Implant(slot : Int) : Option[ImplantType.Value] = { def Implant(slot : Int) : Option[ImplantType.Value] = {

View file

@ -3,8 +3,8 @@ package net.psforever.objects.definition.converter
import net.psforever.objects.{EquipmentSlot, Player} import net.psforever.objects.{EquipmentSlot, Player}
import net.psforever.objects.equipment.Equipment 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.packet.game.objectcreate.{BasicCharacterData, CharacterAppearanceData, CharacterData, DetailedCharacterData, DrawnSlot, ImplantEntry, InternalSlot, InventoryData, PlacementData, RibbonBars, UniformStyle}
import net.psforever.types.GrenadeState import net.psforever.types.{GrenadeState, ImplantType}
import scala.annotation.tailrec import scala.annotation.tailrec
import scala.util.{Success, Try} import scala.util.{Success, Try}
@ -28,26 +28,24 @@ class AvatarConverter extends ObjectCreateConverter[Player]() {
} }
override def DetailedConstructorData(obj : Player) : Try[DetailedCharacterData] = { override def DetailedConstructorData(obj : Player) : Try[DetailedCharacterData] = {
import net.psforever.types.CertificationType._
Success( Success(
DetailedCharacterData( DetailedCharacterData(
MakeAppearanceData(obj), MakeAppearanceData(obj),
0L, obj.BEP,
0L, obj.CEP,
obj.MaxHealth, obj.MaxHealth,
obj.Health, obj.Health,
obj.Armor, obj.Armor,
obj.MaxStamina, obj.MaxStamina,
obj.Stamina, obj.Stamina,
List(StandardAssault, MediumAssault, ATV, Harasser, StandardExoSuit, AgileExoSuit, ReinforcedExoSuit), //TODO certification list obj.Certifications.toList.sortBy(_.id),
List(), //TODO implant list MakeImplantEntries(obj),
List.empty[String], //TODO fte list List.empty[String], //TODO fte list
List.empty[String], //TODO tutorial list List.empty[String], //TODO tutorial list
InventoryData((MakeHolsters(obj, BuildDetailedEquipment) ++ MakeFifthSlot(obj) ++ MakeInventory(obj)).sortBy(_.parentSlot)), InventoryData((MakeHolsters(obj, BuildDetailedEquipment) ++ MakeFifthSlot(obj) ++ MakeInventory(obj)).sortBy(_.parentSlot)),
GetDrawnSlot(obj) GetDrawnSlot(obj)
) )
) )
//TODO tidy this mess up
} }
/** /**
@ -66,8 +64,8 @@ class AvatarConverter extends ObjectCreateConverter[Player]() {
"", "",
0, 0,
obj.isBackpack, obj.isBackpack,
obj.Orientation.y.toInt, obj.Orientation.y,
obj.FacingYawUpper.toInt, obj.FacingYawUpper,
true, true,
GrenadeState.None, GrenadeState.None,
false, 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. * 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. * The inventory is not represented in a `0x17` `Player`, so the conversion is only valid for `0x18` avatars.

View file

@ -12,7 +12,7 @@ import scala.annotation.tailrec
/** /**
* An entry in the `List` of valid implant slots in `DetailedCharacterData`. * 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 implant the type of implant
* @param activation the activation timer * @param activation the activation timer
* @see `ImplantType` * @see `ImplantType`