-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathseed_extractor.dm
204 lines (177 loc) · 6.28 KB
/
seed_extractor.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* Finds and extracts seeds from an object
*
* Checks if the object is such that creates a seed when extracted. Used by seed
* extractors or posably anything that would create seeds in some way. The seeds
* are dropped either at the extractor, if it exists, or where the original object
* was and it qdel's the object
*
* Arguments:
* * O - Object containing the seed, can be the loc of the dumping of seeds
* * t_max - Amount of seed copies to dump, -1 is ranomized
* * extractor - Seed Extractor, used as the dumping loc for the seeds and seed multiplier
* * user - checks if we can remove the object from the inventory
* *
*/
/proc/seedify(obj/item/O, t_max, obj/machinery/seed_extractor/extractor, mob/living/user)
var/t_amount = 0
var/list/seeds = list()
if(t_max == -1)
if(extractor)
t_max = rand(1,4) * extractor.seed_multiplier
else
t_max = rand(1,4)
var/atom/seedloc = O.loc
if(extractor)
seedloc = extractor.loc
if(istype(O, /obj/item/reagent_containers/food/snacks/grown/))
var/obj/item/reagent_containers/food/snacks/grown/F = O
if(F.seed)
if(user && !user.temporarilyRemoveItemFromInventory(O)) //couldn't drop the item
return
while(t_amount < t_max)
var/obj/item/seeds/t_prod = F.seed.Copy()
seeds.Add(t_prod)
t_prod.forceMove(seedloc)
t_amount++
qdel(O)
else if(istype(O, /obj/item/grown))
var/obj/item/grown/F = O
if(F.seed)
if(user && !user.temporarilyRemoveItemFromInventory(O))
return
while(t_amount < t_max)
var/obj/item/seeds/t_prod = F.seed.Copy()
seeds.Add(t_prod)
t_prod.forceMove(seedloc)
t_amount++
qdel(O)
if(user && seeds.len)
var/obj/item/seeds/seed = seeds[1] // all seeds are duplicates, pick the first one in the list
if(user.add_exp(SKILL_SCIENCE, seed.rarity * 10, seed.type))
user.playsound_local(get_turf(seedloc), 'sound/machines/ping.ogg', 25, TRUE)
seedloc.balloon_alert(user, "rare plant catalogued: [initial(seed.product.name)]")
return (seeds.len ? seeds : FALSE)
/obj/machinery/seed_extractor
name = "seed extractor"
desc = "Extracts and bags seeds from produce."
icon = 'icons/obj/hydroponics/equipment.dmi'
icon_state = "sextractor"
density = TRUE
circuit = /obj/item/circuitboard/machine/seed_extractor
/// Associated list of seeds, they are all weak refs. We check the len to see how many refs we have for each
// seed
var/list/piles = list()
/// Starting constants for Refresh parts
var/const/staring_max_seeds = 1000
var/const/staring_seed_multiplier = 1
var/max_seeds = staring_max_seeds
var/seed_multiplier = staring_seed_multiplier
/obj/machinery/seed_extractor/RefreshParts()
for(var/obj/item/stock_parts/matter_bin/B in component_parts)
max_seeds = staring_max_seeds * B.rating
for(var/obj/item/stock_parts/manipulator/M in component_parts)
seed_multiplier = staring_seed_multiplier * M.rating
/obj/machinery/seed_extractor/examine(mob/user)
. = ..()
if(in_range(user, src) || isobserver(user))
. += span_notice("The status display reads: Extracting <b>[seed_multiplier]</b> seed(s) per piece of produce.<br>Machine can store up to <b>[max_seeds]</b> seeds.")
/obj/machinery/seed_extractor/attackby(obj/item/O, mob/living/user, params)
if(default_deconstruction_screwdriver(user, "sextractor_open", "sextractor", O))
return
if(default_pry_open(O))
return
if(default_unfasten_wrench(user, O))
return
if(default_deconstruction_crowbar(O))
return
if(istype(O, /obj/item/storage/bag/plants))
var/obj/item/storage/P = O
var/loaded = 0
for(var/obj/item/seeds/G in P.contents)
if(contents.len >= max_seeds)
break
++loaded
add_seed(G)
if (loaded)
to_chat(user, span_notice("You put as many seeds from \the [O.name] into [src] as you can."))
else
to_chat(user, span_notice("There are no seeds in \the [O.name]."))
return
else if(seedify(O,-1, src, user))
to_chat(user, span_notice("You extract some seeds."))
return
else if (istype(O, /obj/item/seeds))
if(add_seed(O))
to_chat(user, span_notice("You add [O] to [src.name]."))
return
else if(!user.combat_mode)
to_chat(user, span_warning("You can't extract any seeds from \the [O.name]!"))
else
return ..()
/**
* Generate seed string
*
* Creates a string based of the traits of a seed. We use this string as a bucket for all
* seeds that match as well as the key the ui uses to get the seed. We also use the key
* for the data shown in the ui. Javascript parses this string to display
*
* Arguments:
* * O - seed to generate the string from
*/
/obj/machinery/seed_extractor/proc/generate_seed_string(obj/item/seeds/O)
return "name=[O.name];lifespan=[O.lifespan];endurance=[O.endurance];maturation=[O.maturation];production=[O.production];yield=[O.yield];potency=[O.potency]"
/** Add Seeds Proc.
*
* Adds the seeds to the contents and to an associated list that pregenerates the data
* needed to go to the ui handler
*
**/
/obj/machinery/seed_extractor/proc/add_seed(obj/item/seeds/O)
if(contents.len >= 999)
to_chat(usr, span_notice("\The [src] is full."))
return FALSE
var/datum/component/storage/STR = O.loc.GetComponent(/datum/component/storage)
if(STR)
if(!STR.remove_from_storage(O,src))
return FALSE
else if(ismob(O.loc))
var/mob/M = O.loc
if(!M.transferItemToLoc(O, src))
return FALSE
var/seed_string = generate_seed_string(O)
if(piles[seed_string])
piles[seed_string] += WEAKREF(O)
else
piles[seed_string] = list(WEAKREF(O))
. = TRUE
/obj/machinery/seed_extractor/ui_state(mob/user)
return GLOB.notcontained_state
/obj/machinery/seed_extractor/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "SeedExtractor", name)
ui.open()
/obj/machinery/seed_extractor/ui_data()
var/list/V = list()
for(var/key in piles)
if(piles[key])
var/len = length(piles[key])
if(len)
V[key] = len
. = list()
.["seeds"] = V
/obj/machinery/seed_extractor/ui_act(action, params)
if(..())
return
switch(action)
if("select")
var/item = params["item"]
if(piles[item] && length(piles[item]) > 0)
var/datum/weakref/WO = piles[item][1]
var/obj/item/seeds/O = WO.resolve()
if(O)
piles[item] -= WO
O.forceMove(drop_location())
. = TRUE
//to_chat(usr, span_notice("[src] clanks to life briefly before vending [prize.equipment_name]!"))