From 99e9384acb00d5c2314876b42b5f09e1c6710981 Mon Sep 17 00:00:00 2001 From: lukas Date: Mon, 2 Sep 2024 17:13:49 +0200 Subject: [PATCH] chore: separate fleet strategies --- src/main/basedbot/basedbot.ts | 207 +----------------- .../fleet-strategies/atlasnet-lu-strategy.ts | 135 ++++++++++++ .../fleet-strategies/get-fleet-strategy.ts | 20 ++ .../fleet-strategies/mainnet-lu-strategy.ts | 13 ++ .../basedbot/lib/sage/state/user-account.ts | 3 +- 5 files changed, 177 insertions(+), 201 deletions(-) create mode 100644 src/main/basedbot/fleet-strategies/atlasnet-lu-strategy.ts create mode 100644 src/main/basedbot/fleet-strategies/get-fleet-strategy.ts create mode 100644 src/main/basedbot/fleet-strategies/mainnet-lu-strategy.ts diff --git a/src/main/basedbot/basedbot.ts b/src/main/basedbot/basedbot.ts index 067e830e..b526884c 100644 --- a/src/main/basedbot/basedbot.ts +++ b/src/main/basedbot/basedbot.ts @@ -7,25 +7,13 @@ import BN from 'bn.js' import { Sentry } from '../../sentry' -import { config } from '../../config' import { logger } from '../../logger' import { sleep } from '../../service/sleep' import { connection } from '../../service/sol' import { keyPair } from '../../service/wallet' -import { mineBiomass } from './fsm/configs/mine-biomass' -import { mineCarbon } from './fsm/configs/mine-carbon' -import { mineConfig } from './fsm/configs/mine-config' -import { mineCopperOre } from './fsm/configs/mine-copper-ore' -import { mineHydrogen } from './fsm/configs/mine-hydrogen' -import { mineIronOre } from './fsm/configs/mine-iron-ore' -import { mineLumanite } from './fsm/configs/mine-lumanite' -import { mineNitrogen } from './fsm/configs/mine-nitrogen' -import { mineRochinol } from './fsm/configs/mine-rochinol' -import { mineSilicia } from './fsm/configs/mine-silicia' -import { mineTitaniumOre } from './fsm/configs/mine-titanium-ore' +import { getFleetStrategy } from './fleet-strategies/get-fleet-strategy' import { createInfoStrategy } from './fsm/info' -import { createMiningStrategy } from './fsm/mine' import { Strategy } from './fsm/strategy' import { depositCargo } from './lib/sage/act/deposit-cargo' import { settleFleet } from './lib/sage/state/settle-fleet' @@ -35,13 +23,8 @@ import { getFleetInfo, getUserFleets, } from './lib/sage/state/user-fleets' -import { - getMapContext, - mineableByCoordinates, - WorldMap, -} from './lib/sage/state/world-map' +import { getMapContext, WorldMap } from './lib/sage/state/world-map' // eslint-disable-next-line import/max-dependencies -import { Coordinates } from './lib/util/coordinates' // eslint-disable-next-line require-await export const create = async (): Promise => { @@ -152,190 +135,14 @@ export const start = async (): Promise => { const player = await getPlayerContext(keyPair.publicKey, keyPair) const map = await getMapContext(player.game) - const fleetStrategies: Map = - config.sol.rpcEndpoint.includes('atlasnet') - ? new Map([ - [ - 'Armadillo Fleet', - createMiningStrategy(mineBiomass(map), player), - ], - [ - 'Barnacle Fleet', - createMiningStrategy( - mineConfig({ - homeBase: Coordinates.fromNumber(-40, 30), - targetBase: Coordinates.fromNumber(-19, 40), - resource: mineableByCoordinates( - map, - Coordinates.fromNumber(-19, 40), - ) - .values() - .next().value, - }), - player, - ), - ], - [ - 'Cobra Fleet', - createMiningStrategy( - mineConfig({ - homeBase: Coordinates.fromNumber(-40, 30), - targetBase: Coordinates.fromNumber(-18, 23), - resource: mineableByCoordinates( - map, - Coordinates.fromNumber(-18, 23), - ) - .values() - .next().value, - }), - player, - ), - ], - [ - 'Falcon Fleet', - createMiningStrategy(mineCarbon(map), player), - ], - [ - 'Geoffroys Cat Fleet', - createMiningStrategy(mineNitrogen(map), player), - ], - [ - 'Gerbils Fleet', - createMiningStrategy(mineSilicia(map), player), - ], - [ - 'Grasshopper Fleet', - createMiningStrategy(mineLumanite(map), player), - ], - [ - 'Guanaco Fleet', - createMiningStrategy(mineCopperOre(map), player), - ], - [ - 'King Cobra Fleet', - createMiningStrategy(mineIronOre(map), player), - ], - [ - 'Pacific Sardine Fleet', - createMiningStrategy(mineHydrogen(map), player), - ], - [ - 'Porpoise Fleet', - createMiningStrategy(mineRochinol(map), player), - ], - [ - 'Rabbit Fleet', - createMiningStrategy(mineHydrogen(map), player), - ], - [ - 'Smalltooth Sawfish Fleet', - createMiningStrategy(mineTitaniumOre(map), player), - ], - [ - 'Sugar Gliders Fleet', - createMiningStrategy(mineIronOre(map), player), - ], - [ - 'Turkey Fleet', - createMiningStrategy(mineHydrogen(map), player), - ], - - [ - 'Aardwolf Fleet', - createMiningStrategy(mineBiomass(map), player), - ], - [ - 'Antelope Fleet', - createMiningStrategy( - mineConfig({ - homeBase: Coordinates.fromNumber(-40, 30), - targetBase: Coordinates.fromNumber(-19, 40), - resource: mineableByCoordinates( - map, - Coordinates.fromNumber(-19, 40), - ) - .values() - .next().value, - }), - player, - ), - ], - [ - 'Boa Fleet', - createMiningStrategy( - mineConfig({ - homeBase: Coordinates.fromNumber(-40, 30), - targetBase: Coordinates.fromNumber(-18, 23), - resource: mineableByCoordinates( - map, - Coordinates.fromNumber(-18, 23), - ) - .values() - .next().value, - }), - player, - ), - ], - [ - 'Chinchillas Fleet', - createMiningStrategy(mineCarbon(map), player), - ], - [ - 'Fathead Sculpin Fleet', - createMiningStrategy(mineNitrogen(map), player), - ], - [ - 'Giant Tortoise Fleet', - createMiningStrategy(mineSilicia(map), player), - ], - [ - 'Kultarr Fleet', - createMiningStrategy(mineLumanite(map), player), - ], - [ - 'Leopard Seal Fleet', - createMiningStrategy(mineCopperOre(map), player), - ], - [ - 'Pangolin Fleet', - createMiningStrategy(mineIronOre(map), player), - ], - [ - 'Rhinoceros Fleet', - createMiningStrategy(mineHydrogen(map), player), - ], - [ - 'Snow Leopard Fleet', - createMiningStrategy(mineRochinol(map), player), - ], - [ - 'Southern White Faced Owl Fleet', - createMiningStrategy(mineHydrogen(map), player), - ], - [ - 'Turkeys Fleet', - createMiningStrategy(mineTitaniumOre(map), player), - ], - [ - 'Zebra Fleet', - createMiningStrategy(mineIronOre(map), player), - ], - [ - 'Guinea Fowl Fleet', - createMiningStrategy(mineHydrogen(map), player), - ], - ]) - : new Map([ - [ - 'Vaquita Fleet', - createMiningStrategy(mineRochinol(map), player), - ], - ]) - // eslint-disable-next-line no-constant-condition while (true) { try { - await basedbot({ player, map, fleetStrategies }) + await basedbot({ + player, + map, + fleetStrategies: getFleetStrategy(map, player), + }) } catch (e) { Sentry.captureException(e) logger.error(e) diff --git a/src/main/basedbot/fleet-strategies/atlasnet-lu-strategy.ts b/src/main/basedbot/fleet-strategies/atlasnet-lu-strategy.ts new file mode 100644 index 00000000..6218db1c --- /dev/null +++ b/src/main/basedbot/fleet-strategies/atlasnet-lu-strategy.ts @@ -0,0 +1,135 @@ +import { mineBiomass } from '../fsm/configs/mine-biomass' +import { mineCarbon } from '../fsm/configs/mine-carbon' +import { mineConfig } from '../fsm/configs/mine-config' +import { mineCopperOre } from '../fsm/configs/mine-copper-ore' +import { mineHydrogen } from '../fsm/configs/mine-hydrogen' +import { mineIronOre } from '../fsm/configs/mine-iron-ore' +import { mineLumanite } from '../fsm/configs/mine-lumanite' +import { mineNitrogen } from '../fsm/configs/mine-nitrogen' +import { mineRochinol } from '../fsm/configs/mine-rochinol' +import { mineSilicia } from '../fsm/configs/mine-silicia' +import { mineTitaniumOre } from '../fsm/configs/mine-titanium-ore' +import { createMiningStrategy } from '../fsm/mine' +import { Strategy } from '../fsm/strategy' +import { Player } from '../lib/sage/state/user-account' +import { mineableByCoordinates, WorldMap } from '../lib/sage/state/world-map' +import { Coordinates } from '../lib/util/coordinates' + +export const atlasnetLuStrategy = ( + map: WorldMap, + player: Player, +): Map => + new Map([ + ['Armadillo Fleet', createMiningStrategy(mineBiomass(map), player)], + [ + 'Barnacle Fleet', + createMiningStrategy( + mineConfig({ + homeBase: Coordinates.fromNumber(-40, 30), + targetBase: Coordinates.fromNumber(-19, 40), + resource: mineableByCoordinates( + map, + Coordinates.fromNumber(-19, 40), + ) + .values() + .next().value, + }), + player, + ), + ], + [ + 'Cobra Fleet', + createMiningStrategy( + mineConfig({ + homeBase: Coordinates.fromNumber(-40, 30), + targetBase: Coordinates.fromNumber(-18, 23), + resource: mineableByCoordinates( + map, + Coordinates.fromNumber(-18, 23), + ) + .values() + .next().value, + }), + player, + ), + ], + ['Falcon Fleet', createMiningStrategy(mineCarbon(map), player)], + [ + 'Geoffroys Cat Fleet', + createMiningStrategy(mineNitrogen(map), player), + ], + ['Gerbils Fleet', createMiningStrategy(mineSilicia(map), player)], + ['Grasshopper Fleet', createMiningStrategy(mineLumanite(map), player)], + ['Guanaco Fleet', createMiningStrategy(mineCopperOre(map), player)], + ['King Cobra Fleet', createMiningStrategy(mineIronOre(map), player)], + [ + 'Pacific Sardine Fleet', + createMiningStrategy(mineHydrogen(map), player), + ], + ['Porpoise Fleet', createMiningStrategy(mineRochinol(map), player)], + ['Rabbit Fleet', createMiningStrategy(mineHydrogen(map), player)], + [ + 'Smalltooth Sawfish Fleet', + createMiningStrategy(mineTitaniumOre(map), player), + ], + ['Sugar Gliders Fleet', createMiningStrategy(mineIronOre(map), player)], + ['Turkey Fleet', createMiningStrategy(mineHydrogen(map), player)], + + ['Aardwolf Fleet', createMiningStrategy(mineBiomass(map), player)], + [ + 'Antelope Fleet', + createMiningStrategy( + mineConfig({ + homeBase: Coordinates.fromNumber(-40, 30), + targetBase: Coordinates.fromNumber(-19, 40), + resource: mineableByCoordinates( + map, + Coordinates.fromNumber(-19, 40), + ) + .values() + .next().value, + }), + player, + ), + ], + [ + 'Boa Fleet', + createMiningStrategy( + mineConfig({ + homeBase: Coordinates.fromNumber(-40, 30), + targetBase: Coordinates.fromNumber(-18, 23), + resource: mineableByCoordinates( + map, + Coordinates.fromNumber(-18, 23), + ) + .values() + .next().value, + }), + player, + ), + ], + ['Chinchillas Fleet', createMiningStrategy(mineCarbon(map), player)], + [ + 'Fathead Sculpin Fleet', + createMiningStrategy(mineNitrogen(map), player), + ], + [ + 'Giant Tortoise Fleet', + createMiningStrategy(mineSilicia(map), player), + ], + ['Kultarr Fleet', createMiningStrategy(mineLumanite(map), player)], + [ + 'Leopard Seal Fleet', + createMiningStrategy(mineCopperOre(map), player), + ], + ['Pangolin Fleet', createMiningStrategy(mineIronOre(map), player)], + ['Rhinoceros Fleet', createMiningStrategy(mineHydrogen(map), player)], + ['Snow Leopard Fleet', createMiningStrategy(mineRochinol(map), player)], + [ + 'Southern White Faced Owl Fleet', + createMiningStrategy(mineHydrogen(map), player), + ], + ['Turkeys Fleet', createMiningStrategy(mineTitaniumOre(map), player)], + ['Zebra Fleet', createMiningStrategy(mineIronOre(map), player)], + ['Guinea Fowl Fleet', createMiningStrategy(mineHydrogen(map), player)], + ]) diff --git a/src/main/basedbot/fleet-strategies/get-fleet-strategy.ts b/src/main/basedbot/fleet-strategies/get-fleet-strategy.ts new file mode 100644 index 00000000..58b83d32 --- /dev/null +++ b/src/main/basedbot/fleet-strategies/get-fleet-strategy.ts @@ -0,0 +1,20 @@ +import { Strategy } from '../fsm/strategy' +import { Player } from '../lib/sage/state/user-account' +import { WorldMap } from '../lib/sage/state/world-map' + +import { atlasnetLuStrategy } from './atlasnet-lu-strategy' +import { mainnetLuStrategy } from './mainnet-lu-strategy' + +export const getFleetStrategy = ( + map: WorldMap, + player: Player, +): Map => { + switch (player.publicKey.toString()) { + case 'k49Y5xwN7Nyi19TqDR4zbCFuAt8kgy6qMaJ6Kj1wHrn': + return atlasnetLuStrategy(map, player) + case 'AePY3wEoUFcFuXeUU9X26YK6tNKQMZovBgvY54LK2B8N': + return mainnetLuStrategy(map, player) + default: + throw new Error('Unknown strategy') + } +} diff --git a/src/main/basedbot/fleet-strategies/mainnet-lu-strategy.ts b/src/main/basedbot/fleet-strategies/mainnet-lu-strategy.ts new file mode 100644 index 00000000..704ea36b --- /dev/null +++ b/src/main/basedbot/fleet-strategies/mainnet-lu-strategy.ts @@ -0,0 +1,13 @@ +import { mineRochinol } from '../fsm/configs/mine-rochinol' +import { createMiningStrategy } from '../fsm/mine' +import { Strategy } from '../fsm/strategy' +import { Player } from '../lib/sage/state/user-account' +import { WorldMap } from '../lib/sage/state/world-map' + +export const mainnetLuStrategy = ( + map: WorldMap, + player: Player, +): Map => + new Map([ + ['Vaquita Fleet', createMiningStrategy(mineRochinol(map), player)], + ]) diff --git a/src/main/basedbot/lib/sage/state/user-account.ts b/src/main/basedbot/lib/sage/state/user-account.ts index d4587acd..538ea32f 100644 --- a/src/main/basedbot/lib/sage/state/user-account.ts +++ b/src/main/basedbot/lib/sage/state/user-account.ts @@ -33,7 +33,7 @@ export type XpAccount = { } export type Player = { - // TODO: what is this? + publicKey: PublicKey keyIndex: number profile: PlayerProfile profileFaction: ProfileFactionAccount @@ -165,6 +165,7 @@ export const getPlayerContext = async ( } return { + publicKey: user, profile: profile.data, profileFaction: profileFaction.data, keyIndex,