diff --git a/src/main/scala/net/psforever/actors/session/AvatarActor.scala b/src/main/scala/net/psforever/actors/session/AvatarActor.scala index 2f389af9..1aa2c6ca 100644 --- a/src/main/scala/net/psforever/actors/session/AvatarActor.scala +++ b/src/main/scala/net/psforever/actors/session/AvatarActor.scala @@ -442,9 +442,6 @@ class AvatarActor( sessionActor ! SessionActor.SendResponse( PlanetsideAttributeMessage(session.get.player.GUID, 25, cert.value) ) - updateDeployableUIElements( - Deployables.RemoveFromDeployableQuantities(avatar, cert, avatar.certifications) - ) } ctx .run( @@ -462,13 +459,15 @@ class AvatarActor( sessionActor ! SessionActor.SendResponse( PlanetsideAttributeMessage(session.get.player.GUID, 24, certification.value) ) - updateDeployableUIElements( - Deployables.AddToDeployableQuantities(avatar, certification, avatar.certifications) - ) avatar = avatar.copy(certifications = avatar.certifications.diff(replace) + certification) sessionActor ! SessionActor.SendResponse( ItemTransactionResultMessage(terminalGuid, TransactionType.Sell, success = true) ) + + avatar.deployables.UpdateMaxCounts(avatar.certifications) + updateDeployableUIElements( + avatar.deployables.UpdateUI() + ) } } @@ -513,14 +512,15 @@ class AvatarActor( sessionActor ! SessionActor.SendResponse( PlanetsideAttributeMessage(session.get.player.GUID, 25, cert.value) ) - updateDeployableUIElements( - Deployables.RemoveFromDeployableQuantities(avatar, cert, avatar.certifications) - ) } avatar = avatar.copy(certifications = avatar.certifications.diff(remove)) sessionActor ! SessionActor.SendResponse( ItemTransactionResultMessage(terminalGuid, TransactionType.Sell, success = true) ) + avatar.deployables.UpdateMaxCounts(avatar.certifications) + updateDeployableUIElements( + avatar.deployables.UpdateUI() + ) } Behaviors.same @@ -534,9 +534,6 @@ class AvatarActor( sessionActor ! SessionActor.SendResponse( PlanetsideAttributeMessage(session.get.player.GUID, 25, cert.value) ) - updateDeployableUIElements( - Deployables.RemoveFromDeployableQuantities(avatar, cert, avatar.certifications) - ) ctx .run( query[persistence.Certification] @@ -551,9 +548,6 @@ class AvatarActor( sessionActor ! SessionActor.SendResponse( PlanetsideAttributeMessage(session.get.player.GUID, 24, cert.value) ) - updateDeployableUIElements( - Deployables.AddToDeployableQuantities(avatar, cert, avatar.certifications) - ) ctx .run( query[persistence.Certification] @@ -564,6 +558,10 @@ class AvatarActor( .onComplete { case Success(_) => avatar = avatar.copy(certifications = certifications) + avatar.deployables.UpdateMaxCounts(avatar.certifications) + updateDeployableUIElements( + avatar.deployables.UpdateUI() + ) case Failure(exception) => log.error(exception)("db failure") } @@ -1319,7 +1317,7 @@ class AvatarActor( def updateDeployableUIElements(list: List[(Int, Int, Int, Int)]): Unit = { val guid = PlanetSideGUID(0) list.foreach({ - case ((currElem, curr, maxElem, max)) => + case (currElem, curr, maxElem, max) => //fields must update in ordered pairs: max, curr sessionActor ! SessionActor.SendResponse(PlanetsideAttributeMessage(guid, maxElem, max)) sessionActor ! SessionActor.SendResponse(PlanetsideAttributeMessage(guid, currElem, curr)) diff --git a/src/main/scala/net/psforever/objects/Deployables.scala b/src/main/scala/net/psforever/objects/Deployables.scala index 6cb27350..5a12719d 100644 --- a/src/main/scala/net/psforever/objects/Deployables.scala +++ b/src/main/scala/net/psforever/objects/Deployables.scala @@ -141,35 +141,4 @@ object Deployables { avatar.deployables.UpdateUI() } - /** - * The player learned a new certification. - * Update the deployables user interface elements if it was an "Engineering" certification. - * The certification "Advanced Hacking" also relates to an element. - * @param certification the certification that was added - * @param certificationSet all applicable certifications - */ - def AddToDeployableQuantities( - avatar: Avatar, - certification: Certification, - certificationSet: Set[Certification] - ): List[(Int, Int, Int, Int)] = { - avatar.deployables.AddToDeployableQuantities(certification, certificationSet) - avatar.deployables.UpdateUI(certification) - } - - /** - * The player forgot a certification he previously knew. - * Update the deployables user interface elements if it was an "Engineering" certification. - * The certification "Advanced Hacking" also relates to an element. - * @param certification the certification that was added - * @param certificationSet all applicable certifications - */ - def RemoveFromDeployableQuantities( - avatar: Avatar, - certification: Certification, - certificationSet: Set[Certification] - ): List[(Int, Int, Int, Int)] = { - avatar.deployables.RemoveFromDeployableQuantities(certification, certificationSet) - avatar.deployables.UpdateUI(certification) - } } diff --git a/src/main/scala/net/psforever/objects/avatar/DeployableToolbox.scala b/src/main/scala/net/psforever/objects/avatar/DeployableToolbox.scala index e9b05ddd..16b27e72 100644 --- a/src/main/scala/net/psforever/objects/avatar/DeployableToolbox.scala +++ b/src/main/scala/net/psforever/objects/avatar/DeployableToolbox.scala @@ -62,7 +62,7 @@ class DeployableToolbox { */ def Initialize(certifications: Set[Certification]): Boolean = { if (!initialized) { - DeployableToolbox.Initialize(deployableCounts, categoryCounts, certifications) + DeployableToolbox.UpdateMaxCounts(deployableCounts, categoryCounts, certifications) initialized = true true } else { @@ -70,38 +70,10 @@ class DeployableToolbox { } } - /** - * Change the count of deployable units that can be tracked by providing a new certification. - * If the given certification is already factored into the quantities, no changes will occur. - * @param certification the new certification - * @param certificationSet the group of previous certifications being tracked; - * occasionally, important former certification values are required for additional configuration; - * the new certification should already have been added to this group - */ - def AddToDeployableQuantities( - certification: Certification, - certificationSet: Set[Certification] - ): Unit = { - initialized = true - DeployableToolbox.AddToDeployableQuantities(deployableCounts, categoryCounts, certification, certificationSet) + def UpdateMaxCounts(certifications: Set[Certification]) = { + DeployableToolbox.UpdateMaxCounts(deployableCounts, categoryCounts, certifications) } - /** - * Change the count of deployable units that can be tracked - * by designating a certification whose deployables will be removed. - * If the given certification is already factored out of the quantities, no changes will occur. - * @param certification the old certification - * @param certificationSet the group of previous certifications being tracked; - * occasionally, important former certification values are required for additional configuration; - * the new certification should already have been excluded from this group - */ - def RemoveFromDeployableQuantities( - certification: Certification, - certificationSet: Set[Certification] - ): Unit = { - initialized = true - DeployableToolbox.RemoveFromDeployablesQuantities(deployableCounts, categoryCounts, certification, certificationSet) - } /** * Determine if the given deployable can be managed by this toolbox. @@ -473,17 +445,18 @@ object DeployableToolbox { } /** - * Hardcoded maximum values for the category and type initialization. + * Update deployable max counts * @param counts a reference to the type `Bin` object * @param categories a reference to the category `Bin` object * @param certifications a group of certifications for the initial values */ - private def Initialize( + private def UpdateMaxCounts( counts: Map[DeployedItem.Value, DeployableToolbox.Bin], categories: Map[DeployableCategory.Value, DeployableToolbox.Bin], certifications: Set[Certification] ): Unit = { import Certification._ + counts.foreach(_._2.Max = 0) if (certifications.contains(AdvancedEngineering)) { counts(DeployedItem.boomer).Max = 25 counts(DeployedItem.he_mine).Max = 25 @@ -553,162 +526,4 @@ object DeployableToolbox { categories(DeployableCategory.Telepads).Max = 1024 } } - - /** - * Hardcoded maximum values for the category and type initialization upon providing a new certification. - * @param counts a reference to the type `Bin` object - * @param categories a reference to the category `Bin` object - * @param certification the new certification - * @param certificationSet the group of previous certifications being tracked - */ - def AddToDeployableQuantities( - counts: Map[DeployedItem.Value, DeployableToolbox.Bin], - categories: Map[DeployableCategory.Value, DeployableToolbox.Bin], - certification: Certification, - certificationSet: Set[Certification] - ): Unit = { - import Certification._ - if (certificationSet contains certification) { - certification match { - case AdvancedHacking => - if (certificationSet contains CombatEngineering) { - counts(DeployedItem.sensor_shield).Max = 20 - } - - case CombatEngineering => - counts(DeployedItem.boomer).Max = 20 - counts(DeployedItem.he_mine).Max = 20 - counts(DeployedItem.spitfire_turret).Max = 10 - counts(DeployedItem.motionalarmsensor).Max = 20 - categories(DeployableCategory.Boomers).Max = 20 - categories(DeployableCategory.Mines).Max = 20 - categories(DeployableCategory.SmallTurrets).Max = 10 - categories(DeployableCategory.Sensors).Max = 20 - if (certificationSet contains AdvancedHacking) { - counts(DeployedItem.sensor_shield).Max = 20 - } - - case AssaultEngineering => - counts(DeployedItem.jammer_mine).Max = 20 - counts(DeployedItem.portable_manned_turret).Max = 1 //the below turret types are unified - //counts(DeployedItem.portable_manned_turret_nc).Max = 1 - //counts(DeployedItem.portable_manned_turret_tr).Max = 1 - //counts(DeployedItem.portable_manned_turret_vs).Max = 1 - counts(DeployedItem.deployable_shield_generator).Max = 1 - categories(DeployableCategory.FieldTurrets).Max = 1 - categories(DeployableCategory.ShieldGenerators).Max = 1 - - case FortificationEngineering => - counts(DeployedItem.boomer).Max = 25 - counts(DeployedItem.he_mine).Max = 25 - counts(DeployedItem.spitfire_turret).Max = 15 - counts(DeployedItem.motionalarmsensor).Max = 25 - counts(DeployedItem.spitfire_cloaked).Max = 5 - counts(DeployedItem.spitfire_aa).Max = 5 - counts(DeployedItem.tank_traps).Max = 5 - categories(DeployableCategory.Boomers).Max = 25 - categories(DeployableCategory.Mines).Max = 25 - categories(DeployableCategory.SmallTurrets).Max = 15 - categories(DeployableCategory.Sensors).Max = 25 - categories(DeployableCategory.TankTraps).Max = 5 - - case AdvancedEngineering => - if (!certificationSet.contains(AssaultEngineering)) { - AddToDeployableQuantities( - counts, - categories, - AssaultEngineering, - certificationSet ++ Set(AssaultEngineering) - ) - } - if (!certificationSet.contains(FortificationEngineering)) { - AddToDeployableQuantities( - counts, - categories, - FortificationEngineering, - certificationSet ++ Set(FortificationEngineering) - ) - } - -// case GroundSupport => -// counts(DeployedItem.router_telepad_deployable).Max = 1024 -// categories(DeployableCategory.Telepads).Max = 1024 - - case _ => ; - } - } - } - - /** - * Hardcoded zero'd values for the category and type initialization upon ignoring a previous certification. - * @param counts a reference to the type `Bin` object - * @param categories a reference to the category `Bin` object - * @param certification the new certification - * @param certificationSet the group of previous certifications being tracked - */ - def RemoveFromDeployablesQuantities( - counts: Map[DeployedItem.Value, DeployableToolbox.Bin], - categories: Map[DeployableCategory.Value, DeployableToolbox.Bin], - certification: Certification, - certificationSet: Set[Certification] - ): Unit = { - import Certification._ - if (!certificationSet.contains(certification)) { - certification match { - case AdvancedHacking => - counts(DeployedItem.sensor_shield).Max = 0 - - case CombatEngineering => - counts(DeployedItem.boomer).Max = 0 - counts(DeployedItem.he_mine).Max = 0 - counts(DeployedItem.spitfire_turret).Max = 0 - counts(DeployedItem.motionalarmsensor).Max = 0 - counts(DeployedItem.sensor_shield).Max = 0 - categories(DeployableCategory.Boomers).Max = 0 - categories(DeployableCategory.Mines).Max = 0 - categories(DeployableCategory.SmallTurrets).Max = 0 - categories(DeployableCategory.Sensors).Max = 0 - - case AssaultEngineering => - counts(DeployedItem.jammer_mine).Max = 0 - counts(DeployedItem.portable_manned_turret).Max = 0 //the below turret types are unified - //counts(DeployedItem.portable_manned_turret_nc).Max = 0 - //counts(DeployedItem.portable_manned_turret_tr).Max = 0 - //counts(DeployedItem.portable_manned_turret_vs).Max = 0 - counts(DeployedItem.deployable_shield_generator).Max = 0 - categories(DeployableCategory.Sensors).Max = if (certificationSet contains CombatEngineering) 20 else 0 - categories(DeployableCategory.FieldTurrets).Max = 0 - categories(DeployableCategory.ShieldGenerators).Max = 0 - - case FortificationEngineering => - val ce: Int = if (certificationSet contains CombatEngineering) 1 else 0 //true = 1, false = 0 - counts(DeployedItem.boomer).Max = ce * 20 - counts(DeployedItem.he_mine).Max = ce * 20 - counts(DeployedItem.spitfire_turret).Max = ce * 10 - counts(DeployedItem.motionalarmsensor).Max = ce * 20 - counts(DeployedItem.spitfire_cloaked).Max = 0 - counts(DeployedItem.spitfire_aa).Max = 0 - counts(DeployedItem.tank_traps).Max = 0 - categories(DeployableCategory.Boomers).Max = ce * 20 - categories(DeployableCategory.Mines).Max = ce * 20 - categories(DeployableCategory.SmallTurrets).Max = ce * 10 - categories(DeployableCategory.Sensors).Max = ce * 20 - categories(DeployableCategory.TankTraps).Max = 0 - - case AdvancedEngineering => - if (!certificationSet.contains(AssaultEngineering)) { - RemoveFromDeployablesQuantities(counts, categories, AssaultEngineering, certificationSet) - } - if (!certificationSet.contains(FortificationEngineering)) { - RemoveFromDeployablesQuantities(counts, categories, FortificationEngineering, certificationSet) - } - -// case GroundSupport => -// counts(DeployedItem.router_telepad_deployable).Max = 0 -// categories(DeployableCategory.Telepads).Max = 0 - - case _ => ; - } - } - } }