Thread Rating:
  • 6 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API Knowledgebase Questionthread
Author Message
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #11
RE: API Knowledgebase Questionthread
Topper, what do you think is the easiest way to calculate loot from a base?

So far, been doing it by going building by building, checking it's HP (0-1), and multiplying it by the resources given for a certain building at a certain level and adding it to the resource type of that specific building.

Not to mention, to get the building list I had to bypass obfuscated code, so perhaps you can ease it on me.

Here is how I get buildings list:
Code:
function getBuildingsList(){
    var curCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
    for (var k in curCity.get_CityBuildingsData()){
        o = curCity.get_CityBuildingsData()[k];
        if (o === null) continue;
        if (typeof(o.l) == 'undefined') continue;
        if (o.l.length === 0) continue;
        var buildings = o;
    }
    return buildings.l;
}

If u think there's any easier way I would like to hear it =)

Kind regards,
Deyhak.
05-10-2012 01:40 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #12
RE: API Knowledgebase Questionthread
(05-10-2012 01:40 PM)Deyhak Wrote:  Topper, what do you think is the easiest way to calculate loot from a base?

So far, been doing it by going building by building, checking it's HP (0-1), and multiplying it by the resources given for a certain building at a certain level and adding it to the resource type of that specific building.

Not to mention, to get the building list I had to bypass obfuscated code, so perhaps you can ease it on me.

Here is how I get buildings list:
Code:
function getBuildingsList(){
    var curCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
    for (var k in curCity.get_CityBuildingsData()){
        o = curCity.get_CityBuildingsData()[k];
        if (o === null) continue;
        if (typeof(o.l) == 'undefined') continue;
        if (o.l.length === 0) continue;
        var buildings = o;
    }
    return buildings.l;
}

If u think there's any easier way I would like to hear it =)

Kind regards,
Deyhak.

Hi,

to circumvent the obfuscation i would suggest use the

var listBuildings = curCity.get_CityBuildingsData().GetAllBuildingsByTechName(Base.ETechName techName)

function and iterate over the enum.

to get the repair costs of a building, what's actually also the loot, use this:
var/*Base.ResourceCost[]*/ costs = Base.Util.FilterResourceCosts(building.get_UnitLevelRepairRequirements(), false);

and use the health of the building like before to get the real loot value.

i hope this will help you.
05-10-2012 03:41 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #13
RE: API Knowledgebase Questionthread
Correct me if I am wrong, GetAllBuildingsByTechName isn't implemented yet?
(This post was last modified: 05-10-2012 05:11 PM by Deyhak.)
05-10-2012 04:40 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #14
RE: API Knowledgebase Questionthread
(05-10-2012 04:40 PM)Deyhak Wrote:  Correct me if I am wrong, GetAllBuildingsByTechName isn't implemented yet?

you'r right it is not yet patched, but you could use the:

ClientLib.Vis.City.City.GetAllBuildingsFromType (ClientLib.Base.ETechName eTechName)

this gives you a list of ClientLib.Vis.City.CityBuilding.

ClientLib.Vis.City.CityBuilding.get_BuildingDetails() gives you the Data.CityBuilding.
05-10-2012 05:27 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #15
RE: API Knowledgebase Questionthread
I'll give it a shot. Thanks!
05-10-2012 06:17 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #16
RE: API Knowledgebase Questionthread
@Topper

Does the function GetAllBuildingsFromType also don't yet support forgotten bases ?

I got nulls.

Here's my code:

Code:
var city = ClientLib.Vis.VisMain.GetInstance().get_City();
for (var k in (ClientLib.Base.ETechName)){
    var buildingList = city.GetAllBuildingsFromType(ClientLib.Base.ETechName.k);
    console.log(buildingList);
}


Any thoughts?
06-10-2012 05:07 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #17
RE: API Knowledgebase Questionthread
(06-10-2012 05:07 PM)Deyhak Wrote:  @Topper

Does the function GetAllBuildingsFromType also don't yet support forgotten bases ?

I got nulls.

Here's my code:

Code:
var city = ClientLib.Vis.VisMain.GetInstance().get_City();
for (var k in (ClientLib.Base.ETechName)){
    var buildingList = city.GetAllBuildingsFromType(ClientLib.Base.ETechName.k);
    console.log(buildingList);
}


Any thoughts?

I haven't currently access to the code but i would gues yes. But i found another function which isn't that cool but should do the job.

ClientLib.Vis.VisMain.GetInstance().get_City().GetObjectFromPosition(x,y)
(This post was last modified: 06-10-2012 05:29 PM by Topper42.)
06-10-2012 05:29 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #18
RE: API Knowledgebase Questionthread
Yes I have thought of that as well.

Correct me if I am wrong, the grid goes from 0 to 8?

I made a for from 0 to 8 for x and y and all returned nulls!

Something is seriously wrong with the forgotten bases code.
06-10-2012 06:27 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #19
RE: API Knowledgebase Questionthread
(06-10-2012 06:27 PM)Deyhak Wrote:  Yes I have thought of that as well.

Correct me if I am wrong, the grid goes from 0 to 8?

I made a for from 0 to 8 for x and y and all returned nulls!

Something is seriously wrong with the forgotten bases code.

I tried the function(on closed beta 1):
ClientLib.Vis.VisMain.GetInstance().get_City().GetObjectFromPosition(x,y)
x: 0-8 and y: 0-7

The function will return empty resource fields too.

it works well even for camps and bases. you need to be in the city of course or at least set the city as the current city if you need it in the region.
(ClientLib.Data.Cities.prototype.set_CurrentCityId(id))

EDIT:
sorry the function takes pixel coordinates so just use: x: 0-8 and multiply with
ClientLib.Vis.VisMain.GetInstance().get_City().get_GridWidth() and y: 0-7 and multiply with ClientLib.Vis.VisMain.GetInstance().get_City().get_GridHeight()
(This post was last modified: 06-10-2012 07:50 PM by Topper42.)
06-10-2012 07:18 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #20
RE: API Knowledgebase Questionthread
I shall try, thanks!
06-10-2012 10:25 PM
 Search   Quote 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)