hewwo have you tried to work?

This commit is contained in:
Letter N
2020-08-10 10:50:07 +08:00
parent 2f1b769ae4
commit a4040ace26
10 changed files with 634 additions and 146 deletions
+109 -27
View File
@@ -6,6 +6,8 @@
* It is first created when the first ghost signs up to play.
*/
/datum/mafia_controller
///list of observers that should get game updates.
var/list/spectators = list()
///all roles in the game, dead or alive. check their game status if you only want living or dead.
var/list/all_roles = list()
///exists to speed up role retrieval, it's a dict. player_role_lookup[player ckey] will give you the role they play
@@ -48,7 +50,8 @@
///group voting on one person, like putting people to trial or choosing who to kill as mafia
var/list/votes = list()
///and these (judgement_innocent_votes and judgement_guilty_votes) are the judgement phase votes, aka people sorting themselves into guilty and innocent lists. whichever has more wins!
///and these (judgement_innocent_votes, judgement_abstain_votes and judgement_guilty_votes) are the judgement phase votes, aka people sorting themselves into guilty and innocent, and "eh, i don't really care" lists. whichever has more inno or guilty wins!
var/list/judgement_abstain_votes = list()
var/list/judgement_innocent_votes = list()
var/list/judgement_guilty_votes = list()
///current role on trial for the judgement phase, will die if guilty is greater than innocent
@@ -129,7 +132,7 @@
var/team_suffix = team ? "([uppertext(team)] CHAT)" : ""
for(var/M in GLOB.dead_mob_list)
var/mob/spectator = M
if(spectator.ckey in GLOB.mafia_signup || player_role_lookup[spectator.mind.current] != null) //was in current game, or is signed up
if(spectator.ckey in spectators) //was in current game, or spectatin' (won't send to living)
var/link = FOLLOW_LINK(M, town_center_landmark)
to_chat(M, "[link] MAFIA: [msg] [team_suffix]")
@@ -190,8 +193,19 @@
*/
/datum/mafia_controller/proc/check_trial(verbose = TRUE)
var/datum/mafia_role/loser = get_vote_winner("Day")//, majority_of_town = TRUE)
var/loser_votes = get_vote_count(loser,"Day")
if(loser)
// if(loser_votes > 12)
// loser.body.client?.give_award(/datum/award/achievement/mafia/universally_hated, loser.body)
send_message("<b>[loser.body.real_name] wins the day vote, Listen to their defense and vote \"INNOCENT\" or \"GUILTY\"!</b>")
//refresh the lists
judgement_abstain_votes = list()
judgement_innocent_votes = list()
judgement_guilty_votes = list()
for(var/i in all_roles)
var/datum/mafia_role/abstainee = i
if(abstainee.game_status == MAFIA_ALIVE && abstainee != loser)
judgement_abstain_votes += abstainee
on_trial = loser
on_trial.body.forceMove(get_turf(town_center_landmark))
phase = MAFIA_PHASE_JUDGEMENT
@@ -215,8 +229,11 @@
for(var/i in judgement_innocent_votes)
var/datum/mafia_role/role = i
send_message("<span class='green'>[role.body.real_name] voted innocent.</span>")
for(var/ii in judgement_guilty_votes)
for(var/ii in judgement_abstain_votes)
var/datum/mafia_role/role = ii
send_message("<span class='comradio'>[role.body.real_name] abstained.</span>")
for(var/iii in judgement_guilty_votes)
var/datum/mafia_role/role = iii
send_message("<span class='red'>[role.body.real_name] voted guilty.</span>")
if(judgement_guilty_votes.len > judgement_innocent_votes.len) //strictly need majority guilty to lynch
send_message("<span class='red'><b>Guilty wins majority, [on_trial.body.real_name] has been lynched.</b></span>")
@@ -225,9 +242,6 @@
else
send_message("<span class='green'><b>Innocent wins majority, [on_trial.body.real_name] has been spared.</b></span>")
on_trial.body.forceMove(get_turf(on_trial.assigned_landmark))
//by now clowns should have killed someone in guilty list, clear this out
judgement_innocent_votes = list()
judgement_guilty_votes = list()
on_trial = null
//day votes are already cleared, so this will skip the trial and check victory/lockdown/whatever else
next_phase_timer = addtimer(CALLBACK(src, .proc/check_trial, FALSE),judgement_lynch_period,TIMER_STOPPABLE)// small pause to see the guy dead, no verbosity since we already did this
@@ -320,10 +334,8 @@
/**
* Cleans up the game, resetting variables back to the beginning and removing the map with the generator.
*/
/datum/mafia_controller/proc/end_game()
/datum/mafia_controller/proc/end_game(
map_deleter.generate() //remove the map, it will be loaded at the start of the next one
QDEL_LIST(all_roles)
turn = 0
votes = list()
@@ -481,7 +493,7 @@
if(phase != MAFIA_PHASE_VOTING)
return
var/v = get_vote_count(player_role_lookup[source],"Day")
var/mutable_appearance/MA = mutable_appearance('icons/obj/mafia.dmi',"vote_[v]")
var/mutable_appearance/MA = mutable_appearance('icons/obj/mafia.dmi',"vote_[v > 12 ? "over_12" : v]")
overlay_list += MA
/**
@@ -528,13 +540,26 @@
.["judgement_phase"] = FALSE
var/datum/mafia_role/user_role = player_role_lookup[user]
if(user_role)
.["roleinfo"] = list("role" = user_role.name,"desc" = user_role.desc, "action_log" = user_role.role_notes)
.["roleinfo"] = list("role" = user_role.name,"desc" = user_role.desc, "action_log" = user_role.role_notes, "hud_icon" = user_role.hud_icon, "revealed_icon" = user_role.revealed_icon)
var/actions = list()
for(var/action in user_role.actions)
if(user_role.validate_action_target(src,action,null))
actions += action
.["actions"] = actions
.["role_theme"] = user_role.special_theme
else
var/list/lobby_data = list()
for(var/key in GLOB.mafia_signup + GLOB.mafia_bad_signup)
var/list/lobby_member = list()
lobby_member["name"] = key
lobby_member["status"] = "Ready"
if(key in GLOB.mafia_bad_signup)
lobby_member["status"] = "Disconnected"
lobby_member["spectating"] = "Ghost"
if(key in spectators)
lobby_member["spectating"] = "Spectator"
lobby_data += list(lobby_member)
.["lobbydata"] = lobby_data
var/list/player_data = list()
for(var/datum/mafia_role/R in all_roles)
var/list/player_info = list()
@@ -561,6 +586,11 @@
//Not sure on this, should this info be visible
.["all_roles"] = current_setup_text
/datum/mafia_controller/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/spritesheet/mafia),
)
/datum/mafia_controller/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
@@ -606,7 +636,31 @@
helper = role
break
helper.show_help(usr)
if(!user_role || user_role.game_status == MAFIA_DEAD)//ghosts, dead people?
if(!user_role)//just the dead
var/client/C = ui.user.client
switch(action)
if("mf_signup")
if(!SSticker.HasRoundStarted())
to_chat(usr, "<span class='warning'>Wait for the round to start.</span>")
return
if(GLOB.mafia_signup[C.ckey])
GLOB.mafia_signup -= C.ckey
to_chat(usr, "<span class='notice'>You unregister from Mafia.</span>")
return
else
GLOB.mafia_signup[C.ckey] = C
to_chat(usr, "<span class='notice'>You sign up for Mafia.</span>")
if(phase == MAFIA_PHASE_SETUP)
check_signups()
try_autostart()
if("mf_spectate")
if(C.ckey in spectators)
to_chat(usr, "<span class='notice'>You will no longer get messages from the game.</span>")
spectators -= C.ckey
else
to_chat(usr, "<span class='notice'>You will now get messages from the game.</span>")
spectators += C.ckey
if(user_role.game_status == MAFIA_DEAD)
return
var/self_voting = user_role == on_trial ? TRUE : FALSE //used to block people from voting themselves innocent or guilty
//User actions
@@ -637,20 +691,29 @@
return
user_role.handle_action(src,params["atype"],target)
return TRUE
if("vote_innocent")
if(phase != MAFIA_PHASE_JUDGEMENT && !self_voting)
return
to_chat(user_role.body,"Your vote on [on_trial.body.real_name] submitted as INNOCENT!")
judgement_innocent_votes -= user_role//no double voting
judgement_guilty_votes -= user_role//no radical centrism
judgement_innocent_votes += user_role
if("vote_guilty")
if(phase != MAFIA_PHASE_JUDGEMENT && !self_voting)
return
to_chat(user_role.body,"Your vote on [on_trial.body.real_name] submitted as GUILTY!")
judgement_innocent_votes -= user_role//no radical centrism
judgement_guilty_votes -= user_role//no double voting
judgement_guilty_votes += user_role
if(user_role != on_trial)
switch(action)
if("vote_abstain")
if(phase != MAFIA_PHASE_JUDGEMENT || (user_role in judgement_abstain_votes))
return
to_chat(user_role.body,"You have decided to abstain.")
judgement_innocent_votes -= user_role
judgement_guilty_votes -= user_role
judgement_abstain_votes += user_role
if("vote_innocent")
if(phase != MAFIA_PHASE_JUDGEMENT || (user_role in judgement_innocent_votes))
return
to_chat(user_role.body,"Your vote on [on_trial.body.real_name] submitted as INNOCENT!")
judgement_abstain_votes -= user_role//no fakers, and...
judgement_guilty_votes -= user_role//no radical centrism
judgement_innocent_votes += user_role
if("vote_guilty")
if(phase != MAFIA_PHASE_JUDGEMENT || (user_role in judgement_guilty_votes))
return
to_chat(user_role.body,"Your vote on [on_trial.body.real_name] submitted as GUILTY!")
judgement_abstain_votes -= user_role//no fakers, and...
judgement_innocent_votes -= user_role//no radical centrism
judgement_guilty_votes += user_role
/datum/mafia_controller/ui_state(mob/user)
return GLOB.always_state
@@ -699,7 +762,7 @@
//cuts invalid players from signups (disconnected/not a ghost)
var/list/possible_keys = list()
for(var/key in GLOB.mafia_signup)
if(GLOB.directory[key] && GLOB.directory[key] == GLOB.mafia_signup[key])
if(GLOB.directory[key])
var/client/C = GLOB.directory[key]
if(isobserver(C.mob))
possible_keys += key
@@ -739,6 +802,25 @@
if(GLOB.mafia_signup.len >= min_players)//enough people to try and make something
basic_setup()
/**
* Filters inactive player into a different list until they reconnect, and removes players who are no longer ghosts.
*
* If a disconnected player gets a non-ghost mob and reconnects, they will be first put back into mafia_signup then filtered by that.
*/
/datum/mafia_controller/proc/check_signups()
for(var/bad_key in GLOB.mafia_bad_signup)
if(GLOB.directory[bad_key])//they have reconnected if we can search their key and get a client
GLOB.mafia_bad_signup -= bad_key
GLOB.mafia_signup += bad_key
for(var/key in GLOB.mafia_signup)
var/client/C = GLOB.directory[key]
if(!C)//vice versa but in a variable we use later
GLOB.mafia_signup -= key
GLOB.mafia_bad_signup += key
if(!isobserver(C.mob))
//they are back to playing the game, remove them from the signups
GLOB.mafia_signup -= key
/datum/action/innate/mafia_panel
name = "Mafia Panel"
desc = "Use this to play."