def bot_difficulty_settings(bot_type: str, difficulty: str) -> dict: if bot_type == "core": return ujson.load( db_dir.joinpath("base", "botCore.json").open(encoding="utf8")) bot_file = db_dir.joinpath("bots", bot_type, "difficulty", f"{difficulty}.json").open(encoding="utf8") return ujson.load(bot_file)
def __read_templates() -> Tuple[Dict[TemplateId, ItemTemplate], Dict[ TemplateId, NodeTemplate], ]: item_templates: List[ItemTemplate] = [] node_templates: List[NodeTemplate] = [] # Read every file from db/items for item_file_path in db_dir.joinpath("items").glob("*"): file_data: List[dict] = ujson.load( item_file_path.open("r", encoding="utf8")) item_templates.extend( pydantic.parse_obj_as( List[ItemTemplate], (item for item in file_data if item["_type"] == "Item"), )) node_templates.extend( pydantic.parse_obj_as( List[NodeTemplate], (item for item in file_data if item["_type"] == "Node"), )) return ( {tpl.id: tpl for tpl in item_templates}, {tpl.id: tpl for tpl in node_templates}, )
def client_handbook_templates() -> TarkovSuccessResponse[dict]: data: dict = {} for template_path in db_dir.joinpath("templates").glob("*.json"): data[template_path.stem] = ujson.load( template_path.open("r", encoding="utf8")) return TarkovSuccessResponse(data=data)
def __init__( self, trader_type: TraderType, templates_repository: ItemTemplatesRepository, trader_view_factory: Callable[..., BaseTraderView], config: TradersConfig, ): self.__templates_repository = templates_repository self.__view_factory = trader_view_factory self.__config = config self.type: Final[TraderType] = trader_type self.path = db_dir.joinpath("traders", self.type.value) self.__barter_scheme_generator: TraderAssortGenerator if trader_type == TraderType.Fence: self.__barter_scheme_generator = FenceAssortGenerator(self) else: self.__barter_scheme_generator = TraderAssortGenerator(self) self._base: Final[TraderBase] = TraderBase.parse_file( self.path.joinpath("base.json")) self.loyal_level_items: Final[Dict[str, int]] = pydantic.parse_file_as( Dict[str, int], self.path.joinpath("loyal_level_items.json")) self.quest_assort: Final[QuestAssort] = QuestAssort.parse_file( self.path.joinpath("questassort.json")) self.__update()
def __init__( self, config: FleaMarketConfig, templates_repository: ItemTemplatesRepository, globals_repository: GlobalsRepository, item_factory: ItemFactory, ) -> None: self.__config = config self.__templates_repository = templates_repository self.__globals_repository = globals_repository self.__item_factory = item_factory # Creates dictionary with item prices from templates and updates it with prices from flea_prices.json self.item_prices = { tpl.id: tpl.props.CreditsPrice for tpl in self.__templates_repository.templates.values() if tpl.id in category_repository.item_categories and tpl.props.CreditsPrice } item_prices: Dict[TemplateId, int] = pydantic.parse_file_as( Dict[TemplateId, int], db_dir.joinpath("flea_prices.json")) self.item_prices.update( {tpl: price for tpl, price in item_prices.items() if price > 0}) # Load seller usernames. self.seller_names = pydantic.parse_file_as( List[str], db_dir.joinpath("traders", "ragfair", "sellers.json")) # All the item templates that we have prices for self.item_templates = [ tpl for tpl in self.__templates_repository.templates.values() if tpl.id in self.item_prices ] prices = list(self.item_prices.values()) median_price = statistics.median(prices) prices_sorted = sorted(prices) # Calculates low/high percentile, they're used to weight too cheap/expensive items self.percentile_high: int = prices_sorted[int( len(prices) * self.__config.percentile_high)] self.percentile_low: int = prices_sorted[int( len(prices) * self.__config.percentile_low)] self.item_templates_weights = [ self._get_item_template_weight(tpl, median_price) for tpl in self.item_templates ]
def load_locale(locale_name: str) -> dict: locale_data = {} excluded_files = ("menu", locale_name) locale_dir = db_dir.joinpath("locales", locale_name) for file in (path for path in locale_dir.glob("*.json") if path.stem not in excluded_files): locale_data[file.stem] = ujson.load(file.open("r", encoding="utf8")) return locale_data
def _read_item_template_categories( ) -> Dict[TemplateId, ItemTemplateCategoryModel]: template_categories: List[ ItemTemplateCategoryModel] = pydantic.parse_file_as( List[ItemTemplateCategoryModel], db_dir.joinpath("templates", "items.json"), ) return {tpl.Id: tpl for tpl in template_categories}
def create_profile( self, profile_id: str, nickname: str, side: str, ) -> ProfileModel: from tarkov.profile.models import ProfileModel account = self.__account_service.get_account(profile_id) base_profile_dir = db_dir.joinpath("profile", account.edition) starting_outfit = ujson.load( base_profile_dir.joinpath("starting_outfit.json").open() ) character = ujson.load(base_profile_dir.joinpath("character.json").open()) character["Customization"] = starting_outfit[side.lower()] profile: ProfileModel = ProfileModel.parse_obj(character) profile.aid = f"{account.id}" profile.id = f"pmc{account.id}" profile.savage = f"scav{account.id}" profile.Info.Nickname = nickname profile.Info.LowerNickname = nickname.lower() profile.Info.Side = side.capitalize() profile.Info.Voice = f"{side.capitalize()}_1" profile_dir: Final[Path] = root_dir.joinpath( "resources", "profiles", account.id ) profile_dir.mkdir(parents=True, exist_ok=True) with profile_dir.joinpath("pmc_profile.json").open( "w", encoding="utf8" ) as file: file.write(profile.json(exclude_none=True)) # TODO: Scav profile generation, for not it just copies scav_profile = ujson.load( root_dir.joinpath("resources", "scav_profile.json").open( "r", encoding="utf8" ) ) scav_profile["id"] = f"scav{profile.aid}" scav_profile["savage"] = f"scav{profile.aid}" scav_profile["aid"] = profile.aid ujson.dump( scav_profile, profile_dir.joinpath("scav_profile.json").open("w", encoding="utf8"), indent=4, ensure_ascii=False, ) profile_manager.get_profile(profile_id=profile_id) return profile
def client_globals( flea_config: FleaMarketConfig = Depends( Provide[AppContainer.config.flea_market]), ) -> TarkovSuccessResponse[dict]: globals_path = db_dir.joinpath("base", "globals.json") globals_base = ujson.load(globals_path.open(encoding="utf8")) globals_base["time"] = int(datetime.datetime.now().timestamp()) globals_base["config"]["RagFair"][ "minUserLevel"] = flea_config.level_required return TarkovSuccessResponse(data=globals_base)
def client_locations() -> TarkovSuccessResponse[dict]: locations_base_path = db_dir.joinpath("base", "locations.json") locations_base: dict = ujson.load(locations_base_path.open()) for file in (db_dir / "locations").glob("*.json"): map_data = ujson.load(file.open("r")) map_id = map_data["base"]["_Id"] locations_base["locations"][map_id] = map_data["base"] return TarkovSuccessResponse(data=locations_base)
def __init__( self, location: str, templates_repository: ItemTemplatesRepository = Provide[ AppContainer.repos.templates], ): self.templates_repository = templates_repository location_file_path = db_dir.joinpath("locations", f"{location}.json") self.__location: dict = ujson.load( location_file_path.open(encoding="utf8")) self.__base: dict = self.__location["base"] self.__loot: dict = self.__location["loot"] # Cache to store pairs of categories and it's items # for example - Medkits category and all it's medkits self.__category_cache: Dict[str, List[ItemTemplate]] = {}
def client_weather() -> TarkovSuccessResponse[dict]: weather_dir = db_dir.joinpath("weather") weather_files = list(weather_dir.glob("*")) weather_data: dict = ujson.load( random.choice(weather_files).open("r", encoding="utf8")) current_datetime = datetime.datetime.now() delta = current_datetime - start_time current_datetime = current_datetime + delta * weather_data["acceleration"] timestamp = int(current_datetime.timestamp()) date_str = current_datetime.strftime("%Y-%m-%d") time_str = current_datetime.strftime("%H:%M:%S") weather_data["weather"]["timestamp"] = timestamp weather_data["weather"]["date"] = date_str weather_data["weather"]["time"] = f"{date_str} {time_str}" weather_data["date"] = date_str weather_data["time"] = time_str return TarkovSuccessResponse(data=weather_data)
def available_editions(self) -> List[str]: editions_dirs = [ d for d in db_dir.joinpath("profile").glob("*") if d.is_dir() ] return [d.name for d in editions_dirs]
def get_recipe(recipe_id: str) -> dict: recipe_path = db_dir.joinpath("hideout", "production", f"{recipe_id}.json") return ujson.load(recipe_path.open("r", encoding="utf8"))
def __init__(self, preset_factory: Callable[..., BotGeneratorPreset]) -> None: self._bot_base: Final[dict] = ujson.load( db_dir.joinpath("base", "botBase.json").open(encoding="utf8")) self.preset_factory = preset_factory
def _read_categories() -> Dict[CategoryId, CategoryModel]: categories: List[CategoryModel] = pydantic.parse_file_as( List[CategoryModel], db_dir.joinpath("templates", "categories.json"), ) return {category.Id: category for category in categories}
def get_metrics_config() -> TarkovSuccessResponse[dict]: return TarkovSuccessResponse(data=ujson.load( db_dir.joinpath("base", "matchMetrics.json").open(encoding="utf8")))
def __init__(self) -> None: self.globals: GlobalsModel = GlobalsModel.parse_file( db_dir.joinpath("base", "globals.json"))
def client_quest_list() -> TarkovSuccessResponse[list]: all_quests: list = ujson.load( db_dir.joinpath("quests", "all.json").open("r", encoding="utf8")) return TarkovSuccessResponse(data=all_quests)
from server import db_dir from tarkov.models import Base class HideoutSettingsModel(Base): generatorSpeedWithoutFuel: float generatorFuelFlowRate: float airFilterUnitFlowRate: float gpuBoostRate: float settings = HideoutSettingsModel.parse_file( db_dir.joinpath("hideout", "settings.json"))
from server import db_dir from tarkov.hideout.models import HideoutAreaType from tarkov.inventory.types import TemplateId from tarkov.models import Base class HideoutProductionModel(Base): id: str = Field(alias="_id") areaType: HideoutAreaType requirements: List[dict] continuous: bool productionTime: int endProduct: TemplateId count: int productionLimitCount: int class HideoutProductionRepository: production: List[HideoutProductionModel] def __init__(self, production: List[dict]): self.production = pydantic.parse_obj_as(List[HideoutProductionModel], production) production_repository = HideoutProductionRepository(production=[ ujson.load(path.open()) for path in db_dir.joinpath("hideout", "production").glob("*.json") ])
class QuestsContainer(containers.DeclarativeContainer): repository: providers.Provider[QuestsRepository] = providers.Singleton( QuestsRepository, quests_path=db_dir.joinpath("quests", "all.json"))
from typing import List import pydantic import ujson from pydantic import Field from server import db_dir from tarkov.models import Base class ScavcaseProductionModel(Base): id: str = Field(alias="_id") productionTime: int Requirements: List[dict] EndProducts: dict class ScavcaseProductionRepository: production: List[ScavcaseProductionModel] def __init__(self, production: List[dict]): self.production = pydantic.parse_obj_as(List[ScavcaseProductionModel], production) scavcase_production_repository = ScavcaseProductionRepository(production=[ ujson.load(path.open()) for path in db_dir.joinpath("hideout", "scavcase").glob("*.json") ])
def __read_item_categories() -> dict: items = ujson.load( db_dir.joinpath("templates", "items.json").open("r", encoding="utf8")) items = {item["Id"]: item for item in items} return items
requirements: List[Union[Requirements.Area, Requirements.Item, Requirements.TraderLoyalty, Requirements.Skill, ]] bonuses: List[Union[Bonuses.AdditionalSlots, Bonuses.Text, Bonuses.SkillGroupLevelingBoost, Bonuses.StashSize, Bonuses.GenericBonus, ]] slots: int constructionTime: int description: str class HideoutAreaTemplate(Base): id: str = Field(alias="_id") type: int enabled: bool needsFuel: bool takeFromSlotLocked: bool stages: Dict[str, HideoutAreaStage] class HideoutAreasRepository: areas: List[HideoutAreaTemplate] def __init__(self, areas: List[dict]): self.areas = pydantic.parse_obj_as(List[HideoutAreaTemplate], areas) areas_repository = HideoutAreasRepository(areas=[ ujson.load(path.open()) for path in db_dir.joinpath("hideout", "areas").glob("*.json") ])