API talk:1/event details

From Guild Wars 2 Wiki
Jump to: navigation, search

Deserializing the JSON in its current format is difficult because the event ID becomes the object name/type. I think a more desirable format for future versions of the API would be something like...

{

   "events": [
       {
           "id": "EED8A79F-B374-4AE6-BA6F-B7B98D9D7142",
           "name": "Defeat the renegade charr.",
           "level": 42,
           "map_id": 20,
           "flags": [],
           "location": {
               "type": "sphere",
               "center": [
                   -9463.6,
                   -40310.2,
                   -785.799
               ],
               "radius": 2500,
               "rotation": 0
           }
       },
       {
           "id": "BA2B85C5-DE73-4402-BD84-8F53AA394A52",
           "name": "Bonus Event: Cull the Flame Legion",
           "level": 80,
           "map_id": 929,
           "flags": [
               "group_event"
           ],
           "location": {
               "type": "cylinder",
               "center": [
                   -38.7202,
                   -176.915,
                   -892.494
               ],
               "height": 2027.5,
               "radius": 10314.4,
               "rotation": 0
           }
       },
       {
           "id": "CEA84FBF-2368-467C-92EA-7FA60D527C7B",
           "name": "Find a way to open the door and escape the armory.",
           "level": 8,
           "map_id": 19,
           "flags": [
               "group_event"
           ],
           "location": {
               "type": "poly",
               "center": [
                   -45685.2,
                   -13819.6,
                   -1113
               ],
               "z_range": [
                   -2389,
                   163
               ],
               "points": [
                   [
                       -49395.8,
                       -15845.5
                   ],
                   [
                       -42699.7,
                       -15794.1
                   ],
                   [
                       -43053,
                       -14081.4
                   ],
                   [
                       -43629.7,
                       -11725.4
                   ],
                   [
                       -49647.8,
                       -11651.7
                   ]
               ]
           }
       }
   ]

}

Radius[edit]

To convert the radius of an event from the event coordinate system to the the world coordinate system, the radius can be multiplied by 0.042, or 1/24.

Simple proof:

// From "https://wiki.guildwars2.com/wiki/API:1/event_details#Coordinate_recalculation"
function recalc_coords(continent_rect, map_rect, coords){
	return [
		Math.round(continent_rect[0][0]+(continent_rect[1][0]-continent_rect[0][0])*(coords[0]-map_rect[0][0])/(map_rect[1][0]-map_rect[0][0])),
		Math.round(continent_rect[0][1]+(continent_rect[1][1]-continent_rect[0][1])*(1-(coords[1]-map_rect[0][1])/(map_rect[1][1]-map_rect[0][1])))
	]
}

// From "https://api.guildwars2.com/v1/event_details.json"
var event = {"name":"Defeat the renegade charr.","level":42,"map_id":20,"flags":[],"location":{"type":"sphere","center":[-9463.6,-40310.2,-785.799],"radius":2500,"rotation":0}};

// From "https://api.guildwars2.com/v1/maps.json"
var map = {"map_name":"Blazeridge Steppes","min_level":40,"max_level":50,"default_floor":1,"type":"Public","floors":[0,1,2],"region_id":2,"region_name":"Ascalon","continent_id":1,"continent_name":"Tyria","map_rect":[[-24576,-49152],[24576,49152]],"continent_rect":[[29184,12160],[31232,16256]]};

// Getting what we want
var c = map.continent_rect;
var m = map.map_rect;
var e = event.location.center;
var r = event.location.radius;

// Two sample points
var a = recalc_coords(c, m, e); // First point using event center
var b = recalc_coords(c, m, [e[0],e[1]+r]); // Second point r units vertically displaced from event center, on the outer edge of the circle

console.log(a); // [ 29814, 15888 ]
console.log(b); // [ 29814, 15783 ]

// Difference after converting to world coordinate system
var x = b[1] - a[1];

// Conversion ratio
console.log(x/r); // x = 0.042 .... approximately = 1/24

I wish I knew the reason why it was 1/24. -Chieftain AlexUser Chieftain Alex sig.png 23:50, 27 March 2017 (UTC)