Commanders¶
A commander leads an army out of the castle; a castellan defends one.
The server knows both as "lords" (command gli, field LID); the game's
interface and this library call them commanders and castellans.
for commander in client.commanders.get_commanders():
print(commander.commander_id, commander.name, commander.wins, commander.defeats)
for item in commander.equipment:
print(" ", item.equipment_id, item.slot, item.enchantment_level)
castellans = client.commanders.get_castellans()
Both lists come back from the same request; client.commanders.get_all()
returns the whole reply when you want both at once. Both are in the game's
order: commanders by id, castellans by portrait.
The login data already carries the list, and state keeps the last one any reply brought (a rename, a general assignment, an attack info reply, ...), so reading it costs no request:
Who is free to lead¶
idle_commanders and travelling_commanders split the roster by the
movements in state, again without a request. A commander leading one of your
movements is travelling until that movement leaves state, its way home
included. A returning commander stays travelling for one additional second
before appearing in idle_commanders.
The one-second return hold mitigates a measured timing race: the server can
still consider the commander busy after the local movement timer expires.
It is library policy beyond the game client, not confirmation of server
readiness. Movement expiry and arrival callbacks still happen on time.
Outbound attacks get the same one-second margin to bridge the return packet.
A return movement keeps the commander busy for its full trip and return margin.
If no return arrives, the outbound margin expires rather than reserving the
commander indefinitely. Other outbound movements add no hold. No background
confirmation polling is performed. Server rejections such as GGEError.LORD_IS_USED still raise
CommandError, without an automatic retry.
idle = client.commanders.idle_commanders
if idle:
client.attack.send_attack(..., commander_id=idle[0].commander_id)
Rename¶
rename takes either kind and returns the updated CommanderRoster.
The premium commander¶
PREMIUM_COMMANDER_ID (-14) is the premium commander, which the game offers
from level 10. Leading with it is free while your VIP level gives free premium
commanders that you have not used today, or while a premium account runs.
Otherwise it costs rubies, and the game asks first.
from empire_core.commanders import PREMIUM_COMMANDER_ID
from empire_core.gamedata import Unit
print(client.commanders.free_premium_commanders()) # None before the login data
if client.commanders.premium_commander_is_free():
client.movements.send_support(
source_castle_id, target_x, target_y, units={Unit.SWORDMAN: 50},
commander_id=PREMIUM_COMMANDER_ID, use_premium_commander=True,
)
The count comes from state: your VIP points, VIP time and the premium
commanders used today arrive in the login data's vip and in every vip the
server pushes. free_premium_commanders needs the game data only while VIP
time runs. The server sends no vip with a send's reply, so the library
counts its own accepted premium sends (without a premium account) as used
until the next vip arrives; that is the library's choice, not something the
game client does.
send_support, send_troops and send_attack never spend rubies on the
premium commander unless you pass spend_rubies=True. Led by it
(use_premium_commander=True or commander_id=PREMIUM_COMMANDER_ID) when it
is not free, or when that is not known yet, they raise
PremiumCommanderCostError and send nothing. The check and the send hold one
lock, so two premium sends at once cannot both take the last free one.
One known gap: for a conquer attack (attack_type=AttackType.CONQUER) the
game client sends BPC 0 without asking for rubies, whichever commander
leads, unless the target is a capital, village, royal tower, resource island,
monument or laboratory. send_attack does not know the target's area type, so
it checks such an attack like any other; pass use_premium_commander=False
and spend_rubies=True to send what the client sends there.
Related¶
- Skills and generals: a general is assigned to a commander.
- Equipment: putting items on commanders and castellans.
- Attack: every attack is led by a commander.
API: CommandersService,
Commander