Skip to content

Commit

Permalink
Перевод в сигналы
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantornRU committed Nov 12, 2023
1 parent 9546526 commit 514e10d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 55 deletions.
1 change: 1 addition & 0 deletions modular_ss220/clumsy_table/_clumsy_table.dme
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "_clumsy_table.dm"

#include "code/clumsy_table.dm"
#include "code/clumsy_climb_component.dm"
74 changes: 74 additions & 0 deletions modular_ss220/clumsy_table/code/clumsy_climb_component.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/datum/component/clumsy_climb_component
var/thrown_chance = 80 //default for all human-sized livings
var/force_mod = 0.1 //коэффицент уменьшения урона при сбрасывании предмета
var/max_thrown_objects = 15
var/max_thrown_objects_low = 5

/datum/component/clumsy_climb_component/Initialize()
//RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(Repaint))
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE

/datum/component/clumsy_climb_component/RegisterWithParent()
RegisterSignal(parent, COMSIG_MOVABLE_CROSSED, PROC_REF(cross))
RegisterSignal(parent, COMSIG_CLIMBED_ON, PROC_REF(cross))

/datum/component/clumsy_climb_component/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_MOVABLE_CROSSED, COMSIG_CLIMBED_ON))

/datum/component/clumsy_climb_component/proc/cross(atom/table, mob/living/climber)
if(!table.contents)
return

if(!istype(climber))
return

var/mob/living/user = climber
if(user.mob_size <= MOB_SIZE_SMALL && !user.throwing)
return

max_thrown_objects = initial(max_thrown_objects)
if(!user.throwing)
max_thrown_objects = max_thrown_objects_low

clumsy_stuff(user)


/datum/component/clumsy_climb_component/proc/clumsy_stuff(mob/living/user)
if(!user)
return

switch(user.mob_size)
if(MOB_SIZE_LARGE)
thrown_chance = 100
if(MOB_SIZE_SMALL)
thrown_chance = 20
if(MOB_SIZE_TINY)
thrown_chance = 10

if(HAS_TRAIT(user, TRAIT_CLUMSY))
thrown_chance += 20
if(user.mind?.miming)
thrown_chance -= 30

thrown_chance = clamp(thrown_chance, 1, 100)

var/list/thrown_atoms = list()

for(var/turf/T in range(0, user)) //Preventing from rotating stuff in an inventory
for(var/atom/movable/I in T)
if(!I.anchored && !isliving(I) && prob(thrown_chance))
thrown_atoms += I
if(thrown_atoms.len >= max_thrown_objects)
break

var/atom/thrown_target
for(var/obj/item/I in thrown_atoms)
I.force *= force_mod
I.throwforce *= force_mod //no killing using shards :lul:
thrown_target = get_edge_target_turf(user, get_dir(user, get_step_away(I, user)))
I.throw_at(target = thrown_target, range = 1, speed = 1)
I.pixel_x = rand(-6, 6)
I.pixel_y = rand(0, 10)
I.force /= force_mod
I.throwforce /= force_mod
61 changes: 7 additions & 54 deletions modular_ss220/clumsy_table/code/clumsy_table.dm
Original file line number Diff line number Diff line change
@@ -1,59 +1,12 @@
/obj/structure/do_climb(mob/living/user)
if(!user)
return ..()

if(..())
clumsy_stuff(user)
#define COMSIG_CLIMBED_ON "climb_on"

/obj/structure/table/Crossed(atom/movable/AM, oldloc)
/obj/structure/table/Initialize(mapload)
. = ..()
AddComponent(/datum/component/clumsy_climb_component, 15)

if(!isliving(AM))
return
var/mob/living/user = AM
if(user.mob_size <= MOB_SIZE_SMALL && !user.throwing)
return

var/max_throws_count = 5
if(user.throwing)
max_throws_count = 15

clumsy_stuff(user, max_throws_count)

/obj/structure/proc/clumsy_stuff(mob/living/user, max_throws_count = 15)
/obj/structure/do_climb(mob/living/user)
if(!user)
return
var/slopchance = 80 //default for all human-sized livings
var/force_mult = 0.1 //коэффицент уменьшения урона при сбрасывании предмета

switch(user.mob_size)
if(MOB_SIZE_LARGE) slopchance = 100
if(MOB_SIZE_SMALL) slopchance = 20
if(MOB_SIZE_TINY) slopchance = 10

if(HAS_TRAIT(user, TRAIT_CLUMSY))
slopchance += 20
if(user.mind?.miming)
slopchance -= 30

slopchance = clamp(slopchance, 1, 100)

var/list/thrownatoms = list()

for(var/turf/T in range(0, src)) //Preventing from rotating stuff in an inventory
for(var/atom/movable/AM in T)
if(!AM.anchored && !isliving(AM) && prob(slopchance))
thrownatoms += AM
if(thrownatoms.len >= max_throws_count)
break
return ..()

var/atom/throwtarget
for(var/obj/item/AM in thrownatoms)
AM.force *= force_mult
AM.throwforce *= force_mult //no killing using shards :lul:
throwtarget = get_edge_target_turf(user, get_dir(src, get_step_away(AM, src)))
AM.throw_at(target = throwtarget, range = 1, speed = 1)
AM.pixel_x = rand(-6, 6)
AM.pixel_y = rand(0, 10)
AM.force /= force_mult
AM.throwforce /= force_mult
if(..())
SEND_SIGNAL(src, COMSIG_CLIMBED_ON, user)
3 changes: 2 additions & 1 deletion modular_ss220/emotes/code/emote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
user.do_jitter_animation(rand(8 SECONDS, 16 SECONDS), dance_time / 4)
var/obj/structure/table/T = locate() in user.loc
if(T)
T.clumsy_stuff(user)
SEND_SIGNAL(T, COMSIG_CLIMBED_ON, user)


/datum/emote/living/choke/get_sound(mob/living/user)
. = ..()
Expand Down

0 comments on commit 514e10d

Please sign in to comment.