-
-
Notifications
You must be signed in to change notification settings - Fork 452
/
_granters.dm
106 lines (90 loc) · 3.49 KB
/
_granters.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
/**
* Books that teach things.
*
* (Intrinsic actions like bar flinging, spells like fireball or smoke, or martial arts)
*/
/obj/item/book/granter
due_date = 0
unique = 1
/// Flavor messages displayed to mobs reading the granter
var/list/remarks = list()
/// Controls how long a mob must keep the book in his hand to actually successfully learn
var/pages_to_mastery = 3
/// Sanity, whether it's currently being read
var/reading = FALSE
/// The amount of uses on the granter.
var/uses = 1
/// The sounds played as the user's reading the book.
var/list/book_sounds = list(
'sound/effects/pageturn1.ogg',
'sound/effects/pageturn2.ogg',
'sound/effects/pageturn3.ogg',
)
/obj/item/book/granter/attack_self(mob/living/user)
if(reading)
to_chat(user, span_warning("You're already reading this!"))
return FALSE
if(is_blind(user))
to_chat(user, span_warning("You are blind and can't read anything!"))
return FALSE
if(!isliving(user) || !user.can_read(src))
return FALSE
if(!can_learn(user))
return FALSE
if(uses <= 0)
recoil(user)
return FALSE
on_reading_start(user)
reading = TRUE
for(var/i in 1 to pages_to_mastery)
if(!turn_page(user))
on_reading_stopped()
reading = FALSE
return
if(do_after(user, 5 SECONDS, src))
uses--
on_reading_finished(user)
reading = FALSE
return TRUE
/// Called when the user starts to read the granter.
/obj/item/book/granter/proc/on_reading_start(mob/living/user)
to_chat(user, span_notice("You start reading [name]..."))
/// Called when the reading is interrupted without finishing.
/obj/item/book/granter/proc/on_reading_stopped(mob/living/user)
to_chat(user, span_notice("You stop reading..."))
/// Called when the reading is completely finished. This is where the actual granting should happen.
/obj/item/book/granter/proc/on_reading_finished(mob/living/user)
to_chat(user, span_notice("You finish reading [name]!"))
/// The actual "turning over of the page" flavor bit that happens while someone is reading the granter.
/obj/item/book/granter/proc/turn_page(mob/living/user)
playsound(user, pick(book_sounds), 30, TRUE)
if(!do_after(user, 5 SECONDS, src))
return FALSE
to_chat(user, span_notice("[length(remarks) ? pick_n_take(remarks) : "You keep reading..."]"))
return TRUE
/// Effects that occur whenever the book is read when it has no uses left.
/obj/item/book/granter/proc/recoil(mob/living/user)
/// Checks if the user can learn whatever this granter... grants
/obj/item/book/granter/proc/can_learn(mob/living/user)
return TRUE
// Generic action giver
/obj/item/book/granter/action
/// The typepath of action that is given
var/datum/action/granted_action
/// The name of the action, formatted in a more text-friendly way.
var/action_name = ""
/obj/item/book/granter/action/can_learn(mob/living/user)
if(!granted_action)
CRASH("Someone attempted to learn [type], which did not have an action set.")
if(locate(granted_action) in user.actions)
to_chat(user, span_warning("You already know all about [action_name]!"))
return FALSE
return TRUE
/obj/item/book/granter/action/on_reading_start(mob/living/user)
to_chat(user, span_notice("You start reading about [action_name]..."))
/obj/item/book/granter/action/on_reading_finished(mob/living/user)
to_chat(user, span_notice("You feel like you've got a good handle on [action_name]!"))
// Action goes on the mind as the user actually learns the thing in your brain
var/datum/action/new_action = new granted_action(user.mind || user)
new_action.Grant(user)
new_action.build_all_button_icons()