more concise management of purchase timers

This commit is contained in:
Jason_DiDonato@yahoo.com 2021-04-18 09:07:03 -04:00
parent a2bd6999ab
commit 0b7930eeff
2 changed files with 52 additions and 45 deletions

View file

@ -725,8 +725,7 @@ class AvatarActor(
} else {
// TODO save to db
avatar = avatar.copy(purchaseTimes = avatar.purchaseTimes.updated(definition.Name, time))
// we could be more selective and only send what changed, but it doesn't hurt to refresh everything
context.self ! RefreshPurchaseTimes()
refreshPurchaseTimes(Set(definition.Name))
}
Behaviors.same
@ -738,38 +737,7 @@ class AvatarActor(
Behaviors.same
case RefreshPurchaseTimes() =>
avatar.purchaseTimes.foreach {
case (name, purchaseTime) =>
val secondsSincePurchase = Seconds.secondsBetween(purchaseTime, LocalDateTime.now()).getSeconds
Avatar.purchaseCooldowns.find(_._1.Name == name) match {
case Some((obj, cooldown)) if cooldown.toSeconds - secondsSincePurchase > 0 =>
val faction: String = avatar.faction.toString.toLowerCase
val name = obj match {
case GlobalDefinitions.trhev_dualcycler | GlobalDefinitions.nchev_scattercannon |
GlobalDefinitions.vshev_quasar =>
s"${faction}hev_antipersonnel"
case GlobalDefinitions.trhev_pounder | GlobalDefinitions.nchev_falcon |
GlobalDefinitions.vshev_comet =>
s"${faction}hev_antivehicular"
case GlobalDefinitions.trhev_burster | GlobalDefinitions.nchev_sparrow |
GlobalDefinitions.vshev_starfire =>
s"${faction}hev_antiaircraft"
case _ => obj.Name
}
sessionActor ! SessionActor.SendResponse(
AvatarVehicleTimerMessage(
session.get.player.GUID,
name,
cooldown.toSeconds - secondsSincePurchase,
unk1 = true
)
)
case _ => ;
}
}
refreshPurchaseTimes(avatar.purchaseTimes.keys.toSet)
Behaviors.same
case SetVehicle(vehicle) =>
@ -1281,8 +1249,8 @@ class AvatarActor(
loadout.items.split("/").foreach {
case value =>
val (objectType, objectIndex, objectId, toolAmmo) = value.split(",") match {
case Array(a, b, c) => (a, b.toInt, c.toInt, None)
case Array(a, b, c, d) => (a, b.toInt, c.toInt, Some(d))
case Array(a, b: String, c: String) => (a, b.toInt, c.toInt, None)
case Array(a, b: String, c: String, d) => (a, b.toInt, c.toInt, Some(d))
}
objectType match {
@ -1305,9 +1273,9 @@ class AvatarActor(
}
toolAmmo foreach { toolAmmo =>
toolAmmo.split("_").drop(1).foreach { value =>
toolAmmo.toString.split("_").drop(1).foreach { value =>
val (ammoSlots, ammoTypeIndex, ammoBoxDefinition) = value.split("-") match {
case Array(a, b, c) => (a.toInt, b.toInt, c.toInt)
case Array(a: String, b: String, c: String) => (a.toInt, b.toInt, c.toInt)
}
doll.Slot(objectIndex).Equipment.get.asInstanceOf[Tool].AmmoSlots(ammoSlots).AmmoTypeIndex =
ammoTypeIndex
@ -1355,4 +1323,48 @@ class AvatarActor(
})
}
def refreshPurchaseTimes(keys: Set[String]): Unit = {
var keysToDrop: Seq[String] = Nil
keys.foreach { key =>
avatar.purchaseTimes.find { case (name, _) => name.equals(key) } match {
case Some((name, purchaseTime)) =>
val secondsSincePurchase = Seconds.secondsBetween(purchaseTime, LocalDateTime.now()).getSeconds
Avatar.purchaseCooldowns.find(_._1.Name == name) match {
case Some((obj, cooldown)) if cooldown.toSeconds - secondsSincePurchase > 0 =>
val faction : String = avatar.faction.toString.toLowerCase
val name = obj match {
case GlobalDefinitions.trhev_dualcycler |
GlobalDefinitions.nchev_scattercannon |
GlobalDefinitions.vshev_quasar =>
s"${faction}hev_antipersonnel"
case GlobalDefinitions.trhev_pounder |
GlobalDefinitions.nchev_falcon |
GlobalDefinitions.vshev_comet =>
s"${faction}hev_antivehicular"
case GlobalDefinitions.trhev_burster |
GlobalDefinitions.nchev_sparrow |
GlobalDefinitions.vshev_starfire =>
s"${faction}hev_antiaircraft"
case _ =>
obj.Name
}
sessionActor ! SessionActor.SendResponse(
AvatarVehicleTimerMessage(
session.get.player.GUID,
name,
cooldown.toSeconds - secondsSincePurchase,
unk1 = true //TODO? vehicles = true, everything else = false
)
)
case _ =>
keysToDrop = keysToDrop :+ key //key has timed-out
}
case _ => ;
}
}
if (keysToDrop.nonEmpty) {
avatar.copy(purchaseTimes = avatar.purchaseTimes.removedAll(keysToDrop))
}
}
}

View file

@ -1292,7 +1292,7 @@ class SessionActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], con
case PlayerLoaded(tplayer) =>
//same zone
log.info(s"Player ${tplayer.Name} will respawn")
log.info(s"${tplayer.Name} will respawn")
tplayer.avatar = avatar
session = session.copy(player = tplayer)
setupAvatarFunc()
@ -2478,7 +2478,7 @@ class SessionActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], con
case Mountable.CanMount(obj: Vehicle, seat_number, _) =>
CancelZoningProcessWithDescriptiveReason("cancel_mount")
log.info(s"${player.Name} mounts ${obj.Definition.Name} in ${
log.info(s"${player.Name} mounts the ${obj.Definition.Name} in ${
obj.SeatPermissionGroup(seat_number) match {
case Some(AccessPermissionGroup.Driver) => "the driver seat"
case Some(seatType) => s"a $seatType seat, #$seat_number"
@ -2943,11 +2943,6 @@ class SessionActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], con
sendResponse(PlanetsideAttributeMessage(vehicle_guid, 22, 1L)) //mount points off
sendResponse(PlanetsideAttributeMessage(player.GUID, 21, vehicle_guid)) //ownership
avatarActor ! AvatarActor.UpdatePurchaseTime(vehicle.Definition)
Avatar.purchaseCooldowns.get(vehicle.Definition) match {
case Some(cooldown) =>
sendResponse(AvatarVehicleTimerMessage(player.GUID, vehicle.Definition.Name, cooldown.toSeconds, unk1 = true))
case None => ;
}
vehicle.MountPoints.find { case (_, mp) => mp.seatIndex == 0 } match {
case Some((mountPoint, _)) => vehicle.Actor ! Mountable.TryMount(player, mountPoint)
case _ => ;