Skip to content

Commit

Permalink
[MIRROR] Fixes a bug with the scope getting stuck on mobs that get du…
Browse files Browse the repository at this point in the history
…sted or ghost [MDB IGNORE] (#24404)

* Fixes a bug with the scope getting stuck on mobs that get dusted or ghost (#78941)

## About The Pull Request

If you ghost while mid-scope (or similarly, if you get dusted/your mob
gets deleted) the mob's cursor would get all messed up due to some
oversights. This just clears up some of these logic errors and ensures
everything gets cleaned up properly.

Fixes Skyrat-SS13/Skyrat-tg#24189
Fixes tgstation/tgstation#78756

## Why It's Good For The Game

Fixes a bug. I don't think scopes are even in use here but they are
downstream.

<details>
<summary>Deleted and being dusted resets perspective and cursor
properly</summary>

![dreamseeker_SSU4YnEK4n](https://github.com/Skyrat-SS13/Skyrat-tg/assets/13398309/dcaa5238-0067-4923-a956-24c6ba4aa2b3)

![dreamseeker_GZEhuSJSGS](https://github.com/Skyrat-SS13/Skyrat-tg/assets/13398309/2b88db21-6560-486d-94d3-9773fa543c50)

</details>

<details>
<summary>So does ghosting</summary>

![dreamseeker_7n3uXZvDSI](https://github.com/tgstation/tgstation/assets/13398309/08f6272d-baba-4e8e-ae0b-db23331982f7)

</details>

## Changelog

:cl:
fix: being killed or ghosting while being scoped will no longer cause
the cursor offset to persist in a bugged state
/:cl:

---------

Co-authored-by: san7890 <the@ san7890.com>

* Fixes a bug with the scope getting stuck on mobs that get dusted or ghost

---------

Co-authored-by: Bloop <[email protected]>
Co-authored-by: san7890 <the@ san7890.com>
  • Loading branch information
3 people authored and FFMirrorBot committed Oct 17, 2023
1 parent 12ea013 commit bed32c9
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions code/datums/components/scope.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
var/range_modifier = 1
/// Fullscreen object we use for tracking the shots.
var/atom/movable/screen/fullscreen/cursor_catcher/scope/tracker
/// The owner of the tracker's ckey. For comparing with the current owner mob, in case the client has left it (e.g. ghosted).
var/tracker_owner_ckey
/// Are we zooming currently?
var/zooming

/datum/component/scope/Initialize(range_modifier)
if(!isgun(parent))
Expand Down Expand Up @@ -101,21 +105,35 @@
return target_turf

/**
* We start zooming by hiding the mouse pointer, adding our tracker overlay and starting our processing.
* Wrapper for zoom(), so in case we runtime we do not get stuck in a bad state
*
* Arguments:
* * user: The mob we are starting zooming on.
*/
/datum/component/scope/proc/start_zooming(mob/user)
if(!user.client)
if(zoom(user))
zooming = TRUE

/**
* We start zooming by hiding the mouse pointer, adding our tracker overlay and starting our processing.
*
* Arguments:
* * user: The mob we are starting zooming on.
*/
/datum/component/scope/proc/zoom(mob/user)
if(isnull(user.client))
return
if(zooming)
return
user.client.mouse_override_icon = 'icons/effects/mouse_pointers/scope_hide.dmi'
user.update_mouse_pointer()
user.playsound_local(parent, 'sound/weapons/scope.ogg', 75, TRUE)
tracker = user.overlay_fullscreen("scope", /atom/movable/screen/fullscreen/cursor_catcher/scope, 0)
tracker.assign_to_mob(user, range_modifier)
RegisterSignal(user, COMSIG_MOB_SWAP_HANDS, PROC_REF(stop_zooming))
tracker_owner_ckey = user.ckey
RegisterSignals(user, list(COMSIG_MOB_SWAP_HANDS, COMSIG_QDELETING), PROC_REF(stop_zooming))
START_PROCESSING(SSprojectiles, src)
return TRUE

/**
* We stop zooming, canceling processing, resetting stuff back to normal and deleting our tracker.
Expand All @@ -126,15 +144,31 @@
/datum/component/scope/proc/stop_zooming(mob/user)
SIGNAL_HANDLER

if(!zooming)
return

STOP_PROCESSING(SSprojectiles, src)
UnregisterSignal(user, COMSIG_MOB_SWAP_HANDS)
UnregisterSignal(user, list(COMSIG_MOB_SWAP_HANDS, COMSIG_QDELETING))

zooming = FALSE

user.playsound_local(parent, 'sound/weapons/scope.ogg', 75, TRUE, frequency = -1)
user.clear_fullscreen("scope")

// if the client has ended up in another mob, find that mob so we can fix their cursor
var/mob/true_user
if(user.ckey != tracker_owner_ckey)
true_user = get_mob_by_ckey(tracker_owner_ckey)

if(!isnull(true_user))
user = true_user

if(user.client)
animate(user.client, 0.2 SECONDS, pixel_x = 0, pixel_y = 0)
user.client.mouse_override_icon = null
user.update_mouse_pointer()
user.playsound_local(parent, 'sound/weapons/scope.ogg', 75, TRUE, frequency = -1)
tracker = null
user.clear_fullscreen("scope")
tracker_owner_ckey = null

/atom/movable/screen/fullscreen/cursor_catcher/scope
icon_state = "scope"
Expand Down

0 comments on commit bed32c9

Please sign in to comment.