function qst_reward(&$user, &$rewards, &$quest_list) { if (empty($rewards)) { return; } global $lang; $db_changeset = array(); $total_rewards = array(); $comment_dm = ''; foreach ($rewards as $quest_id => $user_data) { foreach ($user_data as $user_id => $planet_data) { foreach ($planet_data as $planet_id => $reward_list) { $comment = sprintf($lang['qst_msg_complete_body'], $quest_list[$quest_id]['quest_name']); $comment_dm .= isset($reward_list[RES_DARK_MATTER]) ? $comment : ''; $comment_reward = array(); foreach ($reward_list as $unit_id => $unit_amount) { $comment_reward[] = $unit_amount . ' ' . $lang['tech'][$unit_id]; $total_rewards[$user_id][$planet_id][$unit_id] += $unit_amount; } $comment .= " {$lang['qst_msg_your_reward']} " . implode(',', $comment_reward); msg_send_simple_message($user['id'], 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['msg_from_admin'], $lang['qst_msg_complete_subject'], $comment); sn_db_perform('{{quest_status}}', array('quest_status_quest_id' => $quest_id, 'quest_status_user_id' => $user_id, 'quest_status_status' => QUEST_STATUS_COMPLETE)); } } } $group_resources = sn_get_groups('resources_loot'); $quest_rewards_allowed = sn_get_groups('quest_rewards'); if (!empty($total_rewards)) { foreach ($total_rewards as $user_id => $planet_data) { $user_row = classSupernova::db_get_record_by_id(LOC_USER, $user_id); foreach ($planet_data as $planet_id => $unit_data) { $local_changeset = array(); foreach ($unit_data as $unit_id => $unit_amount) { if (!isset($quest_rewards_allowed[$unit_id])) { continue; } if ($unit_id == RES_DARK_MATTER) { rpg_points_change($user['id'], RPG_QUEST, $unit_amount, $comment_dm); } elseif (isset($group_resources[$unit_id])) { $local_changeset[pname_resource_name($unit_id)] = array('delta' => $unit_amount); } else { $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user_row, $planet_id); } // unit } if (!empty($local_changeset)) { $planet_id = $planet_id == 0 && isset($user_row['id_planet']) ? $user_row['id_planet'] : $planet_id; $db_changeset[$planet_id ? 'planets' : 'users'][] = array('action' => SQL_OP_UPDATE, P_VERSION => 1, 'where' => array("id" => $planet_id ? $planet_id : $user_id), 'fields' => $local_changeset); } } } classSupernova::db_changeset_apply($db_changeset); } }
function qst_reward(&$user, &$planet, &$rewards, &$quest_list) { global $lang, $sn_data; foreach ($rewards as $quest_id => $rewards_list_string) { $comment_reward = array(); $planet_reward = array(); $user_reward = array(); $user_reward_dm = 0; $comment = sprintf($lang['qst_msg_complete_body'], $quest_list[$quest_id]['quest_name']); $rewards_list_array = explode(';', $rewards_list_string); foreach ($rewards_list_array as $reward_string) { list($reward_id, $reward_amount) = explode(',', $reward_string); $reward_db_name = $sn_data[$reward_id]['name']; $reward_db_string = "`{$reward_db_name}` = `{$reward_db_name}` + {$reward_amount}"; if ($reward_id == RES_DARK_MATTER) { $user_reward_dm = $reward_amount; } if ($sn_data[$reward_id]['location'] == LOC_USER) { $user[$reward_db_name] += $reward_amount; $user_reward[] = $reward_db_string; } elseif ($sn_data[$reward_id]['location'] == LOC_PLANET) { $planet[$reward_db_name] += $reward_amount; $planet_reward[] = $reward_db_string; } else { continue; } $comment_reward[] = $reward_amount . ' ' . $lang['tech'][$reward_id]; } if (!empty($comment_reward)) { $comment .= " {$lang['qst_msg_your_reward']} " . implode(',', $comment_reward); if (!empty($user_reward)) { $user_reward = implode(',', $user_reward); doquery("UPDATE {{users}} SET {$user_reward} WHERE `id` = {$user['id']} LIMIT 1;"); if ($user_reward_dm) { rpg_points_change($user['id'], RPG_QUEST, $user_reward_dm, $comment, true); } } if (!empty($planet_reward)) { $planet_reward = implode(',', $planet_reward); doquery("UPDATE {{planets}} SET {$planet_reward} WHERE `id` = {$planet['id']} LIMIT 1;"); } } sn_db_perform('{{quest_status}}', array('quest_status_quest_id' => $quest_id, 'quest_status_user_id' => $user['id'], 'quest_status_status' => QUEST_STATUS_COMPLETE)); msg_send_simple_message($user['id'], 0, $time_now, MSG_TYPE_ADMIN, $lang['msg_from_admin'], $lang['qst_msg_complete_subject'], $comment); } }