From 951b8da1faab5a74f9e776e4b4ab2cf27d509631 Mon Sep 17 00:00:00 2001
From: Anton Simakov <67688115+GuardianDll@users.noreply.github.com>
Date: Mon, 29 Jul 2024 23:17:47 +0200
Subject: [PATCH] add ar-15 .22 conversion kit (#75210)

* add ar-15 .22 conversion kit

* Update data/json/items/gunmod/conversions.json

* Apply suggestions from code review

Co-authored-by: DoctorBoomstick <102766473+DoctorBoomstick@users.noreply.github.com>

* fix gun not cycling ever

* Update data/json/items/gunmod/conversions.json

* Apply suggestions from code review

Co-authored-by: Holli <78005870+Holli-Git@users.noreply.github.com>

* fix damage modifier, fix documentation also

* Apply suggestions from code review

---------

Co-authored-by: DoctorBoomstick <102766473+DoctorBoomstick@users.noreply.github.com>
Co-authored-by: Holli <78005870+Holli-Git@users.noreply.github.com>
---
 .../conversions/conversion_guns.json          |  6 ++++
 .../nested_conversion_gunmods.json            | 17 +++++++++-
 .../conversions/nested_conversion_guns.json   | 21 +++++++++++-
 data/json/items/gunmod/conversions.json       | 32 ++++++++++++++++++
 data/json/items/magazine/22.json              | 33 +++++++++++++++++++
 .../gunmods/gg_gunmods_blacklist.json         |  1 +
 .../magazines/gg_magazines_migration.json     |  4 ++-
 doc/JSON_INFO.md                              |  2 +-
 8 files changed, 112 insertions(+), 4 deletions(-)

diff --git a/data/json/itemgroups/Weapons_Mods_Ammo/conversions/conversion_guns.json b/data/json/itemgroups/Weapons_Mods_Ammo/conversions/conversion_guns.json
index 2c822b49664da..4de1554643b8d 100644
--- a/data/json/itemgroups/Weapons_Mods_Ammo/conversions/conversion_guns.json
+++ b/data/json/itemgroups/Weapons_Mods_Ammo/conversions/conversion_guns.json
@@ -95,6 +95,12 @@
     "subtype": "collection",
     "entries": [ { "item": "modular_ar15", "contents-item": "retool_ar15_762" } ]
   },
+  {
+    "id": "ar15_22",
+    "type": "item_group",
+    "subtype": "collection",
+    "entries": [ { "item": "modular_ar15", "contents-item": "retool_ar15_22" } ]
+  },
   {
     "id": "mdrx_223",
     "type": "item_group",
diff --git a/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_gunmods.json b/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_gunmods.json
index 7095d60869c78..fcb571d3a6daf 100644
--- a/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_gunmods.json
+++ b/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_gunmods.json
@@ -144,6 +144,20 @@
     "on_overflow": "spill",
     "entries": [ { "item": "retool_ar15_762" }, { "item": "762_ar15mag_30rd", "charges": 0 }, { "group": "nested_retool_extras" } ]
   },
+  {
+    "type": "item_group",
+    "id": "boxed_22_ar15kit",
+    "subtype": "collection",
+    "container-item": "box_retool_large",
+    "on_overflow": "spill",
+    "entries": [
+      { "item": "retool_ar15_22" },
+      {
+        "distribution": [ { "item": "22_ar15mag_10", "charges": 0, "count": 2 }, { "item": "22_ar15mag_28", "charges": 0, "count": 2 } ]
+      },
+      { "group": "nested_retool_extras" }
+    ]
+  },
   {
     "type": "item_group",
     "id": "boxed_223rem_mdrxkit",
@@ -310,7 +324,8 @@
           { "group": "boxed_450bushmaster_ar15kit", "prob": 20 },
           { "group": "boxed_450bushmaster_ar15kit_medium", "prob": 15 },
           { "group": "boxed_450bushmaster_ar15kit_short", "prob": 10 },
-          { "group": "boxed_762_ar15kit", "prob": 30 }
+          { "group": "boxed_762_ar15kit", "prob": 30 },
+          { "group": "boxed_22_ar15kit", "prob": 30 }
         ],
         "prob": 100
       }
diff --git a/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_guns.json b/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_guns.json
index 4d2cc66d78261..5231a55ab25af 100644
--- a/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_guns.json
+++ b/data/json/itemgroups/Weapons_Mods_Ammo/conversions/nested_conversion_guns.json
@@ -97,6 +97,24 @@
       { "group": "on_hand_762" }
     ]
   },
+  {
+    "id": "nested_ar15_retool_22",
+    "type": "item_group",
+    "//": "this is a distribution for the gun, reasonable number of backup mags, and some ammo to repack",
+    "//2": "groups together all identical weapons rechambered for the same caliber and converted with different barrel-lengths.",
+    "subtype": "collection",
+    "ammo": 100,
+    "entries": [
+      { "group": "ar15_22", "charges": [ 0, -1 ] },
+      {
+        "distribution": [
+          { "collection": [ { "item": "22_ar15mag_10" }, { "item": "22_ar15mag_10", "prob": 50 } ] },
+          { "collection": [ { "item": "22_ar15mag_28" }, { "item": "22_ar15mag_28", "prob": 50 } ] }
+        ]
+      },
+      { "group": "on_hand_22" }
+    ]
+  },
   {
     "id": "nested_mdrx_retool_223rem",
     "type": "item_group",
@@ -191,7 +209,8 @@
           { "group": "nested_ar15_retool_300blk", "prob": 20 },
           { "group": "nested_ar15_retool_50beowulf", "prob": 15 },
           { "group": "nested_ar15_retool_450bushmaster", "prob": 15 },
-          { "group": "nested_ar15_retool_762", "prob": 25 }
+          { "group": "nested_ar15_retool_762", "prob": 25 },
+          { "group": "nested_ar15_retool_22", "prob": 15 }
         ],
         "prob": 100
       }
diff --git a/data/json/items/gunmod/conversions.json b/data/json/items/gunmod/conversions.json
index 518a08efba93b..1237975228db5 100644
--- a/data/json/items/gunmod/conversions.json
+++ b/data/json/items/gunmod/conversions.json
@@ -397,6 +397,38 @@
     "min_skills": [ [ "weapon", 2 ] ],
     "add_mod": [ [ "brass catcher", 1 ], [ "bayonet lug", 1 ], [ "rail", 2 ], [ "sights", 1 ], [ "underbarrel", 1 ], [ "muzzle", 1 ] ]
   },
+  {
+    "id": "retool_ar15_22",
+    "type": "GUNMOD",
+    "name": { "str": ".22 upper receiver" },
+    "description": "This is a complete upper receiver assembly containing a barrel, handguard, and bolt carrier group that, given the right knowledge, is installable upon an AR-15-style rifle's lower frame.  Swappable uppers enable compatible firearms to be retooled for different cartridges and barrel lengths, with this kit furnishing a weapon with a 16-inch barrel chambered for .22 rounds.",
+    "//": "M4-22 Gen II Upper 22LR/16''BBL",
+    "variant_type": "gun",
+    "weight": "2275 g",
+    "volume": "1696 ml",
+    "longest_side": "600 mm",
+    "integral_volume": "1696 ml",
+    "integral_weight": "2275 g",
+    "integral_longest_side": "406 mm",
+    "barrel_length": "406 mm",
+    "price": "284 USD 53 cent",
+    "price_postapoc": "5 USD",
+    "material": [ "steel", "plastic" ],
+    "symbol": ":",
+    "color": "dark_gray",
+    "location": "bore",
+    "mod_targets": [ "modular_ar15", "modular_m4_carbine", "modular_m16a4", "modular_m16_auto_rifle", "modular_m27_assault_rifle" ],
+    "install_time": "5 m",
+    "dispersion_modifier": 15,
+    "overwrite_min_cycle_recoil": 83,
+    "//0": "AR has too big recoil for .22 round, 83 is right on the edge of being able to use blackpowder loaded and ratshot",
+    "ammo_modifier": [ "22" ],
+    "magazine_adaptor": [ [ "22", [ "22_ar15mag_10", "22_ar15mag_28" ] ] ],
+    "pocket_mods": [ { "pocket_type": "MAGAZINE_WELL", "item_restriction": [ "22_ar15mag_10", "22_ar15mag_28" ] } ],
+    "min_skills": [ [ "weapon", 2 ] ],
+    "damage_modifier": { "damage_type": "bullet", "amount": 2 },
+    "add_mod": [ [ "brass catcher", 1 ], [ "bayonet lug", 1 ], [ "rail", 2 ], [ "sights", 1 ], [ "underbarrel", 1 ], [ "muzzle", 1 ] ]
+  },
   {
     "id": "retool_mdrx_223rem",
     "type": "GUNMOD",
diff --git a/data/json/items/magazine/22.json b/data/json/items/magazine/22.json
index 1b62008ab2781..9a499b19b92bf 100644
--- a/data/json/items/magazine/22.json
+++ b/data/json/items/magazine/22.json
@@ -42,6 +42,39 @@
     "flags": [ "SPEEDLOADER" ],
     "pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "ammo_restriction": { "22": 19 } } ]
   },
+  {
+    "id": "22_ar15mag_10",
+    "type": "MAGAZINE",
+    "name": { "str": ".22 10-round conversion magazine" },
+    "description": "A black, 10-round polymer magazine for AR-platform rifles converted to fire .22 Long Rifle ammunition.",
+    "weight": "130 g",
+    "volume": "187 ml",
+    "longest_side": "110 mm",
+    "price": "22 USD 99 cent",
+    "price_postapoc": "50 cent",
+    "material": [ "plastic" ],
+    "symbol": "#",
+    "color": "light_gray",
+    "ammo_type": [ "22" ],
+    "flags": [ "MAG_COMPACT" ],
+    "pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "ammo_restriction": { "22": 10 } } ]
+  },
+  {
+    "id": "22_ar15mag_28",
+    "type": "MAGAZINE",
+    "name": { "str": ".22 28-round conversion magazine" },
+    "description": "A black, 28-round polymer magazine for AR-platform rifles converted to fire .22 Long Rifle ammunition.",
+    "weight": "220 g",
+    "volume": "220 ml",
+    "longest_side": "184 mm",
+    "price": "23 USD 99 cent",
+    "price_postapoc": "70 cent",
+    "material": [ "plastic" ],
+    "symbol": "#",
+    "color": "light_gray",
+    "ammo_type": [ "22" ],
+    "pocket_data": [ { "pocket_type": "MAGAZINE", "rigid": true, "ammo_restriction": { "22": 28 } } ]
+  },
   {
     "id": "mosquitomag",
     "looks_like": "glock17_17",
diff --git a/data/mods/Generic_Guns/gunmods/gg_gunmods_blacklist.json b/data/mods/Generic_Guns/gunmods/gg_gunmods_blacklist.json
index 1da0eb03adac4..35367dc2f9434 100644
--- a/data/mods/Generic_Guns/gunmods/gg_gunmods_blacklist.json
+++ b/data/mods/Generic_Guns/gunmods/gg_gunmods_blacklist.json
@@ -36,6 +36,7 @@
       "retool_ar15_450_medium",
       "retool_ar15_450_short",
       "retool_ar15_762",
+      "retool_ar15_22",
       "retool_mdrx_223rem",
       "retool_mdrx_223rem_short",
       "retool_mdrx_223rem_medium",
diff --git a/data/mods/Generic_Guns/magazines/gg_magazines_migration.json b/data/mods/Generic_Guns/magazines/gg_magazines_migration.json
index 2552b7d92551b..4301b430d5b50 100644
--- a/data/mods/Generic_Guns/magazines/gg_magazines_migration.json
+++ b/data/mods/Generic_Guns/magazines/gg_magazines_migration.json
@@ -307,7 +307,9 @@
       "m1carbinebigmag",
       "zpap85mag",
       "papm77mag",
-      "papm77mag_10rd"
+      "papm77mag_10rd",
+      "22_ar15mag_10",
+      "22_ar15mag_28"
     ],
     "type": "MIGRATION",
     "replace": "rifle_mag"
diff --git a/doc/JSON_INFO.md b/doc/JSON_INFO.md
index 27bf9c9618f54..6d8b857ffc4d6 100644
--- a/doc/JSON_INFO.md
+++ b/doc/JSON_INFO.md
@@ -4201,7 +4201,7 @@ Gun mods can be defined like this:
 "ammo_modifier": [ "57" ],     // Optional field which if specified modifies parent gun to use these ammo types
 "magazine_adaptor": [ [ "223", [ "stanag30" ] ] ], // Optional field which changes the types of magazines the parent gun accepts
 "pocket_mods": [ { "pocket_type": "MAGAZINE_WELL", "item_restriction": [ "ai_338mag", "ai_338mag_10" ] } ], // Optional field, alters the original pockets of the weapon ; share the syntax with pocket_data; pocket type MAGAZINE and MAGAZINE_WELL are always overwritten, pocket type CONTAINER is always added to existing pockets; for MAGAZINE and MAGAZINE_WELL both ammo_modifier and magazine_adaptor fields are required to correctly migrate ammo type; type: TOOLMOD can use this field also
-"damage_modifier": -1,         // Optional field increasing or decreasing base gun damage
+"damage_modifier": { "damage_type": "bullet", "amount": -1 }, // Optional field increasing or decreasing base gun damage
 "dispersion_modifier": 15,     // Optional field increasing or decreasing base gun dispersion
 "loudness_modifier": 4,        // Optional field increasing or decreasing base guns loudness
 "range_modifier": 2,           // Optional field increasing or decreasing base gun range