(edited by Cruzyo.7304)
WvW API and Website Question
Yes. I first pull the world list and build an array of $world which will act as a World ID to Name Converter
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://api.guildwars2.com/v1/world_names.json”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlRes = curl_exec($ch);
curl_close($ch);
$w = json_decode($curlRes, true);
$world = array();
foreach ($w as &$v) {
$wid = $v[‘id’];
$world[$wid] = $v[‘name’];
}
unset($v);
I then find the Match that my server (1013) is in.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://api.guildwars2.com/v1/wvw/matches.json”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlRes = curl_exec($ch);
curl_close($ch);
$wld = json_decode($curlRes, true);
foreach ($wld[‘wvw_matches’] as &$v) {
if($v[‘red_world_id’] == ‘1013’ || $v[‘blue_world_id’] == ‘1013’ || $v[‘green_world_id’] == ‘1013’) {
$sormatch = $v[‘wvw_match_id’];
$r[‘id’] = $v[‘red_world_id’];
$b[‘id’] = $v[‘blue_world_id’];
$g[‘id’] = $v[‘green_world_id’];
}
}
unset($v);
Then I build the Objective Array
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://api.guildwars2.com/v1/wvw/objective_names.json”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlRes = curl_exec($ch);
curl_close($ch);
$obj = json_decode($curlRes, true);
$objective = array();
foreach ($obj as &$v) {
$objid = $v[‘id’];
$objective[$objid] = $v[‘name’];
}
unset($v);
Founder, Gaiscioch Community [GSCH] | Gaiscioch Magazine | Twitch | YouTube | Twitter
Proud Resident of Mercenary Server Sanctum of Rall | 6 Year Extra-Life Charity Event Participant
Lastly you need to build the data to import into your table.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://api.guildwars2.com/v1/wvw/match_details.json?match_id=”.$sormatch);
curl_setopt($ch, CURLOPT_HEADER, 0);
$curlRes = curl_exec($ch);
curl_close($ch);
$data = json_decode($curlRes, true);
$r[‘score’] = $data[‘scores’]0;
$r[‘name’] = $world[$r[‘id’]];
$b[‘score’] = $data[‘scores’]1;
$b[‘name’] = $world[$b[‘id’]];
$g[‘score’] = $data[‘scores’]2;
$g[‘name’] = $world[$g[‘id’]];
$side[‘Red’] = $r[‘name’];
$side[‘Blue’] = $b[‘name’];
$side[‘Green’] = $g[‘name’];
$pts[‘Camp’] = “5”;
$pts[‘Keep’] = “25”;
$pts[‘Tower’] = “10”;
$pts[‘Castle’] = “35”;
/*
CALCULATE POINT TOTALS
*/
$battle = $data[‘maps’];
$warzones[‘Center’] = “Eternal Battleground”; $warzonescode[‘Center’] = “eb”;
$warzones[‘BlueHome’] = “Blue Borderlands”; $warzonescode[‘BlueHome’] = “bb”;
$warzones[‘RedHome’] = “Red Borderlands”; $warzonescode[‘RedHome’] = “rb”;
$warzones[‘GreenHome’] = “Green Borderlands”; $warzonescode[‘GreenHome’] = “gb”;
$r[‘tick’] = 0;
$b[‘tick’] = 0;
$g[‘tick’] = 0;
// PRESET TOTALS
$totals[‘eb’][‘sc’] = 0;
$totals[‘eb’][‘tower’] = 0;
$totals[‘eb’][‘keep’] = 0;
$totals[‘eb’][‘castle’] = 0;
$totals[‘bb’][‘sc’] = 0;
$totals[‘bb’][‘tower’] = 0;
$totals[‘bb’][‘keep’] = 0;
$totals[‘bb’][‘castle’] = 0;
$totals[‘gb’][‘sc’] = 0;
$totals[‘gb’][‘tower’] = 0;
$totals[‘gb’][‘keep’] = 0;
$totals[‘gb’][‘castle’] = 0;
$totals[‘rb’][‘sc’] = 0;
$totals[‘rb’][‘tower’] = 0;
$totals[‘rb’][‘keep’] = 0;
$totals[‘rb’][‘castle’] = 0;foreach ($battle as &$v) {
$bg[‘name’] = $warzones[$v[‘type’]];
$bg[‘code’] = $warzonescode[$v[‘type’]];
foreach ($v[‘objectives’] as &$o) {
$id = $o[‘id’];
$type = $objective[$id];
$faction = $side[$o[‘owner’]];
if(isset($o[‘owner_guild’])) {
$claimed = 1;
$text = " and is claimed";
$guild = $o[‘owner_guild’];
} else {
$claimed = 0;
$text = "";
}
if($type == “Keep”) {
$ptsaward = 25;
$objtype = “keep”;
} elseif($type == “Tower”) {
$ptsaward = 10;
$objtype = “tower”;
} elseif($type == “Castle”) {
$ptsaward = 35;
$objtype = “castle”;
} else {
$ptsaward = 5;
$objtype = “sc”;
}
if($faction == “Sanctum of Rall”) {
$totals[$bg[‘code’]][$objtype] = $totals[$bg[‘code’]][$objtype]+1;
}
if($o[‘owner’] == “Red”) { $r[‘tick’] = $r[‘tick’] + $ptsaward; }
if($o[‘owner’] == “Green”) { $g[‘tick’] = $g[‘tick’] + $ptsaward; }
if($o[‘owner’] == “Blue”) { $b[‘tick’] = $b[‘tick’] + $ptsaward; }
}
}
$gb_sc = $totals[‘gb’][‘sc’];
$gb_towers = $totals[‘gb’][‘tower’];
$gb_keeps = $totals[‘gb’][‘keep’];
$gb_pts = ($gb_sc*5) + ($gb_towers*10) + ($gb_keeps*25);$bb_sc = $totals[‘bb’][‘sc’];
$bb_towers = $totals[‘bb’][‘tower’];
$bb_keeps = $totals[‘bb’][‘keep’];
$bb_pts = ($bb_sc*5) + ($bb_towers*10) + ($bb_keeps*25);$rb_sc = $totals[‘rb’][‘sc’];
$rb_towers = $totals[‘rb’][‘tower’];
$rb_keeps = $totals[‘rb’][‘keep’];
$rb_pts = ($rb_sc*5) + ($rb_towers*10) + ($rb_keeps*25);$eb_sc = $totals[‘eb’][‘sc’];
$eb_towers = $totals[‘eb’][‘tower’];
$eb_keeps = $totals[‘eb’][‘keep’];
$eb_castles = $totals[‘eb’][‘castle’];
$eb_pts = ($eb_sc*5) + ($eb_towers*10) + ($eb_keeps*25) + ($eb_castles*35);
Then just take the values and do what you like with them. I insert them into a database. I also cron job the script to run every 15 minutes.
Founder, Gaiscioch Community [GSCH] | Gaiscioch Magazine | Twitch | YouTube | Twitter
Proud Resident of Mercenary Server Sanctum of Rall | 6 Year Extra-Life Charity Event Participant