mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-08 07:52:54 +00:00
The component is initialized with any combination of three flags, EMP_PROTECT_SELF protects against effects that target the object itself, EMP_PROTECT_WIRES protects against wires being messed with similar to the NO_EMP_WIRES_1 flag which this PR removes, EMP_PROTECT_CONTENTS protects against things that are inside the object like organs, internal "non-virtual" power cells and the like This enables (but doesn't introduce) new mechanics such as adding EMP shielding at runtime to any atom, or taking it away.
184 lines
4.6 KiB
Plaintext
184 lines
4.6 KiB
Plaintext
/obj/item/inducer
|
|
name = "inducer"
|
|
desc = "A tool for inductively charging internal power cells."
|
|
icon = 'icons/obj/tools.dmi'
|
|
icon_state = "inducer-engi"
|
|
item_state = "inducer-engi"
|
|
lefthand_file = 'icons/mob/inhands/equipment/tools_lefthand.dmi'
|
|
righthand_file = 'icons/mob/inhands/equipment/tools_righthand.dmi'
|
|
force = 7
|
|
var/powertransfer = 1000
|
|
var/opened = FALSE
|
|
var/cell_type = /obj/item/stock_parts/cell/high
|
|
var/obj/item/stock_parts/cell/cell
|
|
var/recharging = FALSE
|
|
|
|
/obj/item/inducer/Initialize()
|
|
. = ..()
|
|
if(!cell && cell_type)
|
|
cell = new cell_type
|
|
|
|
/obj/item/inducer/proc/induce(obj/item/stock_parts/cell/target, coefficient)
|
|
var/totransfer = min(cell.charge,(powertransfer * coefficient))
|
|
var/transferred = target.give(totransfer)
|
|
cell.use(transferred)
|
|
cell.update_icon()
|
|
target.update_icon()
|
|
|
|
/obj/item/inducer/get_cell()
|
|
return cell
|
|
|
|
/obj/item/inducer/emp_act(severity)
|
|
. = ..()
|
|
if(cell && !(. & EMP_PROTECT_CONTENTS))
|
|
cell.emp_act(severity)
|
|
|
|
/obj/item/inducer/attack_obj(obj/O, mob/living/carbon/user)
|
|
if(user.a_intent == INTENT_HARM)
|
|
return ..()
|
|
|
|
if(cantbeused(user))
|
|
return
|
|
|
|
if(recharge(O, user))
|
|
return
|
|
|
|
return ..()
|
|
|
|
/obj/item/inducer/proc/cantbeused(mob/user)
|
|
if(!user.IsAdvancedToolUser())
|
|
to_chat(user, "<span class='warning'>You don't have the dexterity to use [src]!</span>")
|
|
return TRUE
|
|
|
|
if(!cell)
|
|
to_chat(user, "<span class='warning'>[src] doesn't have a power cell installed!</span>")
|
|
return TRUE
|
|
|
|
if(!cell.charge)
|
|
to_chat(user, "<span class='warning'>[src]'s battery is dead!</span>")
|
|
return TRUE
|
|
return FALSE
|
|
|
|
|
|
/obj/item/inducer/attackby(obj/item/W, mob/user)
|
|
if(istype(W, /obj/item/screwdriver))
|
|
W.play_tool_sound(src)
|
|
if(!opened)
|
|
to_chat(user, "<span class='notice'>You unscrew the battery compartment.</span>")
|
|
opened = TRUE
|
|
update_icon()
|
|
return
|
|
else
|
|
to_chat(user, "<span class='notice'>You close the battery compartment.</span>")
|
|
opened = FALSE
|
|
update_icon()
|
|
return
|
|
if(istype(W, /obj/item/stock_parts/cell))
|
|
if(opened)
|
|
if(!cell)
|
|
if(!user.transferItemToLoc(W, src))
|
|
return
|
|
to_chat(user, "<span class='notice'>You insert [W] into [src].</span>")
|
|
cell = W
|
|
update_icon()
|
|
return
|
|
else
|
|
to_chat(user, "<span class='notice'>[src] already has \a [cell] installed!</span>")
|
|
return
|
|
|
|
if(cantbeused(user))
|
|
return
|
|
|
|
if(recharge(W, user))
|
|
return
|
|
|
|
return ..()
|
|
|
|
/obj/item/inducer/proc/recharge(atom/movable/A, mob/user)
|
|
if(!isturf(A) && user.loc == A)
|
|
return FALSE
|
|
if(recharging)
|
|
return TRUE
|
|
else
|
|
recharging = TRUE
|
|
var/obj/item/stock_parts/cell/C = A.get_cell()
|
|
var/obj/O
|
|
var/coefficient = 1
|
|
if(istype(A, /obj/item/gun/energy))
|
|
to_chat(user,"Error unable to interface with device")
|
|
return FALSE
|
|
if(istype(A, /obj))
|
|
O = A
|
|
if(C)
|
|
var/done_any = FALSE
|
|
if(C.charge >= C.maxcharge)
|
|
to_chat(user, "<span class='notice'>[A] is fully charged!</span>")
|
|
recharging = FALSE
|
|
return TRUE
|
|
user.visible_message("[user] starts recharging [A] with [src].","<span class='notice'>You start recharging [A] with [src].</span>")
|
|
while(C.charge < C.maxcharge)
|
|
if(do_after(user, 10, target = user) && cell.charge)
|
|
done_any = TRUE
|
|
induce(C, coefficient)
|
|
do_sparks(1, FALSE, A)
|
|
if(O)
|
|
O.update_icon()
|
|
else
|
|
break
|
|
if(done_any) // Only show a message if we succeeded at least once
|
|
user.visible_message("[user] recharged [A]!","<span class='notice'>You recharged [A]!</span>")
|
|
recharging = FALSE
|
|
return TRUE
|
|
recharging = FALSE
|
|
|
|
|
|
/obj/item/inducer/attack(mob/M, mob/user)
|
|
if(user.a_intent == INTENT_HARM)
|
|
return ..()
|
|
|
|
if(cantbeused(user))
|
|
return
|
|
|
|
if(recharge(M, user))
|
|
return
|
|
return ..()
|
|
|
|
|
|
/obj/item/inducer/attack_self(mob/user)
|
|
if(opened && cell)
|
|
user.visible_message("[user] removes [cell] from [src]!","<span class='notice'>You remove [cell].</span>")
|
|
cell.update_icon()
|
|
user.put_in_hands(cell)
|
|
cell = null
|
|
update_icon()
|
|
|
|
|
|
/obj/item/inducer/examine(mob/living/M)
|
|
..()
|
|
if(cell)
|
|
to_chat(M, "<span class='notice'>Its display shows: [DisplayEnergy(cell.charge)].</span>")
|
|
else
|
|
to_chat(M,"<span class='notice'>Its display is dark.</span>")
|
|
if(opened)
|
|
to_chat(M,"<span class='notice'>Its battery compartment is open.</span>")
|
|
|
|
/obj/item/inducer/update_icon()
|
|
cut_overlays()
|
|
if(opened)
|
|
if(!cell)
|
|
add_overlay("inducer-nobat")
|
|
else
|
|
add_overlay("inducer-bat")
|
|
|
|
/obj/item/inducer/sci
|
|
icon_state = "inducer-sci"
|
|
item_state = "inducer-sci"
|
|
desc = "A tool for inductively charging internal power cells. This one has a science color scheme, and is less potent than its engineering counterpart."
|
|
cell_type = null
|
|
powertransfer = 500
|
|
opened = TRUE
|
|
|
|
/obj/item/inducer/sci/Initialize()
|
|
. = ..()
|
|
update_icon()
|