From e51d6e73337c94497ea1942a67eeefc06d0eb508 Mon Sep 17 00:00:00 2001 From: spookerton Date: Sun, 13 Nov 2022 12:09:55 +0000 Subject: [PATCH] drakes can break down trees and dig up stumps --- code/game/objects/structures/flora/trees.dm | 78 ++++++++++++------- .../sif/grafadreka/grafadreka_interaction.dm | 22 ++++++ 2 files changed, 74 insertions(+), 26 deletions(-) diff --git a/code/game/objects/structures/flora/trees.dm b/code/game/objects/structures/flora/trees.dm index a5ce24c60d..2f183c5893 100644 --- a/code/game/objects/structures/flora/trees.dm +++ b/code/game/objects/structures/flora/trees.dm @@ -33,39 +33,64 @@ /obj/structure/flora/tree/can_harvest(var/obj/item/I, var/ignore_tool = FALSE) return (!is_stump && (ignore_tool || (harvest_tool && istype(I, harvest_tool))) && harvest_loot && harvest_loot.len && harvest_count < max_harvests) -/obj/structure/flora/tree/attackby(var/obj/item/W, var/mob/living/user) - if(can_harvest(W)) - ..(W, user) + +/obj/structure/flora/tree/attackby(obj/item/item, mob/living/user) + if (can_harvest(item)) + ..(item, user) return - - if(!istype(W)) + if (!istype(item)) return ..() - - if(is_stump) - if(istype(W,/obj/item/shovel)) - if(do_after(user, 5 SECONDS)) - visible_message("\The [user] digs up \the [src] stump with \the [W].") + if (is_stump) + if (istype(item, /obj/item/shovel)) + if (do_after(user, 5 SECONDS)) + visible_message("\The [user] digs up \the [src] stump with \the [item].") qdel(src) return + TryChop(user, item) - visible_message("\The [user] hits \the [src] with \the [W]!") - var/damage_to_do = W.force - if(!W.sharp && !W.edge) - damage_to_do = round(damage_to_do / 4) - if(damage_to_do > 0) - if(W.sharp && W.edge) - playsound(src, 'sound/effects/woodcutting.ogg', 50, 1) - else - playsound(src, W.hitsound, 50, 1) - if(damage_to_do > 5 && !indestructable) - adjust_health(-damage_to_do) - else - to_chat(user, "\The [W] is ineffective at harming \the [src].") - - hit_animation() - user.setClickCooldown(user.get_attack_speed(W)) +/obj/structure/flora/tree/proc/TryChop(mob/living/user, obj/item/item) + var/damage + var/chop + var/cooldown + var/simple_attack_sound + if (!item) + var/mob/living/simple_mob/simple = user + if (!istype(simple)) + return + damage = rand(simple.melee_damage_lower, simple.melee_damage_upper) + chop = simple.attack_sharp + if (!chop) + damage *= 0.25 + cooldown = simple.base_attack_cooldown + simple_attack_sound = simple.attack_sound + else + damage = item.force + chop = item.sharp && item.edge + if (!item.sharp && !item.edge) + damage *= 0.25 + cooldown = user.get_attack_speed(item) + user.visible_message( + SPAN_ITALIC("\The [user] hits \a [src][item ? " with \a [item]": ""]!"), + SPAN_ITALIC("You hit \the [src][item ? " with \the [item]": ""]!"), + range = 5 + ) + damage = round(max(0, damage)) + if (damage) + if (chop) + playsound(src, 'sound/effects/woodcutting.ogg', 50, TRUE) + else if (item) + playsound(src, item.hitsound, 50, TRUE) + else if (simple_attack_sound) + playsound(src, simple_attack_sound, 50, TRUE) + if (indestructable || damage < 5) + to_chat(user, SPAN_WARNING("[item ? "\The [item]" : "You"] cannot damage \the [src].")) + else + adjust_health(-damage) + user.setClickCooldown(cooldown) user.do_attack_animation(src) + hit_animation() + // Shakes the tree slightly, more or less stolen from lockers. /obj/structure/flora/tree/proc/hit_animation() @@ -77,6 +102,7 @@ animate(src, transform=turn(M, shake_animation_degrees * shake_dir), pixel_x=init_px + 2*shake_dir, time=1) animate(transform=M, pixel_x=init_px, time=6, easing=ELASTIC_EASING) + // Used when the tree gets hurt. /obj/structure/flora/tree/proc/adjust_health(var/amount, var/damage_wood = FALSE) if(is_stump || indestructable) diff --git a/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka/grafadreka_interaction.dm b/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka/grafadreka_interaction.dm index e915133e20..f7a5536752 100644 --- a/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka/grafadreka_interaction.dm +++ b/code/modules/mob/living/simple_mob/subtypes/animal/sif/grafadreka/grafadreka_interaction.dm @@ -34,6 +34,28 @@ attack_self(drake) +// This should be generalized out to other simples if they become normally playable. +/obj/structure/flora/tree/interaction_grafadreka(mob/living/simple_mob/animal/sif/grafadreka/drake) + . = TRUE + if (drake.a_intent != I_HURT) + return ..() + if (is_stump) + drake.visible_message( + SPAN_ITALIC("\The [drake] starts to dig at the stump of \a [src]."), + SPAN_ITALIC("You start to dig up the stump of \the [src]."), + range = 5 + ) + if (do_after(drake, 5 SECONDS, src) && !QDELETED(src)) + drake.visible_message( + SPAN_ITALIC("\The [drake] unearths a stump."), + SPAN_NOTICE("You finish digging up the stump."), + range = 1 + ) + qdel(src) + return + TryChop(drake) + + /* Trained drake interactions */ /mob/living/simple_mob/animal/sif/grafadreka/trained/interaction_grafadreka(mob/living/simple_mob/animal/sif/grafadreka/drake)