zkb-points - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of zkb-points.php

  1. <?php
  2.  
  3. <?php
  4.  
  5. $killmail = json_decode('[{"killmail_id":105768021,"zkb":{"locationID":50008241,"hash":"56ec85c4b6acda53409a5ae37345a1d91458f493","fittedValue":3922886564.15,"droppedValue":340907511.39,"destroyedValue":3638168196.23,"totalValue":4005843926.69,"points":322,"npc":false,"solo":false,"awox":false}}]');
  6.  
  7. $rigSizes = array();$rigSizes[17841]=1;$rigSizes['73796']=1;
  8.  
  9. function getRigSize($typeID)
  10. {
  11.     return $rigSizes[$typeId];
  12. }
  13.  
  14. function getPoints() {
  15.     $victim = $killmail['victim'];
  16.     $shipTypeID = $victim['ship_type_id'];
  17.     $items = $victim['items'];
  18.     $shipInfo = Info::getInfo('typeID', $shipTypeID);
  19.     $rigSize = getRigSize($shipTypeID);;
  20.     $shipInfo['rigSize'] = $rigSize;
  21.  
  22.     $dangerFactor = 0;
  23.     $basePoints =  pow(5, @$shipInfo['rigSize']);
  24.     $points = $basePoints;
  25.     foreach ((array) $items as $item) {
  26.         $itemInfo = Info::getInfo('typeID', $item['item_type_id']);
  27.         if (@$itemInfo['categoryID'] != 7) continue;
  28.  
  29.         $flagName = Info::getFlagName($item['flag']); 
  30.         if (($flagName == "Low Slots" || $flagName == "Mid Slots" || $flagName == "High Slots" || $flagName == 'SubSystems') || ($killID < 23970577 && $item['flag'] == 0) ) {
  31.             $typeID = $item['item_type_id'];
  32.             $qty = @$item['quantity_destroyed'] + @$item['quantity_dropped'];
  33.             $metaLevel = Info::getDogma($typeID, 633);
  34.             $meta = 1 + floor($metaLevel / 2);
  35.             $heatDamage = Info::getDogma($typeID, 1211);
  36.             $dangerFactor += ((bool) $heatDamage) * $qty * $meta; // offensive/defensive modules overloading are good for pvp
  37.             $dangerFactor += ($itemInfo['groupID'] == 645) * $qty * $meta; // drone damange multipliers
  38.             $dangerFactor -= ($itemInfo['groupID'] == 54) * $qty * $meta; // Mining ships don't earn as many points
  39.         }
  40.     }
  41.     $points += $dangerFactor;
  42.     $points *= max(0.01, min(1, $dangerFactor / 4));
  43.  
  44.     // Divide by number of ships on killmail
  45.     $numAttackers = sizeof($killmail['attackers']);
  46.     $involvedPenalty = max(1, $numAttackers * max(1, $numAttackers / 2));
  47.     $points = $points / $involvedPenalty;
  48.  
  49.     // Apply a bonus/penalty from -50% to 20% depending on average size of attacking ships
  50.     // For example: Smaller ships blowing up bigger ships get a bonus
  51.     // or bigger ships blowing up smaller ships get a penalty
  52.     $size = 0;
  53.     $hasChar = false;
  54.     foreach ((array) $killmail['attackers'] as $attacker) {
  55.         $hasChar |= @$attacker['character_id'] > 0;
  56.         $shipTypeID = @$attacker['ship_type_id'];
  57.         $categoryID = Info::getInfoField("typeID", $shipTypeID, "categoryID");
  58.         if ($categoryID == 65) return 1; // Structure on your mail, only 1 point
  59.  
  60.         $aInfo = Info::getInfo('typeID', $shipTypeID);
  61.         $aInfo['rigSize'] = self::getRigSize($shipTypeID);
  62.         $size += pow(5, ((@$aInfo['groupID'] != 29) ? @$aInfo['rigSize'] : @$shipInfo['rigSize'] + 1));
  63.     }
  64.     if ($hasChar == false) return 1;
  65.     $avg = max(1, $size / $numAttackers);
  66.     $modifier = min(1.2, max(0.5, $basePoints / $avg));
  67.     $points = (int) floor($points * $modifier);
  68.     
  69.     return max(1, $points);
  70. }
  71.  
  72. echo "Points = " + getPoints();
  73.  
File Description
  • zkb-points
  • PHP Code
  • 14 Jan-2023
  • 3.13 Kb
You can Share it: