mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-17 13:12:37 +00:00
* Refactors CTF (#74342) ## About The Pull Request CTF code is rather infamous for being poor and hard to actually work with, I wanted to add a feature for a mapping march project but the code would not allow for it, so here we are refactoring the entire thing. ## Why It's Good For The Game Replaces some really bad code with slightly less bad code. Should make it much easier to add features onto CTF in the future. ## Changelog 🆑 refactor: CTF has been entirely refactored. fix: Respawn times for CTF now work. qol: CTF players are alerted during control point games when one team is half way to winning. admin: CTF instagib mode can now be toggled from the secrets panel. /🆑 * Refactors CTF --------- Co-authored-by: NamelessFairy <40036527+NamelessFairy@users.noreply.github.com>
80 lines
3.2 KiB
Plaintext
80 lines
3.2 KiB
Plaintext
///A component added to the mind of anyone who is playing in an ongoing CTF match. Any player specific CTF functionality should be implimented here. (someone should impliment score tracking here)
|
|
/datum/component/ctf_player
|
|
///The team that this player is associated with.
|
|
var/team
|
|
///A reference to the players mob, cleared after they die, restored on respawn.
|
|
var/mob/living/player_mob
|
|
///Weather or not the player is currently able to respawn.
|
|
var/can_respawn = TRUE
|
|
///Reference to the game this player is participating in.
|
|
var/datum/ctf_controller/ctf_game
|
|
///Item dropped on death,
|
|
var/death_drop = /obj/effect/powerup/ammo/ctf
|
|
///Reference to players ckey, used for sending messages to them relating to CTF.
|
|
var/ckey_reference
|
|
|
|
/datum/component/ctf_player/Initialize(team, ctf_game, death_drop)
|
|
src.team = team
|
|
src.ctf_game = ctf_game
|
|
src.death_drop = death_drop
|
|
if(!istype(parent, /datum/mind))
|
|
return COMPONENT_INCOMPATIBLE
|
|
var/datum/mind/true_parent = parent
|
|
player_mob = true_parent.current
|
|
ckey_reference = player_mob.ckey
|
|
setup_dusting()
|
|
|
|
/datum/component/ctf_player/PostTransfer()
|
|
if(!istype(parent, /datum/mind))
|
|
return COMPONENT_INCOMPATIBLE
|
|
var/datum/mind/true_parent = parent
|
|
player_mob = true_parent.current
|
|
setup_dusting()
|
|
|
|
///CTF players are dusted upon taking damage that puts them into critical or leaving their body.
|
|
/datum/component/ctf_player/proc/setup_dusting()
|
|
RegisterSignal(player_mob, COMSIG_MOB_AFTER_APPLY_DAMAGE, PROC_REF(damage_type_check))
|
|
RegisterSignal(player_mob, COMSIG_MOB_GHOSTIZED, PROC_REF(ctf_dust))
|
|
|
|
///Stamina and oxygen damage will not dust a player by themself.
|
|
/datum/component/ctf_player/proc/damage_type_check(datum/source, damage, damage_type)
|
|
SIGNAL_HANDLER
|
|
if(damage_type != STAMINA && damage_type != OXY)
|
|
ctf_dust()
|
|
|
|
///Dusts the player and starts a respawn countdown.
|
|
/datum/component/ctf_player/proc/ctf_dust()
|
|
SIGNAL_HANDLER
|
|
if(!HAS_TRAIT(player_mob, TRAIT_CRITICAL_CONDITION) && !player_mob.stat == DEAD && player_mob.client)
|
|
return
|
|
UnregisterSignal(player_mob, list(COMSIG_MOB_AFTER_APPLY_DAMAGE, COMSIG_MOB_GHOSTIZED))
|
|
var/turf/death_turf = get_turf(player_mob)
|
|
player_mob.dust()
|
|
player_mob = null
|
|
can_respawn = FALSE
|
|
addtimer(CALLBACK(src, PROC_REF(allow_respawns)), ctf_game.respawn_cooldown, TIMER_UNIQUE)
|
|
if(death_drop)
|
|
new death_drop(death_turf)
|
|
|
|
///Called after a period of time pulled from ctf_game, allows the player to respawn in CTF.
|
|
/datum/component/ctf_player/proc/allow_respawns()
|
|
can_respawn = TRUE
|
|
send_message(span_notice("You can now respawn in CTF!"))
|
|
|
|
///Sends a message to the player.
|
|
/datum/component/ctf_player/proc/send_message(message)
|
|
to_chat(GLOB.directory[ckey_reference], message)
|
|
|
|
///Called when the associated CTF game ends or their associated team is deleted, dusts the player and deletes this component to ensure no data from it is carried over to future games.
|
|
/datum/component/ctf_player/proc/end_game()
|
|
if(player_mob)
|
|
for(var/obj/item/ctf_flag/flag in player_mob)
|
|
player_mob.dropItemToGround(flag)
|
|
player_mob.dust()
|
|
qdel(src)
|
|
|
|
/datum/component/ctf_player/Destroy(force, silent)
|
|
if(player_mob)
|
|
UnregisterSignal(player_mob, list(COMSIG_MOB_AFTER_APPLY_DAMAGE, COMSIG_MOB_GHOSTIZED))
|
|
return ..()
|