spacetraders.rb/bin/console

48 lines
1.2 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'dotenv'
Dotenv.load!
$LOAD_PATH << File.join(Dir.pwd, 'lib')
require 'pry'
def restart!
load 'lib/space_traders.rb'
include SpaceTraders
end
restart!
c = Client.load_from_env
# c = Client.register name: "Sceptique#{(rand * 10000).round}"
# File.open(".env", "a") { |f| f.write("\nSPACETRADERS_TOKEN=#{c.token}\n") }
Log.debug "client loaded"
contract = Contract.my_contracts(c).first
contract.accept!
contract.reload!
ship = Ship.my_ships(c).first
system = System.systems(c).first
waypoint = system.waypoints.first
# copper ore
target_delivery = contract.terms["deliver"][0]["tradeSymbol"]
destination1 = ship.helper.waypoints.find { |wp| wp.traits.find { |trait| trait["symbol"] == "COMMON_METAL_DEPOSITS" } }.symbol
destination2 = contract.terms["deliver"].first["destinationSymbol"]
ship.navigate! waypoint: destination1
def wait_until(t)
s = t.to_i - Time.now.to_i + 1.second
Log.debug "sleeping until #{t} (#{s} seconds)"
sleep(s) if s > 0
end
wait_until Time.parse(ship.nav.dig("route", "arrival"))
ship.survey!
survey = c.data["surveys"].find { |s| s["deposits"].find { |d| d["symbol"] == target_delivery } }
ship.extract! **survey.to_h
binding.pry