Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New API Code with December Update
Author Message
rhiordd Offline
Producer
*******

Posts: 2,997
Joined: Dec 2011
Post: #1
New API Code with December Update
The new fresh API:

We moved our API functions into a separate namespace, This makes it is easier to understand what the API is and what are just unobfuscated functions.
These function will be tested before every update and this ensures that they are working correctly.

Code:
ClientLib.API

ClientLib.API.Battleground.GetInstance()
ClientLib.API.Battleground.SimulateBattle()
ClientLib.API.Battleground.GetSimulateBattleEndInfos()
ClientLib.API.Battleground.OnSimulateBattleFinished

ClientLib.API.City.GetInstance()
ClientLib.API.City.UpgradeBuildingToLevel(building, newLevel)
ClientLib.API.City.UpgradeAllBuildingsToLevel(newLevel)

ClientLib.API.Util.GetUnitRepairCosts(unitLevel, unitMDBId, damageRatio)

Examples:

Combat simulation with Replay(without unit informations):
Code:
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
ClientLib.API.Battleground.GetInstance().SimulateBattle();
var app = qx.core.Init.getApplication();
app.getPlayArea().setView(ClientLib.Data.PlayerAreaViewMode.pavmCombatReplay, city.get_Id(), 0, 0);

Combat simulation with Replay(with unit information):
Code:
phe.cnc.Util.attachNetEvent(ClientLib.API.Battleground.GetInstance(), "OnSimulateBattleFinished", ClientLib.API.OnSimulateBattleFinished, this, this.OnSimulateBattleFinished);
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
ClientLib.API.Battleground.GetInstance().SimulateBattle();
var app = qx.core.Init.getApplication();
app.getPlayArea().setView(ClientLib.Data.PlayerAreaViewMode.pavmCombatReplay, city.get_Id(), 0, 0);

OnSimulateBattleFinished: function(data)
{
    for (var i = 0; i < data.length; i++)
    {
       var combatId = data[i].Key;
       var unitData = data[i].Value;
      
       var unitMDBID = unitData.t;
       var unitLevel = unitData.l;
       var unitStartHealth = unitData.sh;
       var unitEndHealth = unitData.h;
      
       var repairCosts = ClientLib.API.Util.GetUnitRepairCosts(unitLevel, unitMDBID, unitStartHealth / unitEndHealth);
    }
}

Combat simulation without Replay(with unit information):
Code:
phe.cnc.Util.attachNetEvent(ClientLib.API.Battleground.GetInstance(), "OnSimulateBattleFinished", ClientLib.API.OnSimulateBattleFinished, this, this.OnSimulateBattleFinished);
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
ClientLib.API.Battleground.GetInstance().GetSimulateBattleEndInfos();

OnSimulateBattleFinished: function(data)
{
    for (var i = 0; i < data.length; i++)
    {
       var combatId = data[i].Key;
       var unitData = data[i].Value;
      
       var unitMDBID = unitData.t;
       var unitLevel = unitData.l;
       var unitStartHealth = unitData.sh;
       var unitEndHealth = unitData.h;
      
       var repairCosts = ClientLib.API.Util.GetUnitRepairCosts(unitLevel, unitMDBID, unitStartHealth / unitEndHealth);
    }
}

Upgrade all buildings of the current own city:
Code:
var newLevel = 25
ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(newLevel);

Upgrade one building of the current own city:
Code:
var newLevel = 25
var obj = ClientLib.Vis.VisMain.GetInstance().get_SelectedObject();
if (obj != null && obj.get_VisObjectType() == ClientLib.Vis.VisObject.EObjectType.CityBuildingType)
    ClientLib.API.City.GetInstance().UpgradeBuildingToLevel(obj.get_BuildingDet​ails(), newLevel);

Please always remember. We cannot guarantee working scripts and tools if they dont go through our official API. EA Phenomic does not take any responsibility for working tools in any case.

Please use the provided forum channel for any further questions or requests. Our Development team is very eager to make life as much comfortable as possible.

Thanks.

06-12-2012 03:28 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #2
RE: New API Code with December Update
Big Like =)
10-12-2012 10:59 AM
 Search   Quote 
Tecin Offline
Junior Member
**

Posts: 9
Joined: May 2012
Post: #3
RE: New API Code with December Update
(06-12-2012 03:28 PM)EA_rhiordd Wrote:  Upgrade all buildings of the current own city:
Code:
var newLevel = 25
ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(newLevel);

First quick question: are there similar function for defense and units?

Also i have a problem with this function, because it does not seem to work for me like i expect.

I tested it with this base:
- Hand of Nod and War Factory at level 27
- all other buildings are level 28
- about enough ressources to upgrade Hand of Nod and War Factory

Now my script trys to upgrade all buildings to the level of the construction yard - which got evaluated correctly with 28, but the function:

ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(28);

ended with my base like this:
- Construction Yard at level 29
- War Factory still at level 27
- all other buildings including Hand of Nod are level 28

After transfering resources and testing it again the construction yard got upgraded to level 30, instead of the others buildings being upgraded to level 29.

Is it intended that the construction yard gets upgraded every time or am i doing something wrong?

Thanks,
Tecin
11-12-2012 09:41 AM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #4
RE: New API Code with December Update
(11-12-2012 09:41 AM)Tecin Wrote:  
(06-12-2012 03:28 PM)EA_rhiordd Wrote:  Upgrade all buildings of the current own city:
Code:
var newLevel = 25
ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(newLevel);

First quick question: are there similar function for defense and units?

Also i have a problem with this function, because it does not seem to work for me like i expect.

I tested it with this base:
- Hand of Nod and War Factory at level 27
- all other buildings are level 28
- about enough ressources to upgrade Hand of Nod and War Factory

Now my script trys to upgrade all buildings to the level of the construction yard - which got evaluated correctly with 28, but the function:

ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(28);

ended with my base like this:
- Construction Yard at level 29
- War Factory still at level 27
- all other buildings including Hand of Nod are level 28

After transfering resources and testing it again the construction yard got upgraded to level 30, instead of the others buildings being upgraded to level 29.

Is it intended that the construction yard gets upgraded every time or am i doing something wrong?

Thanks,
Tecin

The function is very simple, it calls for every building the ClientLib.API.City.GetInstance().UpgradeBuildingToLevel(building, newLevel) function. This function upgrades that one building to the new level until the level is reached or you don't have enough resources anymore for the next level.
(This post was last modified: 11-12-2012 10:03 AM by Topper42.)
11-12-2012 10:02 AM
 Search   Quote 
Tecin Offline
Junior Member
**

Posts: 9
Joined: May 2012
Post: #5
RE: New API Code with December Update
Thanks,
but still why did the construction yard end up at level 29 when i called UpgradeAllBuildingsToLevel() to upgrade all buildings to level 28?
11-12-2012 11:36 AM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #6
RE: New API Code with December Update
my script does not recognize "phe"
11-12-2012 11:48 AM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #7
RE: New API Code with December Update
(11-12-2012 11:36 AM)Tecin Wrote:  Thanks,
but still why did the construction yard end up at level 29 when i called UpgradeAllBuildingsToLevel() to upgrade all buildings to level 28?

Hi,

yeah you are right, there is still a bug in that function that is upgrades on level more than you specifiy in the parameter.
11-12-2012 01:41 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #8
RE: New API Code with December Update
(11-12-2012 11:48 AM)Deyhak Wrote:  my script does not recognize "phe"

probably your world isn't patched yet. I tried the Closed Beta 1 world and there it is defined.
11-12-2012 01:47 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #9
RE: New API Code with December Update
Im under the impression that all worlds were patched o.O
11-12-2012 04:43 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #10
RE: New API Code with December Update
(11-12-2012 04:43 PM)Deyhak Wrote:  Im under the impression that all worlds were patched o.O

sadly no, if i remember right there was a false news message on the website, that said all worlds will be patched.
11-12-2012 05:01 PM
 Search   Quote 


Forum Jump:


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