53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
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
|
|
class TradeMission(BaseMission):
|
|
def start_state(self):
|
|
return 'travel-to'
|
|
|
|
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'
|
|
res = self.api.buy(self.ship, resource, amount)
|
|
self.balance(res)
|
|
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 {
|
|
**self.travel_steps('to', 'site', 'dock'),
|
|
'dock': (self.step_dock, 'market-pre'),
|
|
'market-pre': (self.step_market, 'load'),
|
|
'load': (self.step_load, {
|
|
'more': 'market-pre',
|
|
'done': 'market-post'
|
|
}),
|
|
'market-post': (self.step_market, 'travel-back'),
|
|
**self.travel_steps('back', 'dest', 'dock-dest'),
|
|
'dock-dest': (self.step_dock, 'unload'),
|
|
'unload': (self.step_sell, {
|
|
'more': 'unload',
|
|
'done': 'market-dest'
|
|
}),
|
|
'market-dest': (self.step_market, 'report'),
|
|
'report': (self.step_done, 'done')
|
|
}
|