Implant: Second Wind (#880)

* support for the second wind implant; minor enum modifications to damage reasons that were executed for alternate implementation where second wind stopped player from dying once

* vital history entry to note from where the 25hp came
This commit is contained in:
Fate-JH 2021-06-30 20:48:09 -04:00 committed by GitHub
parent 6ac81fc1c6
commit 82579111e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 6 deletions

View file

@ -140,6 +140,9 @@ object AvatarActor {
/** Deinitialize implants (before zoning or respawning) */ /** Deinitialize implants (before zoning or respawning) */
final case class DeinitializeImplants() extends Command final case class DeinitializeImplants() extends Command
/** Deinitialize a certain implant, then initialize it again */
final case class ResetImplant(implant: ImplantType) extends Command
/** Shorthand for DeinitializeImplants and InitializeImplants */ /** Shorthand for DeinitializeImplants and InitializeImplants */
final case class ResetImplants() extends Command final case class ResetImplants() extends Command
@ -172,7 +175,7 @@ object AvatarActor {
private case class ServiceManagerLookupResult(result: ServiceManager.LookupResult) extends Command private case class ServiceManagerLookupResult(result: ServiceManager.LookupResult) extends Command
private case class SetStamina(stamina: Int) extends Command final case class SetStamina(stamina: Int) extends Command
private case class SetImplantInitialized(implantType: ImplantType) extends Command private case class SetImplantInitialized(implantType: ImplantType) extends Command
@ -841,8 +844,7 @@ class AvatarActor(
Behaviors.same Behaviors.same
case RestoreStamina(stamina) => case RestoreStamina(stamina) =>
assert(stamina > 0) if (stamina > 0 && session.get.player.HasGUID) {
if (session.get.player.HasGUID) {
val totalStamina = math.min(avatar.maxStamina, avatar.stamina + stamina) val totalStamina = math.min(avatar.maxStamina, avatar.stamina + stamina)
val fatigued = if (avatar.fatigued && totalStamina >= 20) { val fatigued = if (avatar.fatigued && totalStamina >= 20) {
avatar.implants.zipWithIndex.foreach { avatar.implants.zipWithIndex.foreach {
@ -890,6 +892,10 @@ class AvatarActor(
deinitializeImplants() deinitializeImplants()
Behaviors.same Behaviors.same
case ResetImplant(implantType) =>
resetAnImplant(implantType)
Behaviors.same
case ResetImplants() => case ResetImplants() =>
deinitializeImplants() deinitializeImplants()
initializeImplants() initializeImplants()
@ -1097,6 +1103,42 @@ class AvatarActor(
}) })
} }
def resetAnImplant(implantType: ImplantType): Unit = {
avatar.implants.zipWithIndex.find {
case (Some(imp), _) => imp.definition.implantType == implantType
case (None, _) => false
} match {
case Some((Some(imp), index)) =>
//deactivate
if (imp.active) {
deactivateImplant(implantType)
}
//deinitialize
session.get.zone.AvatarEvents ! AvatarServiceMessage(
session.get.zone.id,
AvatarAction.SendResponse(
Service.defaultPlayerGUID,
AvatarImplantMessage(session.get.player.GUID, ImplantAction.Initialization, index, 0)
)
)
avatar = avatar.copy(
implants = avatar.implants.updated(index, Some(imp.copy(initialized = false, active = false)))
)
//restart initialization process
implantTimers(index).cancel()
implantTimers(index) = context.scheduleOnce(
imp.definition.InitializationDuration.seconds,
context.self,
SetImplantInitialized(implantType)
)
session.get.zone.AvatarEvents ! AvatarServiceMessage(
avatar.name,
AvatarAction.SendResponse(Service.defaultPlayerGUID, ActionProgressMessage(index + 6, 0))
)
case _ => ;
}
}
def deactivateImplant(implantType: ImplantType): Unit = { def deactivateImplant(implantType: ImplantType): Unit = {
avatar.implants.zipWithIndex.collectFirst { avatar.implants.zipWithIndex.collectFirst {
case (Some(implant), index) if implant.definition.implantType == implantType => (implant, index) case (Some(implant), index) if implant.definition.implantType == implantType => (implant, index)

View file

@ -748,8 +748,22 @@ class PlayerControl(player: Player, avatarActor: typed.ActorRef[AvatarActor.Comm
} }
//choose //choose
if (target.Health > 0) { if (target.Health > 0) {
//alive
if (target.Health <= 25 && target.Health + damageToHealth > 25 &&
(player.avatar.implants.flatten.find { _.definition.implantType == ImplantType.SecondWind } match {
case Some(wind) => wind.initialized
case _ => false
})) {
//activate second wind
player.Health += 25
player.History(HealFromImplant(PlayerSource(player), 25, ImplantType.SecondWind))
avatarActor ! AvatarActor.ResetImplant(ImplantType.SecondWind)
avatarActor ! AvatarActor.RestoreStamina(25)
}
//take damage/update
DamageAwareness(target, cause, damageToHealth, damageToArmor, damageToStamina, damageToCapacitor) DamageAwareness(target, cause, damageToHealth, damageToArmor, damageToStamina, damageToCapacitor)
} else { } else {
//ded
DestructionAwareness(target, cause) DestructionAwareness(target, cause)
} }
} }

View file

@ -28,6 +28,8 @@ object DamageResolution extends Enumeration {
AggravatedDirectBurn, //continuous direct hit aggravated damage AggravatedDirectBurn, //continuous direct hit aggravated damage
AggravatedSplash, //splashed aggravated damage AggravatedSplash, //splashed aggravated damage
AggravatedSplashBurn, //continuous splashed aggravated damage AggravatedSplashBurn, //continuous splashed aggravated damage
Explosion //area of effect damage caused by an internal mechanism; unrelated to Splash Explosion, //area of effect damage caused by an internal mechanism; unrelated to Splash
Environmental, //died to environmental causes
Suicide //i don't want to be the one the battles always choose
= Value = Value
} }

View file

@ -17,7 +17,7 @@ import net.psforever.objects.vital.{NoResistanceSelection, SimpleResolutions, Vi
* @param against for the purposes of damage, what kind of target is being acted upon * @param against for the purposes of damage, what kind of target is being acted upon
*/ */
final case class EnvironmentReason(body: PieceOfEnvironment, against: DamageCalculations.Selector) extends DamageReason { final case class EnvironmentReason(body: PieceOfEnvironment, against: DamageCalculations.Selector) extends DamageReason {
def resolution: DamageResolution.Value = DamageResolution.Hit def resolution: DamageResolution.Value = DamageResolution.Environmental
def source: DamageProperties = EnvironmentReason.selectDamage(body) def source: DamageProperties = EnvironmentReason.selectDamage(body)

View file

@ -33,7 +33,7 @@ final case class SuicideReason()
*/ */
def source: DamageProperties = SuicideReason.damageProperties def source: DamageProperties = SuicideReason.damageProperties
def resolution: DamageResolution.Value = DamageResolution.Resolved def resolution: DamageResolution.Value = DamageResolution.Suicide
def same(test: DamageReason): Boolean = { def same(test: DamageReason): Boolean = {
test.source eq source test.source eq source