|
10 | 10 | var/datum/movement_detector/parent_tracker
|
11 | 11 | var/datum/beam/beam
|
12 | 12 | var/atom/movable/tether_visual_target
|
| 13 | + var/tether_name |
| 14 | + var/last_movement = 0 |
13 | 15 |
|
14 |
| -/datum/component/tether/Initialize(tethered_atom_movable, range = 2, durability = INFINITY, tether_icon_state = "tether") |
| 16 | +/datum/component/tether/Initialize(tethered_atom_movable, range = 2, durability = INFINITY, tether_icon_state = "tether", tether_name = "tether") |
15 | 17 | . = ..()
|
16 | 18 | if(!isatom(parent) || !ismovable(tethered_atom_movable))
|
17 | 19 | return COMPONENT_INCOMPATIBLE
|
|
20 | 22 | src.max_range = range
|
21 | 23 | src.durability = durability // movement is bugged right now. Durability wears out 3 times faster than expected. 1 durability should last 1 tile.
|
22 | 24 | src.tether_icon_state = tether_icon_state
|
| 25 | + src.tether_name = tether_name |
23 | 26 |
|
24 | 27 | RegisterSignal(parent, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(on_movement))
|
25 | 28 | RegisterSignal(tethered_atom_movable, COMSIG_MOVABLE_PRE_MOVE, PROC_REF(pre_tethered_movement))
|
26 |
| - RegisterSignal(tethered_atom_movable, COMSIG_ITEM_EQUIPPED, PROC_REF(equipped)) |
| 29 | + RegisterSignal(tethered_atom_movable, COMSIG_ATOM_ATTACK_HAND, PROC_REF(can_equip)) |
27 | 30 | parent_tracker = new /datum/movement_detector(parent, CALLBACK(src, PROC_REF(parent_check_bounds)))
|
28 | 31 | tether_tracker = new /datum/movement_detector(tethered_atom_movable, CALLBACK(src, PROC_REF(check_bounds)))
|
29 | 32 | parent_tracker.fix_signal()
|
|
61 | 64 | // check if the item is in range. If not, try to move it towards the parent.
|
62 | 65 | if(get_dist(get_turf(tethered_to), newloc) <= max_range)
|
63 | 66 | return
|
| 67 | + if(source.pulledby == tethered_to.loc) |
| 68 | + return |
64 | 69 | if(tether_move_towards_parent(newloc))
|
65 | 70 | return
|
66 | 71 | if(get_dir(parent, newloc) & get_dir(parent, tethered_to))
|
|
82 | 87 | to_chat(atom, "<span class='warning'>You can't move in that direction with the [tethered_to] tethered to you!</span>")
|
83 | 88 | return COMPONENT_MOVABLE_BLOCK_PRE_MOVE
|
84 | 89 |
|
85 |
| -// /datum/component/tether/proc/equipped(atom/movable/source, mob/user, slot) |
86 |
| -// // Check to make sure we dont go into an inventory outside of our range |
87 |
| -// if(get_dist(get_turf(parent), get_turf(user)) <= max_range) |
88 |
| -// return |
89 |
| -// addtimer(CALLBACK(src, PROC_REF(tether_move_towards_parent)), 1) // let the tick finish first before dropping it |
| 90 | +/datum/component/tether/proc/can_equip(atom/source, mob/user) |
| 91 | + // Check to make sure we dont go into an inventory outside of our range |
| 92 | + if(get_dist(get_turf(parent), get_turf(user)) > max_range) |
| 93 | + to_chat(user, "<span class='warning'>You try to pick up [tethered_to], you can't pull it's [tether_name] any farther!</span>") |
| 94 | + return COMPONENT_CANCEL_ATTACK_CHAIN |
90 | 95 |
|
91 | 96 | /datum/component/tether/proc/parent_check_bounds(atom/movable/source, atom/mover, atom/old_loc, direction)
|
92 | 97 | // check to see if the parent has moved out of range (while inside another objects contents). If it has, pull the tether towards the parent.
|
93 | 98 | if(get_dist(get_turf(parent), get_turf(tethered_to)) <= max_range)
|
94 | 99 | return
|
| 100 | + if(source.pulledby == tethered_to.loc) |
| 101 | + return |
95 | 102 | tether_move_towards_parent()
|
96 | 103 |
|
97 | 104 | /datum/component/tether/proc/check_bounds(atom/movable/source, atom/mover, atom/old_loc, direction)
|
|
100 | 107 | make_beam(mover)
|
101 | 108 | if(get_dist(get_turf(parent), get_turf(tethered_to)) <= max_range)
|
102 | 109 | return
|
| 110 | + if(ismovable(mover)) |
| 111 | + var/atom/movable/a_mover = mover |
| 112 | + if(a_mover.pulledby == parent || a_mover.pulling == parent) |
| 113 | + return |
103 | 114 | tether_move_towards_parent()
|
104 | 115 |
|
105 | 116 | /datum/component/tether/proc/tether_move_towards_parent(parent_newloc)
|
106 |
| - if(QDELETED(tethered_to) || !istype(tethered_to)) |
107 |
| - return TRUE |
108 |
| - durability_cost() |
109 |
| - if(QDELETED(tethered_to) || !istype(tethered_to)) |
| 117 | + if(QDELETED(tethered_to) || !istype(tethered_to) || last_movement == world.time) |
110 | 118 | return TRUE
|
111 | 119 | var/atom/current_loc = tethered_to.loc
|
112 | 120 | var/i = 0
|
|
118 | 126 | M.drop_item_to_ground(tethered_to)
|
119 | 127 | current_loc = tethered_to.loc
|
120 | 128 | break
|
121 |
| - else if(istype(current_loc, /obj/item/storage)) |
| 129 | + if(istype(current_loc, /obj/item/storage)) |
122 | 130 | var/obj/item/storage/S = current_loc
|
123 | 131 | S.remove_from_storage(tethered_to, get_turf(tethered_to))
|
124 | 132 | current_loc = tethered_to.loc
|
125 | 133 | break
|
126 |
| - else if(istype(current_loc, /obj/structure/closet)) |
| 134 | + if(istype(current_loc, /obj/structure/closet)) |
127 | 135 | var/obj/structure/closet/C = current_loc
|
128 |
| - if(!C.can_open()) |
129 |
| - return |
130 |
| - C.open() |
131 |
| - current_loc = tethered_to.loc |
132 |
| - break |
133 |
| - else if(ismovable(current_loc)) |
| 136 | + if(C.can_open()) |
| 137 | + C.open() |
| 138 | + current_loc = tethered_to.loc |
| 139 | + break |
| 140 | + if(ismovable(current_loc)) |
134 | 141 | var/atom/movable/AM = current_loc
|
135 | 142 | if(AM.anchored)
|
136 | 143 | return FALSE
|
137 | 144 | if(isturf(AM.loc))
|
| 145 | + last_movement = world.time |
| 146 | + durability_cost() |
138 | 147 | step_towards(AM, get_turf(parent)) // holy shitcode
|
139 | 148 | return get_dist(get_turf(parent_newloc || parent), get_turf(tethered_to)) <= max_range
|
140 | 149 | current_loc = current_loc.loc
|
141 | 150 | if(get_dist(get_turf(parent), get_turf(tethered_to)) <= max_range)
|
142 | 151 | return TRUE
|
| 152 | + last_movement = world.time |
| 153 | + durability_cost() |
143 | 154 | if(!step_towards(tethered_to, get_turf(parent))) // shitcode
|
144 | 155 | return durability_cost(2) // use 3 total durability
|
145 | 156 | return TRUE
|
|
154 | 165 | return
|
155 | 166 | durability -= cost
|
156 | 167 | if(durability <= 0 && !QDELETED(tethered_to))
|
157 |
| - tethered_to.visible_message("<span class='warning'>[tethered_to]'s tether wears out and snaps!</span>") |
| 168 | + tethered_to.visible_message("<span class='warning'>[tethered_to]'s [tether_name] wears out and snaps back!</span>") |
158 | 169 | terminate()
|
159 | 170 | return TRUE // it breaks, let the parent move outside of the range again
|
160 | 171 | return FALSE
|
0 commit comments