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