Orbit Refactor, Add Orbiter Count (#16718)

Co-authored-by: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Co-authored-by: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com>
This commit is contained in:
Luc
2022-01-13 10:12:36 -05:00
committed by GitHub
parent 962137f291
commit 8bec8c75b3
12 changed files with 611 additions and 141 deletions
@@ -27,7 +27,7 @@
/obj/item/melee/ghost_sword
name = "spectral blade"
desc = "A rusted and dulled blade. It doesn't look like it'd do much damage. It glows weakly."
desc = "A rusted and dulled blade. It doesn't look like it'd do much damage."
icon_state = "spectral"
item_state = "spectral"
flags = CONDUCT
@@ -43,17 +43,26 @@
/obj/item/melee/ghost_sword/New()
..()
spirits = list()
START_PROCESSING(SSobj, src)
register_signals(src)
RegisterSignal(src, COMSIG_MOVABLE_MOVED, .proc/on_move)
GLOB.poi_list |= src
/obj/item/melee/ghost_sword/Destroy()
for(var/mob/dead/observer/G in spirits)
G.invisibility = initial(G.invisibility)
remove_ghost(G)
spirits.Cut()
STOP_PROCESSING(SSobj, src)
remove_signals(src)
UnregisterSignal(src, COMSIG_MOVABLE_MOVED)
GLOB.poi_list -= src
. = ..()
/obj/item/melee/ghost_sword/examine()
. = ..()
if(spirits)
. += "It appears to pulse with the power of [length(spirits)] vengeful spirits!"
else
. += "It glows weakly."
/obj/item/melee/ghost_sword/attack_self(mob/user)
if(summon_cooldown > world.time)
to_chat(user, "You just recently called out for aid. You don't want to annoy the spirits.")
@@ -70,38 +79,66 @@
if(istype(ghost))
ghost.ManualFollow(src)
/obj/item/melee/ghost_sword/process()
ghost_check()
/obj/item/melee/ghost_sword/proc/add_ghost(atom/movable/orbited, atom/orbiter)
SIGNAL_HANDLER // COMSIG_ATOM_ORBIT_BEGIN
if(!isobserver(orbiter))
return
/obj/item/melee/ghost_sword/proc/ghost_check()
var/ghost_counter = 0
var/turf/T = get_turf(src)
var/list/contents = T.GetAllContents()
var/mob/dead/observer/current_spirits = list()
var/mob/dead/observer/ghost = orbiter
for(var/mob/dead/observer/O in GLOB.player_list)
if((O.orbiting in contents))
ghost_counter++
O.invisibility = 0
current_spirits |= O
register_signals(ghost) // Sure, just in case someone's orbiting an orbiting ghost
for(var/mob/dead/observer/G in spirits - current_spirits)
G.invisibility = initial(G.invisibility)
spirits |= ghost
ghost.invisibility = 0
spirits = current_spirits
/obj/item/melee/ghost_sword/proc/remove_ghost(atom/movable/orbited, atom/orbiter)
SIGNAL_HANDLER // COMSIG_ATOM_ORBIT_STOP
if(!isobserver(orbiter))
return
return ghost_counter
var/mob/dead/observer/ghost = orbiter
remove_signals(ghost)
spirits -= ghost
ghost.invisibility = initial(ghost.invisibility)
/obj/item/melee/ghost_sword/proc/remove_signals(atom/A)
UnregisterSignal(A, COMSIG_ATOM_ORBIT_STOP)
UnregisterSignal(A, COMSIG_ATOM_ORBIT_BEGIN)
/obj/item/melee/ghost_sword/proc/register_signals(atom/A)
RegisterSignal(A, COMSIG_ATOM_ORBIT_BEGIN, .proc/add_ghost)
RegisterSignal(A, COMSIG_ATOM_ORBIT_STOP, .proc/remove_ghost)
/**
* When moving into something's contents
*/
/obj/item/melee/ghost_sword/proc/on_move(atom/movable/this, atom/old_loc, direction)
SIGNAL_HANDLER // on move
// We should only really care about the wielder of the sword and the sword itself when checking ghosts
if(ismob(old_loc))
remove_signals(old_loc)
for(var/mob/dead/observer/orbiter in old_loc.get_orbiters())
remove_ghost(orbiter)
if(ismob(loc))
register_signals(loc)
for(var/mob/dead/observer/orbiter in old_loc.get_orbiters())
add_ghost(orbiter)
/obj/item/melee/ghost_sword/proc/on_leave_item()
SIGNAL_HANDLER // on move
/obj/item/melee/ghost_sword/attack(mob/living/target, mob/living/carbon/human/user)
force = 0
var/ghost_counter = ghost_check()
var/ghost_counter = length(spirits)
force = clamp((ghost_counter * 4), 0, 75)
user.visible_message("<span class='danger'>[user] strikes with the force of [ghost_counter] vengeful spirits!</span>")
..()
/obj/item/melee/ghost_sword/hit_reaction(mob/living/carbon/human/owner, atom/movable/hitby, attack_text = "the attack", final_block_chance = 0, damage = 0, attack_type = MELEE_ATTACK)
var/ghost_counter = ghost_check()
var/ghost_counter = length(spirits)
final_block_chance += clamp((ghost_counter * 5), 0, 75)
owner.visible_message("<span class='danger'>[owner] is protected by a ring of [ghost_counter] ghosts!</span>")
return ..()
@@ -247,7 +247,7 @@
to_chat(user, "<span class='notice'>You release the wisp. It begins to bob around your head.</span>")
icon_state = "lantern"
INVOKE_ASYNC(wisp, /atom/movable/.proc/orbit, user, 20)
wisp.orbit(user, 20)
set_light(0)
user.update_sight()