Advertisement
gabestah

kAuction - VCP Calcs

Nov 10th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.72 KB | None | 0 0
  1. <?php
  2. $vcpRecords = array();
  3. // Check for VCP inserts
  4. foreach ($aVcp as $kVcp => $vVcp) {                  
  5.     $vcpRecords[] = new VcpRaidRecord($vVcp['id'], $_POST['raidId'], $vVcp['seeded'], $vVcp['invited'], $vVcp['absence'], $vVcp['presence'], $vVcp['onlineDate']);
  6. }
  7. if (count($vcpRecords) > 0) {
  8.     // Check if raidId == -1, then get most recent raid and process
  9.     if ($_POST['raidId'] != -1) {
  10.         // Check if raid is valid
  11.         $raid = new Raid(null, null, null, null, $_POST['raidId']);
  12.     }
  13.     if ($_POST['raidId'] == -1 || ($raid->Id && !$raid->VcpProcessed)) { // Need to process
  14.          $vcp = new Vcp();
  15.          $vcp->Records = $vcpRecords;
  16.          $countOnlineRecords = $vcp->CountOnlineRecords();
  17.          // Loop through and process VCP records
  18.          foreach ($vcp->Records as &$activeRecord) {
  19.              // Check if invited, take 0.1
  20.              if ($activeRecord->Invited) {
  21.                  $activeRecord->AttendanceLoss = $activeRecord->AttendanceLoss - 0.1;
  22.              }
  23.              // Online but not invited
  24.              if ($activeRecord->Online && $activeRecord->Presence == 1 && !$activeRecord->Invited) {
  25.                  $activeRecord->OnlineGain = $activeRecord->OnlineGain + 1;
  26.              }
  27.              // Online but tardy, not invited
  28.              //   Determine earnings due to tardiness
  29.              //   Assign earnings, split remaining among online players
  30.              if ($activeRecord->Online && $activeRecord->Presence < 1 && !$activeRecord->Invited) {
  31.                  // Earn something
  32.                  $activeRecord->OnlineGain = $activeRecord->OnlineGain + 1 * $activeRecord->Presence;
  33.                  $activeRecord->TardyLoss = $activeRecord->TardyLoss - 1 + $activeRecord->OnlineGain;
  34.                  // Split tardy loss among online members
  35.                  foreach ($vcp->Records as &$inactiveRecord) {
  36.                      // Check if online
  37.                      if ($inactiveRecord->Online && $inactiveRecord->Id != $activeRecord->Id) {
  38.                          // If online and not matching, divide TardyLoss among online records
  39.                          $inactiveRecord->TardyGain = $inactiveRecord->TardyGain - ($activeRecord->TardyLoss / $countOnlineRecords);
  40.                      }
  41.                  }                                                                
  42.              }
  43.              // Offline
  44.              if (!$activeRecord->Online) {
  45.                  // Check if excused
  46.                  if ($activeRecord->Excused) {
  47.                     // Take away 1 VCP
  48.                     $activeRecord->AbsenceLoss = $activeRecord->AbsenceLoss - 1;
  49.                  } else { // Unexcused
  50.                     // Take away 1.5 VCP
  51.                     $activeRecord->AbsenceLoss = $activeRecord->AbsenceLoss - 1.5;
  52.                  }
  53.                  // Double the loss and split among online members
  54.                  foreach ($vcp->Records as &$inactiveRecord) {
  55.                      if ($inactiveRecord->Online && $inactiveRecord->Id != $activeRecord->Id) {
  56.                          $inactiveRecord->AbsenceGain = $inactiveRecord->AbsenceGain - (($activeRecord->AbsenceLoss * 2) / $countOnlineRecords);                                                                                    
  57.                      }
  58.                  }                                    
  59.              }
  60.          }
  61.          // Loop through and apply all updates
  62.          foreach ($vcp->Records as &$activeRecord) {
  63.              // Create VCP object
  64.              $vcpUpdate = new Vcp(null, null, null, $activeRecord->VcpId);
  65.              if ($vcpUpdate) {
  66.                  // Modify VCP value
  67.                  $vcpUpdate->VCP = $vcpUpdate->VCP +
  68.                               $activeRecord->AbsenceGain +
  69.                               $activeRecord->OnlineGain +
  70.                               $activeRecord->TardyGain +
  71.                               $activeRecord->AbsenceLoss +
  72.                               $activeRecord->AttendanceLoss +
  73.                               $activeRecord->TardyLoss;
  74.                  // Modify seeded
  75.                  $vcpUpdate->Seeded = $activeRecord->Seeded;
  76.                  // Update record
  77.                  $vcpUpdate->Update();
  78.              }
  79.              // Update record numerics (gain/loss)
  80.              $activeRecord->Update();
  81.          }
  82.          if ($raid) {
  83.             // Finally, update raid record as processed
  84.             $raid->VcpProcessed = true;
  85.             $raid->UpdateVcpProcessed();
  86.          }
  87.          // Reload page
  88.          js_redirect($_SERVER['REQUEST_URI'],0);
  89.     }
  90. }
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement