mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-03-25 06:49:07 +00:00
wrote aggravated damage properties into the definitions of projectiles that convey them; basic workflow for aggravation from projectile damage is in place, but not tested
This commit is contained in:
parent
5c8331ed9b
commit
811c7b09b5
6 changed files with 233 additions and 65 deletions
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) 2020 PSForever
|
||||
package net.psforever.objects.avatar
|
||||
|
||||
object Aura extends Enumeration {
|
||||
final val None = Value(0)
|
||||
final val Plasma = Value(1)
|
||||
final val Comet = Value(2)
|
||||
final val Napalm = Value(4)
|
||||
final val Fire = Value(8)
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
// Copyright (c) 2020 PSForever
|
||||
package net.psforever.objects.avatar
|
||||
|
||||
import akka.actor.{Actor, Cancellable}
|
||||
import net.psforever.objects.Player
|
||||
import net.psforever.objects.ballistics.{AggravatedDamage, AggravatedInfo, ResolvedProjectile}
|
||||
import net.psforever.objects.vital.DamageType
|
||||
|
||||
import scala.collection.mutable
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
|
||||
trait AuraEffectBehavior {
|
||||
_ : Actor =>
|
||||
private var activeEffectIndex : Long = 0
|
||||
private var effectsToIds : mutable.HashMap[Aura.Value, List[Long]] = mutable.HashMap.empty[Aura.Value, List[Long]]
|
||||
private var idsToTimers : mutable.LongMap[Cancellable] = mutable.LongMap.empty[Cancellable]
|
||||
private var idsToEntries : mutable.LongMap[AuraEffectBehavior.Entry] = mutable.LongMap.empty[AuraEffectBehavior.Entry]
|
||||
|
||||
def AuraTargetObject : Player
|
||||
|
||||
val auraBehavior : Receive = {
|
||||
case AuraEffectBehavior.Aggravate(id, 0) =>
|
||||
CleanupEffect(id) match {
|
||||
case Aura.None => ;
|
||||
case _ => UpdateAggravatedEffect(AuraTargetObject)
|
||||
}
|
||||
|
||||
case AuraEffectBehavior.Aggravate(id, iteration) => ;
|
||||
idsToTimers.remove(id) match {
|
||||
case Some(timer) => timer.cancel
|
||||
case _ => ;
|
||||
}
|
||||
idsToEntries.get(id) match {
|
||||
case Some(entry) =>
|
||||
//TODO stuff ...
|
||||
idsToTimers += id -> context.system.scheduler.scheduleOnce(
|
||||
entry.effect.infliction_rate milliseconds, self, AuraEffectBehavior.Aggravate(id, iteration - 1))
|
||||
case _ => ;
|
||||
}
|
||||
}
|
||||
|
||||
def AggravationEffect(data : ResolvedProjectile) : Unit = {
|
||||
data.projectile.profile.Aggravated match {
|
||||
case Some(damage)
|
||||
if data.projectile.profile.ProjectileDamageType == DamageType.Aggravated && damage.effect_type != Aura.None =>
|
||||
AggravationEffect(damage, data)
|
||||
case _ => ;
|
||||
}
|
||||
}
|
||||
|
||||
private def AggravationEffect(aggravation : AggravatedDamage, data : ResolvedProjectile) : Unit = {
|
||||
val effect = aggravation.effect_type
|
||||
val obj = AuraTargetObject
|
||||
if(obj.Aura.contains(effect)) { //TODO cumulative?
|
||||
SetupAggravationEntry(aggravation)
|
||||
}
|
||||
else if(obj.Aura.diff(obj.AddEffectToAura(effect)).contains(effect)) {
|
||||
SetupAggravationEntry(aggravation)
|
||||
UpdateAggravatedEffect(obj)
|
||||
}
|
||||
}
|
||||
|
||||
private def SetupAggravationEntry(aggravation : AggravatedDamage) : Unit = {
|
||||
val effect = aggravation.effect_type
|
||||
aggravation.info.foreach { infos =>
|
||||
//get unused id
|
||||
val id = activeEffectIndex
|
||||
activeEffectIndex += 1
|
||||
//pair aura effect with id
|
||||
effectsToIds.get(effect) match {
|
||||
case None | Some(Nil) => effectsToIds += effect -> List(id)
|
||||
case Some(list) => effectsToIds -> (list :+ id)
|
||||
}
|
||||
//pair id with entry
|
||||
idsToEntries += id -> AuraEffectBehavior.Entry(id, infos, aggravation, 0)
|
||||
//pair id with timer
|
||||
val iterations = (aggravation.duration / infos.infliction_rate).toInt
|
||||
idsToTimers += id -> context.system.scheduler.scheduleOnce(infos.infliction_rate milliseconds, self, AuraEffectBehavior.Aggravate(id, iterations))
|
||||
}
|
||||
}
|
||||
|
||||
def CleanupEffect(id : Long) : Aura.Value = {
|
||||
//remove and cancel timer
|
||||
idsToTimers.remove(id) match {
|
||||
case Some(timer) => timer.cancel
|
||||
case _ => ;
|
||||
}
|
||||
//remove entry and cache effect
|
||||
val out = idsToEntries.remove(id) match {
|
||||
case Some(entry) => entry.aggravation.effect_type
|
||||
case _ => Aura.None
|
||||
}
|
||||
//remove id and, if now unsupported, effect
|
||||
(effectsToIds.get(out) match {
|
||||
case Some(list) => (out, list.filterNot(_ == id))
|
||||
case _ => (Aura.None, Nil)
|
||||
}) match {
|
||||
case (Aura.None, _) =>
|
||||
Aura.None
|
||||
case (effect, Nil) =>
|
||||
effectsToIds.remove(effect)
|
||||
effect
|
||||
case (effect, list) =>
|
||||
effectsToIds += effect -> list
|
||||
Aura.None
|
||||
}
|
||||
}
|
||||
|
||||
def EndAllEffects() : Unit = {
|
||||
idsToEntries.clear
|
||||
idsToTimers.values.foreach { _.cancel }
|
||||
idsToTimers.clear
|
||||
effectsToIds.clear
|
||||
UpdateAggravatedEffect(AuraTargetObject)
|
||||
}
|
||||
|
||||
def UpdateAggravatedEffect(target : Player) : Unit = {
|
||||
import services.avatar.{AvatarAction, AvatarServiceMessage}
|
||||
val zone = target.Zone
|
||||
val value = target.Aura.foldLeft(0)(_ + _.id)
|
||||
zone.AvatarEvents ! AvatarServiceMessage(zone.Id, AvatarAction.PlanetsideAttributeToAll(target.GUID, 54, value))
|
||||
}
|
||||
}
|
||||
|
||||
object AuraEffectBehavior {
|
||||
private case class Entry(id : Long, effect : AggravatedInfo, aggravation : AggravatedDamage, damage : Any)
|
||||
|
||||
private case class Aggravate(id : Long, iteration : Int)
|
||||
}
|
||||
|
|
@ -1,13 +1,9 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package net.psforever.objects.ballistics
|
||||
|
||||
import net.psforever.objects.avatar.Aura
|
||||
import net.psforever.objects.vital.DamageType
|
||||
|
||||
object AggravatedEffect extends Enumeration {
|
||||
type Type = Value
|
||||
val Comet, Fire, Plasma, Napalm, None = Value
|
||||
}
|
||||
|
||||
final case class AggravatedInfo(damage_type : DamageType.Value,
|
||||
degradation_percentage : Float,
|
||||
infliction_rate : Long) {
|
||||
|
|
@ -15,7 +11,7 @@ final case class AggravatedInfo(damage_type : DamageType.Value,
|
|||
}
|
||||
|
||||
final case class AggravatedDamage(info : List[AggravatedInfo],
|
||||
effect_type : AggravatedEffect.Value,
|
||||
effect_type : Aura.Value,
|
||||
duration : Long,
|
||||
max_factor : Float,
|
||||
cumulative_damage_degrade : Boolean,
|
||||
|
|
@ -23,13 +19,13 @@ final case class AggravatedDamage(info : List[AggravatedInfo],
|
|||
|
||||
object AggravatedDamage {
|
||||
def apply(info : AggravatedInfo,
|
||||
effect_type : AggravatedEffect.Value,
|
||||
effect_type : Aura.Value,
|
||||
duration : Long,
|
||||
max_factor : Float) : AggravatedDamage =
|
||||
AggravatedDamage(List(info), effect_type, duration, max_factor, cumulative_damage_degrade = true, vanu_aggravated = false)
|
||||
|
||||
def apply(info : AggravatedInfo,
|
||||
effect_type : AggravatedEffect.Value,
|
||||
effect_type : Aura.Value,
|
||||
duration : Long,
|
||||
max_factor : Float,
|
||||
vanu_aggravated : Boolean) : AggravatedDamage =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue