-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathcurse_of_hunger.dm
159 lines (138 loc) · 6.43 KB
/
curse_of_hunger.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
///the point where you can notice the item is hungry on examine.
#define HUNGER_THRESHOLD_WARNING 25
///the point where the item has a chance to eat something on every tick. possibly you!
#define HUNGER_THRESHOLD_TRY_EATING 50
/**
* curse of hunger component; for very hungry items.
*
* Used as a rpgloot suffix and wizard spell!
*/
/datum/component/curse_of_hunger
///whether to add dropdel to the item with curse of hunger, used for temporary curses like the wizard duffelbags
var/add_dropdel
///items given the curse of hunger will not seek out someone else to latch onto until they are dropped for the first time.
var/awakened = FALSE
///counts time passed since it ate food
var/hunger = 0
///The bag's max "health". IE, how many times you need to poison it.
var/max_health = 2
///The bag's current "health". IE, how many more times you need to poison it to stop it.
var/current_health = 2
/datum/component/curse_of_hunger/Initialize(add_dropdel = FALSE, max_health = 2)
. = ..()
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
src.add_dropdel = add_dropdel
src.max_health = max_health
src.current_health = max_health
/datum/component/curse_of_hunger/RegisterWithParent()
. = ..()
var/obj/item/cursed_item = parent
RegisterSignal(cursed_item, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(cursed_item, COMSIG_ITEM_EQUIPPED, PROC_REF(on_equip))
/datum/component/curse_of_hunger/UnregisterFromParent()
. = ..()
UnregisterSignal(parent, list(
COMSIG_ATOM_EXAMINE,
COMSIG_ITEM_EQUIPPED,
COMSIG_ITEM_DROPPED,
))
///signal called on parent being examined
/datum/component/curse_of_hunger/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
if(!awakened)
return //we should not reveal we are cursed until equipped
if(current_health < max_health)
examine_list += span_notice("[parent] looks sick from something it ate.")
if(hunger > HUNGER_THRESHOLD_WARNING)
examine_list += span_danger("[parent] hungers for something to eat...")
///signal called from equipping parent
/datum/component/curse_of_hunger/proc/on_equip(datum/source, mob/equipper, slot)
SIGNAL_HANDLER
var/obj/item/at_least_item = parent
// Items with no slot flags curse on pickup (because hand slot)
if(at_least_item.slot_flags && !(at_least_item.slot_flags & slot))
return
the_curse_begins(equipper)
///signal called from dropping parent
/datum/component/curse_of_hunger/proc/on_drop(datum/source, mob/dropper)
SIGNAL_HANDLER
INVOKE_ASYNC(src, PROC_REF(the_curse_ends), dropper)
/datum/component/curse_of_hunger/proc/the_curse_begins(mob/cursed)
var/obj/item/cursed_item = parent
awakened = TRUE
START_PROCESSING(SSobj, src)
ADD_TRAIT(cursed_item, TRAIT_NODROP, CURSED_ITEM_TRAIT(cursed_item.type))
ADD_TRAIT(cursed, TRAIT_CLUMSY, CURSED_ITEM_TRAIT(cursed_item.type))
ADD_TRAIT(cursed, TRAIT_PACIFISM, CURSED_ITEM_TRAIT(cursed_item.type))
if(add_dropdel)
cursed_item.item_flags |= DROPDEL
RegisterSignal(cursed_item, COMSIG_ITEM_DROPPED, PROC_REF(on_drop))
/datum/component/curse_of_hunger/proc/the_curse_ends(mob/uncursed)
var/obj/item/cursed_item = parent
STOP_PROCESSING(SSobj, src)
REMOVE_TRAIT(cursed_item, TRAIT_NODROP, CURSED_ITEM_TRAIT(cursed_item.type))
REMOVE_TRAIT(uncursed, TRAIT_CLUMSY, CURSED_ITEM_TRAIT(cursed_item.type))
REMOVE_TRAIT(uncursed, TRAIT_PACIFISM, CURSED_ITEM_TRAIT(cursed_item.type))
//remove either one of the signals that could have called this proc
UnregisterSignal(cursed_item, COMSIG_ITEM_DROPPED)
var/turf/vomit_turf = get_turf(cursed_item)
playsound(vomit_turf, 'sound/effects/splat.ogg', 50, TRUE)
new /obj/effect/decal/cleanable/vomit(vomit_turf)
uncursed.dropItemToGround(cursed_item, force = TRUE)
if(!QDELING(cursed_item)) //gives a head start for the person to get away from the cursed item before it begins hunting again!
addtimer(CALLBACK(src, PROC_REF(seek_new_target)), 10 SECONDS)
///proc called after a timer to awaken the AI in the cursed item if it doesn't have a target already.
/datum/component/curse_of_hunger/proc/seek_new_target()
var/obj/item/cursed_item = parent
if(iscarbon(cursed_item.loc))
return
else if(!isturf(cursed_item.loc))
cursed_item.forceMove(get_turf(cursed_item))
//only taking the most reasonable slot is fine since it unequips what is there to equip itself.
// cursed_item.AddElement(/datum/element/cursed, cursed_item.slot_equipment_priority[1])
cursed_item.visible_message(span_warning("[cursed_item] begins to move on [cursed_item.p_their()] own..."))
/datum/component/curse_of_hunger/process(delta_time)
var/obj/item/cursed_item = parent
var/mob/living/carbon/cursed = cursed_item.loc
///check hp
if(current_health <= 0)
the_curse_ends(cursed)
return
hunger += delta_time
if((hunger <= HUNGER_THRESHOLD_TRY_EATING) || prob(80))
return
playsound(cursed_item, 'sound/items/eatfood.ogg', 20, TRUE)
hunger = 0
//check hungry enough to eat something!
for(var/obj/item/food in cursed_item.contents + cursed.contents)
if(!istype(food, /obj/item/reagent_containers/food))
continue
food.forceMove(cursed.loc)
///poisoned food damages it
if(locate(/datum/reagent/toxin) in food.reagents.reagent_list)
var/sick_word = pick("queasy", "sick", "iffy", "unwell")
cursed.visible_message(
span_notice("[cursed_item] eats something from [cursed], and looks [sick_word] afterwards!"),
span_notice("[cursed_item] eats your [food.name] to sate [cursed_item.p_their()] hunger, and looks [sick_word] afterwards!"),
)
current_health--
else
cursed.visible_message(
span_warning("[cursed_item] eats something from [cursed] to sate [cursed_item.p_their()] hunger."),
span_warning("[cursed_item] eats your [food.name] to sate [cursed_item.p_their()] hunger."),
)
cursed.temporarilyRemoveItemFromInventory(food, force = TRUE)
qdel(food)
return
///no food found, but you're dead: it bites you slightly, and doesn't regain health.
if(cursed.stat == DEAD)
cursed.visible_message(span_danger("[cursed_item] nibbles on [cursed]."), span_userdanger("[cursed_item] nibbles on you!"))
cursed.apply_damage(10, BRUTE, BODY_ZONE_CHEST)
return
///no food found: it bites you and regains some health.
cursed.visible_message(span_danger("[cursed_item] bites [cursed]!"), span_userdanger("[cursed_item] bites you to sate [cursed_item.p_their()] hunger!"))
cursed.apply_damage(60, BRUTE, BODY_ZONE_CHEST, wound_bonus = -20, bare_wound_bonus = 20)
current_health = min(current_health + 1, max_health)
#undef HUNGER_THRESHOLD_WARNING
#undef HUNGER_THRESHOLD_TRY_EATING