Files
Bubberstation/code/datums/components/fishing_spot.dm
LemonInTheDark ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](102b79694f)

[Moves signal procs over to their own
file](33d07d01fd)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](335ea4ad08)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](210e57051d)

[And finally passes over the examine
signals](65917658fb)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

65 lines
2.6 KiB
Plaintext

// A thing you can fish in
/datum/component/fishing_spot
/// Defines the probabilities and fish availibilty
var/datum/fish_source/fish_source
/datum/component/fishing_spot/Initialize(configuration)
if(ispath(configuration,/datum/fish_source))
//Create new one of the given type
fish_source = new configuration
else if(istype(configuration,/datum/fish_source))
//Use passed in instance
fish_source = configuration
else
/// Check if it's a preset key
var/datum/fish_source/preset_configuration = GLOB.preset_fish_sources[configuration]
if(!preset_configuration)
stack_trace("Invalid fishing spot configuration \"[configuration]\" passed down to fishing spot component.")
return COMPONENT_INCOMPATIBLE
fish_source = preset_configuration
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, PROC_REF(handle_attackby))
RegisterSignal(parent, COMSIG_FISHING_ROD_CAST, PROC_REF(handle_cast))
/datum/component/fishing_spot/proc/handle_cast(datum/source, obj/item/fishing_rod/rod, mob/user)
SIGNAL_HANDLER
if(try_start_fishing(rod,user))
return FISHING_ROD_CAST_HANDLED
return NONE
/datum/component/fishing_spot/proc/handle_attackby(datum/source, obj/item/item, mob/user, params)
SIGNAL_HANDLER
if(try_start_fishing(item,user))
return COMPONENT_NO_AFTERATTACK
return NONE
/datum/component/fishing_spot/proc/try_start_fishing(obj/item/possibly_rod, mob/user)
SIGNAL_HANDLER
var/obj/item/fishing_rod/rod = possibly_rod
if(!istype(rod))
return
if(HAS_TRAIT(user,TRAIT_GONE_FISHING) || rod.currently_hooked_item)
user.balloon_alert(user, "already fishing")
return COMPONENT_NO_AFTERATTACK
var/denial_reason = fish_source.reason_we_cant_fish(rod, user)
if(denial_reason)
to_chat(user, span_warning(denial_reason))
return COMPONENT_NO_AFTERATTACK
start_fishing_challenge(rod, user)
return COMPONENT_NO_AFTERATTACK
/datum/component/fishing_spot/proc/start_fishing_challenge(obj/item/fishing_rod/rod, mob/user)
/// Roll what we caught based on modified table
var/result = fish_source.roll_reward(rod, user)
var/datum/fishing_challenge/challenge = new(parent, result, rod, user)
challenge.background = fish_source.background
challenge.difficulty = fish_source.calculate_difficulty(result, rod, user)
RegisterSignal(challenge, COMSIG_FISHING_CHALLENGE_COMPLETED, PROC_REF(fishing_completed))
challenge.start(user)
/datum/component/fishing_spot/proc/fishing_completed(datum/fishing_challenge/source, mob/user, success, perfect)
if(success)
var/obj/item/fish/caught = source.reward_path
user.add_mob_memory(/datum/memory/caught_fish, protagonist = user, deuteragonist = initial(caught.name))
fish_source.dispense_reward(source.reward_path, user)