120 lines
4.2 KiB
Python
120 lines
4.2 KiB
Python
from __builtins__ import MiningSite, PointOfInterest
|
|
import json
|
|
|
|
|
|
|
|
class Map:
|
|
"""Utility class for map interactions"""
|
|
journal = get_component("journal")
|
|
planet = get_component("nocturna")
|
|
marks = get_component("markers")
|
|
outposts = get_component("outpost_network")
|
|
note = get_component("notebook")
|
|
construct = get_component("construction_blueprint")
|
|
|
|
## point of intrest methods
|
|
@staticmethod
|
|
def get_unknown_pois() -> list[PointOfInterest]:
|
|
"""return all unscanned points of intrests"""
|
|
return [poi for poi in Map.planet.points_of_interest() if not poi.scanned]
|
|
|
|
@staticmethod
|
|
def get_known_pois() -> list[PointOfInterest]:
|
|
"""return all scanned points of intrests"""
|
|
return [poi for poi in Map.planet.points_of_interest() if poi.scanned]
|
|
|
|
@staticmethod
|
|
def filter_blocklist_pois(pois: list[PointOfInterest], sonar: str) -> list[PointOfInterest]:
|
|
if not isinstance(pois, list):
|
|
return list()
|
|
blocklist = Map.get_blocklist_pois(sonar)
|
|
if not isinstance(blocklist, list) or len(blocklist) == 0:
|
|
return pois
|
|
filterd_pois = list()
|
|
for poi in pois:
|
|
if not isinstance(poi, PointOfInterest):
|
|
continue
|
|
if not f"{poi.x}{poi.y}" in blocklist:
|
|
filterd_pois.append(poi)
|
|
return filterd_pois
|
|
|
|
@staticmethod
|
|
def get_blocklist_pois(sonar: str) -> list[str]:
|
|
"""get blocklisted point of interests for sonar level
|
|
|
|
Args:
|
|
sonar (int): sonar tier. get via vehicle.sonar.tier()
|
|
Return:
|
|
list[str]: list of coords from blocklist, point of intersts like str(x) + str(y)
|
|
"""
|
|
if not sonar in ["basic", "wide", "deep", "seismic"]:
|
|
return list()
|
|
pointer = f"map.scan.blocked.{sonar}"
|
|
if not Map.note.has(pointer):
|
|
return list()
|
|
response = json.loads( Map.note.get(pointer) )
|
|
return response
|
|
|
|
@staticmethod
|
|
def add_blocklist_poi(poi: PointOfInterest, sonar: str) -> bool:
|
|
"""add a new poi to blocklist for sonar level
|
|
|
|
Args:
|
|
poi (PointOfInterest): poi to blacklist
|
|
sonar (int): sonar tier. get via vehicle.sonar.tier()
|
|
Return:
|
|
bool: True if saved successfully
|
|
"""
|
|
if not isinstance(poi, PointOfInterest):
|
|
return False
|
|
if not sonar in ["basic", "wide", "deep", "seismic"]:
|
|
return False
|
|
blocklist = Map.get_blocklist_pois(sonar)
|
|
blocklist.append(f"{poi.x}{poi.y}")
|
|
blocklist = json.dumps( blocklist )
|
|
response = Map.note.set( f"map.scan.blocked.{sonar}", blocklist )
|
|
if response == "ok": return True
|
|
return False
|
|
|
|
## mining methods
|
|
@staticmethod
|
|
def get_mines_by_ressource(ressource: str) -> list[MiningSite]:
|
|
"""collect all known mines with ressource type
|
|
[[helper]]
|
|
|
|
Args:
|
|
ressources (str): ressource id name like `iron_ore` or `silicon`
|
|
Return:
|
|
`list[MiningSite]`: known mines of type `ressource`
|
|
"""
|
|
mines_by_item = dict()
|
|
|
|
# collect all MiningSites and sort by type
|
|
for site in Map.journal.discovered_sites("nocturna"):
|
|
if not isinstance(site, MiningSite):
|
|
continue
|
|
if site.item_id not in mines_by_item:
|
|
mines_by_item[site.item_id] = list()
|
|
|
|
mines_by_item[site.item_id].append(site)
|
|
|
|
# check if ressource in mines and return a list
|
|
if ressource in mines_by_item.keys():
|
|
return mines_by_item[ressource]
|
|
else: return list()
|
|
|
|
@staticmethod
|
|
def get_mines_iron() -> list[MiningSite]:
|
|
"""short method for `get_mines_by_ressources` directly for ìron_ore`"""
|
|
return Map.get_mines_by_ressource("iron_ore")
|
|
|
|
@staticmethod
|
|
def get_mines_silicon() -> list[MiningSite]:
|
|
"""short method for `get_mines_by_ressources` directly for `silicon`"""
|
|
return Map.get_mines_by_ressource("silicon")
|
|
|
|
@staticmethod
|
|
def get_mines_titan() -> list[MiningSite]:
|
|
"""short method for `get_mines_by_ressources` directly for `titanium`"""
|
|
return Map.get_mines_by_ressource("titanium")
|
|
|