Exemplo n.º 1
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  with_character: "CharacterModel",
                                  input_: TakeFromModel) -> None:
        self.check_is_possible(character, with_character)

        if input_.take_resource_id is not None and input_.take_resource_quantity:
            if not self._kernel.resource_lib.have_resource(
                    character_id=with_character.id,
                    resource_id=input_.take_resource_id,
                    quantity=input_.take_resource_quantity,
            ):
                raise ImpossibleAction(
                    f"{with_character.name} n'en à pas assez")

        if input_.take_stuff_id:
            try:
                stuff: StuffModel = self._kernel.stuff_lib.get_stuff(
                    input_.take_stuff_id)
            except NoResultFound:
                raise ImpossibleAction(f"objet inexistant")
            carried_count = self._kernel.stuff_lib.have_stuff_count(
                character_id=with_character.id, stuff_id=stuff.stuff_id)
            if carried_count < (input_.take_stuff_quantity or 1):
                raise ImpossibleAction(
                    f"{with_character.name} n'en à pas assez")
Exemplo n.º 2
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  with_character: "CharacterModel",
                                  input_: AttackModel) -> None:
        # lonely attack when exhausted is not possible
        if input_.lonely is not None and input_.lonely and not character.is_attack_ready(
        ):
            raise ImpossibleAction(
                f"{character.name} n'est pas en mesure de mener cette attaque !"
            )

        # with_character must not been part of attacking affinity
        if input_.as_affinity is not None and self._kernel.affinity_lib.character_is_in_affinity(
                affinity_id=input_.as_affinity,
                character_id=with_character.id):
            raise ImpossibleAction(
                f"Vous ne pouvez pas attaquer un membre d'une même affinités")

        # It must have ready fighter to fight
        if input_.as_affinity is not None and not self._kernel.affinity_lib.count_ready_fighter(
                affinity_id=input_.as_affinity,
                world_row_i=character.world_row_i,
                world_col_i=character.world_col_i,
        ):
            raise ImpossibleAction(
                f"Personne n'est en état de se battre actuellement")
Exemplo n.º 3
0
 def check_is_possible(self, character: "CharacterModel", stuff: "StuffModel") -> None:
     if not stuff.shield:
         raise ImpossibleAction("Ce n'est pas un bouclier")
     if not stuff.ready_for_use:
         raise ImpossibleAction(f"{stuff.name} n'est pas utilisable")
     if character.shield:
         raise ImpossibleAction("Vous utilisez déjà un bouclier")
Exemplo n.º 4
0
 def check_is_possible(self, character: "CharacterModel", stuff: "StuffModel") -> None:
     if not stuff.armor:
         raise ImpossibleAction("Ce n'est pas une armure/protection")
     if not stuff.ready_for_use:
         raise ImpossibleAction(f"{stuff.name} n'est pas utilisable")
     if character.armor:
         raise ImpossibleAction("Vous utilisez déjà une armure/protection")
Exemplo n.º 5
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  input_: CheatsModel) -> None:
        if not input_.cheat_id:
            raise ImpossibleAction("Choix du cheat nécessaire")

        if input_.cheat_id in self._get_available_cheats(character):
            return

        raise ImpossibleAction("Ce cheat ne vous est pas accessible")
Exemplo n.º 6
0
    def _check_attack_lonely(self, character: CharacterModel,
                             defense: DefendDescription, aff: str) -> None:
        if not character.is_attack_ready():
            raise ImpossibleAction("Vous n'etes pas en état de vous battre")

        # by affinities, character can be in defense side. In that case, don't permit the fight
        if character.id in [f.id for f in defense.all_fighters]:
            raise ImpossibleAction(
                "Vous ne pouvez pas mener cette attaque car parmis les defenseur se trouve "
                f"des personnes avec lesquelles vous etes affiliés. Affinités en défense: {aff}"
            )
Exemplo n.º 7
0
 def check_is_possible(self, character: "CharacterModel",
                       with_character: "CharacterModel") -> None:
     # TODO BS: Check here is possible too with affinities (like chief
     #  can manipulate, firendship, etc)
     if not with_character.vulnerable:
         raise ImpossibleAction(
             f"{with_character.name} est en capacité de se defendre")
     else:
         if not character.is_attack_ready():
             raise ImpossibleAction(
                 f"{character.name} ne peut contraindre {with_character.name}"
             )
Exemplo n.º 8
0
    def check_request_is_possible(
        self,
        character: "CharacterModel",
        with_character: "CharacterModel",
        input_: TeachKnowledgeModel,
    ) -> None:
        self.check_is_possible(character, with_character)
        if input_.knowledge_id not in character.knowledges:
            raise ImpossibleAction(
                f"{character.name} n'a pas cette connaisance")

        if input_.ap is not None and character.action_points < input_.ap:
            raise ImpossibleAction(
                f"{character.name} n'a pas assez de points d'actions")
Exemplo n.º 9
0
    def check_is_possible(self, character: "CharacterModel",
                          resource_id: str) -> None:
        if not self._kernel.resource_lib.have_resource(character.id,
                                                       resource_id):
            raise ImpossibleAction("Vous ne possedez pas cette resource")

        # TODO BS 2019-09-10: manage more than two resource mix
        for carried_resource in self._kernel.resource_lib.get_carried_by(
                character.id):
            for resource_mix_description in self._kernel.game.config.get_resource_mixs_with(
                [resource_id, carried_resource.id]):
                return

        raise ImpossibleAction("Aucune association possible")
Exemplo n.º 10
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  input_: LearnKnowledgeModel) -> None:
        if input_.knowledge_id is not None:
            if input_.knowledge_id in character.knowledges:
                raise ImpossibleAction("Connaissance déjà acquise")
            knowledge_description = self._kernel.game.config.knowledge[
                input_.knowledge_id]
            for required_knowledge_id in knowledge_description.requires:
                if required_knowledge_id not in character.knowledges:
                    raise ImpossibleAction(
                        f"Cette connaissance ne peut pas encore etre abordé")

        if input_.ap is not None:
            if character.action_points < input_.ap:
                raise ImpossibleAction("Pas assez de points d'actions")
Exemplo n.º 11
0
    def check_is_possible(self, character: "CharacterModel",
                          stuff: "StuffModel") -> None:
        # TODO BS 2019-07-31: check is owned stuff
        if stuff.stuff_id in self._description.properties["accept_stuff_ids"]:
            return

        raise ImpossibleAction(f"Vous ne pouvez pas le manger")
Exemplo n.º 12
0
 def check_request_is_possible(
     self, character: "CharacterModel", stuff: "StuffModel", input_: ContinueStuffModel
 ) -> None:
     self.check_is_possible(character, stuff)
     if input_.ap:
         if character.action_points < input_.ap:
             raise ImpossibleAction(f"{character.name} ne possède passez de points d'actions")
Exemplo n.º 13
0
 def check_request_is_possible(self, character: "CharacterModel",
                               resource_id: str,
                               input_: input_model) -> None:
     if not self._kernel.resource_lib.have_resource(
             character.id, resource_id, quantity=input_.quantity):
         raise ImpossibleAction(
             "Vous ne possedez pas assez de cette resource")
Exemplo n.º 14
0
 def check_is_possible(self, character: "CharacterModel",
                       with_character: "CharacterModel") -> None:
     # FIXME BS: en fait, toute les actions doivent tester si la cible est sur la meme zone ...
     if (character.world_row_i != with_character.world_row_i
             or character.world_col_i != with_character.world_col_i):
         raise ImpossibleAction(
             "Les personnages ne sont pas sur la meme zone")
Exemplo n.º 15
0
 def check_is_possible(self, character: "CharacterModel",
                       with_character: "CharacterModel") -> None:
     if not (character.world_row_i == with_character.world_row_i
             and character.world_col_i == with_character.world_col_i
             and not self._kernel.character_lib.is_following(
                 character.id, with_character.id)):
         raise ImpossibleAction(
             f"{with_character.name} ne se trouve pas ici")
Exemplo n.º 16
0
    def check_is_possible(self, character: "CharacterModel",
                          resource_id: str) -> None:
        accept_resources_ids = [
            rd.id for rd in self._description.properties["accept_resources"]
        ]
        if resource_id in accept_resources_ids:
            return

        raise ImpossibleAction("Non consommable")
Exemplo n.º 17
0
    def check_is_possible(self, character: "CharacterModel") -> None:
        for resource in self._kernel.game.world_manager.get_resource_on_or_around(
                world_row_i=character.world_row_i,
                world_col_i=character.world_col_i,
                zone_row_i=character.zone_row_i,
                zone_col_i=character.zone_col_i,
        ):
            return

        raise ImpossibleAction("Il n'y a rien à collecter ici")
Exemplo n.º 18
0
    def check_is_possible(self, character: "CharacterModel", stuff: "StuffModel") -> None:
        # Consider action ca be possible (displayed in interface) if at least one of required stuff
        # is owned by character
        carried = self._kernel.stuff_lib.get_carried_by(character.id)
        carried_stuff_ids = [r.stuff_id for r in carried]

        for require in self._description.properties["require"]:
            if "stuff" in require and require["stuff"] in carried_stuff_ids:
                return

        raise ImpossibleAction("Aucune resource requise n'est possédé")
Exemplo n.º 19
0
    def check_is_possible(self, character: "CharacterModel",
                          stuff: "StuffModel") -> None:
        # TODO BS 2019-07-31: check is owned stuff
        accept_resources_ids = [
            rd.id for rd in self._description.properties["accept_resources"]
        ]
        if (stuff.filled_with_resource is not None
                and stuff.filled_with_resource in accept_resources_ids):
            return

        raise ImpossibleAction(f"Il n'y a pas de quoi boire la dedans")
Exemplo n.º 20
0
    def check_request_is_possible(
        self, character: "CharacterModel", input_: BeginStuffModel
    ) -> None:
        self.check_is_possible(character)
        check_common_is_possible(self._kernel, description=self._description, character=character)

        cost = self.get_cost(character)
        if character.action_points < cost:
            raise ImpossibleAction(
                f"{character.name} no possède pas assez de points d'actions "
                f"({round(cost, 2)} nécessaires)"
            )

        for consume in self._description.properties["consume"]:
            if "resource" in consume:
                resource_id = consume["resource"]
                resource_description = self._kernel.game.config.resources[resource_id]
                quantity = consume["quantity"]
                quantity_str = quantity_to_str(quantity, resource_description.unit, self._kernel)
                if not self._kernel.resource_lib.have_resource(
                    character.id, resource_id=resource_id, quantity=quantity
                ):
                    resource_description = self._kernel.game.config.resources[resource_id]
                    raise ImpossibleAction(
                        f"Vous ne possédez pas assez de {resource_description.name}: {quantity_str} nécessaire(s)"
                    )

            elif "stuff" in consume:
                stuff_id = consume["stuff"]
                quantity = consume["quantity"]
                if (
                    self._kernel.stuff_lib.have_stuff_count(character.id, stuff_id=stuff_id)
                    < quantity
                ):
                    stuff_properties = self._kernel.game.stuff_manager.get_stuff_properties_by_id(
                        stuff_id
                    )
                    raise ImpossibleAction(
                        f"Vous ne possédez pas assez de {stuff_properties.name}: {quantity} nécessaire(s)"
                    )
Exemplo n.º 21
0
    def check_request_is_possible(self, character: "CharacterModel", input_: BuildModel) -> None:
        check_common_is_possible(
            kernel=self._kernel, description=self._description, character=character
        )
        build_id = self._description.properties["build_id"]
        build_description = self._kernel.game.config.builds[build_id]

        if character.action_points < self.get_cost(character, input_):
            raise ImpossibleAction("Pas assez de points d'actions")

        for require in build_description.build_require_resources:
            if not self._kernel.resource_lib.have_resource(
                character.id, resource_id=require.resource_id, quantity=require.quantity
            ):
                resource_properties = self._kernel.game.config.resources[require.resource_id]
                required_quantity_str = quantity_to_str(
                    require.quantity, resource_properties.unit, self._kernel
                )
                raise ImpossibleAction(
                    f"Vous ne possedez pas assez de {resource_properties.name} "
                    f"({required_quantity_str} requis)"
                )
Exemplo n.º 22
0
    def check_is_possible(self, character: "CharacterModel",
                          stuff: "StuffModel") -> None:
        for fill_acceptable_type in self._kernel.game.config.fill_with_material_ids:
            for resource in self._kernel.game.world_manager.get_resource_on_or_around(
                    world_row_i=character.world_row_i,
                    world_col_i=character.world_col_i,
                    zone_row_i=character.zone_row_i,
                    zone_col_i=character.zone_col_i,
                    material_type=fill_acceptable_type,
            ):
                return

        raise ImpossibleAction("Rien à proximité ne correspond")
Exemplo n.º 23
0
def check_common_is_possible(
    kernel: "Kernel", description: "ActionDescriptionModel", character: "CharacterModel"
) -> None:
    character_stuff_ids = [s.stuff_id for s in kernel.stuff_lib.get_carried_by(character.id)]
    character_skill_ids = []  # TODO BS 2019-09-26: code it
    one_of_required_stuff_found = False
    one_of_required_skill_found = False
    one_of_required_abilities = False

    for required_one_of_stuff_id in description.properties["required_one_of_stuff_ids"]:
        if required_one_of_stuff_id in character_stuff_ids:
            one_of_required_stuff_found = True

    for required_one_of_skill in description.properties["required_one_of_skills"]:
        if required_one_of_skill.id in character_skill_ids:
            one_of_required_skill_found = True

    if kernel.character_lib.have_from_of_abilities(
        character, abilities=description.properties["required_one_of_abilities"]
    ):
        one_of_required_abilities = True

    if description.properties["required_one_of_stuff_ids"] and not one_of_required_stuff_found:
        raise ImpossibleAction("Manque de matériel")

    if description.properties["required_one_of_skills"] and not one_of_required_skill_found:
        raise ImpossibleAction("Manque d'expérience")

    if description.properties["required_one_of_abilities"] and not one_of_required_abilities:
        raise ImpossibleAction("Manque de matériels ou de compétences")

    for required_all_stuff_id in description.properties["required_all_stuff_ids"]:
        if required_all_stuff_id not in character_stuff_ids:
            raise ImpossibleAction("Manque de matériels")

    for required_all_skill_id in description.properties["required_all_skills"]:
        if required_all_skill_id not in character_skill_ids:
            raise ImpossibleAction("Manque de compétences")
Exemplo n.º 24
0
    def check_is_possible(self, character: "CharacterModel") -> None:
        accept_resources_ids = [
            rd.id for rd in self._description.properties["accept_resources"]
        ]
        for resource in self._kernel.game.world_manager.get_resource_on_or_around(
                world_row_i=character.world_row_i,
                world_col_i=character.world_col_i,
                zone_row_i=character.zone_row_i,
                zone_col_i=character.zone_col_i,
                material_type=self._kernel.game.config.liquid_material_id,
        ):
            if resource.type_.value in accept_resources_ids:
                return

        raise ImpossibleAction("Il n'y a pas à boire à proximité")
Exemplo n.º 25
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  input_: DrinkResourceModel) -> None:
        accept_resources_ids = [
            rd.id for rd in self._description.properties["accept_resources"]
        ]
        for resource in self._kernel.game.world_manager.get_resource_on_or_around(
                world_row_i=character.world_row_i,
                world_col_i=character.world_col_i,
                zone_row_i=character.zone_row_i,
                zone_col_i=character.zone_col_i,
                material_type=self._kernel.game.config.liquid_material_id,
        ):
            if resource.id == input_.resource_id and input_.resource_id in accept_resources_ids:
                return

        raise ImpossibleAction(
            f"Il n'y a pas de {input_.resource_id} à proximité")
Exemplo n.º 26
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  input_: input_model) -> None:
        # FIXME BS 2019-08-27: check input_.row_i and input_.col_i are near
        # FIXME BS 2019-08-29: check if quantity is possible
        resources = self._kernel.game.world_manager.get_resources_at(
            world_row_i=character.world_row_i,
            world_col_i=character.world_col_i,
            zone_row_i=input_.row_i,
            zone_col_i=input_.col_i,
        )
        resource_ids = [resource.id for resource in resources]

        if input_.resource_id in resource_ids:
            return

        raise ImpossibleAction(
            f"Il n'y a pas de '{input_.resource_id}' à cet endroit")
Exemplo n.º 27
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  resource_id: str,
                                  input_: EatResourceModel) -> None:
        self.check_is_possible(character, resource_id)

        # TODO BS 2019-09-14: perf
        carried_resource = next(
            (cr
             for cr in self._kernel.resource_lib.get_carried_by(character.id)
             if cr.id == resource_id))

        require = self._description.properties["require"]
        if carried_resource.quantity >= require:
            return

        unit_name = self._kernel.translation.get(carried_resource.unit)
        raise ImpossibleAction(
            f"Vous ne possédez pas assez de {carried_resource.name} "
            f"({require} {unit_name} requis)")
Exemplo n.º 28
0
    def check_request_is_possible(self, character: "CharacterModel",
                                  resource_id: str,
                                  input_: input_model) -> None:
        self.check_is_possible(character, resource_id)

        if input_.quantity is not None:
            resource_mix = self._kernel.game.config.resource_mixs[
                input_.resource_mix_id]
            unit_name = self._kernel.translation.get(
                resource_mix.produce_resource.unit)

            for required_resource in resource_mix.required_resources:
                carried_resource = self._kernel.resource_lib.get_one_carried_by(
                    character_id=character.id,
                    resource_id=required_resource.resource.id)
                required_quantity = required_resource.coeff * input_.quantity
                if carried_resource.quantity < required_quantity:
                    raise ImpossibleAction(
                        f"Vous ne possédez pas assez de {required_resource.resource.name}: "
                        f"Quantité nécessaire: {required_quantity} {unit_name}, "
                        f"vous n'en avez que {carried_resource.quantity} {unit_name}"
                    )
Exemplo n.º 29
0
 def check_is_possible(self, character: "CharacterModel",
                       stuff: "StuffModel") -> None:
     if stuff.carried_by != character.id:
         raise ImpossibleAction("Vous ne possedez pas cet objet")
Exemplo n.º 30
0
 def check_is_possible(self, character: "CharacterModel",
                       resource_id: str) -> None:
     if not self._kernel.resource_lib.have_resource(character.id,
                                                    resource_id):
         raise ImpossibleAction("Vous ne possedez pas cette resource")