|
4 | 4 | scan_desc = "kleptomania"
|
5 | 5 | gain_text = "<span class='warning'>You feel a strong urge to grab things.</span>"
|
6 | 6 | lose_text = "<span class='notice'>You no longer feel the urge to grab things.</span>"
|
| 7 | + // The percent chance for kleptomania to actually activate every tick |
| 8 | + var/kleptomania_chance = 2.5 |
| 9 | + // The percent chance to pickpocket from someone, instead of from the ground. |
| 10 | + var/pickpocket_chance = 25 |
7 | 11 |
|
8 |
| -/datum/brain_trauma/mild/kleptomania/on_gain() |
9 |
| - owner.apply_status_effect(/datum/status_effect/kleptomania) |
10 |
| - ..() |
| 12 | +/datum/brain_trauma/mild/kleptomania/on_life(seconds_per_tick, times_fired) |
| 13 | + if(owner.incapacitated()) |
| 14 | + return |
| 15 | + if(!SPT_PROB(kleptomania_chance, seconds_per_tick)) |
| 16 | + return |
| 17 | + if(!owner.has_active_hand()) |
| 18 | + return |
| 19 | + if(owner.get_active_held_item()) |
| 20 | + return |
11 | 21 |
|
12 |
| -/datum/brain_trauma/mild/kleptomania/on_lose() |
13 |
| - owner.remove_status_effect(/datum/status_effect/kleptomania) |
14 |
| - ..() |
| 22 | + if(prob(pickpocket_chance)) |
| 23 | + steal_from_someone() |
| 24 | + else |
| 25 | + steal_from_ground() |
15 | 26 |
|
16 |
| -/datum/status_effect/kleptomania |
17 |
| - id = "kleptomania" |
18 |
| - status_type = STATUS_EFFECT_UNIQUE |
19 |
| - alert_type = null |
20 |
| - var/kleptomania_chance = 2.5 |
| 27 | +/datum/brain_trauma/mild/kleptomania/proc/steal_from_someone() |
| 28 | + var/list/potential_victims = list() |
| 29 | + for(var/mob/living/carbon/human/potential_victim in view(1, owner)) |
| 30 | + if(potential_victim == owner) |
| 31 | + continue |
| 32 | + potential_victims += potential_victim |
| 33 | + |
| 34 | + if(!length(potential_victims)) |
| 35 | + return |
| 36 | + |
| 37 | + var/mob/living/carbon/human/victim = pick(potential_victims) |
| 38 | + |
| 39 | + var/list/items_in_pockets = victim.get_pockets() |
| 40 | + if(!length(items_in_pockets)) |
| 41 | + return |
| 42 | + |
| 43 | + var/obj/item/item_to_steal = pick(items_in_pockets) |
| 44 | + owner.visible_message( |
| 45 | + span_warning("[owner] attempts to remove [item_to_steal] from [victim]'s pocket!"), |
| 46 | + span_warning("You attempt to remove [item_to_steal] from [victim]'s pocket."), |
| 47 | + span_warning("You hear someone rummaging through pockets.") |
| 48 | + ) |
| 49 | + |
| 50 | + if(!do_after(owner, item_to_steal.strip_delay, victim) || !victim.temporarilyRemoveItemFromInventory(item_to_steal)) |
| 51 | + owner.visible_message( |
| 52 | + span_warning("[owner] fails to pickpocket [victim]."), |
| 53 | + span_warning("You fail to pick [victim]'s pocket."), |
| 54 | + null |
| 55 | + ) |
| 56 | + return |
| 57 | + |
| 58 | + owner.visible_message( |
| 59 | + span_warning("[owner] removes [item_to_steal] from [victim]'s pocket!"), |
| 60 | + span_warning("You remove [item_to_steal] from [victim]'s pocket."), |
| 61 | + null |
| 62 | + ) |
| 63 | + |
| 64 | + owner.log_message("picked [victim.name]'s pockets (kleptomania)", LOG_ATTACK, color = "orange") |
| 65 | + |
| 66 | + if(QDELETED(item_to_steal)) |
| 67 | + return |
| 68 | + if(!owner.putItemFromInventoryInHandIfPossible(item_to_steal, owner.active_hand_index, TRUE)) |
| 69 | + item_to_steal.forceMove(owner.drop_location()) |
| 70 | + |
| 71 | +/datum/brain_trauma/mild/kleptomania/proc/steal_from_ground() |
| 72 | + // Get a list of anything that's not nailed down or already worn by the brain trauma's owner. |
| 73 | + var/list/stealables = list() |
| 74 | + var/list/currently_worn_gear = owner.get_all_gear() |
| 75 | + for(var/obj/item/potential_stealable in oview(1, owner)) |
| 76 | + if(potential_stealable.anchored) |
| 77 | + continue |
| 78 | + if(potential_stealable in currently_worn_gear) |
| 79 | + continue |
| 80 | + if(!potential_stealable.Adjacent(owner)) |
| 81 | + continue |
| 82 | + stealables += potential_stealable |
| 83 | + |
| 84 | + // Shuffle the list of stealables, then loop through it until we find an item to grab. |
| 85 | + for(var/obj/item/stealable as anything in shuffle(stealables)) |
| 86 | + if(!owner.CanReach(stealable, view_only = TRUE)) |
| 87 | + continue |
21 | 88 |
|
22 |
| -/datum/status_effect/kleptomania/tick() |
23 |
| - if(prob(kleptomania_chance) && owner.m_intent == MOVE_INTENT_RUN && !owner.get_active_held_item() && !(owner.incapacitated()) && owner.has_active_hand()) |
24 |
| - if(prob(25)) //we pick pockets |
25 |
| - for(var/mob/living/carbon/human/victim in view(1, owner)) |
26 |
| - var/pockets = victim.get_pockets() |
27 |
| - if(victim != owner && length(pockets)) |
28 |
| - var/obj/item/I = pick(pockets) |
29 |
| - owner.visible_message("<span class='warning'>[owner] attempts to remove [I] from [victim]'s pocket!</span>","<span class='warning'>You attempt to remove [I] from [victim]'s pocket.</span>", FALSE, 1) |
30 |
| - if(do_after(owner, I.strip_delay, victim) && victim.temporarilyRemoveItemFromInventory(I)) |
31 |
| - owner.visible_message("<span class='warning'>[owner] removes [I] from [victim]'s pocket!</span>","<span class='warning'>You remove [I] from [victim]'s pocket.</span>", FALSE, 1) |
32 |
| - log_admin("[key_name(usr)] picked [victim.name]'s pockets with Kleptomania trait.") |
33 |
| - if(!QDELETED(I) && !owner.putItemFromInventoryInHandIfPossible(I, owner.active_hand_index, TRUE, TRUE)) |
34 |
| - I.forceMove(owner.drop_location()) |
35 |
| - break |
36 |
| - else |
37 |
| - owner.visible_message("<span class='warning'>[owner] fails to pickpocket [victim].</span>","<span class='warning'>You fail to pick [victim]'s pocket.</span>", FALSE, 1) |
38 |
| - else //we pick stuff off the ground |
39 |
| - var/mob/living/carbon/C = owner |
40 |
| - for(var/obj/item/I in oview(1, C)) |
41 |
| - if(!I.anchored && !(I in C.get_all_gear()) && I.Adjacent(C)) //anything that's not nailed down or worn |
42 |
| - I.attack_hand(C) |
43 |
| - break |
| 89 | + owner.log_message("attempted to pick up (kleptomania)", LOG_ATTACK, color = "orange") |
| 90 | + stealable.attack_hand(owner) |
| 91 | + break |
44 | 92 |
|
45 | 93 | /mob/living/carbon/human/proc/get_pockets()
|
46 | 94 | var/list/pockets = list()
|
|
0 commit comments