From 27a7eeee8ba76f103b72109d46cedcc94df44b30 Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Mon, 22 Feb 2021 09:13:46 +0000 Subject: [PATCH] Stunbaton Refactor (#15313) * Baton refactor V1 * Var name * Stunbatons 1.2 update_icon() and examine() just got moved, no changes to them. --- code/game/objects/items/weapons/stunbaton.dm | 254 +++++++++---------- code/game/objects/items/weapons/teleprod.dm | 19 +- 2 files changed, 128 insertions(+), 145 deletions(-) diff --git a/code/game/objects/items/weapons/stunbaton.dm b/code/game/objects/items/weapons/stunbaton.dm index b1c4419e869..8edba5c577d 100644 --- a/code/game/objects/items/weapons/stunbaton.dm +++ b/code/game/objects/items/weapons/stunbaton.dm @@ -7,66 +7,41 @@ slot_flags = SLOT_BELT force = 10 throwforce = 7 - w_class = WEIGHT_CLASS_NORMAL origin_tech = "combat=2" attack_verb = list("beaten") armor = list("melee" = 0, "bullet" = 0, "laser" = 0, "energy" = 0, "bomb" = 50, "bio" = 0, "rad" = 0, "fire" = 80, "acid" = 80) + /// How many life ticks does the stun last for var/stunforce = 7 - var/status = 0 - var/obj/item/stock_parts/cell/high/cell = null + /// Is the baton currently turned on + var/turned_on = FALSE + /// How much power does it cost to stun someone var/hitcost = 1000 + /// Chance for the baton to stun when thrown at someone var/throw_hit_chance = 35 + var/obj/item/stock_parts/cell/high/cell = null -/obj/item/melee/baton/suicide_act(mob/user) - user.visible_message("[user] is putting the live [name] in [user.p_their()] mouth! It looks like [user.p_theyre()] trying to commit suicide.") - return FIRELOSS - -/obj/item/melee/baton/get_cell() - return cell - -/obj/item/melee/baton/New() - ..() +/obj/item/melee/baton/Initialize(mapload) + . = ..() update_icon() - return + +/obj/item/melee/baton/loaded/Initialize(mapload) //this one starts with a cell pre-installed. + if(isrobot(loc.loc)) // First loc would be the module + var/mob/living/silicon/robot/R = loc.loc + cell = R.cell + else + cell = new(src) + return ..() /obj/item/melee/baton/Destroy() QDEL_NULL(cell) return ..() -/obj/item/melee/baton/throw_impact(atom/hit_atom) - ..() - if(status && prob(throw_hit_chance)) - baton_stun(hit_atom) - -/obj/item/melee/baton/loaded/New() //this one starts with a cell pre-installed. - ..() - cell = new(src) - update_icon() - return - -/obj/item/melee/baton/proc/deductcharge(var/chrgdeductamt) - if(isrobot(loc)) - var/mob/living/silicon/robot/R = loc - if(R.cell && R.cell.charge < (hitcost+chrgdeductamt)) - status = 0 - update_icon() - playsound(loc, "sparks", 75, 1, -1) - if(R.cell.use(chrgdeductamt)) - return 1 - else - return 0 - if(cell) - if(cell.charge < (hitcost+chrgdeductamt)) // If after the deduction the baton doesn't have enough charge for a stun hit it turns off. - status = 0 - update_icon() - playsound(loc, "sparks", 75, 1, -1) - if(cell.use(chrgdeductamt)) - return 1 - else - return 0 +/obj/item/melee/baton/suicide_act(mob/user) + user.visible_message("[user] is putting the live [name] in [user.p_their()] mouth! It looks like [user.p_theyre()] trying to commit suicide.") + return FIRELOSS /obj/item/melee/baton/update_icon() - if(status) + if(turned_on) icon_state = "[base_icon]_active" else if(!cell) icon_state = "[base_icon]_nocell" @@ -75,110 +50,123 @@ /obj/item/melee/baton/examine(mob/user) . = ..() - if(isrobot(loc)) + if(isrobot(user)) . += "This baton is drawing power directly from your own internal charge." if(cell) . += "The baton is [round(cell.percent())]% charged." - if(!cell) + else . += "The baton does not have a power source installed." -/obj/item/melee/baton/attackby(obj/item/W, mob/user, params) - if(istype(W, /obj/item/stock_parts/cell)) - var/obj/item/stock_parts/cell/C = W - if(cell) - to_chat(user, "[src] already has a cell.") - else - if(C.maxcharge < hitcost) - to_chat(user, "[src] requires a higher capacity cell.") - return - if(!user.unEquip(W)) - return - W.loc = src - cell = W - to_chat(user, "You install a cell in [src].") - update_icon() +/obj/item/melee/baton/get_cell() + return cell - else if(istype(W, /obj/item/screwdriver)) +/obj/item/melee/baton/throw_impact(atom/hit_atom) + ..() + if(prob(throw_hit_chance) && turned_on && isliving(hit_atom)) + baton_stun(hit_atom) + +/** + * Removes the specified amount of charge from the batons power cell. + * + * If `src` is a cyborg baton, this removes the charge from the borg's internal power cell instead. + * Arguments: + * * amount - The amount of battery charge to be used. + */ +/obj/item/melee/baton/proc/deductcharge(amount) + if(!cell) + return + cell.use(amount) + if(cell.charge < (hitcost)) // If after the deduction the baton doesn't have enough charge for a stun hit it turns off. + turned_on = FALSE + update_icon() + playsound(src, "sparks", 75, TRUE, -1) + +/obj/item/melee/baton/attackby(obj/item/I, mob/user, params) + if(istype(I, /obj/item/stock_parts/cell)) + var/obj/item/stock_parts/cell/C = I if(cell) - cell.update_icon() - cell.loc = get_turf(src.loc) - cell = null - to_chat(user, "You remove the cell from the [src].") - status = 0 - update_icon() + to_chat(user, "[src] already has a cell!") return - ..() - return + if(C.maxcharge < hitcost) + to_chat(user, "[src] requires a higher capacity cell!") + return + if(!user.unEquip(I)) + return + I.forceMove(src) + cell = I + to_chat(user, "You install [I] into [src].") + update_icon() + +/obj/item/melee/baton/screwdriver_act(mob/living/user, obj/item/I) + if(!cell) + to_chat(user, "There's no cell installed!") + return + if(!I.use_tool(src, user, volume = I.tool_volume)) + return + + user.put_in_hands(cell) + to_chat(user, "You remove [cell] from [src].") + cell.update_icon() + cell = null + turned_on = FALSE + update_icon() /obj/item/melee/baton/attack_self(mob/user) - - if(isrobot(loc)) - var/mob/living/silicon/robot/R = loc - if(R && R.cell && R.cell.charge >= (hitcost)) - status = !status - to_chat(user, "[src] is now [status ? "on" : "off"].") - playsound(loc, "sparks", 75, 1, -1) - else - status = 0 - to_chat(user, "You do not have enough reserve power to charge the [src]!") - else if(cell && cell.charge >= hitcost) - status = !status - to_chat(user, "[src] is now [status ? "on" : "off"].") - playsound(loc, "sparks", 75, 1, -1) + if(cell?.charge >= hitcost) + turned_on = !turned_on + to_chat(user, "[src] is now [turned_on ? "on" : "off"].") + playsound(src, "sparks", 75, TRUE, -1) else - status = 0 - if(!cell) + if(isrobot(loc)) + to_chat(user, "You do not have enough reserve power to charge [src]!") + else if(!cell) to_chat(user, "[src] does not have a power source!") else to_chat(user, "[src] is out of charge.") update_icon() add_fingerprint(user) + /obj/item/melee/baton/attack(mob/M, mob/living/user) - if(status && HAS_TRAIT(user, TRAIT_CLUMSY) && prob(50)) - user.visible_message("[user] accidentally hits [user.p_them()]self with [src]!", \ + if(turned_on && HAS_TRAIT(user, TRAIT_CLUMSY) && prob(50)) + user.visible_message("[user] accidentally hits [user.p_them()]self with [src]!", "You accidentally hit yourself with [src]!") - user.Weaken(stunforce*3) + user.Weaken(stunforce * 3) deductcharge(hitcost) return - if(isrobot(M)) - ..() + if(isrobot(M)) // Can't stunbaton borgs + return ..() + + if(!isliving(M)) return + var/mob/living/L = M if(ishuman(M)) var/mob/living/carbon/human/H = M if(check_martial_counter(H, user)) return - if(!isliving(M)) + if(user.a_intent == INTENT_HARM) + if(turned_on) + baton_stun(L, user) + return ..() // Whack them too if in harm intent + + if(!turned_on) + L.visible_message("[user] has prodded [L] with [src]. Luckily it was off.", + "[L == user ? "You prod yourself" : "[user] has prodded you"] with [src]. Luckily it was off.") return - var/mob/living/L = M - - if(user.a_intent != INTENT_HARM) - if(status) - user.do_attack_animation(L) - baton_stun(L, user) - else - L.visible_message("[user] has prodded [L] with [src]. Luckily it was off.", \ - "[user] has prodded you with [src]. Luckily it was off") - return - else - if(status) - baton_stun(L, user) - ..() - + baton_stun(L, user) + user.do_attack_animation(L) /obj/item/melee/baton/proc/baton_stun(mob/living/L, mob/user) - if(!ismob(L)) //because this was being called on turfs for some reason - return - if(ishuman(L)) var/mob/living/carbon/human/H = L if(H.check_shields(src, 0, "[user]'s [name]", MELEE_ATTACK)) //No message; check_shields() handles that - playsound(L, 'sound/weapons/genhit.ogg', 50, 1) + playsound(L, 'sound/weapons/genhit.ogg', 50, TRUE) return + H.forcesay(GLOB.hit_appends) if(iscarbon(L)) var/mob/living/carbon/C = L @@ -186,39 +174,34 @@ L.Stun(stunforce) L.Weaken(stunforce) - L.SetStuttering(stunforce) + L.Stuttering(stunforce) if(user) L.lastattacker = user.real_name L.lastattackerckey = user.ckey - L.visible_message("[user] has stunned [L] with [src]!", \ - "[user] has stunned you with [src]!") + L.visible_message("[user] has stunned [L] with [src]!", + "[L == user ? "You stun yourself" : "[user] has stunned you"] with [src]!") add_attack_logs(user, L, "stunned") - playsound(loc, 'sound/weapons/egloves.ogg', 50, 1, -1) - + playsound(src, 'sound/weapons/egloves.ogg', 50, TRUE, -1) deductcharge(hitcost) - if(ishuman(L)) - var/mob/living/carbon/human/H = L - H.forcesay(GLOB.hit_appends) /obj/item/melee/baton/emp_act(severity) + . = ..() if(cell) deductcharge(1000 / severity) - ..() /obj/item/melee/baton/wash(mob/user, atom/source) - if(cell) - if(cell.charge > 0 && status == 1) - flick("baton_active", source) - user.Stun(stunforce) - user.Weaken(stunforce) - user.stuttering = stunforce - deductcharge(hitcost) - user.visible_message("[user] shocks [user.p_them()]self while attempting to wash the active [src]!", \ - "You unwisely attempt to wash [src] while it's still on.") - playsound(src, "sparks", 50, 1) - return 1 + if(turned_on && cell?.charge) + flick("baton_active", source) + user.Stun(stunforce) + user.Weaken(stunforce) + user.SetStuttering(stunforce) + deductcharge(hitcost) + user.visible_message("[user] shocks [user.p_them()]self while attempting to wash the active [src]!", + "You unwisely attempt to wash [src] while it's still on.") + playsound(src, "sparks", 50, TRUE) + return TRUE ..() //Makeshift stun baton. Replacement for stun gloves. @@ -228,7 +211,6 @@ icon_state = "stunprod_nocell" base_icon = "stunprod" item_state = "prod" - w_class = WEIGHT_CLASS_NORMAL force = 3 throwforce = 5 stunforce = 5 @@ -237,8 +219,8 @@ slot_flags = SLOT_BACK var/obj/item/assembly/igniter/sparkler = null -/obj/item/melee/baton/cattleprod/New() - ..() +/obj/item/melee/baton/cattleprod/Initialize(mapload) + . = ..() sparkler = new(src) /obj/item/melee/baton/cattleprod/Destroy() @@ -247,4 +229,4 @@ /obj/item/melee/baton/cattleprod/baton_stun() if(sparkler.activate()) - ..() + return ..() diff --git a/code/game/objects/items/weapons/teleprod.dm b/code/game/objects/items/weapons/teleprod.dm index 023d55609fa..b15d843c98c 100644 --- a/code/game/objects/items/weapons/teleprod.dm +++ b/code/game/objects/items/weapons/teleprod.dm @@ -8,12 +8,13 @@ /obj/item/melee/baton/cattleprod/teleprod/attack(mob/living/carbon/M, mob/living/carbon/user)//handles making things teleport when hit ..() - if(status) - if(HAS_TRAIT(user, TRAIT_CLUMSY) && prob(50)) - user.visible_message("[user] accidentally hits [user.p_them()]self with [src]!", \ - "You accidentally hit yourself with [src]!") - user.Weaken(stunforce*3) - deductcharge(hitcost) - do_teleport(user, get_turf(user), 50)//honk honk - else if(iscarbon(M) && !M.anchored) - do_teleport(M, get_turf(M), 15) + if(!turned_on) + return + if(HAS_TRAIT(user, TRAIT_CLUMSY) && prob(50)) + user.visible_message("[user] accidentally hits [user.p_them()]self with [src]!", + "You accidentally hit yourself with [src]!") + user.Weaken(stunforce * 3) + deductcharge(hitcost) + do_teleport(user, get_turf(user), 50)//honk honk + else if(iscarbon(M) && !M.anchored) + do_teleport(M, get_turf(M), 15)