mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-07-14 07:55:07 +00:00
more concise management of purchase timers
This commit is contained in:
parent
a2bd6999ab
commit
0b7930eeff
2 changed files with 52 additions and 45 deletions
|
|
@ -725,8 +725,7 @@ class AvatarActor(
|
||||||
} else {
|
} else {
|
||||||
// TODO save to db
|
// TODO save to db
|
||||||
avatar = avatar.copy(purchaseTimes = avatar.purchaseTimes.updated(definition.Name, time))
|
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
|
refreshPurchaseTimes(Set(definition.Name))
|
||||||
context.self ! RefreshPurchaseTimes()
|
|
||||||
}
|
}
|
||||||
Behaviors.same
|
Behaviors.same
|
||||||
|
|
||||||
|
|
@ -738,38 +737,7 @@ class AvatarActor(
|
||||||
Behaviors.same
|
Behaviors.same
|
||||||
|
|
||||||
case RefreshPurchaseTimes() =>
|
case RefreshPurchaseTimes() =>
|
||||||
avatar.purchaseTimes.foreach {
|
refreshPurchaseTimes(avatar.purchaseTimes.keys.toSet)
|
||||||
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 _ => ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Behaviors.same
|
Behaviors.same
|
||||||
|
|
||||||
case SetVehicle(vehicle) =>
|
case SetVehicle(vehicle) =>
|
||||||
|
|
@ -1281,8 +1249,8 @@ class AvatarActor(
|
||||||
loadout.items.split("/").foreach {
|
loadout.items.split("/").foreach {
|
||||||
case value =>
|
case value =>
|
||||||
val (objectType, objectIndex, objectId, toolAmmo) = value.split(",") match {
|
val (objectType, objectIndex, objectId, toolAmmo) = value.split(",") match {
|
||||||
case Array(a, b, c) => (a, b.toInt, c.toInt, None)
|
case Array(a, b: String, c: String) => (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, d) => (a, b.toInt, c.toInt, Some(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
objectType match {
|
objectType match {
|
||||||
|
|
@ -1305,9 +1273,9 @@ class AvatarActor(
|
||||||
}
|
}
|
||||||
|
|
||||||
toolAmmo foreach { toolAmmo =>
|
toolAmmo foreach { toolAmmo =>
|
||||||
toolAmmo.split("_").drop(1).foreach { value =>
|
toolAmmo.toString.split("_").drop(1).foreach { value =>
|
||||||
val (ammoSlots, ammoTypeIndex, ammoBoxDefinition) = value.split("-") match {
|
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 =
|
doll.Slot(objectIndex).Equipment.get.asInstanceOf[Tool].AmmoSlots(ammoSlots).AmmoTypeIndex =
|
||||||
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1292,7 +1292,7 @@ class SessionActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], con
|
||||||
|
|
||||||
case PlayerLoaded(tplayer) =>
|
case PlayerLoaded(tplayer) =>
|
||||||
//same zone
|
//same zone
|
||||||
log.info(s"Player ${tplayer.Name} will respawn")
|
log.info(s"${tplayer.Name} will respawn")
|
||||||
tplayer.avatar = avatar
|
tplayer.avatar = avatar
|
||||||
session = session.copy(player = tplayer)
|
session = session.copy(player = tplayer)
|
||||||
setupAvatarFunc()
|
setupAvatarFunc()
|
||||||
|
|
@ -2478,7 +2478,7 @@ class SessionActor(middlewareActor: typed.ActorRef[MiddlewareActor.Command], con
|
||||||
|
|
||||||
case Mountable.CanMount(obj: Vehicle, seat_number, _) =>
|
case Mountable.CanMount(obj: Vehicle, seat_number, _) =>
|
||||||
CancelZoningProcessWithDescriptiveReason("cancel_mount")
|
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 {
|
obj.SeatPermissionGroup(seat_number) match {
|
||||||
case Some(AccessPermissionGroup.Driver) => "the driver seat"
|
case Some(AccessPermissionGroup.Driver) => "the driver seat"
|
||||||
case Some(seatType) => s"a $seatType seat, #$seat_number"
|
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(vehicle_guid, 22, 1L)) //mount points off
|
||||||
sendResponse(PlanetsideAttributeMessage(player.GUID, 21, vehicle_guid)) //ownership
|
sendResponse(PlanetsideAttributeMessage(player.GUID, 21, vehicle_guid)) //ownership
|
||||||
avatarActor ! AvatarActor.UpdatePurchaseTime(vehicle.Definition)
|
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 {
|
vehicle.MountPoints.find { case (_, mp) => mp.seatIndex == 0 } match {
|
||||||
case Some((mountPoint, _)) => vehicle.Actor ! Mountable.TryMount(player, mountPoint)
|
case Some((mountPoint, _)) => vehicle.Actor ! Mountable.TryMount(player, mountPoint)
|
||||||
case _ => ;
|
case _ => ;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue