# Damage Refactoring ## Goals - Refactor damage application to be more consistent, especially when it comes to items. - Standardise various elements of damage application. - For example, objects with a similar sharpness should have the same style of damage application, one shouldn't cause bleeding while the other does something entirely else. - Get us in a position where damage can be easilly expanded on in the future and allow us to implement features such as wounds/injuries. - This in of itself should provide little changes to current damage, except for cases where the damage was being applied inconsistently; in which cases it will be made more consistent. ## Damage Application Some things cannot be standardised when applying damage as it will always be different for every object, for example force and armour penetration. These will always be passed in if the damage dealing requires it. Applying damage without an instantiated damage source: ```c#! target.apply_damage(/datum/damage_source/chemical, /datum/damage/burn, 20 * rem) ``` Apply damage with an instantiated damage source: ```c#! damage_source.apply_direct(target, /datum/damage/burn, 20 * rem) ``` ## Damage Source Defines some parameters for what is dealing damage. These will be consistently applied. For example, a battle hammer may have a heavy blunt damage source and things like knifes would have a short blade damage source. Toolboxes would have a light blunt damage source etc. Things like chemicals and armour bypassing damage sources would have their own datums. ```c! // This is for applying the damage directly to the target rather than from performing an attack. /datum/damage_source/proc/apply_direct(mob/living/target, damage_type, damage_amount, target_zone, update_health = TRUE) // Has an atom target to allow for easy refactoring to swing combat later // Default behaviour is to just apply directly if the target is a mob or deal structural damage if the target is a structure (how?) /datum/damage_source/proc/deal_attack(mob/living/attacker, obj/item/attacking_item, atom/target, damage_type, damage_amount, target_zone = null, update_health = TRUE) ``` Applies the damage source to the specified target with the provided damage amount. This will do different things depending on the damage source, chemical damage is internal and will apply the damage directly. > [name=PowerfulBacon] [color=#8222f7] If we are instantiating a damage source for every object this will need to be done lazilly, otherwise we may get a decent performance cost at roundstart from instantiating so many of these objects. Damage sources will be able to define stuff such as the actions/procs to call when damage is defined and how to mutate the damage type (For example, a sharp object may have a higher chance of inflicting bleeding damage as well). **What is applied here?** - Armour calculations - Damage type translation (sharp injury to blunt injury if wearing armour, for example) - Bleeding - Choosing where to attack (internal organ, bodypart, mob as a whole) **What ones will we need?** - Sharp Light (Light knives) - Sharp Heavy (Energy sword) - Blunt Light (Toolboxes, Wrenches, etc.) - Blunt Point (Screwdrivers) - Blunt Heavy (Battle-axes) - Unarmed - Stunning (Stun batons, takes stamina armour into account) - Chemical (Chemicals, may deal internal organ damage in future) - Magic (Magical weapons or supernatural events) - Gunshot (Bullet armour, may be expanded to deal internal organ injueries/wounds or could be expanded to have different calibers in the future) - Laser (Takes into account laser armour) - Energy (Takes into account energy armour) - Temperature (Account for temperature resistances?) - Fire (Fire armour resistance) - Crush (Airlock/elevator crushing. Accounts for melee armour.) - Explosion (Overall body damage from explosions. Ignores damage type, will apply both brute and burn. Respects explosive armour.) - Pressure (Overall body damage from pressure) - Abstract (Direct damage application with no conditions) - Acid (Takes into account acid armour) - Electricity (Takes into account insulation) We can add other specific sources as needed which just use the default behaviour of applying the damage directly. ## Damage Type Simplies the type of damage that will be applied. For now these are just burn, brute, oxyloss, cloneloss, brain however will be expanded on in the future if we want a more complicated medical system. This makes new damage types much easier to add as it is more modularised. In the future these may be expanded to either: - Implement wound support/harder to heal damages - Implement all damages as wounds (Similar to barotrauma/rimworld damage style) ``` /datum/damage/proc/apply(mob/living/target, damage) /datum/damage/proc/apply(obj/item/organ/target, damage) /datum/damage/proc/apply(obj/item/bodypart/target, damage) ``` Armour penetration is applied in the damage source and this simply applies the damage directly to the mob, in the specified amount by doing something like calling adjustBruteLoss. **What is applied here?** - Damage directly to mob in the specified amount. **What ones will we need?** - Burn - Brute - Clone - Oxyloss - Toxin loss - Brain (this is used in VV and is a damage type? Its a bit less shitcodey with this solution) ## Additional **Q: We may want to move towards something like swing combat in the future. How can we make apply_damage either easy enough to refactor or have enough data that all we would need to do is modify the contents of the apply damage function?** This has been thought about and applied in the above proposal. This is why we have both apply_direct and deal_attack. Deal_attack will allow us to give certain damage sources different swing combat effects. **Q: Should we refactor things that can recieve damage into a datum or component so that we don't need to have 3 different apply procs? Really we need interfaces for this but byond doesn't support it.** For now, we will just do type checks for structures and organs. **Q: How should we handle healing damage?** - Needs to be able to handle overall and specific injury healing for the future (support wound handling) - Doesn't need stuff like armour penetration or swing combat potential support.