players in seats have their mounted information shortened in a more straightforward, less fault-prone way; stamina recharge command shortened

This commit is contained in:
Fate-JH 2023-05-08 14:15:04 -04:00
parent 6907a3a7e1
commit 5337f37363
6 changed files with 24 additions and 30 deletions

View file

@ -1606,11 +1606,7 @@ class AvatarActor(
Behaviors.same
case RestoreStamina(stamina) =>
tryRestoreStaminaForSession(stamina) match {
case Some(sess) =>
actuallyRestoreStamina(stamina, sess)
case _ => ;
}
tryRestoreStaminaForSession(stamina).collect { actuallyRestoreStamina(stamina, _) }
Behaviors.same
case RestoreStaminaPeriodically(stamina) =>
@ -1871,11 +1867,7 @@ class AvatarActor(
)
)
// if we need to start stamina regeneration
tryRestoreStaminaForSession(stamina = 1) match {
case Some(_) =>
defaultStaminaRegen(initialDelay = 0.5f seconds)
case _ => ;
}
tryRestoreStaminaForSession(stamina = 1).collect { _ => defaultStaminaRegen(initialDelay = 0.5f seconds) }
replyTo ! AvatarLoginResponse(avatar)
case Failure(e) =>
log.error(e)("db failure")
@ -1965,11 +1957,7 @@ class AvatarActor(
}
def restoreStaminaPeriodically(stamina: Int): Unit = {
tryRestoreStaminaForSession(stamina) match {
case Some(sess) =>
actuallyRestoreStaminaIfStationary(stamina, sess)
case _ => ;
}
tryRestoreStaminaForSession(stamina).collect { actuallyRestoreStaminaIfStationary(stamina, _) }
startIfStoppedStaminaRegen(initialDelay = 0.5f seconds)
}

View file

@ -36,7 +36,7 @@ import net.psforever.objects.sourcing.PlayerSource
import net.psforever.objects.vital.collision.CollisionReason
import net.psforever.objects.vital.environment.EnvironmentReason
import net.psforever.objects.vital.etc.{PainboxReason, SuicideReason}
import net.psforever.objects.vital.interaction.{DamageInteraction, DamageResult}
import net.psforever.objects.vital.interaction.{Adversarial, DamageInteraction, DamageResult}
import net.psforever.services.hart.ShuttleState
import net.psforever.packet.PlanetSideGamePacket
@ -1033,21 +1033,23 @@ class PlayerControl(player: Player, avatarActor: typed.ActorRef[AvatarActor.Comm
)
//TODO other methods of death?
val pentry = PlayerSource(target)
(cause.adversarial match {
case out @ Some(_) =>
out
case _ =>
cause
.adversarial
.collect { case out @ Adversarial(attacker, _, _) if attacker != PlayerSource.Nobody => out }
.orElse {
target.LastDamage.collect {
case attack if System.currentTimeMillis() - attack.interaction.hitTime < (10 seconds).toMillis =>
attack.adversarial
attack
.adversarial
.collect { case out @ Adversarial(attacker, _, _) if attacker != PlayerSource.Nobody => out }
}.flatten
}) match {
} match {
case Some(adversarial) =>
events ! AvatarServiceMessage(
zoneChannel,
AvatarAction.DestroyDisplay(adversarial.attacker, pentry, adversarial.implement)
)
case None =>
case _ =>
events ! AvatarServiceMessage(zoneChannel, AvatarAction.DestroyDisplay(pentry, pentry, 0))
}
}

View file

@ -59,7 +59,9 @@ object AmenitySource {
)
amenity.copy(occupants = obj match {
case o: Mountable =>
o.Seats.values.flatMap { _.occupants }.map { p => PlayerSource.inSeat(p, o, amenity) }.toList
o.Seats
.collect { case (num, seat) if seat.isOccupied => (num, seat.occupants.head) }
.map { case (num, p) => PlayerSource.inSeat(p, amenity, num) }.toList
case _ =>
Nil
})

View file

@ -109,17 +109,17 @@ object PlayerSource {
* even if this function is entirely for the purpose of establishing that the player is an occupant of the mountable entity.<br>
* Don't think too much about it.
* @param player player
* @param mount mountable entity in which the player should be seated
* @param source a `SourceEntry` for the aforementioned mountable entity
* @param seatNumber the attributed seating index in which the player is mounted in `source`
* @return a `PlayerSource` entity
*/
def inSeat(player: Player, mount: Mountable, source: SourceEntry): PlayerSource = {
def inSeat(player: Player, source: SourceEntry, seatNumber: Int): PlayerSource = {
val exosuit = player.ExoSuit
val faction = player.Faction
PlayerSource(
player.Definition,
exosuit,
Some((source, mount.PassengerInSeat(player).get)),
Some((source, seatNumber)),
player.Health,
player.Armor,
player.Position,

View file

@ -57,7 +57,9 @@ object TurretSource {
)
turret.copy(occupants = obj match {
case o: Mountable =>
o.Seats.values.flatMap { _.occupants }.map { p => PlayerSource.inSeat(p, o, turret) }.toList
o.Seats
.collect { case (num, seat) if seat.isOccupied => (num, seat.occupants.head) }
.map { case (num, p) => PlayerSource.inSeat(p, turret, num) }.toList
case _ =>
Nil
})

View file

@ -53,9 +53,9 @@ object VehicleSource {
)
)
vehicle.copy(occupants = {
obj.Seats.values.map { seat =>
obj.Seats.map { case (seatNumber, seat) =>
seat.occupant match {
case Some(p) => PlayerSource.inSeat(p, obj, vehicle) //shallow
case Some(p) => PlayerSource.inSeat(p, vehicle, seatNumber) //shallow
case _ => PlayerSource.Nobody
}
}.toList