Files
Bubberstation/code/datums/elements/wall_smasher.dm
SkyratBot fcebbd61a9 [MIRROR] Basic Mob Carp Bonus Part: Wall smashing [MDB IGNORE] (#17791)
* Basic Mob Carp Bonus Part: Wall smashing (#71524)

## About The Pull Request

Atomisation of #71421
This moves the attack function of "environment smash" flags which allow
simple mobs to attack walls into an element, so that we can put it on
other things later.
For some reason while working on carp I convinced myself that they had
"environment_smash" flags, which they do not, so this actually is not
relevant to carp in any way.

While implementing this I learned that the way wall smashing works is
stupid, because walls don't have health and so resultingly if a mob can
attack walls it deletes them in a single click. If we ever decide to
change this then it should be easier in an element than in three
different `attack_animal` reactions.
This is especially silly with the "wumborian fugu" item which allows any
mob it is used on to instantly delete reinforced walls, and also to
destroy tables if they click them like seven or eight times (because it
does not increase their object damage in any way).

## Why It's Good For The Game

Eventually someone will port a basic mob which does use this behaviour
(most of the mining ones for instance) and then this will be useful.
If we ever rebalance wall smashing to not instantly delete walls then
this will also be useful.
Admins can apply this to a mob to allow it to delete walls if they
wanted to do that for some reason, they probably shouldn't to be honest
at least until after we've done point two unless they trust the player
not to just use it to deconstruct the space station.

## Changelog
🆑
refactor: Moves wall smashing out of simple mob code and into an element
we can reuse for basic mobs later
/🆑

* Basic Mob Carp Bonus Part: Wall smashing

* SR mobs

Co-authored-by: Jacquerel <hnevard@gmail.com>
Co-authored-by: tastyfish <crazychris32@gmail.com>
2022-11-28 16:42:19 -05:00

72 lines
2.6 KiB
Plaintext

/**
* # Wall Smasher
* An element you put on mobs to let their attacks break walls
* If put in the hands of a player this can cause a lot of problems, be careful
*/
/datum/element/wall_smasher
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
/// Either ENVIRONMENT_SMASH_WALLS or ENVIRONMENT_SMASH_RWALLS, as in '_DEFINES/mobs.dm'
var/strength_flag
/datum/element/wall_smasher/Attach(datum/target, strength_flag = ENVIRONMENT_SMASH_WALLS)
. = ..()
if (. == ELEMENT_INCOMPATIBLE)
return ELEMENT_INCOMPATIBLE
if (!isliving(target))
return ELEMENT_INCOMPATIBLE
src.strength_flag = strength_flag
RegisterSignals(target, list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_HUMAN_EARLY_UNARMED_ATTACK), PROC_REF(on_unarm_attack)) // Players
RegisterSignal(target, COMSIG_HOSTILE_PRE_ATTACKINGTARGET, PROC_REF(on_pre_attackingtarget)) // AI
if (isanimal(target))
var/mob/living/simple_animal/animal_target = target
animal_target.environment_smash = strength_flag
/datum/element/wall_smasher/Detach(datum/target)
UnregisterSignal(target, list(COMSIG_LIVING_UNARMED_ATTACK, COMSIG_HUMAN_EARLY_UNARMED_ATTACK, COMSIG_HOSTILE_PRE_ATTACKINGTARGET))
if (isanimal(target))
var/mob/living/simple_animal/animal_target = target
animal_target.environment_smash = initial(animal_target.environment_smash)
return ..()
/datum/element/wall_smasher/proc/on_unarm_attack(mob/living/puncher, atom/target, proximity, modifiers)
SIGNAL_HANDLER
try_smashing(puncher, target)
/datum/element/wall_smasher/proc/on_pre_attackingtarget(mob/living/puncher, atom/target)
SIGNAL_HANDLER
try_smashing(puncher, target)
/datum/element/wall_smasher/proc/try_smashing(mob/living/puncher, atom/target)
if (!isturf(target))
return
if (isfloorturf(target))
return
if (isindestructiblewall(target))
return
puncher.changeNext_move(CLICK_CD_MELEE)
puncher.do_attack_animation(target)
if (ismineralturf(target))
var/turf/closed/mineral/mineral_wall = target
mineral_wall.gets_drilled(puncher)
return COMPONENT_HOSTILE_NO_ATTACK
if (!iswallturf(target)) // In case you're some kind of non-wall non-mineral closed turf yet to be invented
return COMPONENT_HOSTILE_NO_ATTACK
var/turf/closed/wall/wall_turf = target
if (istype(wall_turf, /turf/closed/wall/r_wall) && strength_flag != ENVIRONMENT_SMASH_RWALLS)
playsound(wall_turf, 'sound/effects/bang.ogg', 50, vary = TRUE)
wall_turf.balloon_alert(puncher, "too tough!")
return COMPONENT_HOSTILE_NO_ATTACK
wall_turf.dismantle_wall(devastated = TRUE)
playsound(wall_turf, 'sound/effects/meteorimpact.ogg', 100, vary = TRUE)
return COMPONENT_HOSTILE_NO_ATTACK