mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
refactoring how materials effects are added to atoms (#86901)
## About The Pull Request I'm "cooking" the materials system a bit, specifically the code responsible for applying and removing effects. My goal is to move most of the code to the objects-side, split it in smaller procs that can be more easily overriden or called for object-specific modifiers and effects, while also revamping things all around to better support items made from multiple materials (the cleric mace will most likely be one in this PR, with the handle and tip made of different materials). PR NO LONGER WIP, TESTED AND ALL, CLERIC MACES CAN NOW BE MADE OF TWO MATERIALS. ## Why It's Good For The Game One of the nastiest flaws with the materials system is that it's just unfeasable to have items made of multiple mats (with effects enabled) right now, as they easily tend to override each other, where some of the modifiers and effects should only be applied the main material. Beside, the system's starting to show signs of its time, from the several type checks used to apply different effects, the one letter variables to the the material flags that are still being passed down as arguments when you can access them from the atom/source arg anyway. It would be disonhest of me if I went ahead and coded material fishing rods or whatever fish fuckery with materials without ensuring it won't further the technical debt the feature currently has. ## Changelog 🆑 refactor: Refactored materials code. report any issue. add: Cleric maces (The autolathe-printable weapon design from outer space) can now be made of two different materials. balance: Buffed cleric maces a little. fix: toolboxes' stats are now affected by materials again. /🆑 --------- Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com>
This commit is contained in:
committed by
Majkl-J
co-authored by
_0Steven
parent
e5dad4ea31
commit
2531d69ff4
@@ -77,18 +77,19 @@
|
||||
amount = new_amount
|
||||
while(amount > max_amount)
|
||||
amount -= max_amount
|
||||
new type(loc, max_amount, FALSE)
|
||||
new type(loc, max_amount, FALSE, mat_override, mat_amt)
|
||||
if(!merge_type)
|
||||
merge_type = type
|
||||
|
||||
if(LAZYLEN(mat_override))
|
||||
set_mats_per_unit(mat_override, mat_amt)
|
||||
else if(LAZYLEN(mats_per_unit))
|
||||
set_mats_per_unit(mats_per_unit, 1)
|
||||
else if(LAZYLEN(custom_materials))
|
||||
set_mats_per_unit(custom_materials, amount ? 1/amount : 1)
|
||||
|
||||
. = ..()
|
||||
|
||||
var/materials_mult = amount
|
||||
if(LAZYLEN(mat_override))
|
||||
materials_mult *= mat_amt
|
||||
mats_per_unit = mat_override
|
||||
if(LAZYLEN(mats_per_unit))
|
||||
initialize_materials(mats_per_unit, materials_mult)
|
||||
|
||||
if(merge)
|
||||
for(var/obj/item/stack/item_stack in loc)
|
||||
if(item_stack == src)
|
||||
@@ -118,26 +119,15 @@
|
||||
if(is_path_in_list(merge_type, GLOB.golem_stack_food_directory))
|
||||
AddComponent(/datum/component/golem_food, golem_food_key = merge_type)
|
||||
|
||||
/** Sets the amount of materials per unit for this stack.
|
||||
*
|
||||
* Arguments:
|
||||
* - [mats][/list]: The value to set the mats per unit to.
|
||||
* - multiplier: The amount to multiply the mats per unit by. Defaults to 1.
|
||||
*/
|
||||
/obj/item/stack/proc/set_mats_per_unit(list/mats, multiplier=1)
|
||||
mats_per_unit = SSmaterials.FindOrCreateMaterialCombo(mats, multiplier)
|
||||
update_custom_materials()
|
||||
|
||||
/** Updates the custom materials list of this stack.
|
||||
*/
|
||||
///Called to lazily update the materials of the item whenever the used or if more is added
|
||||
/obj/item/stack/proc/update_custom_materials()
|
||||
set_custom_materials(mats_per_unit, amount, is_update=TRUE)
|
||||
if(length(mats_per_unit))
|
||||
set_custom_materials(mats_per_unit, amount)
|
||||
|
||||
/**
|
||||
* Override to make things like metalgen accurately set custom materials
|
||||
*/
|
||||
/obj/item/stack/set_custom_materials(list/materials, multiplier=1, is_update=FALSE)
|
||||
return is_update ? ..() : set_mats_per_unit(materials, multiplier/(amount || 1))
|
||||
/obj/item/stack/apply_material_effects(list/materials)
|
||||
. = ..()
|
||||
if(amount)
|
||||
mats_per_unit = SSmaterials.FindOrCreateMaterialCombo(materials, 1/amount)
|
||||
|
||||
/obj/item/stack/blend_requirements()
|
||||
if(is_cyborg)
|
||||
@@ -440,7 +430,7 @@
|
||||
if((recipe.crafting_flags & CRAFT_APPLIES_MATS) && LAZYLEN(mats_per_unit))
|
||||
if(isstack(created))
|
||||
var/obj/item/stack/crafted_stack = created
|
||||
crafted_stack.set_mats_per_unit(mats_per_unit, recipe.req_amount / recipe.res_amount)
|
||||
crafted_stack.set_custom_materials(mats_per_unit, (recipe.req_amount / recipe.res_amount) * crafted_stack.amount)
|
||||
else
|
||||
created.set_custom_materials(mats_per_unit, recipe.req_amount / recipe.res_amount)
|
||||
|
||||
@@ -543,8 +533,7 @@
|
||||
amount -= used
|
||||
if(check && is_zero_amount(delete_if_zero = TRUE))
|
||||
return TRUE
|
||||
if(length(mats_per_unit))
|
||||
update_custom_materials()
|
||||
update_custom_materials()
|
||||
update_appearance()
|
||||
update_weight()
|
||||
return TRUE
|
||||
@@ -591,8 +580,7 @@
|
||||
source.add_charge(_amount * cost)
|
||||
else
|
||||
amount += _amount
|
||||
if(length(mats_per_unit))
|
||||
update_custom_materials()
|
||||
update_custom_materials()
|
||||
update_appearance()
|
||||
update_weight()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user