diff --git a/code/game/objects/items/eightball.dm b/code/game/objects/items/eightball.dm index 7b8354b0a77..737ba7e947c 100644 --- a/code/game/objects/items/eightball.dm +++ b/code/game/objects/items/eightball.dm @@ -11,8 +11,8 @@ var/shaking = FALSE var/on_cooldown = FALSE - var/shake_time = 50 - var/cooldown_time = 100 + var/shake_time = 5 SECONDS + var/cooldown_time = 10 SECONDS var/static/list/possible_answers = list( "It is certain", @@ -42,11 +42,16 @@ return INITIALIZE_HINT_QDEL /obj/item/toy/eightball/proc/MakeHaunted() - . = prob(1) - if(.) + if(prob(1)) new /obj/item/toy/eightball/haunted(loc) + return TRUE + return FALSE /obj/item/toy/eightball/attack_self(mob/user) + if(..()) + return + + . = TRUE if(shaking) return @@ -60,23 +65,19 @@ start_shaking(user) if(do_after(user, shake_time)) - var/answer = get_answer() - say(answer) + say(get_answer()) on_cooldown = TRUE - addtimer(CALLBACK(src, PROC_REF(clear_cooldown)), cooldown_time) + addtimer(VARSET_CALLBACK(src, on_cooldown, FALSE), cooldown_time) shaking = FALSE -/obj/item/toy/eightball/proc/start_shaking(user) +/obj/item/toy/eightball/proc/start_shaking(mob/user) return /obj/item/toy/eightball/proc/get_answer() return pick(possible_answers) -/obj/item/toy/eightball/proc/clear_cooldown() - on_cooldown = FALSE - // A broken magic eightball, it only says "YOU SUCK" over and over again. /obj/item/toy/eightball/broken @@ -97,7 +98,7 @@ /obj/item/toy/eightball/haunted shake_time = 30 SECONDS cooldown_time = 3 MINUTES - var/last_message + var/last_message = "Nothing!" var/selected_message //these kind of store the same thing but one is easier to work with. var/list/votes = list() @@ -160,6 +161,7 @@ notify_ghosts("[user] is shaking [src], hoping to get an answer to \"[selected_message]\"", source=src, enter_link="(Click to help)", action=NOTIFY_ATTACK, header = "Magic eightball") /obj/item/toy/eightball/haunted/Topic(href, href_list) + . = ..() if(href_list["interact"]) if(isobserver(usr)) interact(usr) @@ -169,7 +171,7 @@ var/top_vote for(var/vote in votes) - var/amount_of_votes = length(votes[vote]) + var/amount_of_votes = votes[vote] if(amount_of_votes > top_amount) top_vote = vote top_amount = amount_of_votes @@ -186,12 +188,19 @@ voted.Cut() - return top_vote + var/list/top_options = haunted_answers[top_vote] + return pick(top_options) + +// Only ghosts can interact because only ghosts can open the ui +/obj/item/toy/eightball/haunted/can_interact(mob/living/user) + return isobserver(user) /obj/item/toy/eightball/haunted/ui_state(mob/user) return GLOB.observer_state /obj/item/toy/eightball/haunted/ui_interact(mob/user, datum/tgui/ui) + if(!isobserver(user)) + return ui = SStgui.try_update_ui(user, src, ui) if(!ui) ui = new(user, src, "EightBallVote", name) @@ -224,9 +233,11 @@ var/selected_answer = params["answer"] if(!(selected_answer in haunted_answers)) return - if(user.ckey in voted) - return - else - votes[selected_answer] += 1 - voted[user.ckey] = selected_answer - . = TRUE + var/oldvote = voted[user.ckey] + if(oldvote) + // detract their old vote + votes[oldvote] -= 1 + + votes[selected_answer] += 1 + voted[user.ckey] = selected_answer + return TRUE