function add_card_owner_status($card, $player, $status) { if (get_status($card, $player) != $status) { $values["player"] = $player; $values["card"] = $card; $values["game"] = game; $values["turn"] = turn; $values["status"] = $status; create_entry("owned", array("card", "game", "player", "status", "turn"), array(), $values); $card_type = select_card($card, array("type"))["type"]; $all_typed_cards = array_of_ids(select_cards(array("type" => $card_type))); if ($status == owned) { foreach (select_suspects() as $other_player) { if ($other_player["id"] != $player) { add_card_owner_status($card, $other_player["id"], not_owned); } } $known_cards = known_cards_player($player); if (count($known_cards) == select_cards_player($player)) { foreach (select_cards(array("id" => array("NOT IN", $known_cards))) as $other_card) { add_card_owner_status($other_card["id"], $player, not_owned); } } $known_cards = known_cards_type($card_type); if (count($known_cards) + 1 == count($all_typed_cards)) { foreach (array_diff($all_typed_cards, $known_cards) as $left_out_card) { foreach (select_suspects() as $other_player) { add_card_owner_status($left_out_card, $other_player["id"], not_owned); } } } } elseif ($status == not_owned) { foreach (select_turns() as $turn) { $turn = select_turn($turn["id"], array("weapon", "room", "suspect", "witness")); if ($turn["witness"] == $player) { if ($turn["weapon"] == $card && get_status($turn["room"], $player) == not_owned || $turn["room"] == $card && get_status($turn["weapon"], $player) == not_owned) { add_card_owner_status($turn["suspect"], $player, owned); } elseif ($turn["weapon"] == $card && get_status($turn["suspect"], $player) == not_owned || $turn["suspect"] == $card && get_status($turn["weapon"], $player) == not_owned) { add_card_owner_status($turn["room"], $player, owned); } elseif ($turn["suspect"] == $card && get_status($turn["room"], $player) == not_owned || $turn["room"] == $card && get_status($turn["suspect"], $player) == not_owned) { add_card_owner_status($turn["weapon"], $player, owned); } } } if (exists_murder_card($card_type)) { foreach (select_cards(array("type" => $card_type)) as $other_card) { $unknown_owners = select_unknown_owners($other_card["id"]); if (count($unknown_owners) == 1) { foreach ($unknown_owners as $owner) { add_card_owner_status($other_card["id"], $owner, owned); } } } } } } }
add_card_owner_status($_POST["room"], $_POST["witness"], owned); break; case weapon: add_card_owner_status($_POST["weapon"], $_POST["witness"], owned); break; case suspect: add_card_owner_status($_POST["suspect"], $_POST["witness"], owned); break; } } if (get_status($_POST["room"], $_POST["witness"]) == not_owned && get_status($_POST["weapon"], $_POST["witness"]) == not_owned) { add_card_owner_status($_POST["suspect"], $_POST["witness"], owned); } elseif (get_status($_POST["weapon"], $_POST["witness"]) == not_owned && get_status($_POST["suspect"], $_POST["witness"]) == not_owned) { add_card_owner_status($_POST["room"], $_POST["witness"], owned); } elseif (get_status($_POST["room"], $_POST["witness"]) == not_owned && get_status($_POST["suspect"], $_POST["witness"]) == not_owned) { add_card_owner_status($_POST["weapon"], $_POST["witness"], owned); } increment_turn(); redirect_to_action("show"); break; case "skip": increment_turn(); redirect_to_action("show"); break; case "show": break; case "daybook": break; case "revert": $turn = max(array_of_ids(select_turns())); delete_turn($turn);