mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
## About The Pull Request 516 requires float layered overlays to be using pixel_w and pixel_z instead of pixel_x and pixel_y respectively, unless we want visual/layering errors. This makes sense, as w,z are for visual effects only. Sadly seems we were not entirely consistent in this, and many things seem to have been using x,y incorrectly. This hopefully fixes that, and thus also fixes layering issues. Complete 1:1 compatibility not guaranteed. I did the lazy way suggested to me by SmArtKar to speed it up (Runtiming inside apply_overlays), and this is still included in the PR to flash out possible issues in a TM (Plus I will need someone to grep the runtimes for me after the TM period to make sure nothing was missed). After this is done I'll remove all these extra checks. Lints will probably be failing for a bit, got to wait for [this update](https://github.com/SpaceManiac/SpacemanDMM/commit/4b77cd487d0a7b6a069df20356b701af5b20489d) to them to make it into release. Or just unlint the lines, though that's probably gonna produce code debt ## Why It's Good For The Game Fixes this massive 516 mess, hopefully. closes #90281 ## Changelog 🆑 refactor: Changed many of our use cases for pixel_x and pixel_y correctly into pixel_w and pixel_z, fixing layering issues in the process. /🆑 --------- Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: SmArtKar <master.of.bagets@gmail.com>
172 lines
5.7 KiB
Plaintext
172 lines
5.7 KiB
Plaintext
/datum/component/throwbonus_on_windup
|
|
///the maximum windup bonus
|
|
var/maximum_bonus = 20
|
|
///additional behavior if we exceed the maximum bonus
|
|
var/datum/callback/pass_maximum_callback
|
|
///the player currently winding up their throw
|
|
var/datum/weakref/holder
|
|
///the current bonus we are at
|
|
var/throwforce_bonus = 0
|
|
///the bar relaying feedback to the player
|
|
var/obj/effect/overlay/windup_bar/our_bar
|
|
///any additional behavior we should look for before applying the bonus
|
|
var/datum/callback/apply_bonus_callback
|
|
///sound we play after successfully damaging the enemy with a bonus
|
|
var/sound_on_success
|
|
///effect we play after successfully damaging the enemy with a bonus
|
|
var/effect_on_success
|
|
///how fast we increase the wind up counter on process
|
|
var/windup_increment_speed
|
|
///text we display when we start winding up
|
|
var/throw_text
|
|
|
|
/datum/component/throwbonus_on_windup/Initialize(maximum_bonus = 20, windup_increment_speed = 1, pass_maximum_callback, apply_bonus_callback, sound_on_success, effect_on_success, throw_text)
|
|
. = ..()
|
|
if(!isitem(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
|
|
src.maximum_bonus = maximum_bonus
|
|
src.pass_maximum_callback = pass_maximum_callback
|
|
src.apply_bonus_callback = apply_bonus_callback
|
|
src.sound_on_success = sound_on_success
|
|
src.effect_on_success = effect_on_success
|
|
src.windup_increment_speed = windup_increment_speed
|
|
src.throw_text = throw_text
|
|
|
|
/datum/component/throwbonus_on_windup/proc/on_equip(datum/source, mob/living/equipper, slot)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!(slot & ITEM_SLOT_HANDS) || holder?.resolve())
|
|
return
|
|
holder = WEAKREF(equipper)
|
|
RegisterSignal(equipper, COMSIG_LIVING_THROW_MODE_TOGGLE, PROC_REF(throw_change))
|
|
RegisterSignal(equipper, COMSIG_MOB_SWAP_HANDS, PROC_REF(on_hands_swap))
|
|
if(equipper.throw_mode)
|
|
start_windup()
|
|
|
|
/datum/component/throwbonus_on_windup/proc/start_windup()
|
|
|
|
throwforce_bonus = initial(throwforce_bonus)
|
|
var/mob/living/our_holder = holder?.resolve()
|
|
if(isnull(holder))
|
|
return
|
|
if(throw_text)
|
|
to_chat(our_holder, span_warning(throw_text))
|
|
var/x_position = CEILING(our_holder.get_visual_width() * 0.5, 1)
|
|
our_bar = new()
|
|
our_bar.maximum_count = maximum_bonus
|
|
our_bar.pixel_x = x_position
|
|
our_holder.vis_contents += our_bar
|
|
START_PROCESSING(SSfastprocess, src)
|
|
|
|
/datum/component/throwbonus_on_windup/RegisterWithParent()
|
|
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(on_equip))
|
|
RegisterSignal(parent, COMSIG_MOVABLE_MOVED, PROC_REF(on_move))
|
|
RegisterSignal(parent, COMSIG_MOVABLE_PRE_IMPACT, PROC_REF(on_thrown))
|
|
|
|
/datum/component/throwbonus_on_windup/UnregisterFromParent()
|
|
UnregisterSignal(parent, list(COMSIG_ITEM_EQUIPPED, COMSIG_MOVABLE_MOVED, COMSIG_MOVABLE_PRE_IMPACT))
|
|
var/atom/our_holder = holder?.resolve()
|
|
if(!isnull(our_holder))
|
|
UnregisterSignal(our_holder, list(COMSIG_LIVING_THROW_MODE_TOGGLE, COMSIG_MOB_SWAP_HANDS))
|
|
|
|
/datum/component/throwbonus_on_windup/Destroy()
|
|
STOP_PROCESSING(SSfastprocess, src)
|
|
QDEL_NULL(our_bar)
|
|
holder = null
|
|
return ..()
|
|
|
|
/datum/component/throwbonus_on_windup/proc/throw_change(datum/source, throw_mode)
|
|
SIGNAL_HANDLER
|
|
|
|
if(throw_mode)
|
|
start_windup()
|
|
else
|
|
end_windup()
|
|
|
|
/datum/component/throwbonus_on_windup/proc/on_hands_swap(mob/living/source)
|
|
SIGNAL_HANDLER
|
|
|
|
if(source.get_active_held_item() != parent)
|
|
end_windup()
|
|
return
|
|
|
|
if(source.throw_mode)
|
|
start_windup()
|
|
|
|
/datum/component/throwbonus_on_windup/process(seconds_per_tick)
|
|
if(throwforce_bonus > maximum_bonus)
|
|
var/mob/living/our_holder = holder?.resolve()
|
|
pass_maximum_callback?.Invoke(our_holder)
|
|
end_windup()
|
|
return PROCESS_KILL
|
|
|
|
our_bar.recalculate_position(min(throwforce_bonus, maximum_bonus))
|
|
throwforce_bonus += windup_increment_speed
|
|
|
|
/datum/component/throwbonus_on_windup/proc/on_move(obj/item/source, atom/entering_loc)
|
|
SIGNAL_HANDLER
|
|
end_windup()
|
|
var/mob/living/our_holder = holder?.resolve()
|
|
if(isnull(our_holder))
|
|
return
|
|
holder = null
|
|
UnregisterSignal(our_holder, list(COMSIG_LIVING_THROW_MODE_TOGGLE, COMSIG_MOB_SWAP_HANDS))
|
|
|
|
/datum/component/throwbonus_on_windup/proc/end_windup()
|
|
QDEL_NULL(our_bar)
|
|
STOP_PROCESSING(SSfastprocess, src)
|
|
|
|
/datum/component/throwbonus_on_windup/proc/on_thrown(datum/source, atom/hit_atom, datum/thrownthing/throwingdatum)
|
|
SIGNAL_HANDLER
|
|
|
|
var/damage_to_apply = throwforce_bonus
|
|
throwforce_bonus = initial(throwforce_bonus)
|
|
if(!isliving(hit_atom))
|
|
return
|
|
|
|
if(apply_bonus_callback && !apply_bonus_callback.Invoke(hit_atom, damage_to_apply))
|
|
return
|
|
|
|
if(effect_on_success)
|
|
new effect_on_success(get_turf(hit_atom))
|
|
if(sound_on_success)
|
|
playsound(hit_atom, sound_on_success, 50, TRUE)
|
|
|
|
var/mob/living/living_target = hit_atom
|
|
living_target.apply_damage(damage_to_apply)
|
|
|
|
/obj/effect/overlay/windup_bar
|
|
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
|
|
anchored = TRUE
|
|
vis_flags = VIS_INHERIT_DIR | VIS_INHERIT_PLANE
|
|
icon = 'icons/effects/effects.dmi'
|
|
icon_state = "windup_bar"
|
|
layer = ABOVE_ALL_MOB_LAYER
|
|
///the maximum windup bonus
|
|
var/maximum_count = INFINITY
|
|
///the current count we are at
|
|
var/current_count = 0
|
|
|
|
/obj/effect/overlay/windup_bar/proc/recalculate_position(input_count)
|
|
current_count = input_count
|
|
update_appearance(UPDATE_OVERLAYS)
|
|
|
|
/obj/effect/overlay/windup_bar/update_overlays()
|
|
. = ..()
|
|
var/static/list/bar_positions = list(0, 2, 4, 6, 8)
|
|
var/current_percentage = current_count / maximum_count
|
|
var/bars_to_add = CEILING(length(bar_positions) * current_percentage, 1)
|
|
for(var/curr_number in 1 to bars_to_add)
|
|
var/bar_color
|
|
switch(curr_number)
|
|
if(1 to 2)
|
|
bar_color = "windup_red"
|
|
if(2 to 4)
|
|
bar_color = "windup_green"
|
|
if(4 to 5)
|
|
bar_color = "windup_purple"
|
|
var/mutable_appearance/bar_overlay = mutable_appearance(icon = icon, icon_state = bar_color, layer = ABOVE_HUD_PLANE)
|
|
bar_overlay.pixel_z = bar_positions[curr_number]
|
|
. += bar_overlay
|