/
rep_purchase_base.dm
65 lines (61 loc) · 1.76 KB
/
rep_purchase_base.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* # Rep Purchase
*
* Describes something that can be purchased with Contractor Rep.
*/
/datum/rep_purchase
/// The display name of the purchase.
var/name = ""
/// The description of the purchase.
var/description = "This shouldn't appear."
/// The price in Contractor Rep of the purchase.
var/cost = 0
/// How many times the purchase can be made.
/// -1 means infinite stock.
var/stock = -1
/**
* Attempts to perform the purchase.
*
* Returns TRUE or FALSE depending on whether the purchase succeeded.
*
* Arguments:
* * hub - The contractor hub.
* * user - The user who is making the purchase.
*/
/datum/rep_purchase/proc/buy(datum/contractor_hub/hub, mob/living/carbon/human/user)
. = FALSE
if(hub.owner.current != user)
to_chat(user, "<span class='warning'>You were not recognized as this hub's original user.</span>")
return
if(hub.rep < cost)
to_chat(user, "<span class='warning'>You do not have enough Rep.</span>")
return
if(stock == 0)
to_chat(user, "<span class='warning'>This item is out of stock.</span>")
return
else if(stock > 0)
stock--
hub.rep -= cost
on_buy(hub, user)
return TRUE
/**
* Called when the purchase was made successfully.
*
* Arguments:
* * hub - The contractor hub.
* * user - The user who made the purchase.
*/
/datum/rep_purchase/proc/on_buy(datum/contractor_hub/hub, mob/living/carbon/human/user)
return
/**
* # Rep Purchase - Item
*
* Describes an item that can be purchased with Contractor Rep.
*/
/datum/rep_purchase/item
/// The typepath of the item to instantiate and give to the buyer on purchase.
var/obj/item/item_type = null
/datum/rep_purchase/item/on_buy(datum/contractor_hub/hub, mob/living/carbon/human/user)
..()
var/obj/item/I = new item_type(user)
user.put_in_hands(I)