diff --git a/data/json/faults/fixes_gun.json b/data/json/faults/fixes_gun.json index 3da92cd342e49..6665665e0a0f3 100644 --- a/data/json/faults/fixes_gun.json +++ b/data/json/faults/fixes_gun.json @@ -26,6 +26,21 @@ "time_save_profs": { "prof_gun_cleaning": 0.5 }, "time_save_flags": { "EASY_CLEAN": 0.5 } }, + { + "type": "fault_fix", + "id": "mend_gun_fouling_quick", + "name": "Swab gun", + "success_msg": "You quickly swab your %s to remove black powder residue and prevent further corrosion.", + "time": "1 m", + "faults_removed": [ "fault_gun_blackpowder" ], + "faults_added": [ "fault_gun_blackpowder" ], + "skills": { "mechanics": 1 }, + "set_variables": { "rust_timer": "0" }, + "adjust_variables_multiply": { "dirt": 0.8 }, + "requirements": [ [ "gun_cleaning_quick", 1 ] ], + "time_save_profs": { "prof_gun_cleaning": 0.5 }, + "time_save_flags": { "EASY_CLEAN": 0.5 } + }, { "type": "fault_fix", "id": "mend_gun_fouling_clean_and_lube", diff --git a/data/json/requirements/toolsets.json b/data/json/requirements/toolsets.json index ae89ec812d0cf..5412ac6038e81 100644 --- a/data/json/requirements/toolsets.json +++ b/data/json/requirements/toolsets.json @@ -62,6 +62,13 @@ [ [ "cotton_patchwork", 1 ], [ "fur", 1 ], [ "faux_fur", 1 ], [ "felt_patch", 1 ], [ "cotton_ball", 2 ] ] ] }, + { + "id": "gun_cleaning_quick", + "type": "requirement", + "//": "Requires a rod/wire and cloth patch or similar item.", + "tools": [ [ [ "pipe_cleaner", -1 ], [ "small_repairkit", -1 ], [ "large_repairkit", -1 ] ] ], + "components": [ [ [ "cotton_patchwork", 1 ], [ "fur", 1 ], [ "faux_fur", 1 ], [ "felt_patch", 1 ], [ "cotton_ball", 2 ] ] ] + }, { "id": "gun_lubrication", "type": "requirement", diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md index 88aa5daad0e4a..4645fc9f8460e 100644 --- a/doc/JSON_INFO.md +++ b/doc/JSON_INFO.md @@ -1653,6 +1653,7 @@ Fault fixes are methods to fix faults, the fixes can optionally add other faults "faults_added": [ "fault_gun_unlubricated" ], // faults added when fix is applied "skills": { "mechanics": 1 }, // skills required to apply fix "set_variables": { "dirt": "0" }, // sets the variables on the item when fix is applied + "adjust_variables_multiply": { "dirt": ".8" }, // adjusts the variables on the item when fix is applied using MULTIPLICATION "requirements": [ [ "gun_cleaning", 1 ] ], // requirements array, see below "mod_damage": 1000, // damage to modify on item when fix is applied, can be negative to repair "mod_degradation": 50, // degradation to modify on item when fix is applied, can be negative to reduce degradation diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index d510d9f99180c..05db524e634cc 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -2734,6 +2734,11 @@ void activity_handlers::mend_item_finish( player_activity *act, Character *you ) for( const auto &[var_name, var_value] : fix.set_variables ) { target.set_var( var_name, var_value ); } + for( const auto &[var_name, var_value] : fix.adjust_variables_multiply ) { + const double var_value_multiplier = var_value; + const double var_oldvalue = target.get_var( var_name, 0.0 ); + target.set_var( var_name, std::round( var_oldvalue * var_value_multiplier ) ); + } const std::string start_durability = target.durability_indicator( true ); diff --git a/src/fault.cpp b/src/fault.cpp index e5d3a9697f1a4..8653874314ce3 100644 --- a/src/fault.cpp +++ b/src/fault.cpp @@ -164,10 +164,12 @@ const requirement_data &fault_fix::get_requirements() const void fault_fix::load( const JsonObject &jo, std::string_view ) { + fault_fix f; mandatory( jo, was_loaded, "name", name ); optional( jo, was_loaded, "success_msg", success_msg ); optional( jo, was_loaded, "time", time ); optional( jo, was_loaded, "set_variables", set_variables ); + optional( jo, was_loaded, "adjust_variables_multiply", adjust_variables_multiply ); optional( jo, was_loaded, "skills", skills ); optional( jo, was_loaded, "faults_removed", faults_removed ); optional( jo, was_loaded, "faults_added", faults_added ); diff --git a/src/fault.h b/src/fault.h index b2512d66d306b..2abb3ab847cac 100644 --- a/src/fault.h +++ b/src/fault.h @@ -40,6 +40,8 @@ class fault_fix translation success_msg; // message to print on applying successfully time_duration time = 0_seconds; std::map set_variables; // item vars applied to item + // item vars adjustment(s) applied to item via multiplication; // item vars adjustment(s) applied to item via multiplication + std::map adjust_variables_multiply; std::map skills; // map of skill_id to required level std::set faults_removed; // which faults are removed on applying std::set faults_added; // which faults are added on applying diff --git a/src/item.cpp b/src/item.cpp index 050d63b7807f9..c1bb7ba75aeb8 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -14025,9 +14025,10 @@ bool item::process_tool( Character *carrier, const tripoint &pos ) bool item::process_blackpowder_fouling( Character *carrier ) { - // rust is deterministic. 12 hours for first rust, then 24 (36 total), then 36 (72 total) and finally 48 (120 hours to go to XX) - // this speeds up by the amount the gun is dirty, 2-6x as fast depending on dirt level. - set_var( "rust_timer", get_var( "rust_timer", 0 ) + 1 + get_var( "dirt", 0 ) / 2000 ); + // Rust is deterministic. At a total modifier of 1 (the max): 12 hours for first rust, then 24 (36 total), then 36 (72 total) and finally 48 (120 hours to go to XX) + // this speeds up by the amount the gun is dirty, 2-6x as fast depending on dirt level. At minimum dirt, the modifier is 0.3x the speed of the above mentioned figures. + set_var( "rust_timer", get_var( "rust_timer", 0 ) + std::min( 0.3 + get_var( "dirt", 0 ) / 200, + 1.0 ) ); double time_mult = 1.0 + ( 4.0 * static_cast( damage() ) ) / static_cast ( max_damage() ); if( damage() < max_damage() && get_var( "rust_timer", 0 ) > 43200.0 * time_mult ) {