/** * @param $user User */ public static function createNewScenario($user) { global $db, $PARTY_IDS, $PARTY_NAMES; //Figure out what job the user has if ($user->job_id == JOB_IDS::REPORTER) { $effected_party_id = rand(1, count($PARTY_IDS)); $is_users_party = $effected_party_id == $user->party_id; $target_name = Scenario::generateRandomName(); //Is the news good or bad? And how bad? $severity_scale = rand(1, 100); // 50 is neutral, 1 is terrible, 100 very good $random_event = null; $options = array(); if ($severity_scale < 10) { //terrible event $random_event = $db->query_one("SELECT scenario_description, scenario_title FROM scenario_descriptions WHERE job_id = {$user->job_id} AND severity_scale = " . SEVERITY_SCALE::TERRIBLE . " ORDER BY RAND() LIMIT 1"); } else { if ($severity_scale <= 50) { //mildly bad event $random_event = $db->query_one("SELECT scenario_description, scenario_title FROM scenario_descriptions WHERE job_id = {$user->job_id} AND severity_scale = " . SEVERITY_SCALE::MILDLY_BAD . " ORDER BY RAND() LIMIT 1"); } else { if ($severity_scale <= 90) { //mildly good event $random_event = $db->query_one("SELECT scenario_description, scenario_title FROM scenario_descriptions WHERE job_id = {$user->job_id} AND severity_scale = " . SEVERITY_SCALE::MILDLY_GOOD . " ORDER BY RAND() LIMIT 1"); } else { //amazing event. $random_event = $db->query_one("SELECT scenario_description, scenario_title FROM scenario_descriptions WHERE job_id = {$user->job_id} AND severity_scale = " . SEVERITY_SCALE::AMAZING . " ORDER BY RAND() LIMIT 1"); } } } $options[0] = array("text" => "Stretch the negatives"); $options[1] = array("text" => "Report just the facts"); $options[2] = array("text" => "Downplay/minimize with facts"); $options[3] = array("text" => "Stretch the positive angles"); //add the NAME and PARTY into the event. // event: "[name] ([party]) was speeding and got out of a ticket because they are a politician. $scenario_description = str_replace(array("[name]", "[party]"), array($target_name, $PARTY_IDS[$effected_party_id]), $random_event['scenario_description']); $scenario_title = str_replace(array("[name]", "[party]"), array($target_name, $PARTY_IDS[$effected_party_id]), $random_event['scenario_title']); //save to database $scenario_id = $db->query("INSERT INTO scenarios\n (user_id, job_id,\n description, name,\n scenario_status, scenario_date, severity,\n target_name, effected_party_id)\n VALUES\n ({$user->user_id}, {$user->job_id}, x'" . bin2hex($scenario_description) . "', x'" . bin2hex($scenario_title) . "', 0, DATE(NOW()), {$severity_scale}, x'" . bin2hex($target_name) . "', {$effected_party_id})"); //insert the options $option_inserts = array(); foreach ($options as $option) { $empty_array = serialize(array()); $option_inserts[] = "({$scenario_id}, x'" . bin2hex($option['text']) . "',x'" . bin2hex($empty_array) . "')"; } $db->query("INSERT INTO scenario_options (scenario_id, scenario_option_description, scenario_option_result) VALUES " . implode(",", $option_inserts)); } return new Scenario($scenario_id); }