/
_shapeshift.dm
270 lines (215 loc) · 9.06 KB
/
_shapeshift.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/datum/action/cooldown/spell/shapeshift
button_icon_state = "shapeshift"
school = SCHOOL_TRANSMUTATION
cooldown_time = 10 SECONDS
/// Whehter we revert to our human form on death.
var/revert_on_death = TRUE
/// Whether we die when our shapeshifted form is killed
var/die_with_shapeshifted_form = TRUE
/// Whether we convert our health from one form to another
var/convert_damage = TRUE
/// If convert damage is true, the damage type we deal when converting damage back and forth
var/convert_damage_type = BRUTE
/// Our chosen type
var/mob/living/shapeshift_type
/// All possible types we can become
var/list/atom/possible_shapes
/datum/action/cooldown/spell/shapeshift/is_valid_target(atom/cast_on)
return isliving(cast_on)
/datum/action/cooldown/spell/shapeshift/proc/is_shifted(mob/living/cast_on)
return locate(/obj/shapeshift_holder) in cast_on
/datum/action/cooldown/spell/shapeshift/before_cast(atom/cast_on)
. = ..()
if(. & SPELL_CANCEL_CAST)
return
if(shapeshift_type)
return
if(length(possible_shapes) == 1)
shapeshift_type = possible_shapes[1]
return
var/list/shape_names_to_types = list()
var/list/shape_names_to_image = list()
if(!length(shape_names_to_types) || !length(shape_names_to_image))
for(var/atom/path as anything in possible_shapes)
var/shape_name = initial(path.name)
shape_names_to_types[shape_name] = path
shape_names_to_image[shape_name] = image(icon = initial(path.icon), icon_state = initial(path.icon_state))
var/picked_type = show_radial_menu(
cast_on,
cast_on,
shape_names_to_image,
custom_check = CALLBACK(src, .proc/check_menu, cast_on),
radius = 38,
)
if(!picked_type)
return . | SPELL_CANCEL_CAST
var/atom/shift_type = shape_names_to_types[picked_type]
if(!ispath(shift_type))
return . | SPELL_CANCEL_CAST
shapeshift_type = shift_type || pick(possible_shapes)
if(QDELETED(src) || QDELETED(owner) || !can_cast_spell(feedback = FALSE))
return . | SPELL_CANCEL_CAST
/datum/action/cooldown/spell/shapeshift/cast(mob/living/cast_on)
. = ..()
cast_on.buckled?.unbuckle_mob(cast_on, force = TRUE)
var/currently_ventcrawling = (cast_on.movement_type & VENTCRAWLING)
// Do the shift back or forth
if(is_shifted(cast_on))
restore_form(cast_on)
else
do_shapeshift(cast_on)
// The shift is done, let's make sure they're in a valid state now
// If we're not ventcrawling, we don't need to mind
if(!currently_ventcrawling)
return
// We are ventcrawling - can our new form support ventcrawling?
if(HAS_TRAIT(cast_on, TRAIT_VENTCRAWLER_ALWAYS) || HAS_TRAIT(cast_on, TRAIT_VENTCRAWLER_NUDE))
return
// Uh oh. You've shapeshifted into something that can't fit into a vent, while ventcrawling.
eject_from_vents(cast_on)
/// Whenever someone shapeshifts within a vent,
/// and enters a state in which they are no longer a ventcrawler,
/// they are brutally ejected from the vents. In the form of gibs.
/datum/action/cooldown/spell/shapeshift/proc/eject_from_vents(mob/living/cast_on)
var/obj/machinery/atmospherics/pipe_you_die_in = cast_on.loc
var/datum/pipeline/our_pipeline
var/pipenets = pipe_you_die_in.return_pipenets()
if(islist(pipenets))
our_pipeline = pipenets[1]
else
our_pipeline = pipenets
to_chat(cast_on, span_userdanger("Casting [src] inside of [pipe_you_die_in] quickly turns you into a bloody mush!"))
var/obj/effect/gib_type = isalien(cast_on) ? /obj/effect/gibspawner/xeno : /obj/effect/gibspawner/generic
for(var/obj/machinery/atmospherics/components/unary/possible_vent in range(10, get_turf(cast_on)))
if(length(possible_vent.parents) && possible_vent.parents[1] == our_pipeline)
new gib_type(get_turf(possible_vent))
playsound(possible_vent, 'sound/effects/reee.ogg', 75, TRUE)
priority_announce("We detected a pipe blockage around [get_area(get_turf(cast_on))], please dispatch someone to investigate.", "Central Command")
cast_on.death()
qdel(cast_on)
/datum/action/cooldown/spell/shapeshift/proc/check_menu(mob/living/caster)
if(QDELETED(src))
return FALSE
if(QDELETED(caster))
return FALSE
return !caster.incapacitated()
/datum/action/cooldown/spell/shapeshift/proc/do_shapeshift(mob/living/caster)
if(is_shifted(caster))
to_chat(caster, span_warning("You're already shapeshifted!"))
CRASH("[type] called do_shapeshift while shapeshifted.")
var/mob/living/new_shape = new shapeshift_type(caster.loc)
var/obj/shapeshift_holder/new_shape_holder = new(new_shape, src, caster)
spell_requirements &= ~(SPELL_REQUIRES_HUMAN|SPELL_REQUIRES_WIZARD_GARB)
return new_shape_holder
/datum/action/cooldown/spell/shapeshift/proc/restore_form(mob/living/caster)
var/obj/shapeshift_holder/current_shift = is_shifted(caster)
if(QDELETED(current_shift))
return
var/mob/living/restored_player = current_shift.stored
current_shift.restore()
spell_requirements = initial(spell_requirements) // Miiight mess with admin stuff.
return restored_player
// Maybe one day, this can be a component or something
// Until then, this is what holds data between wizard and shapeshift form whenever shapeshift is cast.
/obj/shapeshift_holder
name = "Shapeshift holder"
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | ON_FIRE | UNACIDABLE | ACID_PROOF
var/mob/living/stored
var/mob/living/shape
var/restoring = FALSE
var/datum/action/cooldown/spell/shapeshift/source
/obj/shapeshift_holder/Initialize(mapload, datum/action/cooldown/spell/shapeshift/_source, mob/living/caster)
. = ..()
source = _source
shape = loc
if(!istype(shape))
stack_trace("shapeshift holder created outside mob/living")
return INITIALIZE_HINT_QDEL
stored = caster
// Transfer the Shapeshift spell over, if we actually own it
if(source.owner == caster)
source.Grant(shape)
// Also transfer over any actions bound to them specifically - this leaves behind item actions and similar
// (Mindbound actions are automatically tranferred over, so we don't need to worry about it)
for(var/datum/action/bodybound_action as anything in caster.actions)
if(bodybound_action.target != caster)
continue
bodybound_action.Grant(shape)
if(stored.mind)
stored.mind.transfer_to(shape)
stored.forceMove(src)
stored.notransform = TRUE
if(source.convert_damage)
var/damage_percent = (stored.maxHealth - stored.health) / stored.maxHealth;
var/damapply = damage_percent * shape.maxHealth;
shape.apply_damage(damapply, source.convert_damage_type, forced = TRUE, wound_bonus = CANT_WOUND);
shape.blood_volume = stored.blood_volume;
RegisterSignal(shape, list(COMSIG_PARENT_QDELETING, COMSIG_LIVING_DEATH), .proc/shape_death)
RegisterSignal(stored, list(COMSIG_PARENT_QDELETING, COMSIG_LIVING_DEATH), .proc/caster_death)
/obj/shapeshift_holder/Destroy()
// restore_form manages signal unregistering. If restoring is TRUE, we've already unregistered the signals and we're here
// because restore() qdel'd src.
if(!restoring)
restore()
stored = null
shape = null
return ..()
/obj/shapeshift_holder/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE)
. = ..()
if(!restoring && !QDELETED(src))
restore()
/obj/shapeshift_holder/handle_atom_del(atom/A)
if(A == stored && !restoring)
restore()
/obj/shapeshift_holder/Exited(atom/movable/gone, direction)
if(stored == gone && !restoring)
restore()
/obj/shapeshift_holder/proc/caster_death()
SIGNAL_HANDLER
//Something kills the stored caster through direct damage.
if(source.revert_on_death)
restore(death = TRUE)
else
shape.death()
/obj/shapeshift_holder/proc/shape_death()
SIGNAL_HANDLER
//Shape dies.
if(source.die_with_shapeshifted_form)
if(source.revert_on_death)
restore(death = TRUE)
else
restore()
/obj/shapeshift_holder/proc/restore(death=FALSE)
// Destroy() calls this proc if it hasn't been called. Unregistering here prevents multiple qdel loops
// when caster and shape both die at the same time.
UnregisterSignal(shape, list(COMSIG_PARENT_QDELETING, COMSIG_LIVING_DEATH))
UnregisterSignal(stored, list(COMSIG_PARENT_QDELETING, COMSIG_LIVING_DEATH))
restoring = TRUE
// Give Shapeshift back to the OG, if we actually own it
// (Shapeshift into mindswap may change the action's owner)
if(!QDELETED(source) && source.owner == shape)
source.Grant(stored)
// Also transfer their bodybound actions back
for(var/datum/action/bodybound_action as anything in shape.actions)
if(bodybound_action.target != stored)
continue
bodybound_action.Grant(stored)
stored.forceMove(shape.loc)
stored.notransform = FALSE
if(shape.mind)
shape.mind.transfer_to(stored)
if(death)
stored.death()
else if(source.convert_damage)
stored.revive(full_heal = TRUE, admin_revive = FALSE)
var/damage_percent = (shape.maxHealth - shape.health)/shape.maxHealth;
var/damapply = stored.maxHealth * damage_percent
stored.apply_damage(damapply, source.convert_damage_type, forced = TRUE, wound_bonus=CANT_WOUND)
if(source.convert_damage)
stored.blood_volume = shape.blood_volume;
// This guard is important because restore() can also be called on COMSIG_PARENT_QDELETING for shape, as well as on death.
// This can happen in, for example, [/proc/wabbajack] where the mob hit is qdel'd.
if(!QDELETED(shape))
QDEL_NULL(shape)
qdel(src)
return stored