Skip to content

Instantly share code, notes, and snippets.

@Artefact2
Created October 30, 2016 12:43
Show Gist options
  • Save Artefact2/2a9c541bd21fb8bdba50a4359a8386ba to your computer and use it in GitHub Desktop.
Save Artefact2/2a9c541bd21fb8bdba50a4359a8386ba to your computer and use it in GitHub Desktop.

Revisions

  1. Artefact2 created this gist Oct 30, 2016.
    57 changes: 57 additions & 0 deletions sreq.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    <?php
    /* Author: Romain Dal Maso <[email protected]>
    *
    * This program is free software. It comes without any warranty, to the
    * extent permitted by applicable law. You can redistribute it and/or
    * modify it under the terms of the Do What The Fuck You Want To Public
    * License, Version 2, as published by Sam Hocevar. See
    * http://sam.zoy.org/wtfpl/COPYING for more details. */

    if($argc !== 2) {
    fprintf(STDERR, "Usage: %s <dna-string>\n", $argv[0]);
    die(1);
    }
    $dna = $argv[1];

    /* XXX: cache this, obviously */
    $csvattribs = explode("\n", shell_exec('curl -s "https://www.fuzzwork.co.uk/dump/latest/dgmTypeAttributes.csv.bz2" | bunzip2'));

    $rs = [
    182 => 277, /* RequiredSkill1 => RequiredSkill1Level */
    183 => 278, /* etc… */
    184 => 279,
    1285 => 1286,
    1289 => 1287,
    1290 => 1288,
    ];
    $iattr = array_flip(array_merge(array_keys($rs), array_values($rs)));
    $attribs = [];

    foreach($csvattribs as $row) {
    if($row === '') continue;

    list($typeid, $attributeid, $valint, $valfloat) = explode(",", $row);
    if(isset($iattr[$attributeid])) {
    $val = ($valint === 'None') ? floatval($valfloat) : intval($valint);
    if(!$val) continue;
    $attribs[$typeid][$attributeid] = $val;
    }
    }

    $requirements = [];

    foreach(explode(':', $dna) as $dnap) {
    if($dnap === '') continue;
    $typeid = explode(';', $dnap, 2)[0];

    foreach($rs as $s => $sl) {
    if(!isset($attribs[$typeid][$s])) continue;
    $s = $attribs[$typeid][$s];
    $sl = $attribs[$typeid][$sl];

    $l = $requirements[$s] ?? 0;
    $requirements[$s] = max($l, $sl);
    }
    }

    echo json_encode($requirements, JSON_PRETTY_PRINT)."\n";