Module genshin.client.components.calculator.calculator
Calculator builder object.
Over-engineered for the sake of extendability and maintainability.
Classes
class Calculator (client: Client, *, lang: typing.Optional[str] = None)
-
Builder for the genshin impact enhancement calculator.
Expand source code
class Calculator: """Builder for the genshin impact enhancement calculator.""" client: Client lang: typing.Optional[str] character: typing.Optional[CharacterResolver] weapon: typing.Optional[WeaponResolver] artifacts: typing.Optional[ArtifactResolver] talents: typing.Optional[TalentResolver] _state: CalculatorState def __init__(self, client: Client, *, lang: typing.Optional[str] = None) -> None: self.client = client self.lang = lang self.character = None self.weapon = None self.artifacts = None self.talents = None self._state = CalculatorState(client) def set_character( self, character: types.IDOr[genshin_models.BaseCharacter], current: typing.Optional[int] = None, target: typing.Optional[int] = None, *, element: typing.Optional[int] = None, ) -> Calculator: """Set the character.""" self.character = CharacterResolver(character, current, target, element=element) self._state.character_id = self.character.id return self def set_weapon(self, id: int, current: int, target: int) -> Calculator: """Set the weapon.""" self.weapon = WeaponResolver(id, current, target) return self def add_artifact(self, id: int, current: int, target: int) -> Calculator: """Add an artifact.""" if type(self.artifacts) is not ArtifactResolver: self.artifacts = ArtifactResolver() self.artifacts.add_artifact(id, current, target) return self def set_artifact_set(self, any_artifact_id: int, current: int, target: int) -> Calculator: """Set an artifact set.""" self.artifacts = ArtifactSetResolver(any_artifact_id, current, target) return self def add_talent(self, group_id: int, current: int, target: int) -> Calculator: """Add a talent.""" if type(self.talents) is not TalentResolver: self.talents = TalentResolver() self.talents.add_talent(group_id, current, target) return self def with_current_weapon(self, target: int) -> Calculator: """Set the weapon of the selected character.""" self.weapon = CurrentWeaponResolver(target) return self def with_current_artifacts( self, target: typing.Optional[int] = None, *, flower: typing.Optional[int] = None, feather: typing.Optional[int] = None, sands: typing.Optional[int] = None, goblet: typing.Optional[int] = None, circlet: typing.Optional[int] = None, ) -> Calculator: """Add all artifacts of the selected character.""" self.artifacts = CurrentArtifactResolver( target, flower=flower, feather=feather, sands=sands, goblet=goblet, circlet=circlet, ) return self def with_current_talents( self, target: typing.Optional[int] = None, current: typing.Optional[int] = None, *, attack: typing.Optional[int] = None, skill: typing.Optional[int] = None, burst: typing.Optional[int] = None, ) -> Calculator: """Add all talents of the currently selected character.""" self.talents = CurrentTalentResolver( target=target, current=current, attack=attack, skill=skill, burst=burst, ) return self async def build(self) -> typing.Mapping[str, typing.Any]: """Build the calculator object.""" data: dict[str, typing.Any] = {} if self.character: data.update(await self.character(self._state)) if self.weapon: data["weapon"] = await self.weapon(self._state) if self.artifacts: data["reliquary_list"] = await self.artifacts(self._state) if self.talents: data["skill_list"] = await self.talents(self._state) return data async def calculate(self) -> models.CalculatorResult: """Execute the calculator.""" return await self.client._execute_calculator(await self.build(), lang=self.lang) def __await__(self) -> typing.Generator[typing.Any, None, models.CalculatorResult]: return self.calculate().__await__()
Class variables
var artifacts : typing.Optional[ArtifactResolver]
var character : typing.Optional[CharacterResolver]
var client : Client
var lang : typing.Optional[str]
var talents : typing.Optional[TalentResolver]
var weapon : typing.Optional[WeaponResolver]
Methods
def add_artifact(self, id: int, current: int, target: int) ‑> Calculator
-
Add an artifact.
def add_talent(self, group_id: int, current: int, target: int) ‑> Calculator
-
Add a talent.
async def build(self) ‑> Mapping[str, Any]
-
Build the calculator object.
async def calculate(self) ‑> CalculatorResult
-
Execute the calculator.
def set_artifact_set(self, any_artifact_id: int, current: int, target: int) ‑> Calculator
-
Set an artifact set.
def set_character(self, character: types.IDOr[genshin_models.BaseCharacter], current: typing.Optional[int] = None, target: typing.Optional[int] = None, *, element: typing.Optional[int] = None) ‑> Calculator
-
Set the character.
def set_weapon(self, id: int, current: int, target: int) ‑> Calculator
-
Set the weapon.
def with_current_artifacts(self, target: typing.Optional[int] = None, *, flower: typing.Optional[int] = None, feather: typing.Optional[int] = None, sands: typing.Optional[int] = None, goblet: typing.Optional[int] = None, circlet: typing.Optional[int] = None) ‑> Calculator
-
Add all artifacts of the selected character.
def with_current_talents(self, target: typing.Optional[int] = None, current: typing.Optional[int] = None, *, attack: typing.Optional[int] = None, skill: typing.Optional[int] = None, burst: typing.Optional[int] = None) ‑> Calculator
-
Add all talents of the currently selected character.
def with_current_weapon(self, target: int) ‑> Calculator
-
Set the weapon of the selected character.
class FurnishingCalculator (client: Client, *, lang: typing.Optional[str] = None)
-
Builder for the genshin impact furnishing calculator.
Expand source code
class FurnishingCalculator: """Builder for the genshin impact furnishing calculator.""" client: Client lang: typing.Optional[str] furnishings: dict[int, int] replica_code: typing.Optional[int] = None replica_region: typing.Optional[str] = None def __init__(self, client: Client, *, lang: typing.Optional[str] = None) -> None: self.client = client self.lang = lang self.furnishings = {} self.replica_code = None self.replica_region = None def add_furnishing(self, id: types.IDOr[models.CalculatorFurnishing], amount: int = 1) -> FurnishingCalculator: """Add a furnishing.""" self.furnishings.setdefault(int(id), 0) self.furnishings[int(id)] += amount return self def with_replica(self, code: int, *, region: typing.Optional[str] = None) -> FurnishingCalculator: """Set the replica code.""" self.replica_code = code self.replica_region = region return self async def build(self) -> typing.Mapping[str, typing.Any]: """Build the calculator object.""" data: dict[str, typing.Any] = {} if self.replica_code: furnishings = await self.client.get_teapot_replica_blueprint(self.replica_code, region=self.replica_region) self.furnishings.update({furnishing.id: furnishing.amount or 1 for furnishing in furnishings}) data["list"] = [{"id": id, "cnt": amount} for id, amount in self.furnishings.items()] return data async def calculate(self) -> models.CalculatorFurnishingResults: """Execute the calculator.""" return await self.client._execute_furnishings_calculator(await self.build(), lang=self.lang) def __await__(self) -> typing.Generator[typing.Any, None, models.CalculatorFurnishingResults]: return self.calculate().__await__()
Class variables
var client : Client
var furnishings : dict[int, int]
var lang : typing.Optional[str]
var replica_code : typing.Optional[int]
var replica_region : typing.Optional[str]
Methods
def add_furnishing(self, id: types.IDOr[models.CalculatorFurnishing], amount: int = 1) ‑> FurnishingCalculator
-
Add a furnishing.
async def build(self) ‑> Mapping[str, Any]
-
Build the calculator object.
async def calculate(self) ‑> CalculatorFurnishingResults
-
Execute the calculator.
def with_replica(self, code: int, *, region: typing.Optional[str] = None) ‑> FurnishingCalculator
-
Set the replica code.