|
| 1 | +/obj/item/blackmarket_uplink |
| 2 | + name = "Black Market Uplink" |
| 3 | + icon = 'icons/obj/blackmarket.dmi' |
| 4 | + icon_state = "uplink" |
| 5 | + |
| 6 | + // UI variables. |
| 7 | + var/ui_x = 720 |
| 8 | + var/ui_y = 480 |
| 9 | + var/viewing_category |
| 10 | + var/viewing_market |
| 11 | + var/selected_item |
| 12 | + var/buying |
| 13 | + |
| 14 | + /// How much money is inserted into the uplink. |
| 15 | + var/money = 0 |
| 16 | + /// List of typepaths for "/datum/blackmarket_market"s that this uplink can access. |
| 17 | + var/list/accessible_markets = list(/datum/blackmarket_market/blackmarket) |
| 18 | + |
| 19 | +/obj/item/blackmarket_uplink/Initialize() |
| 20 | + . = ..() |
| 21 | + if(accessible_markets.len) |
| 22 | + viewing_market = accessible_markets[1] |
| 23 | + var/list/categories = SSblackmarket.markets[viewing_market].categories |
| 24 | + if(categories && categories.len) |
| 25 | + viewing_category = categories[1] |
| 26 | + |
| 27 | +/obj/item/blackmarket_uplink/attackby(obj/item/I, mob/user, params) |
| 28 | + if(istype(I, /obj/item/holochip) || istype(I, /obj/item/stack/spacecash) || istype(I, /obj/item/coin)) |
| 29 | + var/worth = I.get_item_credit_value() |
| 30 | + if(!worth) |
| 31 | + to_chat(user, span_warning("[I] doesn't seem to be worth anything!")) |
| 32 | + money += worth |
| 33 | + to_chat(user, span_notice("You slot [I] into [src] and it reports a total of [money] credits inserted.")) |
| 34 | + qdel(I) |
| 35 | + return |
| 36 | + . = ..() |
| 37 | + |
| 38 | +/obj/item/blackmarket_uplink/AltClick(mob/user) |
| 39 | + if(!isliving(user) || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) |
| 40 | + return |
| 41 | + |
| 42 | + var/amount_to_remove = FLOOR(input(user, "How much do you want to withdraw? Current Amount: [money]", "Withdraw Funds", 5) as num|null, 1) |
| 43 | + if(!user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK)) |
| 44 | + return |
| 45 | + |
| 46 | + if(!amount_to_remove || amount_to_remove < 0) |
| 47 | + return |
| 48 | + if(amount_to_remove > money) |
| 49 | + to_chat(user, span_warning("There is only [money] credits in [src]")) |
| 50 | + return |
| 51 | + |
| 52 | + var/obj/item/holochip/holochip = new (user.drop_location(), amount_to_remove) |
| 53 | + money -= amount_to_remove |
| 54 | + holochip.name = "washed " + holochip.name |
| 55 | + user.put_in_hands(holochip) |
| 56 | + to_chat(user, span_notice("You withdraw [amount_to_remove] credits into a holochip.")) |
| 57 | + |
| 58 | +/obj/item/blackmarket_uplink/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state) |
| 59 | + ui = SStgui.try_update_ui(user, src, ui) |
| 60 | + if(!ui) |
| 61 | + ui = new(user, src, "BlackMarketUplink", "Black Market Uplink") |
| 62 | + ui.open() |
| 63 | + ui.set_autoupdate(TRUE) |
| 64 | + |
| 65 | +/obj/item/blackmarket_uplink/ui_data(mob/user) |
| 66 | + var/list/data = list() |
| 67 | + var/datum/blackmarket_market/market = viewing_market ? SSblackmarket.markets[viewing_market] : null |
| 68 | + data["categories"] = market ? market.categories : null |
| 69 | + data["delivery_methods"] = list() |
| 70 | + if(market) |
| 71 | + for(var/delivery in market.shipping) |
| 72 | + data["delivery_methods"] += list(list("name" = delivery, "price" = market.shipping[delivery])) |
| 73 | + data["money"] = money |
| 74 | + data["buying"] = buying |
| 75 | + data["items"] = list() |
| 76 | + data["viewing_category"] = viewing_category |
| 77 | + data["viewing_market"] = viewing_market |
| 78 | + if(viewing_category && market) |
| 79 | + if(market.available_items[viewing_category]) |
| 80 | + for(var/datum/blackmarket_item/I in market.available_items[viewing_category]) |
| 81 | + data["items"] += list(list( |
| 82 | + "id" = I.type, |
| 83 | + "name" = I.name, |
| 84 | + "cost" = I.price, |
| 85 | + "amount" = I.stock, |
| 86 | + "desc" = I.desc || I.name |
| 87 | + )) |
| 88 | + return data |
| 89 | + |
| 90 | +/obj/item/blackmarket_uplink/ui_static_data(mob/user) |
| 91 | + var/list/data = list() |
| 92 | + data["delivery_method_description"] = SSblackmarket.shipping_method_descriptions |
| 93 | + data["markets"] = list() |
| 94 | + for(var/M in accessible_markets) |
| 95 | + var/datum/blackmarket_market/BM = SSblackmarket.markets[M] |
| 96 | + data["markets"] += list(list( |
| 97 | + "id" = M, |
| 98 | + "name" = BM.name |
| 99 | + )) |
| 100 | + return data |
| 101 | + |
| 102 | +/obj/item/blackmarket_uplink/ui_act(action, params) |
| 103 | + if(..()) |
| 104 | + return |
| 105 | + switch(action) |
| 106 | + if("set_category") |
| 107 | + if(isnull(params["category"])) |
| 108 | + return |
| 109 | + if(isnull(viewing_market)) |
| 110 | + return |
| 111 | + if(!(params["category"] in SSblackmarket.markets[viewing_market].categories)) |
| 112 | + return |
| 113 | + viewing_category = params["category"] |
| 114 | + . = TRUE |
| 115 | + if("set_market") |
| 116 | + if(isnull(params["market"])) |
| 117 | + return |
| 118 | + var/market = text2path(params["market"]) |
| 119 | + if(!(market in accessible_markets)) |
| 120 | + return |
| 121 | + |
| 122 | + viewing_market = market |
| 123 | + |
| 124 | + var/list/categories = SSblackmarket.markets[viewing_market].categories |
| 125 | + if(categories && categories.len) |
| 126 | + viewing_category = categories[1] |
| 127 | + else |
| 128 | + viewing_category = null |
| 129 | + . = TRUE |
| 130 | + if("select") |
| 131 | + if(isnull(params["item"])) |
| 132 | + return |
| 133 | + var/item = text2path(params["item"]) |
| 134 | + selected_item = item |
| 135 | + buying = TRUE |
| 136 | + . = TRUE |
| 137 | + if("cancel") |
| 138 | + selected_item = null |
| 139 | + buying = FALSE |
| 140 | + . = TRUE |
| 141 | + if("buy") |
| 142 | + if(isnull(params["method"])) |
| 143 | + return |
| 144 | + if(isnull(selected_item)) |
| 145 | + buying = FALSE |
| 146 | + return |
| 147 | + var/datum/blackmarket_market/market = SSblackmarket.markets[viewing_market] |
| 148 | + market.purchase(selected_item, viewing_category, params["method"], src, usr) |
| 149 | + |
| 150 | + buying = FALSE |
| 151 | + selected_item = null |
| 152 | + |
| 153 | +/datum/crafting_recipe/blackmarket_uplink |
| 154 | + name = "Black Market Uplink" |
| 155 | + result = /obj/item/blackmarket_uplink |
| 156 | + time = 30 |
| 157 | + tool_behaviors = list(TOOL_SCREWDRIVER, TOOL_WIRECUTTER, TOOL_MULTITOOL) |
| 158 | + reqs = list( |
| 159 | + /obj/item/stock_parts/subspace/amplifier = 1, |
| 160 | + /obj/item/stack/cable_coil = 15, |
| 161 | + /obj/item/radio = 1, |
| 162 | + /obj/item/analyzer = 1 |
| 163 | + ) |
| 164 | + category = CAT_MISC |
0 commit comments