Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor caltrop component into element #56020

Merged
merged 3 commits into from Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/__DEFINES/dcs/flags.dm
Expand Up @@ -37,9 +37,9 @@
#define ARCH_MAXDROP "max_drop_amount" //each item's max drop amount

//Ouch my toes!
#define CALTROP_BYPASS_SHOES 1
#define CALTROP_IGNORE_WALKERS 2
#define CALTROP_SILENT 3
#define CALTROP_BYPASS_SHOES (1 << 0)
#define CALTROP_IGNORE_WALKERS (1 << 1)
#define CALTROP_SILENT (1 << 2)

//Ingredient type in datum/component/customizable_reagent_holder
#define CUSTOM_INGREDIENT_TYPE_EDIBLE 1
Expand Down
66 changes: 0 additions & 66 deletions code/datums/components/caltrop.dm

This file was deleted.

83 changes: 83 additions & 0 deletions code/datums/elements/caltrop.dm
@@ -0,0 +1,83 @@
/**
* Caltrop element; for hurting people when they walk over this.
*
* Used for broken glass, cactuses and four sided dice.
*/
/datum/element/caltrop
element_flags = ELEMENT_BESPOKE
id_arg_index = 2

///Minimum damage done when crossed
var/min_damage

///Maximum damage done when crossed
var/max_damage

///Probability of actually "firing", stunning and doing damage
var/probability

///Miscelanous caltrop flags; shoe bypassing, walking interaction, silence
var/flags

/datum/element/caltrop/Attach(datum/target, min_damage = 0, max_damage = 0, probability = 100, flags = NONE)
. = ..()
if(!isatom(target))
return ELEMENT_INCOMPATIBLE

src.min_damage = min_damage
src.max_damage = max(min_damage, max_damage)
src.probability = probability
src.flags = flags

RegisterSignal(target, COMSIG_MOVABLE_CROSSED, .proc/Crossed)

/datum/element/caltrop/proc/Crossed(atom/caltrop, atom/movable/AM)
SIGNAL_HANDLER

if(!prob(probability))
return

if(!ishuman(AM))
return

var/mob/living/carbon/human/H = AM
if(HAS_TRAIT(H, TRAIT_PIERCEIMMUNE))
return

if((flags & CALTROP_IGNORE_WALKERS) && H.m_intent == MOVE_INTENT_WALK)
return

if(H.movement_type & (FLOATING|FLYING)) //check if they are able to pass over us
//gravity checking only our parent would prevent us from triggering they're using magboots / other gravity assisting items that would cause them to still touch us.
return

if(H.buckled) //if they're buckled to something, that something should be checked instead.
return

if(H.body_position == LYING_DOWN) //if we're not standing we cant step on the caltrop
return

var/picked_def_zone = pick(BODY_ZONE_L_LEG, BODY_ZONE_R_LEG)
var/obj/item/bodypart/O = H.get_bodypart(picked_def_zone)
if(!istype(O))
return

if(O.status == BODYPART_ROBOTIC)
return

if (!(flags & CALTROP_BYPASS_SHOES))
if ((H.wear_suit?.body_parts_covered | H.w_uniform?.body_parts_covered | H.shoes?.body_parts_covered) & FEET)
return

var/damage = rand(min_damage, max_damage)
if(HAS_TRAIT(H, TRAIT_LIGHT_STEP))
damage *= 0.75


if(!(flags & CALTROP_SILENT) && !H.has_status_effect(/datum/status_effect/caltropped))
H.apply_status_effect(/datum/status_effect/caltropped)
H.visible_message("<span class='danger'>[H] steps on [caltrop].</span>", \
"<span class='userdanger'>You step on [caltrop]!</span>")

H.apply_damage(damage, BRUTE, picked_def_zone, wound_bonus = CANT_WOUND)
H.Paralyze(60)
16 changes: 16 additions & 0 deletions code/datums/status_effects/neutral.dm
Expand Up @@ -292,3 +292,19 @@
/// Something fishy is going on here...
/datum/status_effect/high_fiving/proc/dropped_slap(obj/item/source)
slap_item = null

/*
* A status effect used for preventing caltrop message spam
*
* While a mob has this status effect, they won't recieve any messages about
* stepping on caltrops. But they will be stunned and damaged regardless.
*
* The status effect itself has no effect, other than to disappear after
* a second.
*/
/datum/status_effect/caltropped
id = "caltropped"
duration = 1 SECONDS
tick_interval = INFINITY
status_type = STATUS_EFFECT_REFRESH
alert_type = null
3 changes: 2 additions & 1 deletion code/game/objects/items/dice.dm
Expand Up @@ -88,7 +88,8 @@

/obj/item/dice/d4/Initialize(mapload)
. = ..()
AddComponent(/datum/component/caltrop, 1, 4) //1d4 damage
// 1d4 damage
AddElement(/datum/element/caltrop, min_damage = 1, max_damage = 4)

/obj/item/dice/d6
name = "d6"
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/stacks/sheets/glass.dm
Expand Up @@ -273,7 +273,7 @@ GLOBAL_LIST_INIT(plastitaniumglass_recipes, list(

/obj/item/shard/Initialize()
. = ..()
AddComponent(/datum/component/caltrop, force)
AddElement(/datum/element/caltrop, min_damage = force)
AddComponent(/datum/component/butchering, 150, 65)
icon_state = pick("large", "medium", "small")
switch(icon_state)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/hydroponics/grown/towercap.dm
Expand Up @@ -143,7 +143,7 @@

/obj/structure/punji_sticks/Initialize(mapload)
. = ..()
AddComponent(/datum/component/caltrop, 20, 30, 100, CALTROP_BYPASS_SHOES)
AddElement(/datum/element/caltrop, min_damage = 20, max_damage = 30, flags = CALTROP_BYPASS_SHOES)

/obj/structure/punji_sticks/spikes
name = "wooden spikes"
Expand Down
3 changes: 1 addition & 2 deletions code/modules/mining/lavaland/ash_flora.dm
Expand Up @@ -144,8 +144,7 @@

/obj/structure/flora/ash/cacti/Initialize(mapload)
. = ..()
// min dmg 3, max dmg 6, prob(70)
AddComponent(/datum/component/caltrop, 3, 6, 70)
AddElement(/datum/element/caltrop, min_damage = 3, max_damage = 6, probability = 70)

///Snow flora to exist on icebox.
/obj/structure/flora/ash/chilly
Expand Down
4 changes: 2 additions & 2 deletions code/modules/mob/living/simple_animal/hostile/cockroach.dm
Expand Up @@ -106,9 +106,9 @@
sharpness = SHARP_POINTY
squish_chance = 0 // manual squish if relevant

/mob/living/simple_animal/hostile/cockroach/hauberoach/ComponentInitialize()
/mob/living/simple_animal/hostile/cockroach/hauberoach/Initialize()
. = ..()
AddComponent(/datum/component/caltrop, 10, 15, 100, (CALTROP_BYPASS_SHOES | CALTROP_SILENT))
AddElement(/datum/element/caltrop, min_damage = 10, max_damage = 15, flags = (CALTROP_BYPASS_SHOES | CALTROP_SILENT))

/mob/living/simple_animal/hostile/cockroach/hauberoach/Crossed(atom/movable/AM)
var/mob/living/A = AM
Expand Down
5 changes: 1 addition & 4 deletions code/modules/power/lighting.dm
Expand Up @@ -909,12 +909,9 @@
/obj/item/light/Initialize()
. = ..()
create_reagents(LIGHT_REAGENT_CAPACITY, INJECTABLE | DRAINABLE)
AddElement(/datum/element/caltrop, min_damage = force)
update()

/obj/item/light/ComponentInitialize()
. = ..()
AddComponent(/datum/component/caltrop, force)

/obj/item/light/Crossed(atom/movable/AM)
. = ..()
if(!isliving(AM))
Expand Down
2 changes: 1 addition & 1 deletion tgstation.dme
Expand Up @@ -426,7 +426,6 @@
#include "code\datums\components\beetlejuice.dm"
#include "code\datums\components\bloodysoles.dm"
#include "code\datums\components\butchering.dm"
#include "code\datums\components\caltrop.dm"
#include "code\datums\components\chasm.dm"
#include "code\datums\components\construction.dm"
#include "code\datums\components\creamed.dm"
Expand Down Expand Up @@ -590,6 +589,7 @@
#include "code\datums\elements\art.dm"
#include "code\datums\elements\bed_tucking.dm"
#include "code\datums\elements\bsa_blocker.dm"
#include "code\datums\elements\caltrop.dm"
#include "code\datums\elements\cleaning.dm"
#include "code\datums\elements\decal.dm"
#include "code\datums\elements\digitalcamo.dm"
Expand Down