0ptr/nullptr/missions/trade.py

53 lines
1.7 KiB
Python
Raw Normal View History

from nullptr.missions.base import BaseMission, MissionParam
from nullptr.models.waypoint import Waypoint
from nullptr.models.survey import Survey
from nullptr.models.contract import Contract
2024-01-13 20:42:49 +00:00
class TradeMission(BaseMission):
def start_state(self):
return 'travel-to'
2024-01-15 18:39:08 +00:00
def step_load(self):
credits = self.api.agent.credits
cargo_space = self.ship.cargo_capacity - self.ship.cargo_units
smkt = self.store.get('Marketplace', self.st('site'))
dmkt = self.store.get('Marketplace', self.st('dest'))
resource = self.analyzer.find_deal(smkt, dmkt)
if resource is None:
return 'done'
price = smkt.buy_price(resource)
volume = smkt.volume(resource)
affordable = credits // price
amount = min(cargo_space, affordable, volume)
if amount == 0:
return 'done'
2024-01-20 19:33:50 +00:00
res = self.api.buy(self.ship, resource, amount)
self.balance(res)
2024-01-15 18:39:08 +00:00
return 'done' if amount == cargo_space else 'more'
@classmethod
def params(cls):
return {
'site': MissionParam(Waypoint, True),
'dest': MissionParam(Waypoint, True),
}
def steps(self):
return {
2024-01-06 06:17:53 +00:00
**self.travel_steps('to', 'site', 'dock'),
'dock': (self.step_dock, 'market-pre'),
'market-pre': (self.step_market, 'load'),
2024-01-15 18:39:08 +00:00
'load': (self.step_load, {
'more': 'market-pre',
'done': 'market-post'
}),
2024-01-06 06:17:53 +00:00
'market-post': (self.step_market, 'travel-back'),
**self.travel_steps('back', 'dest', 'dock-dest'),
'dock-dest': (self.step_dock, 'unload'),
2024-01-16 18:13:10 +00:00
'unload': (self.step_sell, {
'more': 'unload',
'done': 'market-dest'
}),
2024-01-20 19:33:50 +00:00
'market-dest': (self.step_market, 'report'),
'report': (self.step_done, 'done')
}