[MIRROR] Give basic mob ranged attacks a cooldown [MDB IGNORE] (#23062)

* Give basic mob ranged attacks a cooldown (#77575)

## About The Pull Request

Atomised change from a different PR I am working on.
This changes the basic mob ranged attacks element into a component so
that it can also track an attack cooldown on the mob, preventing it from
firing until the cooldown is complete.
This was possible with simple mobs but wasn't kept going forwards when
converting things to basic ones.

## Why It's Good For The Game

Ideally player and mob behaviour should be unified as much as is
realistically possible. Currently mobs which are designed to fire a
powerful weapon slowly can blast as rapidly as the click cooldown if
placed under control of a player, which is not ideal.
This isn't currently aligned for melee attacks either but I will look at
that later.

## Changelog

🆑
fix: Player-controlled basic mobs with ranged attacks can now only fire
about as fast as AI-controlled ones.
/🆑

* Give basic mob ranged attacks a cooldown

* Modular update

---------

Co-authored-by: Jacquerel <hnevard@gmail.com>
Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-08-13 19:18:09 -04:00
committed by GitHub
co-authored by Jacquerel Giz
parent e9065a1f3e
commit b967c2787c
10 changed files with 95 additions and 67 deletions
@@ -78,7 +78,7 @@
. = ..()
var/static/list/stickman_drops = list(/obj/item/gun/ballistic/automatic/pistol/stickman)
AddElement(/datum/element/death_drops, stickman_drops)
AddElement(/datum/element/ranged_attacks, /obj/item/ammo_casing/c9mm, 'sound/misc/bang.ogg')
AddComponent(/datum/component/ranged_attacks, casing_type = /obj/item/ammo_casing/c9mm, projectile_sound = 'sound/misc/bang.ogg', cooldown_time = 5 SECONDS)
/datum/ai_controller/basic_controller/stickman/ranged
planning_subtrees = list(
@@ -34,6 +34,8 @@
ai_controller = /datum/ai_controller/basic_controller/hivebot
///does this type do range attacks?
var/ranged_attacker = FALSE
/// How often can we shoot?
var/ranged_attack_cooldown = 3 SECONDS
/mob/living/basic/hivebot/Initialize(mapload)
@@ -43,7 +45,7 @@
AddElement(/datum/element/appearance_on_aggro, overlay_icon = icon, overlay_state = "[initial(icon_state)]_attack")
if(!ranged_attacker)
return
AddElement(/datum/element/ranged_attacks, /obj/item/ammo_casing/hivebot)
AddComponent(/datum/component/ranged_attacks, /obj/item/ammo_casing/hivebot, cooldown_time = ranged_attack_cooldown)
/mob/living/basic/hivebot/death(gibbed)
do_sparks(number = 3, cardinal_only = TRUE, source = src)
@@ -64,6 +66,7 @@
icon_dead = "ranged"
ranged_attacker = TRUE
ai_controller = /datum/ai_controller/basic_controller/hivebot/ranged/rapid
ranged_attack_cooldown = 1.5 SECONDS
/mob/living/basic/hivebot/strong
name = "strong hivebot"
@@ -32,7 +32,7 @@
/mob/living/basic/syndicate/russian/ranged/Initialize(mapload)
. = ..()
AddElement(/datum/element/ranged_attacks, casingtype, projectilesound)
AddComponent(/datum/component/ranged_attacks, casing_type = casingtype, projectile_sound = projectilesound, cooldown_time = 1 SECONDS)
/mob/living/basic/syndicate/russian/ranged/lootless
loot = list()
@@ -134,12 +134,16 @@
loot = list(/obj/effect/gibspawner/human)
ai_controller = /datum/ai_controller/basic_controller/syndicate/ranged
r_hand = /obj/item/gun/ballistic/automatic/pistol
/// Type of bullet we use
var/casingtype = /obj/item/ammo_casing/c9mm
/// Sound to play when firing weapon
var/projectilesound = 'sound/weapons/gun/pistol/shot.ogg'
/// Time between taking shots
var/ranged_cooldown = 1 SECONDS
/mob/living/basic/syndicate/ranged/Initialize(mapload)
. = ..()
AddElement(/datum/element/ranged_attacks, casingtype, projectilesound)
AddComponent(/datum/component/ranged_attacks, casing_type = casingtype, projectile_sound = projectilesound, cooldown_time = ranged_cooldown)
/mob/living/basic/syndicate/ranged/infiltrator //shuttle loan event
projectilesound = 'sound/weapons/gun/smg/shot_suppressed.ogg'
@@ -168,6 +172,7 @@
casingtype = /obj/item/ammo_casing/c45
projectilesound = 'sound/weapons/gun/smg/shot.ogg'
ai_controller = /datum/ai_controller/basic_controller/syndicate/ranged/burst
ranged_cooldown = 3 SECONDS
r_hand = /obj/item/gun/ballistic/automatic/c20r
/mob/living/basic/syndicate/ranged/smg/pilot //caravan ambush ruin
@@ -197,6 +202,7 @@
/mob/living/basic/syndicate/ranged/shotgun
casingtype = /obj/item/ammo_casing/shotgun/buckshot //buckshot (up to 72.5 brute) fired in a two-round burst
ai_controller = /datum/ai_controller/basic_controller/syndicate/ranged/shotgunner
ranged_cooldown = 3 SECONDS
r_hand = /obj/item/gun/ballistic/shotgun/bulldog
/mob/living/basic/syndicate/ranged/shotgun/space
@@ -96,7 +96,7 @@
/mob/living/basic/cockroach/glockroach/Initialize(mapload)
. = ..()
AddElement(/datum/element/ranged_attacks, /obj/item/ammo_casing/glockroach)
AddComponent(/datum/component/ranged_attacks, casing_type = /obj/item/ammo_casing/glockroach, cooldown_time = 1 SECONDS)
/datum/ai_controller/basic_controller/cockroach/glockroach
planning_subtrees = list(