mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 14:08:31 +01:00
Fixes transforming items getting their force incorrectly modified when metalgenned multiple times (#95739)
## About The Pull Request Transforming weapons could change their sharpness which would break material force modification as materials modify the force differently based on item sharpness. Also the force was hard reset every time you switched it on or off, which would also break the math. I've rewritten the transforming component to preserve force and sharpness, and account for different sharpness of the item when switched on/off. Additionally, I've updated the two-handed component to use the new system to make it easier to work with/less prone to breaking. ## Why It's Good For The Game <img width="557" height="218" alt="image" src="https://github.com/user-attachments/assets/59cfb21a-e97e-4843-9c11-c87ed32384a9" /> ## Changelog 🆑 fix: Transforming items like eswords should no longer get absurd stats when metalgenned multiple times in a row /🆑
This commit is contained in:
+66
-41
@@ -2066,47 +2066,8 @@
|
||||
obj_flags |= CONDUCTS_ELECTRICITY
|
||||
|
||||
/obj/item/change_material_strength(datum/material/material, mat_amount, multiplier, remove = FALSE)
|
||||
var/density = material.get_property(MATERIAL_DENSITY)
|
||||
var/hardness = material.get_property(MATERIAL_HARDNESS)
|
||||
var/flexibility = material.get_property(MATERIAL_FLEXIBILITY)
|
||||
|
||||
// Item force calculation depends on its initial (assumed to be main) sharpness
|
||||
// Transforming component doesn't work with materials at all and will need a refactor to change that, so we don't care about it here.
|
||||
|
||||
var/force_mod = 1
|
||||
var/throwforce_mod = 1
|
||||
|
||||
switch (sharpness)
|
||||
if (NONE)
|
||||
// Blunt items are really hurt by all the flexing
|
||||
force_mod = (1 + (density - 4) * 0.1) / (1 + flexibility * 0.1)
|
||||
throwforce_mod = 1 + (density - 4) * 0.1 - flexibility * 0.1
|
||||
|
||||
if (SHARP_EDGED)
|
||||
// Sharp items don't care about density and need high hardness to get a real bonus, but can tolerate (and benefit from) some flex
|
||||
force_mod = 1 + (hardness - 4) * 0.1
|
||||
throwforce_mod = 1 + (hardness - 4) * 0.1
|
||||
|
||||
// Peaks out at 20% at flexibility of 1, drops off up to -80% at 10
|
||||
if (flexibility < 2)
|
||||
force_mod *= 1 + (1 - abs(1 - flexibility)) * 0.2
|
||||
throwforce_mod += (1 - abs(1 - flexibility)) * 0.2
|
||||
else
|
||||
force_mod *= 1 - (flexibility - 2) * 0.1
|
||||
throwforce_mod -= (flexibility - 2) * 0.1
|
||||
|
||||
if (SHARP_POINTY)
|
||||
// Pointy items care about both density and hardness
|
||||
force_mod = 1 + MATERIAL_PROPERTY_DIVERGENCE(density, 4, 6) * 0.05 + (hardness - 4) * 0.1
|
||||
throwforce_mod = 1 + MATERIAL_PROPERTY_DIVERGENCE(density, 4, 6) * 0.05 * 0.05 + (hardness - 4) * 0.1
|
||||
// But are not affected by flexibility until higher values, although they don't benefit from it either
|
||||
if (flexibility > 4)
|
||||
force_mod *= (1 - (flexibility - 4) * 0.2)
|
||||
throwforce_mod -= (flexibility - 4) * 0.2
|
||||
|
||||
// Just for sanity in case something breaks
|
||||
force_mod = round(clamp(force_mod, MATERIAL_MIN_FORCE_MULTIPLIER, MATERIAL_MAX_FORCE_MULTIPLIER), 0.01)
|
||||
throwforce_mod = round(clamp(throwforce_mod, MATERIAL_MIN_FORCE_MULTIPLIER, MATERIAL_MAX_FORCE_MULTIPLIER), 0.01)
|
||||
var/force_mod = get_material_force_modifier(material)
|
||||
var/throwforce_mod = get_material_throwforce_modifier(material)
|
||||
|
||||
if (!remove)
|
||||
force *= GET_MATERIAL_MODIFIER(force_mod, multiplier)
|
||||
@@ -2115,6 +2076,70 @@
|
||||
force /= GET_MATERIAL_MODIFIER(force_mod, multiplier)
|
||||
throwforce /= GET_MATERIAL_MODIFIER(throwforce_mod, multiplier)
|
||||
|
||||
/// Returns a force multiplier from a material for a given sharpness
|
||||
/obj/item/proc/get_material_force_modifier(datum/material/material, item_sharpness = get_sharpness())
|
||||
var/density = material.get_property(MATERIAL_DENSITY)
|
||||
var/hardness = material.get_property(MATERIAL_HARDNESS)
|
||||
var/flexibility = material.get_property(MATERIAL_FLEXIBILITY)
|
||||
var/force_mod = 1
|
||||
switch (item_sharpness)
|
||||
if (NONE)
|
||||
// Blunt items are really hurt by all the flexing
|
||||
force_mod = (1 + (density - 4) * 0.1) / (1 + flexibility * 0.1)
|
||||
|
||||
if (SHARP_EDGED)
|
||||
// Sharp items don't care about density and need high hardness to get a real bonus, but can tolerate (and benefit from) some flex
|
||||
force_mod = 1 + (hardness - 4) * 0.1
|
||||
|
||||
// Peaks out at 20% at flexibility of 1, drops off up to -80% at 10
|
||||
if (flexibility < 2)
|
||||
force_mod *= 1 + (1 - abs(1 - flexibility)) * 0.2
|
||||
else
|
||||
force_mod *= 1 - (flexibility - 2) * 0.1
|
||||
|
||||
if (SHARP_POINTY)
|
||||
// Pointy items care about both density and hardness
|
||||
force_mod = 1 + MATERIAL_PROPERTY_DIVERGENCE(density, 4, 6) * 0.05 + (hardness - 4) * 0.1
|
||||
// But are not affected by flexibility until higher values, although they don't benefit from it either
|
||||
if (flexibility > 4)
|
||||
force_mod *= (1 - (flexibility - 4) * 0.2)
|
||||
|
||||
// Just for sanity in case something breaks
|
||||
force_mod = round(clamp(force_mod, MATERIAL_MIN_FORCE_MULTIPLIER, MATERIAL_MAX_FORCE_MULTIPLIER), 0.01)
|
||||
return force_mod
|
||||
|
||||
/// Returns a force multiplier from a material for a given sharpness
|
||||
/obj/item/proc/get_material_throwforce_modifier(datum/material/material, item_sharpness = get_sharpness())
|
||||
var/density = material.get_property(MATERIAL_DENSITY)
|
||||
var/hardness = material.get_property(MATERIAL_HARDNESS)
|
||||
var/flexibility = material.get_property(MATERIAL_FLEXIBILITY)
|
||||
var/throwforce_mod = 1
|
||||
switch (item_sharpness)
|
||||
if (NONE)
|
||||
// Blunt items are really hurt by all the flexing
|
||||
throwforce_mod = 1 + (density - 4) * 0.1 - flexibility * 0.1
|
||||
|
||||
if (SHARP_EDGED)
|
||||
// Sharp items don't care about density and need high hardness to get a real bonus, but can tolerate (and benefit from) some flex
|
||||
throwforce_mod = 1 + (hardness - 4) * 0.1
|
||||
|
||||
// Peaks out at 20% at flexibility of 1, drops off up to -80% at 10
|
||||
if (flexibility < 2)
|
||||
throwforce_mod += (1 - abs(1 - flexibility)) * 0.2
|
||||
else
|
||||
throwforce_mod -= (flexibility - 2) * 0.1
|
||||
|
||||
if (SHARP_POINTY)
|
||||
// Pointy items care about both density and hardness
|
||||
throwforce_mod = 1 + MATERIAL_PROPERTY_DIVERGENCE(density, 4, 6) * 0.05 * 0.05 + (hardness - 4) * 0.1
|
||||
// But are not affected by flexibility until higher values, although they don't benefit from it either
|
||||
if (flexibility > 4)
|
||||
throwforce_mod -= (flexibility - 4) * 0.2
|
||||
|
||||
// Just for sanity in case something breaks
|
||||
throwforce_mod = round(clamp(throwforce_mod, MATERIAL_MIN_FORCE_MULTIPLIER, MATERIAL_MAX_FORCE_MULTIPLIER), 0.01)
|
||||
return throwforce_mod
|
||||
|
||||
/**
|
||||
* Returns the atom(either itself or an internal module) that will interact/attack the target on behalf of us
|
||||
* For example an object can have different `tool_behaviours` (e.g borg omni tool) but will return an internal reference of that tool to attack for us
|
||||
|
||||
Reference in New Issue
Block a user