This commit is contained in:
Gandalf
2022-03-30 16:35:20 +01:00
committed by GitHub
parent 8fe5d5965a
commit d1cf2c19a1
4 changed files with 67 additions and 14 deletions
@@ -34,7 +34,7 @@ GLOBAL_LIST_INIT(armament_entries, build_armament_list())
// ditto for the description
spawned_armament_entry.description ||= initial(spawned_armament_entry.item_type.desc)
// Make our icon cache for the UI.
spawned_armament_entry.create_icon_cache()
spawned_armament_entry.setup()
// Now that we've set up our datum, we can add it to the correct category
if(spawned_armament_entry.category)
if(spawned_armament_entry.subcategory)
@@ -94,9 +94,17 @@ GLOBAL_LIST_INIT(armament_entries, build_armament_list())
var/cached_base64
/// The maximum amount of this item that can be equipped.
var/max_purchase = 1
/// Do we have magazines for purchase?
var/magazine
/// If we have a magazine, how much is it?
var/magazine_cost = 1
/datum/armament_entry/proc/create_icon_cache() // TODO: Make this use overlays.
/datum/armament_entry/proc/setup() // TODO: Make this use overlays.
var/obj/item/test_item = new item_type()
if(istype(test_item, /obj/item/gun/ballistic))
var/obj/item/gun/ballistic/ballistic_test = test_item
if(!ballistic_test.internal_magazine)
magazine = ballistic_test.mag_type
cached_base64 = icon2base64(getFlatIcon(test_item, no_anim = TRUE))
qdel(test_item)
@@ -68,6 +68,8 @@
"icon" = armament_entry.cached_base64,
"name" = armament_entry.name,
"cost" = armament_entry.cost,
"buyable_ammo" = armament_entry.magazine ? TRUE : FALSE,
"magazine_cost" = armament_entry.magazine_cost,
"quantity" = armament_entry.max_purchase,
"purchased" = purchased_items[armament_entry] ? purchased_items[armament_entry] : 0,
"description" = armament_entry.description,
@@ -98,22 +100,47 @@
switch(action)
if("equip_item")
var/datum/armament_entry/armament_entry
for(var/category in GLOB.armament_entries)
for(var/subcategory in GLOB.armament_entries[category][CATEGORY_ENTRY])
armament_entry = locate(params["armament_ref"]) in GLOB.armament_entries[category][CATEGORY_ENTRY][subcategory]
if(armament_entry)
break
if(armament_entry)
break
if(!armament_entry)
var/check = check_item(params["armament_ref"])
if(!check)
return
if(products && !(armament_entry.type in products))
select_armament(usr, check)
if("buy_ammo")
var/check = check_item(params["armament_ref"])
if(!check)
return
select_armament(usr, armament_entry)
buy_ammo(usr, check, params["quantity"])
if("eject_card")
eject_card(usr)
/obj/machinery/armament_station/proc/buy_ammo(mob/user, datum/armament_entry/armament_entry, quantity = 1)
if(!armament_entry.magazine)
return
if(!inserted_card)
to_chat(user, span_warning("No card inserted!"))
return
var/quantity_cost = armament_entry.magazine_cost * quantity
if(!inserted_card.use_points(quantity_cost))
to_chat(user, span_warning("Not enough points!"))
return
for(var/i in 1 to quantity)
new armament_entry.magazine(drop_location())
/obj/machinery/armament_station/proc/check_item(reference)
var/datum/armament_entry/armament_entry
for(var/category in GLOB.armament_entries)
for(var/subcategory in GLOB.armament_entries[category][CATEGORY_ENTRY])
armament_entry = locate(reference) in GLOB.armament_entries[category][CATEGORY_ENTRY][subcategory]
if(armament_entry)
break
if(armament_entry)
break
if(!armament_entry)
return FALSE
if(products && !(armament_entry.type in products))
return FALSE
return armament_entry
/obj/machinery/armament_station/proc/eject_card(mob/user)
if(!inserted_card)
to_chat(user, span_warning("No card inserted!"))