PSF-LoginServer/src/main/scala/net/psforever/objects/BoomerDeployable.scala
Fate-JH 92063ba3a2
Fixing Tests (#1204)
* fixed about half of the unworking tests, and commented out one

* stubborn tests that pass on their own but don't tend to pass in clusters; also, a certain test that terminates an actor when a mostly unrelated entity has its propertries changed from default, just weird

* reviewing logic and operations pairs to ensure that functionality should have been retained from parent structure; moving handling case from individual player modes to session actor, which makes it much closer to the pattern

* while it's still a dice roll, all tests currently implemented are capable of passing

* deployable vehicles should properly deploy again now that they don't have to fight with themselves for the ability to deploy

* boomers are no longer owned if the trigger is dropped (how long has this been not working?)

* redid DamageFeedbackMessage packet because I thought I could use it for something; didn't use it for anything; boomers are no longer responsive to explosive sympathy

* redid combat engineering explosive logic

* redid (cleaned-up) implant logic

* implant initialization timers now saved to the database; uninitialized implants will appear as uninitialized when the character loads; passive initialized implants will always start as activate

* renaming methods; progress bar calculations change

* accounting for implants that are in the act of being initialized
2024-06-22 01:42:25 -04:00

125 lines
4.2 KiB
Scala

// Copyright (c) 2017 PSForever
package net.psforever.objects
import akka.actor.{ActorContext, Props}
import net.psforever.objects.ce.{Deployable, DeployedItem}
import net.psforever.objects.guid.{GUIDTask, TaskWorkflow}
import net.psforever.objects.serverobject.affinity.FactionAffinity
import net.psforever.objects.serverobject.{CommonMessages, PlanetSideServerObject}
import net.psforever.objects.sourcing.{PlayerSource, SourceEntry}
import net.psforever.objects.vital.Vitality
import net.psforever.objects.vital.etc.TriggerUsedReason
import net.psforever.objects.vital.interaction.DamageInteraction
import net.psforever.objects.zones.Zone
import net.psforever.services.Service
import net.psforever.services.avatar.{AvatarAction, AvatarServiceMessage}
import net.psforever.types.PlanetSideEmpire
import scala.annotation.unused
class BoomerDeployable(cdef: ExplosiveDeployableDefinition)
extends ExplosiveDeployable(cdef) {
private var trigger: Option[BoomerTrigger] = None
def Trigger: Option[BoomerTrigger] = trigger
def Trigger_=(item: BoomerTrigger): Option[BoomerTrigger] = {
if (trigger.isEmpty) { //can only set trigger once
trigger = Some(item)
}
Trigger
}
def Trigger_=(item: Option[BoomerTrigger]): Option[BoomerTrigger] = {
if (item.isEmpty) {
trigger = None
}
Trigger
}
}
class BoomerDeployableDefinition(private val objectId: Int)
extends ExplosiveDeployableDefinition(objectId) {
override def Initialize(obj: Deployable, context: ActorContext): Unit = {
obj.Actor =
context.actorOf(Props(classOf[BoomerDeployableControl], obj), PlanetSideServerObject.UniqueActorName(obj))
}
}
object BoomerDeployableDefinition {
def apply(dtype: DeployedItem.Value): BoomerDeployableDefinition = {
new BoomerDeployableDefinition(dtype.id)
}
}
class BoomerDeployableControl(mine: BoomerDeployable)
extends ExplosiveDeployableControl(mine) {
def receive: Receive =
commonMineBehavior
.orElse {
case CommonMessages.Use(player, Some(trigger: BoomerTrigger)) if mine.Trigger.contains(trigger) =>
// the trigger damages the mine, which sets it off, which causes an explosion
// think of this as an initiator to the proper explosion
HandleDamage(
mine,
DamageInteraction(
SourceEntry(mine),
TriggerUsedReason(PlayerSource(player), trigger.GUID),
mine.Position
).calculate()(mine),
damage = 0
)
case _ => ()
}
def loseOwnership(@unused faction: PlanetSideEmpire.Value): Unit = {
super.loseOwnership(mine, PlanetSideEmpire.NEUTRAL)
val guid = mine.OwnerGuid
mine.AssignOwnership(None)
mine.OwnerGuid = guid
}
override def gainOwnership(player: Player): Unit = {
mine.Faction = PlanetSideEmpire.NEUTRAL //force map icon redraw
super.gainOwnership(player, player.Faction)
}
override def dismissDeployable() : Unit = {
super.dismissDeployable()
val zone = mine.Zone
mine.Trigger match {
case Some(trigger) =>
mine.Trigger = None
trigger.Companion = None
val guid = trigger.GUID
Zone.EquipmentIs.Where(trigger, guid, zone) match {
case Some(Zone.EquipmentIs.InContainer(container, index)) =>
container.Slot(index).Equipment = None
case Some(Zone.EquipmentIs.OnGround()) =>
zone.Ground ! Zone.Ground.RemoveItem(guid)
case _ => ()
}
zone.AvatarEvents! AvatarServiceMessage(
zone.id,
AvatarAction.ObjectDelete(Service.defaultPlayerGUID, guid)
)
TaskWorkflow.execute(GUIDTask.unregisterObject(zone.GUID, trigger))
case None => ()
}
}
/**
* Boomers are not bothered by explosive sympathy
* but can still be affected by sources of jammering.
* @param obj the entity being damaged
* @param damage the amount of damage
* @param data historical information about the damage
* @return `true`, if the target can be affected;
* `false`, otherwise
*/
override def CanDetonate(obj: Vitality with FactionAffinity, damage: Int, data: DamageInteraction): Boolean = {
super.CanDetonate(obj, damage, data) || data.cause.isInstanceOf[TriggerUsedReason]
}
}