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. // Set DEBUG=true in zkb-points.go to print out the necessary data structures
  4. // run it here https://wtools.io/php-sandbox/bIOo
  5. $killmail = json_decode('{"attackers":[{"character_id":96850177,"corporation_id":1000181,"damage_done":4390,"faction_id":500004,"final_blow":true,"security_status":-2.7,"ship_type_id":73796,"weapon_type_id":3178}],"killmail_id":106052948,"killmail_time":"2023-01-13T22:27:40Z","solar_system_id":30003837,"victim":{"character_id":2117587567,"corporation_id":1000169,"damage_taken":4390,"items":[{"flag":5,"item_type_id":12618,"quantity_dropped":250,"singleton":0},{"flag":94,"item_type_id":33892,"quantity_destroyed":1,"singleton":0},{"flag":27,"item_type_id":23009,"quantity_destroyed":28,"singleton":0},{"flag":13,"item_type_id":10190,"quantity_dropped":1,"singleton":0},{"flag":14,"item_type_id":2048,"quantity_dropped":1,"singleton":0},{"flag":11,"item_type_id":33076,"quantity_dropped":1,"singleton":0},{"flag":28,"item_type_id":23009,"quantity_dropped":28,"singleton":0},{"flag":92,"item_type_id":33892,"quantity_destroyed":1,"singleton":0},{"flag":5,"item_type_id":12620,"quantity_destroyed":250,"singleton":0},{"flag":29,"item_type_id":4471,"quantity_destroyed":1,"singleton":0},{"flag":11,"item_type_id":28668,"quantity_destroyed":6,"singleton":0},{"flag":27,"item_type_id":3074,"quantity_destroyed":1,"singleton":0},{"flag":12,"item_type_id":1236,"quantity_destroyed":1,"singleton":0},{"flag":21,"item_type_id":438,"quantity_dropped":1,"singleton":0},{"flag":19,"item_type_id":527,"quantity_dropped":1,"singleton":0},{"flag":28,"item_type_id":3074,"quantity_destroyed":1,"singleton":0},{"flag":93,"item_type_id":33892,"quantity_destroyed":1,"singleton":0},{"flag":20,"item_type_id":448,"quantity_destroyed":1,"singleton":0},{"flag":87,"item_type_id":2456,"quantity_destroyed":2,"singleton":0},{"flag":5,"item_type_id":23009,"quantity_destroyed":650,"singleton":0},{"flag":5,"item_type_id":23019,"quantity_destroyed":466,"singleton":0}],"position":{"x":330675010117.81995,"y":-99715637062.42049,"z":-156409520215.90182},"ship_type_id":17841},"zkb":{"locationID":40242853,"hash":"5724ddbb8580b65062f4bc365f9df44398c053d7","fittedValue":29191310.05,"droppedValue":4506906.28,"destroyedValue":26067214.44,"totalValue":30574120.71,"points":22,"npc":false,"solo":true,"awox":false,"esi":"https://esi.evetech.net/latest/killmails/106052948/5724ddbb8580b65062f4bc365f9df44398c053d7/","url":"https://zkillboard.com/kill/106052948/"}}', true);
  6.  
  7. $rigSizes = array(17841=>1,73796=>1);
  8. $categories = array(17841=>0,73796=>0,12618=>0,33892=>0,23009=>0,10190=>0,2048=>0,33076=>0,23009=>0,33892=>0,12620=>0,4471=>2118,28668=>0,3074=>0,1236=>0,438=>23,527=>11,3074=>0,33892=>0,448=>2,2456=>0,23009=>0,23019=>0);
  9. $itemFlagNames = array('_'=>0,23009=>'High Slots',10190=>'Low Slots',2048=>'Low Slots',33076=>'Low Slots',23009=>'High Slots',4471=>'High Slots',28668=>'Low Slots',3074=>'High Slots',1236=>'Low Slots',438=>'Mid Slots',527=>'Mid Slots',3074=>'High Slots',448=>'Mid Slots');
  10. $metaLevels = array('_'=>0,12618=>5,33892=>0,23009=>0,10190=>5,2048=>5,33076=>0,23009=>0,33892=>0,12620=>5,4471=>0,28668=>0,3074=>0,1236=>5,438=>0,527=>0,3074=>0,33892=>0,448=>0,2456=>5,23009=>0,23019=>0);
  11. $canHeat = array('_'=>0,12618=>false,33892=>false,23009=>false,10190=>false,2048=>false,33076=>true,23009=>false,33892=>false,12620=>false,4471=>true,28668=>false,3074=>true,1236=>false,438=>true,527=>true,3074=>true,33892=>false,448=>true,2456=>false,23009=>false,23019=>false);
  12.  $groupIds = array('_'=>0,12618=>373,33892=>773,23009=>85,10190=>302,2048=>60,33076=>1199,23009=>85,33892=>773,12620=>373,4471=>71,28668=>916,3074=>74,1236=>764,438=>46,527=>65,3074=>74,33892=>773,448=>52,2456=>100,23009=>85,23019=>85,73796=>420);
  13.  
  14. function getPoints() {
  15.     global $killmail, $rigSizes, $categories, $itemFlagNames, $metaLevels, $canHeat, $groupIds;
  16.     
  17.     $victim = $killmail['victim'];
  18.     $shipTypeID = $victim['ship_type_id'];
  19.     $items = $victim['items'];
  20.     $rigSize = $rigSizes[$shipTypeID];
  21.     $killID = $killmail['killmail_id'];
  22.  
  23.     $dangerFactor = 0;
  24.     $basePoints =  pow(5, $rigSize);
  25.     $points = $basePoints;
  26.     
  27.     foreach ((array) $items as $item) {
  28.         $typeID = $item['item_type_id'];
  29.         $categoryID = $categories[$typeID];
  30.  
  31.         $flagName = array_key_exists($typeID, $itemFlagNames) ? $itemFlagNames[$typeID] : 'no';
  32.         if (($flagName == "Low Slots" || $flagName == "Mid Slots" || $flagName == "High Slots" || $flagName == 'SubSystems') || ($killID < 23970577 && $item['flag'] == 0) ) {
  33.             $qty = @$item['quantity_destroyed'] + @$item['quantity_dropped'];
  34.             $metaLevel = $metaLevels[$typeID];
  35.             $meta = 1 + floor($metaLevel / 2);
  36.             $heatDamage = $canHeat[$typeID];
  37.             $dangerFactor += ((bool) $heatDamage) * $qty * $meta; // offensive/defensive modules overloading are good for pvp
  38.             $dangerFactor += ($groupIds[$typeID] == 645) * $qty * $meta; // drone damange multipliers
  39.             $dangerFactor -= ($groupIds[$typeID] == 54) * $qty * $meta; // Mining ships don't earn as many points
  40.         }
  41.     }
  42.     echo "Points before dangerFactor($dangerFactor) - $points\n";
  43.     $points += $dangerFactor;
  44.     $points *= max(0.01, min(1, $dangerFactor / 4));
  45.     echo "Points = $points, dangerFactor = $dangerFactor\n";
  46.  
  47.     // Divide by number of ships on killmail
  48.     $numAttackers = sizeof($killmail['attackers']);
  49.     $involvedPenalty = max(1, $numAttackers * max(1, $numAttackers / 2));
  50.     $points = $points / $involvedPenalty;
  51.     echo "Points = $points, numAttackers=$numAttackers, involvedPenalty=$involvedPenalty\n";
  52.  
  53.     // Apply a bonus/penalty from -50% to 20% depending on average size of attacking ships
  54.     // For example: Smaller ships blowing up bigger ships get a bonus
  55.     // or bigger ships blowing up smaller ships get a penalty
  56.     $size = 0;
  57.     $hasChar = false;
  58.     foreach ((array) $killmail['attackers'] as $attacker) {
  59.         $hasChar |= @$attacker['character_id'] > 0;
  60.         $shipTypeID = @$attacker['ship_type_id'];
  61.         $categoryID = $categories[@$attacker['ship_type_id']];
  62.         if ($categoryID == 65) return 1; // Structure on your mail, only 1 point
  63.  
  64.         $aInfo['rigSize'] = $rigSizes[$shipTypeID];
  65.         $groupId = $groupIds[$shipTypeID];
  66.         $size += pow(5, (($groupId != 29) ? $rigSizes[$shipTypeID] : $rigSizes[$shipTypeID] + 1));
  67.     }
  68.     if ($hasChar == false) return 1;
  69.     $avg = max(1, $size / $numAttackers);
  70.     $modifier = min(1.2, max(0.5, $basePoints / $avg));
  71.     $points = (int) floor($points * $modifier);
  72.  
  73.     
  74.     return max(1, $points);
  75. }
  76.  
  77. $totalPoints = getPoints();
  78. $zkbPoints = $killmail['zkb']['points'];
  79. echo "Final Points = $totalPoints, ZKB points = $zkbPoints";
  80.  
File Description
  • zkb-points
  • PHP Code
  • 16 Jan-2023
  • 6.6 Kb
You can Share it: