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 {
private val default = new Implant(ImplantDefinition(ImplantType.RangeMagnifier))
private val default = new Implant(ImplantDefinition(ImplantType.None))
def apply() : ImplantSlot = {
new ImplantSlot()

View file

@ -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] = {

View file

@ -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.

View file

@ -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`