-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathgrillable.dm
89 lines (68 loc) · 3.25 KB
/
grillable.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
/datum/component/grillable
///Result atom type of grilling this object
var/atom/cook_result
///Amount of time required to cook the food
var/required_cook_time = 2 MINUTES
///Is this a positive grill result?
var/positive_result = TRUE
///Time spent cooking so far
var/current_cook_time = 0
///Are we currently grilling?
var/currently_grilling = FALSE
///Do we use the large steam sprite?
var/use_large_steam_sprite = FALSE
/datum/component/grillable/Initialize(cook_result, required_cook_time, positive_result, use_large_steam_sprite)
. = ..()
if(!isitem(parent)) //Only items support grilling at the moment
return COMPONENT_INCOMPATIBLE
src.cook_result = cook_result
src.required_cook_time = required_cook_time
src.positive_result = positive_result
src.use_large_steam_sprite = use_large_steam_sprite
RegisterSignal(parent, COMSIG_ITEM_GRILLED, PROC_REF(OnGrill))
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(OnExamine))
///Ran every time an item is grilled by something
/datum/component/grillable/proc/OnGrill(datum/source, atom/used_grill, delta_time = 1)
. = COMPONENT_HANDLED_GRILLING
current_cook_time += delta_time * 10 //turn it into ds
if(current_cook_time >= required_cook_time)
FinishGrilling(used_grill)
else if(!currently_grilling) //We havn't started grilling yet
StartGrilling(used_grill)
///Ran when an object starts grilling on something
/datum/component/grillable/proc/StartGrilling(atom/grill_source)
currently_grilling = TRUE
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(OnMoved))
AddGrilledItemOverlay(parent)
var/atom/atom_parent = parent
atom_parent.update_appearance(UPDATE_ICON)
///Ran when an object finished grilling
/datum/component/grillable/proc/FinishGrilling(atom/grill_source)
var/atom/original_object = parent
var/atom/grilled_result = new cook_result(original_object.loc)
grilled_result.pixel_x = original_object.pixel_x
grilled_result.pixel_y = original_object.pixel_y
grill_source.visible_message("<span class='[positive_result ? "notice" : "warning"]'>[parent] turns into \a [grilled_result]!</span>")
SEND_SIGNAL(parent, COMSIG_GRILL_COMPLETED, grilled_result)
currently_grilling = FALSE
qdel(parent)
///Ran when an object almost finishes grilling
/datum/component/grillable/proc/OnExamine(atom/A, mob/user, list/examine_list)
if(!current_cook_time) //Not grilled yet
return
if(positive_result)
if(current_cook_time <= required_cook_time * 0.75)
examine_list += "<span class='notice'>[parent] probably needs to be cooked a bit longer!</span>"
else if(current_cook_time <= required_cook_time)
examine_list += "<span class='notice'>[parent] seems to be almost finished cooking!</span>"
else
examine_list += "<span class='danger'>[parent] should probably not be cooked for much longer!</span>"
///Ran when an object moves from the grill
/datum/component/grillable/proc/OnMoved(atom/A, atom/OldLoc, Dir, Forced)
SIGNAL_HANDLER
currently_grilling = FALSE
UnregisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS)
UnregisterSignal(parent, COMSIG_MOVABLE_MOVED)
A.update_appearance()
/datum/component/grillable/proc/AddGrilledItemOverlay(obj/source)
source.add_overlay(mutable_appearance('icons/effects/steam.dmi', "[use_large_steam_sprite ? "steam_triple" : "steam_single"]", ABOVE_OBJ_LAYER))