Files
Bubberstation/code/datums/components/focused_attacker.dm
MrMelbert 9664d24c13 Refactors UnarmedAttack so we don't have like 4 Unarmed Attack signals, kills two more snowflake species procs (#78991)
## About The Pull Request

- Deletes `spec_unarmedattack`
- Deletes `spec_unarmedattacked`
- Replaces `COMSIG_HUMAN_EARLY_UNARMED_ATTACK` with
`COMSIG_LIVING_EARLY_UNARMED_ATTACK`
- Replaces uses of `COMSIG_HUMAN_MELEE_UNARMED_ATTACK` with
`COMSIG_LIVING_EARLY_UNARMED_ATTACK`
- Fixes(?)(I've never seen this work) / Elementizes Monkey ability to
bite while handcuffed
- Monkey clever `attack paw` / `attack hand` thing is now handled the
same on the human level (via `resolve_unarmed_attack`)

## Why It's Good For The Game

Atomized from swing branch. I was really annoyed with these two signals,
this kinda unifies the behavior between living and human mobs (they were
already quite similar).

One thing of note is that this will make dis-coordinated humans use
`attack_paw` rather than `attack_hand`, so they'll bite people instead
of punching them. I'm not sure if this is what we want, if we wanna
tweak that before then I can by all means.

## Changelog

🆑 Melbert
refactor: Refactored unarmed attacking mechanisms, this means
dis-coordinated humans will now bite people like monkeys (like how
coordinated monkeys punch people like humans?)
refactor: Dis-coordinated humans smashing up machines now use their
hands, rather than their paws
/🆑

---------

Co-authored-by: san7890 <the@san7890.com>
2023-10-15 22:25:19 -06:00

72 lines
2.5 KiB
Plaintext

/**
* Increases our attack damage every time we attack the same target
* Not compatible with any other component or status effect which modifies attack damage
*/
/datum/component/focused_attacker
/// Amount of damage we gain per attack
var/gain_per_attack
/// Maximum amount by which we can increase our attack power
var/maximum_gain
/// The last thing we attacked
var/atom/last_target
/datum/component/focused_attacker/Initialize(gain_per_attack = 5, maximum_gain = 25)
. = ..()
if (!isliving(parent) && !isitem(parent))
return COMPONENT_INCOMPATIBLE
src.maximum_gain = maximum_gain
src.gain_per_attack = gain_per_attack
/datum/component/focused_attacker/Destroy(force, silent)
if (!isnull(last_target))
UnregisterSignal(last_target, COMSIG_QDELETING)
return ..()
/datum/component/focused_attacker/RegisterWithParent()
if (isliving(parent))
RegisterSignal(parent, COMSIG_LIVING_UNARMED_ATTACK, PROC_REF(pre_mob_attack))
else
RegisterSignal(parent, COMSIG_ITEM_PRE_ATTACK, PROC_REF(pre_item_attack))
/datum/component/focused_attacker/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_ITEM_PRE_ATTACK))
/// Before a mob attacks, try increasing its attack power
/datum/component/focused_attacker/proc/pre_mob_attack(mob/living/attacker, atom/target)
SIGNAL_HANDLER
if (isnull(target) || isturf(target))
return
if (target == last_target)
if (attacker.melee_damage_lower - initial(attacker.melee_damage_lower) >= maximum_gain)
return
attacker.melee_damage_lower += gain_per_attack
attacker.melee_damage_upper += gain_per_attack
return
attacker.melee_damage_lower = initial(attacker.melee_damage_lower)
attacker.melee_damage_upper = initial(attacker.melee_damage_upper)
register_new_target(target)
/// Before an item attacks, try increasing its attack power
/datum/component/focused_attacker/proc/pre_item_attack(obj/item/weapon, atom/target, mob/user, params)
SIGNAL_HANDLER
if (target == last_target)
if (weapon.force - initial(weapon.force) < maximum_gain)
weapon.force += gain_per_attack
return
weapon.force = initial(weapon.force)
register_new_target(target)
/// Register a new target
/datum/component/focused_attacker/proc/register_new_target(atom/target)
if (!isnull(last_target))
UnregisterSignal(last_target, COMSIG_QDELETING)
last_target = target
RegisterSignal(target, COMSIG_QDELETING, PROC_REF(on_target_deleted))
/// Drop our target ref on deletion
/datum/component/focused_attacker/proc/on_target_deleted(target)
SIGNAL_HANDLER
last_target = null