Skip to content

Commit

Permalink
accounting for implants that are in the act of being initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
Fate-JH committed Jun 20, 2024
1 parent 48a1e13 commit 0c26f29
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/main/scala/net/psforever/actors/session/AvatarActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3430,14 +3430,7 @@ class AvatarActor(
if (implantTimers.lift(slot).exists(_.isCancelled)) {
val curr = System.currentTimeMillis()
val implantTimer = implant.timer
val (actualDelay, futureDelay, actionProgress): (FiniteDuration, Long, Long) = if (implantTimer > curr) {
val countedDelay = math.max(0L, (implantTimer - curr) / 1000L)
val fullNormalDelay = implant.definition.InitializationDuration.toFloat
val progress = (100f * ((fullNormalDelay - countedDelay.toFloat) / fullNormalDelay)).toLong
(countedDelay.seconds, implantTimer, progress)
} else {
(delay, curr + delay.toMillis, 0L)
}
val (actualDelay, futureDelay, actionProgress) = calculateImplantTimerStats(implant, delay)
//start initialization process
setImplantInitializedTimer(implant, slot, actualDelay)
// Start client-side initialization timer, visible on the character screen
Expand All @@ -3453,6 +3446,19 @@ class AvatarActor(
}
}

private def calculateImplantTimerStats(implant: Implant, delay: FiniteDuration): (FiniteDuration, Long, Long) = {
val curr = System.currentTimeMillis()
val implantTimer = implant.timer
if (implantTimer > curr) {
val countedDelay = math.max(0L, (implantTimer - curr) / 1000L)
val fullNormalDelay = implant.definition.InitializationDuration.toFloat
val progress = (100f * ((fullNormalDelay - countedDelay.toFloat) / fullNormalDelay)).toLong
(countedDelay.seconds, implantTimer, progress)
} else {
(delay, curr + delay.toMillis, 0L)
}
}

private def deinitializeImplants(): Unit = {
avatarCopy(avatar.copy(implants = avatar
.implants
Expand All @@ -3462,17 +3468,25 @@ class AvatarActor(
Some(deinitializeImplant(deactivateImplant(implant, slot), slot))
case (Some(implant), slot) if implant.initialized =>
Some(deinitializeImplant(implant, slot))
case (Some(implant), slot) if implantTimers.lift(slot).exists(timer => !timer.isCancelled) =>
Some(stopImplantInitializationTimer(implant, slot))
case (implantOpt, _) =>
implantOpt
}
))
}

private def deinitializeImplant(implant: Implant, slot: Int): Implant = {
val outImplant = stopImplantInitializationTimer(implant, slot)
session.get.zone.AvatarEvents ! AvatarServiceMessage(
session.get.zone.id,
AvatarAction.AvatarImplant(session.get.player.GUID, ImplantAction.Initialization, slot, 0)
)
outImplant
}

def stopImplantInitializationTimer(implant: Implant, slot: Int): Implant = {
cancelImplantInitializedTimer(slot)
//can not formally stop the initialization time on the character information window; set it to 100 to make it look blank
session.get.zone.AvatarEvents ! AvatarServiceMessage(
avatar.name,
Expand Down Expand Up @@ -3655,12 +3669,19 @@ class AvatarActor(
case (Some(implant), slot) if implant.active && !implant.definition.Passive =>
//deactivate active non-passive implant
Some(deactivateImplant(implant, slot))
case (Some(implant), slot) if !implant.initialized && implantTimers(slot).isCancelled =>
case (Some(implant), slot) if !implant.initialized && implantTimers.lift(slot).exists(_.isCancelled) =>
//restart stopped/unstarted initialization process
Some(startReinitializeImplant(implant, slot))
case (implantOpt, _) =>
//fine as is
case (implantOpt @ Some(implant), slot) =>
//update ongoing progress
val actionProgress = calculateImplantTimerStats(implant, AvatarActor.initializationTime(implant))._3
session.get.zone.AvatarEvents ! AvatarServiceMessage(
avatar.name,
AvatarAction.SendResponse(Service.defaultPlayerGUID, ActionProgressMessage(slot + 6, actionProgress))
)
implantOpt
case (None, _) =>
None
}
)
)
Expand Down

0 comments on commit 0c26f29

Please sign in to comment.