Skip to content

Latest commit

 

History

History
777 lines (649 loc) · 19.8 KB

README.md

File metadata and controls

777 lines (649 loc) · 19.8 KB

pyogame

logo

OGame is a browser-based, money-management and space-war themed massively multiplayer online browser game with over two million accounts.

This lib is supposed to help write scripts and bots for your needs. it supports ogame_version: 8.4.0 version 22

install

pip install ogame

update

pip install ogame==8.4.0.22

dont want to wait for new updates download direct from the develop branch

pip install git+https://github.com/alaingilbert/pyogame.git@develop

get started

Code Snippets

Code Style

Discord

Join Discord

You wanna try a finished bot

pyogame.net~~

functions

login

from ogame import OGame
from ogame.constants import destination, coordinates, ships, mission, speed, buildings, status
 
empire = OGame(UNI, USER, PASSWORD)

#optional
empire = OGame(UNI, USER, PASSWORD, user_agent='NCSA_Mosaic/2.0 (Windows 3.1)', 
                                    proxy='https://proxy.com:port', 
                                    language='us'
)

test

This is a command that will try to run all functions with parameters. 
empire.test()                       returns bool

If this lib is running for long time it is recommended to test it during run time. 
If it fails you can set up a telegram message. A test creates alot of traffic

if not empire.test():
    raise RuntimeWarning("Pyogame test failed, there are functions that dont work anymore. Be Careful")
    # warn the User

get attacked

empire.attacked()                   returns bool 

get neutral

empire.neutral()                    returns bool 

get friendly

empire.friendly()                   returns bool 

get server (universe)

server = empire.server()
server.version                      returns str
server.Speed.universe               returns int
server.Speed.fleet                  returns int
server.Donut.galaxy                 returns bool
server.Donut.system                 returns bool

get characterclass

Get the class of your Ogame Account['miner', 'explorer', 'warrior', 'none]
empire.character_class()            return string

get rank

empire.rank()                       return int

get planet id's

empire.planet_ids()                 returns list 

empire.id_by_planet_name('name')    returns int

empire.name_by_planet_id(id)        return string

empire.planet_names()               returns list

get moon id's

empire.moon_ids()                   returns list

empire.moon_names()                 returns list

**keep in mind to prefer planets id's moon id dont works on every function**

abandon planet

empire.abandon_planet(id)           returns bool

** keep in mind that this is truly final, that no more fleets are needed at the 
departure or destination of this planet and that there is no construction or research underway on it.

rename planet

empire.rename_planet(id,'new_name') returns bool

** keep in mind that the name must contain at least two characters **

coordinates

coordinates have the format [galaxy, system, position, destination]

destination is referred to planet moon or debris on that coordinate planet=1 debris=2 moon=3
for example [1,200,16,3] = galaxy=1, system=200, position=16, destination=3 for moon
with from ogame.constants import destination the process is much more readable.

when you dont give it an destination it will default to planet

                                        returns list
from ogame.constants import coordinates, destination
pos = coordinates(
    galaxy=1,
    system=2,
    position=12,
    dest=destination.debris
)

coordinates(1, 2, 12, destination.moon)
coordinates(1, 2, 12, destination.debris)
coordinates(1, 2, 12, destination.planet) or coordinates(1, 2, 12)

get slot celestials

returns how many planet slots are free to colonize

slot = empire.slot_celestial()          returns class
slot.free                               returns int
slot.total                              returns int

get celestial

works with planet's and moon's

celestial = empire.celestial(id)        returns class
celestial.temperature                   returns list
celestial.diameter                      returns int
celestial.coordinates                   returns list
celestial.used                          return int
celestial.total                         return int
celestial.free                          return int

get celestial coordinates

works with planet's and moon's

empire.celestial_coordinates(id)        returns list

get celestial queue

get research, building and shipyard construction time works with planet's and moon's

empire.celestial_queue(id)              returns list

queue = empire.celestial_queue(id)
queue.list                              returns list
queue.research                          returns datetime
queue.buildings                         returns datetime
queue.shipyard                          returns datetime

resources

resources have the format [metal, crystal, deuterium]
darkmatter & energy are irrelevant, because you cant transport these.
It is used for transport and market functions

from ogame.constants import resources
res = resources(metal=1, crystal=2, deuterium=3)
[1, 2, 3]

get resources

empire.resources(id)                    returns class(object)

res = empire.resources(id)
res.resources                           returns resources
res.day_production                      returns resources
res.storage                             returns resources
res.darkmatter                          returns int
res.energy                              returns int
res.metal                               returns int
res.crystal                             returns int
res.deuterium                           returns int

get/set resources settings

empire.resources_settings(id)                       returns class(object)
empire.resources_settings(id, settings)             returns class(object)

settings = empire.resources_settings(id, settings)
settings.list                                       returns list
settings.metal_mine                                 returns int
settings.crystal_mine                               returns int
settings.deuterium_mine                             returns int
settings.solar_plant                                returns int
settings.fusion_plant                               returns int
settings.solar_satellite                            returns int
settings.crawler                                    returns int
settings = empire.resources_settings(id)

print(
       settings.list,
       settings.metal_mine,
       settings.crystal_mine,
       settings.deuterium_mine,
       settings.solar_plant,
       settings.fusion_plant,
       settings.solar_satellite,
       settings.crawler
     )

settings = empire.resources_settings(id,
        settings={
            buildings.metal_mine: speed.max,
            buildings.crystal_mine: speed.min,
            buildings.fusion_plant: 0,
            buildings.solar_satellite: speed._50,
        }
    )

print(settings.list)

get prices

get prices of buildings or ships. Level is mandatory if you pass buildings that exist only once like mines.
from ogame.constants import price

price(technology, level)                return resources

price(buildings.metal_mine, level=14))
price(ships.deathstar(100))

get supply

empire.supply(id)                       returns class(object)

sup = empire.supply(id)

sup.metal_mine.level                    returns int
sup.metal_mine.is_possible              returns bool (possible to build)
sup.metal_mine.in_construction          returns bool

sup.crystal_mine
sup.deuterium_mine
sup.solar_plant
sup.fusion_plant 
sup.metal_storage
sup.crystal_storage
sup.deuterium_storage                   returns class(object)

get facilities

empire.facilities(id)                   returns class(object) 

fac = empire.facilities(id)

fac.robotics_factory.level              returns int
fac.robotics_factory.is_possible        returns bool (possible to build)
fac.robotics_factory.in_construction    returns bool

fac.shipyard
fac.research_laboratory
fac.alliance_depot
fac.missile_silo
fac.nanite_factory
fac.terraformer
fac.repair_dock

get moon facilities

empire.moon_facilities(id)              returns class(object) 

fac = empire.moon_facilities(id) 
fac.robotics_factory.level              returns int
fac.robotics_factory.is_possible        returns bool (possible to build)
fac.robotics_factory.in_construction    returns bool

fac.shipyard
fac.moon_base
fac.sensor_phalanx 
fac.jump_gate

get traider

empire.traider(id)                  returns Exception("function not implemented yet PLS contribute")

get research

empire.research(id)                   returns class(object) 

res = empire.research(id)

res.energy.level
res.energy.is_possible
res.energy.in_construction

res.laser
res.ion
res.hyperspace
res.plasma
res.combustion_drive
res.impulse_drive
res.hyperspace_drive
res.espionage
res.computer
res.astrophysics
res.research_network
res.graviton
res.weapons
res.shielding
res.armor

get ships

empire.ships(id)                    returns class(object) 

shi = empire.ships(id)

shi.light_fighter.amount
shi.light_fighter.is_possible
shi.light_fighter.in_construction

shi.heavy_fighter
shi.cruiser
shi.battleship
shi.interceptor
shi.bomber
shi.destroyer
shi.deathstar
shi.reaper
shi.explorer
shi.small_transporter
shi.large_transporter
shi.colonyShip
shi.recycler
shi.espionage_probe
shi.solarSatellite
shi.crawler

get defences

empire.defences(id)                 returns class(object) 

def = empire.defences(id)

def.rocket_launcher.amount
def.rocket_launcher.is_possible
def.rocket_launcher.in_construction

def.laser_cannon_light
def.laser_cannon_heavy
def.gauss_cannon
def.ion_cannon
def.plasma_cannon
def.shield_dome_small
def.shield_dome_large
def.missile_interceptor
def.missile_interplanetary

get galaxy

empire.galaxy(coordinates)          returns list of class(object)
for planet in empire.galaxy(coordinates(randint(1,6), randint(1,499))):
    print(planet.list)
    print(planet.name, planet.position, planet.player, planet.player_id, planet.rank, planet.status, planet.moon)
    if status.inactive in planet.status and status.vacation not in planet.status:
        #Farm Inactive

get debris in galaxy

empire.galaxy_debris(coordinates)               returns list of class(object)

or use planet coordinates to get only the target debris

empire.galaxy_debris(planet_coordinates)        returns class(object)

pos = empire.galaxy_debris(planet_coordinates)
pos.list                                        returns list
pos.position                                    returns list
pos.has_debris                                  returns bool
pos.resources                                   returns list
pos.metal                                       returns int
pos.crystal                                     returns int
pos.deuterium                                   returns int
for position in empire.galaxy_debris(coordinates(1, 20)):
    print(position.list)
    print(position.position, position.has_debris, position.resources, position.metal, position.crystal, position.deuterium)
    if position.has_debris:
        # Can send recyclers

position = empire.galaxy_debris(coordinates(1, 20, 12))
print(position.list)
print(position.position, position.has_debris, position.resources, position.metal, position.crystal, position.deuterium)
if position.has_debris:
    # Can send recyclers

get ally

Returns your current Ally name None if you didnt join one yet

empire.ally()                       returns list

get officers

officers = empire.officers()
officers.commander                  returns bool
officers.admiral                    returns bool
officers.engineer                   returns bool
officers.geologist                  returns bool
officers.technocrat                 returns bool

get shop

empire.shop()                       returns Exception("function not implemented yet PLS contribute")

get slot

Get the actual free and total Fleet slots you have available
slot = empire.slot_fleet()
slot.fleet.total                     returns int
slot.fleet.free                      returns int
slot.expedition.total                returns int
slot.expedition.free                 returns int

get fleet

empire.fleet()                      returns list of class(object)
for fleet in empire.fleet():
    if fleet.mission == mission.expedition:
        print(fleet.list)
        print(  
                fleet.id, 
                fleet.mission, 
                fleet.diplomacy, 
                fleet.player, 
                fleet.player_id,
                fleet.returns, 
                fleet.arrival, 
                fleet.origin, 
                fleet.destination
            )

get hostile fleet

empire.hostile_fleet()              returns list of class(object)
for fleet in empire.hostile_fleet():
    print(fleet.list)

get friendly fleet

empire.hostile_fleet()              returns list of class(object)
for fleet in empire.friendly_fleet():
    print(fleet.list)

get phalanx

~~Dangereous!!! it gets you banned when not valid
empire.phalanx(coordinates, id)     returns list of class(object)~~

for fleet in empire.phalanx(moon_id, coordinates(2, 410, 7)):
    if fleet.mission == mission.expedition:
        print(fleet.list)
        print(fleet.id, fleet.mission, fleet.returns, fleet.arrival, fleet.origin, fleet.destination)

get spyreports

empire.spyreports()                           returns list of class(object)
empire.spyreports(firstpage=1, lastpage=30)   returns list of class(object)

reports = empire.spyreports()
report = reports[0]
report.name                                   returns str
report.position                               returns list
report.moon                                   returns bool
report.datetime                               returns str
report.metal                                  returns int
report.crystal                                returns int
report.deuterium                              returns int
report.fleet                                  returns dict
report.defenses                               returns dict
report.buildings                              returns dict
report.research                               returns dict
report.api                                    returns str
report.list                                   returns list
for report in empire.spyreports():
    print(report.list)

send fleet (for both version 7.6 and 8.0.0)

from ogame.constants import coordinates, mission, speed, fleet
empire.send_fleet(mission=mission.expedition,
                  id=id,
                  where=coordinates(1, 12, 16),
                  ships=fleet(light_fighter=12, bomber=1, cruiser=100),
                  resources=[0, 0, 0],  # optional default no resources
                  speed=speed.max,      # optional default speed.max
                  holdingtime=2)        # optional default 0 will be needed by expeditions
                 
                                        returns bool

return fleet

empire.return_fleet(fleet_id):          returns bool

You can't return hostile Fleets :p use the friendly fleet function to avoid confusion.
True if the Fleet you want to return is possible to retreat

send message

empire.send_message(player_id, msg)     returns bool

build

Buildings

from ogame.constants import buildings
empire.build(what=buildings.alliance_depot, 
             id=id)

buildings.metal_mine
buildings.crystal_mine
buildings.deuterium_mine
buildings.solar_plant
buildings.fusion_plant
buildings.solar_satellite(int)
buildings.crawler(int)
buildings.metal_storage
buildings.crystal_storage
buildings.deuterium_storage

buildings.robotics_factory
buildings.shipyard
buildings.research_laboratory
buildings.alliance_depot
buildings.missile_silo
buildings.nanite_factory
buildings.terraformer
buildings.repair_dock

empire.build(what=buildings.rocket_launcher(10), 
             id=id)

buildings.rocket_launcher(int)
buildings.laser_cannon_light(int)
buildings.laser_cannon_heavy(int)
buildings.gauss_cannon(int)
buildings.ion_cannon(int)
buildings.plasma_cannon(int)
buildings.shield_dome_small(int)
buildings.shield_dome_large(int)
buildings.missile_interceptor(int)
buildings.missile_interplanetary(int)

buildings.moon_base
buildings.sensor_phalanx
buildings.jump_gate

Ships

from ogame.constants import ships
empire.build(what=ships.bomber(10), 
             id=id)

ships.light_fighter(int)
ships.heavy_fighter(int)
ships.cruiser(int)
ships.battleship(int)
ships.interceptor(int)
ships.bomber(int)
ships.destroyer(int)
ships.deathstar(int)
ships.reaper(int)
ships.explorer(int)
ships.small_transporter(int)
ships.large_transporter(int)
ships.colonyShip(int)
ships.recycler(int)
ships.espionage_probe(int)
                 
                                        returns None

do research

from ogame.constants import research
empire.build(what=research.energy,
             id=id)

research.energy
research.laser
research.ion
research.hyperspace
research.plasma
research.combustion_drive
research.impulse_drive
research.hyperspace_drive
research.espionage
research.computer
research.astrophysics
research.research_network
research.graviton
research.weapons
research.shielding
research.armor
                 
                                        returns None

deconstruct

from ogame.constants import buildings
empire.deconstruct(what=buildings.metal_mine,
                   id=id)

buildings.metal_mine
buildings.crystal_mine
buildings.deuterium_mine
buildings.solar_plant
buildings.fusion_plant
buildings.metal_storage
buildings.crystal_storage
buildings.deuterium_storage

buildings.robotics_factory
buildings.shipyard
buildings.research_laboratory
buildings.missile_silo
buildings.nanite_factory

buildings.sensor_phalanx
buildings.jump_gate
 

                                        returns None

cancel building and research progress

Buildings

If you need to cancel the construction or deconstruction of a building
empire.cancel_building(id)              returns None

Research

If you need to cancel the current ongoing research
empire.cancel_research(id)              returns None

collect rubble field

 
this will collect your rubble field at the planet id.
                
empire.collect_rubble_field(id)         returns None

im i still loged In?

                 
empire.is_logged_in()                   returns Bool

relogin

                 
empire.relogin()                        returns Bool

switch universes with the same login
empire.relogin('UNI')

keep going

If you are running code for long time you can decorate it with the keep going Decorator. If the function gets logged out it will try to relogin and continuing execution.

@empire.keep_going
def run():
    while True:
        print(empire.attacked())
        time.sleep(1)

logout

                 
empire.logout()                         returns Bool