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 __init__(self, profile_id: str): self.profile_id = profile_id self.profile_dir = root_dir.joinpath("resources", "profiles", profile_id) self.pmc_profile_path = self.profile_dir.joinpath("pmc_profile.json") self.scav_profile_path = self.profile_dir.joinpath("scav_profile.json")
from datetime import timedelta from pathlib import Path from typing import ClassVar from server import root_dir from tarkov.models import BaseConfig config_dir = root_dir.joinpath("config") config_dir.mkdir(parents=True, exist_ok=True) class FleaMarketConfig(BaseConfig): __config_path__: ClassVar[Path] = config_dir.joinpath("flea_market.yaml") offers_amount: int = 7500 percentile_high: float = 0.98 percentile_low: float = 0.2 level_required: int = 10 class BotGenerationConfig(BaseConfig): __config_path__: ClassVar[Path] = config_dir.joinpath( "bot_generation.yaml") scav_chance: float = 1 bear_chance: float = 0.5 usec_change: float = 0.5 class TradersConfig(BaseConfig): __config_path__: ClassVar[Path] = config_dir.joinpath("traders.yaml")
app.include_router(friend_router) app.include_router(hideout_router) app.include_router(lang_router) app.include_router(insurance_router) app.include_router(singleplayer_router) app.include_router(misc_router) app.include_router(flea_market_router) app.include_router(match_router) app.include_router(launcher_router) app.include_router(bots_router) app.include_router(offraid_router) app.mount( "/files", StaticFiles(directory=str(root_dir.joinpath("resources", "static"))), name="static", ) @app.middleware("http") async def log_response_time(request: Request, call_next: Callable) -> Response: start_time = time.time() response = await call_next(request) response_time = round(time.time() - start_time, 3) logger.debug(f"Response time: {response_time}s") return response @app.exception_handler(RequestValidationError) async def request_validation_exc_handler(
from typing import Callable, List from unittest.mock import patch import pytest from dependency_injector.wiring import Provide, inject from server import root_dir from server.container import AppContainer from tarkov.inventory.factories import ItemFactory from tarkov.inventory.inventory import PlayerInventory from tarkov.inventory.models import InventoryModel, Item, ItemTemplate from tarkov.inventory.repositories import ItemTemplatesRepository from tarkov.profile.models import ProfileModel from tarkov.profile.profile import Profile TEST_RESOURCES_PATH = root_dir.joinpath("tarkov", "tests", "resources") @pytest.fixture() def player_profile() -> Profile: profile = Profile("profile_id") profile.pmc = ProfileModel.parse_file( TEST_RESOURCES_PATH.joinpath("pmc_profile.json")) return profile @pytest.fixture() def inventory(player_profile: Profile) -> PlayerInventory: inventory = PlayerInventory(player_profile) inventory.read() return inventory
def __init__(self) -> None: self.accounts: List[Account] = [] self.path = root_dir.joinpath("resources", "profiles.json") self.__read()
def exists(profile_id: str) -> bool: return root_dir.joinpath("resources", "profiles", profile_id).exists()