Jump to content
Game-Labs Forum

Public "API" for Naval Action


Recommended Posts

function getAllTowns(){
 var options = {
     "contentType" : "ContentService.MimeType.JAVASCRIPT",
   };

var url_ports = "http://storage.googleapis.com/nacleanopenworldprodshards/Ports_cleanopenworldprodeu1.json";
eval(UrlFetchApp.fetch(url_ports,options).getContentText());// Ports
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Ports");
  sheet.getRange(1, 1, 368, 4).clearContent();

  sheet.getRange(1, 1).setValue("Id");
  sheet.getRange(1, 2).setValue("Name");
  sheet.getRange(1, 3).setValue("NationId");
  sheet.getRange(1, 4).setValue("Nation Name");
  sheet.getRange(1, 5).setValue("ConquestFlagTimeSlot");
  sheet.getRange(1, 6).setValue("LordProtector");
  
  var index = 0;
  var Nation = "not set";
  for(index = 0; index < Ports.length; index++){
    switch(Ports[index].Nation)
    {
      case 0: Nation = "Neutral";
      break;
      case 1: Nation = "Pirates";
      break;
      case 2: Nation = "Espana";
      break;
      case 3: Nation = "France";
      break;
      case 4: Nation = "Great Britain";
      break;
      case 5: Nation = "Verenigde Provincien";
      break;
      case 6: Nation = "Danmark-Norge";
      break;
      case 7: Nation = "Sverige";
      break;
      case 8: Nation = "United States";
      break;
      case 9: Nation = "Free Towns";
      break;
      default: Nation = "not set";
    }
  sheet.getRange(index+2, 1).setValue(Ports[index].Id);
  sheet.getRange(index+2, 2).setValue(Ports[index].Name);
  sheet.getRange(index+2, 3).setValue(Ports[index].Nation);
  sheet.getRange(index+2, 4).setValue(Nation);
  sheet.getRange(index+2, 5).setValue(Ports[index].ConquestFlagTimeSlot);
  sheet.getRange(index+2, 6).setValue(Ports[index].Capturer);
  }
}

man, those breaks are ugly. But I dig the google doc.

 

Those case statements are not even necessary as all they do is provide a name to. 

(pseudo code fix for break statments)

 

for(int NUM; <= portsList.size; NUM++)

  

sheet.getRange(NUM+2, 1).setValue.arrayOfPorts[NUM].Id);

sheet.getRange(NUM+2, 2).setValue.arrayOfPorts[NUM] .Name);

sheet.getRange(NUM+2, 3).setValue.arrayOfPorts[NUM] .NationID);

sheet.getRange(NUM+2, 4).setValue.arrayOfPorts[NUM] .Nation;

sheet.getRange(NUM+2, 5).setValue.arrayOfPorts[NUM] .ConquestFlagTimeSlot;

sheet.getRange(NUM+2, 6).setValue.arrayOfPorts[NUM] .Capturer);

Link to comment
Share on other sites

I like the data dumps. If you're new to json you can see it formatted on sites like http://jsonviewer.stack.hu/(no affiliation there). Load the URL to the specified file name in the "API" spec.

 

I'm not convinced that making the data available, or even available in real time would negatively impact game play. After all, you can just ask in the forums what "iron ore" is selling at in Kingston/Port Royal and someone will probably answer. Maybe not for every port but I guess that depends on numerous factors that beyond the scope of this thread. I don't see stats on how many players are sailing from port to port every day to check prices or if the requirement to do so in order to get updated prices affects the time they spend in the game. However, why not try? Doesn't that sort of thing fall in line with testing?

 

I'd like to see a real-time tool publishing the data from the database, or even in semi-real time like an update every 30 minutes and accessible via an easily coded open API like REST. If the server hit is, or becomes too much of a burden then data dumps could be made to a NoSql solution running on CUDA. You can process millions of records per second with a good GPU and not worry about performance as much as band width.

 

These data dumps are cool. Thanks for sharing.

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Hi there.

Here is an other map done thanks to this api. The goal was to try to gather all features we can find on differents map (like burningsails, tdamap etc...) and add some features.

The map is Siegfried's map, thank you for your amazing job !

 

You can find it here : http://map.licornes.eu/

This is an opensource project under MIT licence so you can do almost whatever you want with it : https://github.com/Rodrive/na-map

You can contribute to it and report some issues or event features requests. I will i accept pull requests, all your help is welcome.

 

I am developing it on my free time so the evolution may be low and the code quality not great since i dont have the time to refactor it (and new with the techno).

It works pretty well with chrome but i'm having issues with some firefox users, the map is lagging / freezing but i didnt succeed to reproduce on my own environment those issues.

  • Like 3
Link to comment
Share on other sites

Hi there.

Here is an other map done thanks to this api. The goal was to try to gather all features we can find on differents map (like burningsails, tdamap etc...) and add some features.

The map is Siegfried's map, thank you for your amazing job !

 

You can find it here : http://map.licornes.eu/

This is an opensource project under MIT licence so you can do almost whatever you want with it : https://github.com/Rodrive/na-map

You can contribute to it and report some issues or event features requests. I will i accept pull requests, all your help is welcome.

 

I am developing it on my free time so the evolution may be low and the code quality not great since i dont have the time to refactor it (and new with the techno).

It works pretty well with chrome but i'm having issues with some firefox users, the map is lagging / freezing but i didnt succeed to reproduce on my own environment those issues.

 

I'm afraid you are coming up as a 'dangerous website' in my Internet Security. There are 'Drive By Downloads' on your site according to it. You might want to take a look at what might be causing that...?

 

trtc_sig.png

Link to comment
Share on other sites

I'm afraid you are coming up as a 'dangerous website' in my Internet Security. There are 'Drive By Downloads' on your site according to it. You might want to take a look at what might be causing that...?

 

trtc_sig.png

 

Hi, thanks for your feedback. Unfortunatly you are the first one to have this issue. Can you tell me a bit more about what is your browser and which version please.

Link to comment
Share on other sites

Hi there.

Here is an other map done thanks to this api. The goal was to try to gather all features we can find on differents map (like burningsails, tdamap etc...) and add some features.

The map is Siegfried's map, thank you for your amazing job !

 

You can find it here : http://map.licornes.eu/

This is an opensource project under MIT licence so you can do almost whatever you want with it : https://github.com/Rodrive/na-map

You can contribute to it and report some issues or event features requests. I will i accept pull requests, all your help is welcome.

 

I am developing it on my free time so the evolution may be low and the code quality not great since i dont have the time to refactor it (and new with the techno).

It works pretty well with chrome but i'm having issues with some firefox users, the map is lagging / freezing but i didnt succeed to reproduce on my own environment those issues.

Super

Link to comment
Share on other sites

Hi, thanks for your feedback. Unfortunatly you are the first one to have this issue. Can you tell me a bit more about what is your browser and which version please.

 

It's the Norton internet security plugin in chrome that's giving me the warning. If I drill down further into the info it's giving it's talking about the fact that you are redirected from the domain name given to another site which 'is known to host malicious downloads'. Are you hosting on some kind of shared webspace? It's probably someone else that is causing the problem, but I thought I'd give you the head's up.

 

This is a link to the info I get (In Dutch I'm afraid...unless it works out the language from your computer settings)

 

https://safeweb.norton.com/report/show?url=http:%2F%2Fmap.licornes.eu%2F&product=NSBU&version=22.6.0.142〈=1301&source=toolbar

 

trtc_sig.png

Link to comment
Share on other sites

It's the Norton internet security plugin in chrome that's giving me the warning. If I drill down further into the info it's giving it's talking about the fact that you are redirected from the domain name given to another site which 'is known to host malicious downloads'. Are you hosting on some kind of shared webspace? It's probably someone else that is causing the problem, but I thought I'd give you the head's up.

 

This is a link to the info I get (In Dutch I'm afraid...unless it works out the language from your computer settings)

 

https://safeweb.norton.com/report/show?url=http:%2F%2Fmap.licornes.eu%2F&product=NSBU&version=22.6.0.142〈=1301&source=toolbar

 

trtc_sig.png

Thanks for giving me those details. It's really strange what Norton tells you. I dont host anything else than this map and other local stuff on this server... Moreover the threat is "Drive by download". But the map only calls this exacts same url : all ressources download come from map.licornes.eu not from another website which could inject malicious content like malware or other stuff. It's like Norton had put this url in an "untrusted list" but the thing is this url had been created 5 days ago and i dont have any other site on this url...

 

But again thanks for your investigation and report. I will try to fix this with Norton.

Link to comment
Share on other sites

I think, the best solution is check http headers (request HEAD) x-goog-hash or Etag.
If values changed from last time then download new data.
===
Я думаю, лучшим решением будет проверка http заголовков x-goog-hash или Etag используя запрос HEAD.
Если заголовки изменились с прошлой проверки, то необходимо загрузить данные.

If ((x-goog-hash <> x-goog-hash_last) or (Etag <> Etag_last)) then update_data else exit;
HEAD http://storage.googleapis.com/nacleanopenworldprodshards/ItemTemplates_cleanopenworldprodeu1.json HTTP/1.1

HTTP/1.1 200 OK
X-GUploader-UploadID: AEnB2UoIQL2VQm8UwPS477Ybx3jkp-pannbrY917cxyK5kg7592neUadToUsK1H1IOo8c-KlZsFsUvwzeDjCr4ykWIhDtQ88dA
Date: Wed, 25 May 2016 07:41:28 GMT
Cache-Control: max-age=14400
Expires: Wed, 25 May 2016 11:41:28 GMT
Last-Modified: Tue, 24 May 2016 07:20:03 GMT
ETag: "1ce8bae9a854fd90b52a146734e99ea8"
x-goog-generation: 1464074403842000
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 641380
Content-Type: text/plain
x-goog-hash: crc32c=W2psAw==
x-goog-hash: md5=HOi66ahU/ZC1KhRnNOmeqA==
x-goog-storage-class: STANDARD
Accept-Ranges: bytes
Content-Length: 641380
Server: UploadServer

Link to comment
Share on other sites

A couple of questions about the ConquestFlagTimeSlot attribute:

 

* ConquestFlagTimeSlot == -1 when the port is not susceptible to capture (a capital or free town), though there are some ports that have -1 anyway.  Does -1 also indicate cases where the capturer forget to set the Conquest Time Slot?

 

* How is the "can't be bought from N to M" time window (shown in game) determined?  Is there a rule?

 

Thanks!

Link to comment
Share on other sites

A couple of questions about the ConquestFlagTimeSlot attribute:

 

* ConquestFlagTimeSlot == -1 when the port is not susceptible to capture (a capital or free town), though there are some ports that have -1 anyway.  Does -1 also indicate cases where the capturer forget to set the Conquest Time Slot?

 

* How is the "can't be bought from N to M" time window (shown in game) determined?  Is there a rule?

 

Thanks!

ConquestFlagTimeSlot is -1 when the capture window is "anytime", otherwise it indicates the starting hour of a 2-hour window in the UTC timezone.

 

"Cant be bought" <- Referring to conquest flags? They all have the same cant-be-bought window, which is basically the hours surrounding the server maintenance time window.

Link to comment
Share on other sites

Thanks for the confirmation that -1 is anytime, except for those that can't be captured.

 

Before I asked, I checked to see if any of the "Can't be bought" times were different, or if they were all the same -- I guess I made a mistake there.

 

Thanks!

Link to comment
Share on other sites

The only ones that cannot be captured are capitals AFAIK, so you should be safe to do something along these lines:

 

if(port.capital)
{
  console.log('It cannot be captured.');
}
else
{
  console.log('It can be captured '+ translateCaptureWindow(port.timeslot));
}

function translateCaptureWindow(baseWindow) {
  var padLeft = function(inpt) {
    var str = "" + inpt;
    var pad = "00";
    return pad.substring(0, pad.length - str.length) + str;
  };
  if(baseWindow == -1)
  {
    return 'anytime';
  }
  else {
    baseWindow = parseInt(baseWindow);
    return 'between '+ padLeft(baseWindow) +' and '+ padLeft(parseInt(baseWindow+2)) +' UTC';
  }
}
Link to comment
Share on other sites

  • 2 weeks later...

 Are modules not regularItems? This is from SetupItemData. How do I reference modules, I already got them on the list but it wont recognize them in the shop. 

   for (var p = 0; p < Shops[i].RegularItems.length; p++) {
                        if (Shops[i].RegularItems[p].TemplateId == item.Id) {d
                            var amount = Shops[i].RegularItems[p].Quantity;
                            var sellPrice = Shops[i].RegularItems[p].SellPrice;
                            var buyPrice = Shops[i].RegularItems[p].BuyPrice;

                            info += " <span class=\"label label-default\">"
                                        + "<span class=\"label label-warning label-pill pull-xs-left\">" + amount + "</span> "
                                        + "<span class=\"label label-danger label-pill pull-xs-left\">" + buyPrice + "</span> "
                                        + "<span class=\"label label-info label-pill pull-xs-left\">" + sellPrice + "</span> "
                                        + getPortFromId(Shops[i].Id).Name + "</span> ";

                            break;
                        }
                    }
Link to comment
Share on other sites

A follow up to my previous question, I managed to get shops that have available mods to show up by modifying the statement to include names. 

removed because broken

To show all template names instead of just resources,

I changed 

  var templateNames = [];
            for (var t in ItemTemplates) {
                if (ItemTemplates[t].__type.indexOf("MaterialTemplate") != -1
                    || ItemTemplates[t].__type.indexOf("ResourceTemplate") != -1) {
                    suggestions.push(ItemTemplates[t].Name);
                    templateNames.push(ItemTemplates[t].Name);
                }
            }

to

var templateNames = [];
            for (var t in ItemTemplates) {
               
                	
                    suggestions.push(ItemTemplates[t].Name);
                    templateNames.push(ItemTemplates[t].Name);
                    			
                
            }

Still having trouble with 

if (Shops[i].RegularItems[p].TemplateId == item.Id)


How do I compare a module name?

Edited by Crayon
Link to comment
Share on other sites

Id like to request that the port cool down date info be added to the port data feed, e.g. the seven-day cool down proposed for the June 28th update. Ideally, just add a date component to the port battle window time field.

Having that data available will make both in-game and real life planning much less tedious.

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...