diff --git a/monkestation/code/modules/datums/brain_damage/mild.dm b/monkestation/code/modules/datums/brain_damage/mild.dm index a0d10cda3a9b..a57c380ca48e 100644 --- a/monkestation/code/modules/datums/brain_damage/mild.dm +++ b/monkestation/code/modules/datums/brain_damage/mild.dm @@ -4,43 +4,91 @@ scan_desc = "kleptomania" gain_text = "You feel a strong urge to grab things." lose_text = "You no longer feel the urge to grab things." + // The percent chance for kleptomania to actually activate every tick + var/kleptomania_chance = 2.5 + // The percent chance to pickpocket from someone, instead of from the ground. + var/pickpocket_chance = 25 -/datum/brain_trauma/mild/kleptomania/on_gain() - owner.apply_status_effect(/datum/status_effect/kleptomania) - ..() +/datum/brain_trauma/mild/kleptomania/on_life(seconds_per_tick, times_fired) + if(owner.incapacitated()) + return + if(!SPT_PROB(kleptomania_chance, seconds_per_tick)) + return + if(!owner.has_active_hand()) + return + if(owner.get_active_held_item()) + return -/datum/brain_trauma/mild/kleptomania/on_lose() - owner.remove_status_effect(/datum/status_effect/kleptomania) - ..() + if(prob(pickpocket_chance)) + steal_from_someone() + else + steal_from_ground() -/datum/status_effect/kleptomania - id = "kleptomania" - status_type = STATUS_EFFECT_UNIQUE - alert_type = null - var/kleptomania_chance = 2.5 +/datum/brain_trauma/mild/kleptomania/proc/steal_from_someone() + var/list/potential_victims = list() + for(var/mob/living/carbon/human/potential_victim in view(1, owner)) + if(potential_victim == owner) + continue + potential_victims += potential_victim + + if(!length(potential_victims)) + return + + var/mob/living/carbon/human/victim = pick(potential_victims) + + var/list/items_in_pockets = victim.get_pockets() + if(!length(items_in_pockets)) + return + + var/obj/item/item_to_steal = pick(items_in_pockets) + owner.visible_message( + span_warning("[owner] attempts to remove [item_to_steal] from [victim]'s pocket!"), + span_warning("You attempt to remove [item_to_steal] from [victim]'s pocket."), + span_warning("You hear someone rummaging through pockets.") + ) + + if(!do_after(owner, item_to_steal.strip_delay, victim) || !victim.temporarilyRemoveItemFromInventory(item_to_steal)) + owner.visible_message( + span_warning("[owner] fails to pickpocket [victim]."), + span_warning("You fail to pick [victim]'s pocket."), + null + ) + return + + owner.visible_message( + span_warning("[owner] removes [item_to_steal] from [victim]'s pocket!"), + span_warning("You remove [item_to_steal] from [victim]'s pocket."), + null + ) + + owner.log_message("picked [victim.name]'s pockets (kleptomania)", LOG_ATTACK, color = "orange") + + if(QDELETED(item_to_steal)) + return + if(!owner.putItemFromInventoryInHandIfPossible(item_to_steal, owner.active_hand_index, TRUE)) + item_to_steal.forceMove(owner.drop_location()) + +/datum/brain_trauma/mild/kleptomania/proc/steal_from_ground() + // Get a list of anything that's not nailed down or already worn by the brain trauma's owner. + var/list/stealables = list() + var/list/currently_worn_gear = owner.get_all_gear() + for(var/obj/item/potential_stealable in oview(1, owner)) + if(potential_stealable.anchored) + continue + if(potential_stealable in currently_worn_gear) + continue + if(!potential_stealable.Adjacent(owner)) + continue + stealables += potential_stealable + + // Shuffle the list of stealables, then loop through it until we find an item to grab. + for(var/obj/item/stealable as anything in shuffle(stealables)) + if(!owner.CanReach(stealable, view_only = TRUE)) + continue -/datum/status_effect/kleptomania/tick() - if(prob(kleptomania_chance) && owner.m_intent == MOVE_INTENT_RUN && !owner.get_active_held_item() && !(owner.incapacitated()) && owner.has_active_hand()) - if(prob(25)) //we pick pockets - for(var/mob/living/carbon/human/victim in view(1, owner)) - var/pockets = victim.get_pockets() - if(victim != owner && length(pockets)) - var/obj/item/I = pick(pockets) - owner.visible_message("[owner] attempts to remove [I] from [victim]'s pocket!","You attempt to remove [I] from [victim]'s pocket.", FALSE, 1) - if(do_after(owner, I.strip_delay, victim) && victim.temporarilyRemoveItemFromInventory(I)) - owner.visible_message("[owner] removes [I] from [victim]'s pocket!","You remove [I] from [victim]'s pocket.", FALSE, 1) - log_admin("[key_name(usr)] picked [victim.name]'s pockets with Kleptomania trait.") - if(!QDELETED(I) && !owner.putItemFromInventoryInHandIfPossible(I, owner.active_hand_index, TRUE, TRUE)) - I.forceMove(owner.drop_location()) - break - else - owner.visible_message("[owner] fails to pickpocket [victim].","You fail to pick [victim]'s pocket.", FALSE, 1) - else //we pick stuff off the ground - var/mob/living/carbon/C = owner - for(var/obj/item/I in oview(1, C)) - if(!I.anchored && !(I in C.get_all_gear()) && I.Adjacent(C)) //anything that's not nailed down or worn - I.attack_hand(C) - break + owner.log_message("attempted to pick up (kleptomania)", LOG_ATTACK, color = "orange") + stealable.attack_hand(owner) + break /mob/living/carbon/human/proc/get_pockets() var/list/pockets = list()