1.4.0 • Published 3 months ago

@slk333/lib-ogame v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Various functions and types related to the original Ogame browser game.

costs

mines and facilities

getStructureUpgradeCost("crystalMine", 9)
/* { metalAmount: 2061, crystalAmount: 1030, deuteriumAmount: 0 } */

ships and defenses

getShipCost("lightFighter")
/* { metalAmount: 3000, crystalAmount: 1000, deuteriumAmount: 0 } */

getDefenseCost("rocketLauncher")
/* { metalAmount: 2000, crystalAmount: 0, deuteriumAmount: 0 } */

construction time

mines and facilities

getStructureConstructionTime({
    structureName: "researchLab",
    level: 5,
    roboticsFactory: 3,
    naniteFactory: 0,
})
/* 2304 seconds*/

ships and defenses

getShipConstructionTime({
    shipName: "lightFighter",
    shipyard: 5,
    naniteFactory: 1,
})
/* 480 seconds*/

getDefenseConstructionTime({
    defenseName: "rocketLauncher",
    shipyard: 5,
    naniteFactory: 1,
})
/* 240 seconds*/

// DEPRECATED: Use getShipConstructionTime or getDefenseConstructionTime instead
getShipyardUnitConstructionTime(
    { name: "lightFighter", type: "ship" },
    5, // shipyardLevel
    1 // naniteLevel
)
/* 480 seconds*/

production

getMetalMineProduction_s(25)
/* 2.25694444 metal per second */

getCrystalMineProduction_s(25)
/* 1.50472222 crystal per second */

getDeuteriumProduction_s(25)
/* 1.08333333 deuterium per second */
/* fixed temperature: 0°C */

derive data from planet

resources at date

computeResourcesForPlanetAtDate(planet, date)
/* { metalAmount: 51908, crystalAmount: 25767, deuteriumAmount: 10372 } 
/* expects a Date */

production

computeProductionForPlanet(planet)
/* { metalProduction_s: 0.5302, crystalProduction_s: 0.2133, deuteriumProduction_s: 0.1036 } */

costs and durations

computeStructureUpgradeCostForPlanet(planet, "metalMine")
/* { metalAmount: 26273, crystalAmount: 6568, deuteriumAmount: 0 } */

computeStructureUpgradeTimeForPlanet(planet, "metalMine")
/* 1970 seconds */

planet shape

export interface Planet {
    id: string
    name: string
    owner: {
        id: string
        name: string
    }
    coordinates: Coordinates
    structures: Record<StructureName, PlanetStructure>
    ships: Record<ShipName, { name: ShipName; count: number }>
    resources: ResourcesRecord
    snapshotDate: string
    pendingStructure: {
        name: StructureName
        completionDate: string
    } | null
    pendingShipyardUnit: {
        shipyardUnit: ShipyardUnit
        completionDate: string
    } | null
    structureQueue: StructureName[]
    shipyardQueue: ScheduledShipyardOrder[]
}
const samplePlanet: Planet = {
    id: "planetAlpha",
    name: "Alpha Centauri Bb",
    owner: {
        id: "player123",
        name: "GalacticOverlord",
    },
    coordinates: { galaxy: 1, system: 100, position: 7, type: "planet" },
    structures: {
        metalMine: { name: "metalMine", level: 15 },
        crystalMine: { name: "crystalMine", level: 12 },
        deuteriumSynthesizer: { name: "deuteriumSynthesizer", level: 10 },
        roboticsFactory: { name: "roboticsFactory", level: 5 },
        shipyard: { name: "shipyard", level: 6 },
        researchLab: { name: "researchLab", level: 7 },
        naniteFactory: { name: "naniteFactory", level: 2 },
    },
    ships: {
        lightFighter: { name: "lightFighter", count: 50 },
        heavyFighter: { name: "heavyFighter", count: 0 },
        cruiser: { name: "cruiser", count: 0 },
        /* ... */
    },
    resources: { metalAmount: 50000, crystalAmount: 25000, deuteriumAmount: 10000 },
    snapshotDate: new Date("2025-05-29T10:00:00.000Z").toISOString(),
    pendingStructure: null,
    pendingShipyardUnit: null,
    structureQueue: [],
    shipyardQueue: [],
}

misc

Format resources

formatResourceAmount(1234567)
/* "1.2M" */
1.2.0

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago

1.4.0

3 months ago

0.5.0

10 months ago

0.7.0

6 months ago

0.4.20

10 months ago

1.1.0

4 months ago

0.4.21

10 months ago

1.3.0

4 months ago

0.4.19

10 months ago

0.4.17

10 months ago

0.4.18

10 months ago

0.4.15

10 months ago

0.4.16

10 months ago

0.6.3

10 months ago

0.8.0

4 months ago

0.6.2

10 months ago

0.6.5

10 months ago

0.6.4

10 months ago

0.6.1

10 months ago

0.6.0

10 months ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.10

1 year ago

0.4.13

1 year ago

0.4.14

1 year ago

0.4.11

1 year ago

0.4.12

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.1

1 year ago

0.2.3

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.2.2

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago