Skip to content

Commit

Permalink
Parrying Refactor, Adding Parrying to Select Two-handed Weapons: Parr…
Browse files Browse the repository at this point in the history
…y This You Filthy Casual! (ParadiseSS13#26043)

* Refactors parrying and how parrying is handled. Also gives most of the melee wizard weapons parrying as well as most two handed weapons.

* Forgor the blood spear :)

* Renames `special_parry_condition` to `requires_two_hands`

* Apply suggestions from code review

Co-authored-by: DGamerL <[email protected]>
Signed-off-by: Spaghetti-bit <[email protected]>

* Update code/datums/components/parry.dm

Co-authored-by: Luc <[email protected]>
Signed-off-by: Spaghetti-bit <[email protected]>

* Apply suggestions from code review

Co-authored-by: Luc <[email protected]>
Signed-off-by: Spaghetti-bit <[email protected]>

* applies suggestion from @lewcc

* Removes the two handed requirement from cult spear as per @qwerty's request

* Apply suggestions from code review (1/2) from hal

Co-authored-by: Charlie <[email protected]>
Signed-off-by: Spaghetti-bit <[email protected]>

* Apply suggestions from code review (2/2)

* ...accidentally removed an icon in `energy_melee_weapons.dm` when I deconflicted stuff. 💀 ready for review.

* Again, variable added back during deconflict. issues resolved.

* Update code/game/objects/items/weapons/shields.dm

Signed-off-by: DGamerL <[email protected]>

---------

Signed-off-by: Spaghetti-bit <[email protected]>
Signed-off-by: DGamerL <[email protected]>
Co-authored-by: DGamerL <[email protected]>
Co-authored-by: Luc <[email protected]>
Co-authored-by: Charlie <[email protected]>
  • Loading branch information
4 people authored Jul 30, 2024
1 parent 6f00060 commit cbeedfc
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 78 deletions.
2 changes: 2 additions & 0 deletions code/__HELPERS/trait_helpers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
#define TRAIT_NO_THROWN_MESSAGE "no_message_when_thrown"
/// Makes the item not display a message on storage insertion
#define TRAIT_SILENT_INSERTION "silent_insertion"
/// Makes an item active, this is generally used by energy based weapons or toggle based items.
#define TRAIT_ITEM_ACTIVE "item_active"

/// A surgical tool; when in hand in help intent (and with a surgery in progress) won't attack the user
#define TRAIT_SURGICAL "surgical_tool"
Expand Down
3 changes: 2 additions & 1 deletion code/_globalvars/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ GLOBAL_LIST_INIT(traits_by_type, list(
"TRAIT_XENO_INTERACTABLE" = TRAIT_XENO_INTERACTABLE,
"TRAIT_NO_THROWN_MESSAGE" = TRAIT_NO_THROWN_MESSAGE,
"TRAIT_SILENT_INSERTION" = TRAIT_SILENT_INSERTION,
"TRAIT_HYPOSPRAY_IMMUNE" = TRAIT_HYPOSPRAY_IMMUNE
"TRAIT_HYPOSPRAY_IMMUNE" = TRAIT_HYPOSPRAY_IMMUNE,
"TRAIT_ITEM_ACTIVE" = TRAIT_ITEM_ACTIVE
),

/turf = list(
Expand Down
12 changes: 11 additions & 1 deletion code/datums/components/parry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
var/no_parry_sound
/// Text to be shown to users who examine the parent. Will list which type of attacks it can parry.
var/examine_text
/// Does this item have a require a condition to meet before being able to parry? This is for two handed weapons that can parry. (Default: FALSE)
var/requires_two_hands = FALSE
/// Does this item require activation? This is for activation based items or energy weapons.
var/requires_activation = FALSE

/datum/component/parry/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(equipped))
Expand All @@ -32,7 +36,7 @@
if(ismob(I.loc))
UnregisterSignal(I.loc, COMSIG_HUMAN_PARRY)

/datum/component/parry/Initialize(_stamina_constant = 0, _stamina_coefficient = 0, _parry_time_out_time = PARRY_DEFAULT_TIMEOUT, _parryable_attack_types = ALL_ATTACK_TYPES, _parry_cooldown = 2 SECONDS, _no_parry_sound = FALSE)
/datum/component/parry/Initialize(_stamina_constant = 0, _stamina_coefficient = 0, _parry_time_out_time = PARRY_DEFAULT_TIMEOUT, _parryable_attack_types = ALL_ATTACK_TYPES, _parry_cooldown = 2 SECONDS, _no_parry_sound = FALSE, _requires_two_hands = FALSE, _requires_activation = FALSE)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE

Expand All @@ -41,6 +45,8 @@
stamina_coefficient = _stamina_coefficient
parry_cooldown = _parry_cooldown
no_parry_sound = _no_parry_sound
requires_two_hands = _requires_two_hands
requires_activation = _requires_activation
if(islist(_parryable_attack_types))
parryable_attack_types = _parryable_attack_types
else
Expand Down Expand Up @@ -73,6 +79,10 @@
/datum/component/parry/proc/start_parry(mob/living/L)
SIGNAL_HANDLER
var/time_since_parry = world.time - time_parried
if(requires_two_hands && !HAS_TRAIT(parent, TRAIT_WIELDED)) // If our item has special conditions before being able to parry.
return
if(requires_activation && !HAS_TRAIT(parent, TRAIT_ITEM_ACTIVE)) // If our item requires an activation to be able to parry. [E-sword / Teleshield, etc.]
return
if(time_since_parry < parry_cooldown) // stops spam
return

Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/cult/cult_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@

/obj/item/cult_spear/Initialize(mapload)
. = ..()
AddComponent(/datum/component/parry, _stamina_constant = 2, _stamina_coefficient = 0.4, _parryable_attack_types = ALL_ATTACK_TYPES, _parry_cooldown = (5 / 3) SECONDS ) // 0.666667 seconds for 60% uptime.
AddComponent(/datum/component/parry, _stamina_constant = 2, _stamina_coefficient = 0.4, _parryable_attack_types = ALL_ATTACK_TYPES, _parry_cooldown = (5 / 3) SECONDS) // 0.666667 seconds for 60% uptime.
AddComponent(/datum/component/two_handed, force_wielded = 24, force_unwielded = force, icon_wielded = "[base_icon_state]1")

/obj/item/cult_spear/Destroy()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/cigs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ LIGHTERS ARE IN LIGHTERS.DM

else if(istype(I, /obj/item/melee/energy/sword/saber))
var/obj/item/melee/energy/sword/saber/S = I
if(S.active)
if(HAS_TRAIT(S, TRAIT_ITEM_ACTIVE))
light("<span class='warning'>[user] makes a violent slashing motion, barely missing [user.p_their()] nose as light flashes. [user.p_they(TRUE)] light[user.p_s()] [user.p_their()] [name] with [S] in the process.</span>")

else if(istype(I, /obj/item/assembly/igniter))
Expand Down
95 changes: 51 additions & 44 deletions code/game/objects/items/weapons/melee/energy_melee_weapons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
name = "generic energy blade"
desc = "If you can see this and didn't spawn it in as an admin, make an issue report on GitHub."
icon = 'icons/obj/weapons/energy_melee.dmi'
var/active = FALSE
/// Damage done when active. Does not stack with force_off.
var/force_on = 30
/// Damage done when thrown while active. Does not stack with throwforce_off.
Expand Down Expand Up @@ -78,8 +77,21 @@
if(HAS_TRAIT(user, TRAIT_CLUMSY) && prob(50))
to_chat(user, "<span class='warning'>You accidentally cut yourself with [src], like a doofus!</span>")
user.take_organ_damage(5,5)
active = !active
if(active)
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
REMOVE_TRAIT(src, TRAIT_ITEM_ACTIVE, TRAIT_GENERIC)
force = force_off
throwforce = throwforce_off
hitsound = initial(hitsound)
throw_speed = initial(throw_speed)
if(length(attack_verb_on))
attack_verb = list()
icon_state = initial(icon_state)
w_class = initial(w_class)
playsound(user, 'sound/weapons/saberoff.ogg', 35, 1) //changed it from 50% volume to 35% because deafness
set_light(0)
to_chat(user, "<span class='notice'>[src] can now be concealed.</span>")
else
ADD_TRAIT(src, TRAIT_ITEM_ACTIVE, TRAIT_GENERIC)
force = force_on
throwforce = throwforce_on
hitsound = 'sound/weapons/blade1.ogg'
Expand All @@ -95,18 +107,7 @@
w_class = w_class_on
playsound(user, 'sound/weapons/saberon.ogg', 35, 1) //changed it from 50% volume to 35% because deafness
to_chat(user, "<span class='notice'>[src] is now active.</span>")
else
force = force_off
throwforce = throwforce_off
hitsound = initial(hitsound)
throw_speed = initial(throw_speed)
if(length(attack_verb_on))
attack_verb = list()
icon_state = initial(icon_state)
w_class = initial(w_class)
playsound(user, 'sound/weapons/saberoff.ogg', 35, 1) //changed it from 50% volume to 35% because deafness
set_light(0)
to_chat(user, "<span class='notice'>[src] can now be concealed.</span>")

if(ishuman(user))
var/mob/living/carbon/human/H = user
H.update_inv_l_hand()
Expand All @@ -115,7 +116,9 @@
return

/obj/item/melee/energy/get_heat()
return active * 3500
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
return 3500
return 0

/obj/item/melee/energy/proc/try_sharpen(obj/item/item, amount, max_amount)
SIGNAL_HANDLER // COMSIG_ITEM_SHARPEN_ACT
Expand Down Expand Up @@ -180,14 +183,14 @@
..()
if(item_color == null)
item_color = pick("red", "blue", "green", "purple")
AddComponent(/datum/component/parry, _stamina_constant = 2, _stamina_coefficient = 0.5, _parryable_attack_types = ALL_ATTACK_TYPES)
AddComponent(/datum/component/parry, _stamina_constant = 2, _stamina_coefficient = 0.5, _parryable_attack_types = ALL_ATTACK_TYPES, _requires_activation = TRUE)

/obj/item/melee/energy/sword/examine(mob/user)
. = ..()
. += "<span class='notice'>Can parry melee attacks and sometimes blocks ranged energy attacks. Use in hand to turn off and on.</span>"

/obj/item/melee/energy/sword/hit_reaction(mob/living/carbon/human/owner, atom/movable/hitby, attack_text = "the attack", final_block_chance = 0, damage = 0, attack_type = MELEE_ATTACK)
if(active)
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
return ..()
return FALSE

Expand All @@ -198,7 +201,7 @@
/obj/item/melee/energy/sword/cyborg/attack(mob/M, mob/living/silicon/robot/R)
if(R.cell)
var/obj/item/stock_parts/cell/C = R.cell
if(active && !(C.use(hitcost)))
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE) && !(C.use(hitcost)))
attack_self(R)
to_chat(R, "<span class='notice'>It's out of charge!</span>")
return
Expand Down Expand Up @@ -251,7 +254,7 @@
item_color = "rainbow"
to_chat(user, "<span class='warning'>RNBW_ENGAGE</span>")

if(active)
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
icon_state = "swordrainbow"
// Updating overlays, copied from welder code.
// I tried calling attack_self twice, which looked cool, except it somehow didn't update the overlays!!
Expand All @@ -265,7 +268,7 @@


/obj/item/melee/energy/sword/saber/hit_reaction(mob/living/carbon/human/owner, atom/movable/hitby, attack_text = "the attack", final_block_chance = 0, damage = 0, attack_type = MELEE_ATTACK)
if(!active)
if(!HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
return FALSE
. = ..()
if(!.) // they did not block the attack
Expand Down Expand Up @@ -322,13 +325,16 @@
icon_state = "blade"
force = 30 //Normal attacks deal esword damage
hitsound = 'sound/weapons/blade1.ogg'
active = TRUE
throwforce = 1//Throwing or dropping the item deletes it.
throw_speed = 3
throw_range = 1
w_class = WEIGHT_CLASS_BULKY //So you can't hide it in your pocket or some such.
sharp = TRUE

/obj/item/melee/energy/blade/Initialize(mapload)
. = ..()
ADD_TRAIT(src, TRAIT_ITEM_ACTIVE, ROUNDSTART_TRAIT)

/obj/item/melee/energy/blade/attack_self(mob/user)
return

Expand Down Expand Up @@ -374,7 +380,7 @@
return
var/datum/status_effect/saw_bleed/B = target.has_status_effect(STATUS_EFFECT_SAWBLEED)
if(!B)
if(!active) //This isn't in the above if-check so that the else doesn't care about active
if(!HAS_TRAIT(src, TRAIT_ITEM_ACTIVE)) //This isn't in the above if-check so that the else doesn't care about active
target.apply_status_effect(STATUS_EFFECT_SAWBLEED)
else
B.add_bleed(B.bleed_buildup)
Expand All @@ -394,8 +400,21 @@
if(HAS_TRAIT(H, TRAIT_CLUMSY) && prob(50))
to_chat(H, "<span class='warning'>You accidentally cut yourself with [src], like a doofus!</span>")
H.take_organ_damage(10,10)
active = !active
if(active)
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
REMOVE_TRAIT(src, TRAIT_ITEM_ACTIVE, TRAIT_GENERIC)
force = force_off
throwforce = throwforce_off
hitsound = initial(hitsound)
throw_speed = initial(throw_speed)
if(length(attack_verb_on))
attack_verb = list()
icon_state = initial(icon_state)
w_class = initial(w_class)
playsound(user, 'sound/magic/fellowship_armory.ogg', 35, 1) //changed it from 50% volume to 35% because deafness
set_light(0)
to_chat(user, "<span class='notice'>You close [src]. It will now attack rapidly and cause fauna to bleed.</span>")
else
ADD_TRAIT(src, TRAIT_ITEM_ACTIVE, TRAIT_GENERIC)
force = force_on
throwforce = throwforce_on
hitsound = 'sound/weapons/bladeslice.ogg'
Expand All @@ -409,20 +428,8 @@
icon_state = "sword[item_color]"
set_light(brightness_on, l_color=colormap[item_color])
w_class = w_class_on
playsound(user, 'sound/magic/fellowship_armory.ogg', 35, TRUE, frequency = 90000 - (active * 30000))
playsound(user, 'sound/magic/fellowship_armory.ogg', 35, TRUE, frequency = 90000 - (HAS_TRAIT(src, TRAIT_ITEM_ACTIVE) * 30000))
to_chat(user, "<span class='notice'>You open [src]. It will now cleave enemies in a wide arc and deal additional damage to fauna.</span>")
else
force = force_off
throwforce = throwforce_off
hitsound = initial(hitsound)
throw_speed = initial(throw_speed)
if(length(attack_verb_on))
attack_verb = list()
icon_state = initial(icon_state)
w_class = initial(w_class)
playsound(user, 'sound/magic/fellowship_armory.ogg', 35, 1) //changed it from 50% volume to 35% because deafness
set_light(0)
to_chat(user, "<span class='notice'>You close [src]. It will now attack rapidly and cause fauna to bleed.</span>")

if(ishuman(user))
var/mob/living/carbon/human/H = user
Expand All @@ -433,27 +440,27 @@

/obj/item/melee/energy/cleaving_saw/examine(mob/user)
. = ..()
. += "<span class='notice'>It is [active ? "open, will cleave enemies in a wide arc and deal additional damage to fauna":"closed, and can be used for rapid consecutive attacks that cause fauna to bleed"].<br>\
. += "<span class='notice'>It is [HAS_TRAIT(src, TRAIT_ITEM_ACTIVE) ? "open, will cleave enemies in a wide arc and deal additional damage to fauna":"closed, and can be used for rapid consecutive attacks that cause fauna to bleed"].<br>\
Both modes will build up existing bleed effects, doing a burst of high damage if the bleed is built up high enough.<br>\
Transforming it immediately after an attack causes the next attack to come out faster.</span>"

/obj/item/melee/energy/cleaving_saw/suicide_act(mob/user)
user.visible_message("<span class='suicide'>[user] is [active ? "closing [src] on [user.p_their()] neck" : "opening [src] into [user.p_their()] chest"]! It looks like [user.p_theyre()] trying to commit suicide!</span>")
user.visible_message("<span class='suicide'>[user] is [HAS_TRAIT(src, TRAIT_ITEM_ACTIVE) ? "closing [src] on [user.p_their()] neck" : "opening [src] into [user.p_their()] chest"]! It looks like [user.p_theyre()] trying to commit suicide!</span>")
transform_cooldown = 0
transform_weapon(user, TRUE)
return BRUTELOSS

/obj/item/melee/energy/cleaving_saw/melee_attack_chain(mob/user, atom/target, params)
..()
if(!active)
if(!HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
user.changeNext_move(CLICK_CD_MELEE * 0.5) //when closed, it attacks very rapidly

/obj/item/melee/energy/cleaving_saw/attack(mob/living/target, mob/living/carbon/human/user)
if(!active || swiping || !target.density || get_turf(target) == get_turf(user))
if(!active)
if(!HAS_TRAIT(src, TRAIT_ITEM_ACTIVE) || swiping || !target.density || get_turf(target) == get_turf(user))
if(!HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
faction_bonus_force = 0
..()
if(!active)
if(!HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
faction_bonus_force = initial(faction_bonus_force)
else
var/turf/user_turf = get_turf(user)
Expand Down
30 changes: 16 additions & 14 deletions code/game/objects/items/weapons/shields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -139,32 +139,34 @@
throw_speed = 3
throw_range = 4
w_class = WEIGHT_CLASS_NORMAL
var/active = FALSE

/obj/item/shield/riot/tele/add_parry_component()
AddComponent(/datum/component/parry, _stamina_constant = 2, _stamina_coefficient = 0.7, _parryable_attack_types = ALL_ATTACK_TYPES, _parry_cooldown = (5 / 3) SECONDS, _requires_activation = TRUE)

/obj/item/shield/riot/tele/hit_reaction(mob/living/carbon/human/owner, atom/movable/hitby, attack_text = "the attack", final_block_chance = 0, damage = 0, attack_type = MELEE_ATTACK)
if(active)
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
return ..()
return FALSE // by not calling the parent the hit_reaction signal is never sent

/obj/item/shield/riot/tele/attack_self(mob/living/user)
active = !active
icon_state = "teleriot[active]"
playsound(src.loc, 'sound/weapons/batonextend.ogg', 50, 1)

if(active)
force = 8
throwforce = 5
throw_speed = 2
w_class = WEIGHT_CLASS_BULKY
slot_flags = SLOT_FLAG_BACK
to_chat(user, "<span class='notice'>You extend \the [src].</span>")
else
if(HAS_TRAIT(src, TRAIT_ITEM_ACTIVE))
REMOVE_TRAIT(src,TRAIT_ITEM_ACTIVE, TRAIT_GENERIC)
force = 3
throwforce = 3
throw_speed = 3
w_class = WEIGHT_CLASS_NORMAL
slot_flags = null
to_chat(user, "<span class='notice'>[src] can now be concealed.</span>")
else
ADD_TRAIT(src, TRAIT_ITEM_ACTIVE, TRAIT_GENERIC)
force = 8
throwforce = 5
throw_speed = 2
w_class = WEIGHT_CLASS_BULKY
slot_flags = SLOT_FLAG_BACK
to_chat(user, "<span class='notice'>You extend \the [src].</span>")
icon_state = "teleriot[HAS_TRAIT(src, TRAIT_ITEM_ACTIVE)]"
playsound(loc, 'sound/weapons/batonextend.ogg', 50, TRUE)
if(ishuman(user))
var/mob/living/carbon/human/H = user
H.update_inv_l_hand()
Expand Down
Loading

0 comments on commit cbeedfc

Please sign in to comment.