Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $vcpRecords = array();
- // Check for VCP inserts
- foreach ($aVcp as $kVcp => $vVcp) {
- $vcpRecords[] = new VcpRaidRecord($vVcp['id'], $_POST['raidId'], $vVcp['seeded'], $vVcp['invited'], $vVcp['absence'], $vVcp['presence'], $vVcp['onlineDate']);
- }
- if (count($vcpRecords) > 0) {
- // Check if raidId == -1, then get most recent raid and process
- if ($_POST['raidId'] != -1) {
- // Check if raid is valid
- $raid = new Raid(null, null, null, null, $_POST['raidId']);
- }
- if ($_POST['raidId'] == -1 || ($raid->Id && !$raid->VcpProcessed)) { // Need to process
- $vcp = new Vcp();
- $vcp->Records = $vcpRecords;
- $countOnlineRecords = $vcp->CountOnlineRecords();
- // Loop through and process VCP records
- foreach ($vcp->Records as &$activeRecord) {
- // Check if invited, take 0.1
- if ($activeRecord->Invited) {
- $activeRecord->AttendanceLoss = $activeRecord->AttendanceLoss - 0.1;
- }
- // Online but not invited
- if ($activeRecord->Online && $activeRecord->Presence == 1 && !$activeRecord->Invited) {
- $activeRecord->OnlineGain = $activeRecord->OnlineGain + 1;
- }
- // Online but tardy, not invited
- // Determine earnings due to tardiness
- // Assign earnings, split remaining among online players
- if ($activeRecord->Online && $activeRecord->Presence < 1 && !$activeRecord->Invited) {
- // Earn something
- $activeRecord->OnlineGain = $activeRecord->OnlineGain + 1 * $activeRecord->Presence;
- $activeRecord->TardyLoss = $activeRecord->TardyLoss - 1 + $activeRecord->OnlineGain;
- // Split tardy loss among online members
- foreach ($vcp->Records as &$inactiveRecord) {
- // Check if online
- if ($inactiveRecord->Online && $inactiveRecord->Id != $activeRecord->Id) {
- // If online and not matching, divide TardyLoss among online records
- $inactiveRecord->TardyGain = $inactiveRecord->TardyGain - ($activeRecord->TardyLoss / $countOnlineRecords);
- }
- }
- }
- // Offline
- if (!$activeRecord->Online) {
- // Check if excused
- if ($activeRecord->Excused) {
- // Take away 1 VCP
- $activeRecord->AbsenceLoss = $activeRecord->AbsenceLoss - 1;
- } else { // Unexcused
- // Take away 1.5 VCP
- $activeRecord->AbsenceLoss = $activeRecord->AbsenceLoss - 1.5;
- }
- // Double the loss and split among online members
- foreach ($vcp->Records as &$inactiveRecord) {
- if ($inactiveRecord->Online && $inactiveRecord->Id != $activeRecord->Id) {
- $inactiveRecord->AbsenceGain = $inactiveRecord->AbsenceGain - (($activeRecord->AbsenceLoss * 2) / $countOnlineRecords);
- }
- }
- }
- }
- // Loop through and apply all updates
- foreach ($vcp->Records as &$activeRecord) {
- // Create VCP object
- $vcpUpdate = new Vcp(null, null, null, $activeRecord->VcpId);
- if ($vcpUpdate) {
- // Modify VCP value
- $vcpUpdate->VCP = $vcpUpdate->VCP +
- $activeRecord->AbsenceGain +
- $activeRecord->OnlineGain +
- $activeRecord->TardyGain +
- $activeRecord->AbsenceLoss +
- $activeRecord->AttendanceLoss +
- $activeRecord->TardyLoss;
- // Modify seeded
- $vcpUpdate->Seeded = $activeRecord->Seeded;
- // Update record
- $vcpUpdate->Update();
- }
- // Update record numerics (gain/loss)
- $activeRecord->Update();
- }
- if ($raid) {
- // Finally, update raid record as processed
- $raid->VcpProcessed = true;
- $raid->UpdateVcpProcessed();
- }
- // Reload page
- js_redirect($_SERVER['REQUEST_URI'],0);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement