ID:265043
 
Code:
mob
var
Health
Health_Max
Energy
Energy_Max
Mitigation
Critical
Haste
Level
list/Threat[0]
proc
Damaged(var/mob/Attacker,damage)
if(istype(src,/mob/Monster))
Threat += (damage/2)*(Attacker.Mitigation) //What do I put here instead of this?
Health = max(0,min(Health_Max - damage,Health_Max))
DeathCheck()
DeathCheck(var/mob/Attacker)
if(Health <= 0)
Health = 0
Threat = 0
if(istype(src,/mob/Monster)) del src


Problem description:
So what I'm trying to do is make a system so when you're attacking an enemy AI the attacker goes into a list where the value of Threat is saved and when you keep attacking that value goes up. I'm trying to figure out how to add the attackers and their threat value onto the Enemy AI and how to access the values in the list and add onto it. I'm trying hard to remember how to use Associative Lists since this is my first time back coding in 2 years.

Like When Two People Attack the same Enemy I want their names or something to distinguish them saved into the Enemy's Threat List along with a value. The Value will be used to determine which attacker the Enemy will attack. I'll also want to use the list as a list of attackers so when I want the Enemy to attack a random attacker in the list I want to be able to do that.

Should I save the attackers mob inside the list?

Associative Lists?

Edited it a bit, Im not sure if this is right
    proc
Damaged(var/mob/Attacker,damage)
Health = max(0,min(Health_Max - damage,Health_Max))
ThreatCheck(Attacker,damage)
DeathCheck(Attacker)

ThreatCheck(var/mob/Attacker,damage)
if(!Threat) Threat=list()
if(istype(src,/mob/Monster))
Threat[Attacker.name] += round((damage/100)*(Attacker.Mitigation/100))

CheckThreat(var/name)
if(name in Threat) return Threat[name]

DeathCheck(var/mob/Attacker)
if(Health <= 0)
Health = 0
if(istype(src,/mob/Monster)) del src
In response to Max Omega
Halp ):
In response to Max Omega
1. You can use objects as keys in the associative list, you don't have to use the mob's name.

2. I'd keep damage and threat in separate procs. That way it's clear where damage mitigation is applied and it's clear where threat is being modified.

mob
var
health
list/threat = list()

proc
damage(mob/attacker, damage)
// apply damage reduction
damage = damage - defense

// add threat
add_threat(attacker, damage)

add_threat(mob/attacker, damage)
if(attacker in threat)
threat[attacker] += damage
else
threat[attacker] = damage


In the mob's AI routine you can find the mob with the highest threat and use that as their target.