/pyogame

OGame wrapper.

Primary LanguagePythonMIT LicenseMIT

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: 7.6.6 version 20

install

pip install ogame

update

pip install ogame==7.6.6.20

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.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**

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 celestial data

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

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.darkmatter                          returns int
res.energy                              returns int
res.metal                               returns int
res.crystal                             returns int
res.deuterium                           returns int

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.metal_mine.cost                     returns resources

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()                   returns class(object) 

res = empire.research()

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 ally

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

empire.ally()                       returns list

get officers

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

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.free                     returns int
slot.expedition.total

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)
for report in empire.spyreports():
    print(report.fright)

send fleet

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

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