Ejemplo n.º 1
0
    return knowledge in agent_data.knows


def add_knowledge(agent, knowledge):
    """Add a knowledge item to the agent

    Args:
        agent: A :class:`fife_rpg.entities.rpg_entity.RPGEntity` that has a
        agent component.

        knowledge: A string containing the knowledge
    """
    agent_data = getattr(agent, Agent.registered_as)
    agent_data.knows.add(knowledge)


def register_script_commands(module=""):
    """Register commands for this module"""
    from fife_rpg.systems.scriptingsystem import ScriptingSystem
    ScriptingSystem.register_command("knows", knows, module)
    ScriptingSystem.register_command("add_knowledge", add_knowledge, module)

# Register console commands
try:
    from fife_rpg.console_commands import register_command
    register_command("AddKnowledge", lambda application, agent_name, knowledge:
                     add_knowledge(application.world.get_entity(agent_name),
                                   knowledge))
except AlreadyRegisteredError:
    pass
Ejemplo n.º 2
0
    def identifier(self):
        """Returns the identifier of the entity"""
        return getattr(self, General.registered_as).identifier


def set_component_value(entity, component, field, value):
    """Sets the field value of an entities component to the specified value

    Args:
        entity: A :class:`fife_rpg.entities.rpg_entity.RPGEntity`

        component: The name of the component

        field: The field of the component

        value: The value to which the field is set
    """
    component_data = getattr(entity, component)
    setattr(component_data, field, value)


try:
    from fife_rpg.console_commands import register_command

    register_command(
        "SetComponentValue",
        lambda application, entity_name, *args: set_component_value(application.world.get_entity(entity_name), *args),
    )
except AlreadyRegisteredError:
    pass
Ejemplo n.º 3
0

# pylint: disable=C0111
# register console commmands
def __set_variable_console(application, *args):
    if not GameVariables.registered_as:
        return "The GameVariables system is not active."
    game_variables = getattr(application.world.systems,
                             GameVariables.registered_as)
    try:
        return game_variables.set_variable(*args)
    except TypeError as error:
        return str(error).replace("set_variable()", "SetVariable")

try:
    register_command("SetVariable", __set_variable_console)
except AlreadyRegisteredError:
    pass


def __delete_variable_console(application, *args):
    if not GameVariables.registered_as:
        return "The GameVariables system is not active."
    game_variables = getattr(application.world.systems,
                             GameVariables.registered_as)
    try:
        return game_variables.delete_variable(*args)
    except TypeError as error:
        return str(error).replace("delete_variable()", "DeleteVariable")

try:
Ejemplo n.º 4
0

# pylint: disable=C0111
# register console commmands
def __set_variable_console(application, *args):
    if not GameVariables.registered_as:
        return "The GameVariables system is not active."
    game_variables = getattr(application.world.systems,
                             GameVariables.registered_as)
    try:
        return game_variables.set_variable(*args)
    except TypeError as error:
        return str(error).replace("set_variable()", "SetVariable")

try:
    register_command("SetVariable", __set_variable_console)
except AlreadyRegisteredError:
    pass


def __delete_variable_console(application, *args):
    if not GameVariables.registered_as:
        return "The GameVariables system is not active."
    game_variables = getattr(application.world.systems,
                             GameVariables.registered_as)
    try:
        return game_variables.delete_variable(*args)
    except TypeError as error:
        return str(error).replace("delete_variable()", "DeleteVariable")

try:
Ejemplo n.º 5
0
def add_knowledge(agent, knowledge):
    """Add a knowledge item to the agent

    Args:
        agent: A :class:`fife_rpg.entities.rpg_entity.RPGEntity` that has a
        agent component.

        knowledge: A string containing the knowledge
    """
    agent_data = getattr(agent, Agent.registered_as)
    agent_data.knows.add(knowledge)


def register_script_commands(module=""):
    """Register commands for this module"""
    from fife_rpg.systems.scriptingsystem import ScriptingSystem
    ScriptingSystem.register_command("knows", knows, module)
    ScriptingSystem.register_command("add_knowledge", add_knowledge, module)


# Register console commands
try:
    from fife_rpg.console_commands import register_command
    register_command(
        "AddKnowledge",
        lambda application, agent_name, knowledge: add_knowledge(
            application.world.get_entity(agent_name), knowledge))
except AlreadyRegisteredError:
    pass
Ejemplo n.º 6
0
    @property
    def identifier(self):
        """Returns the identifier of the entity"""
        return getattr(self, General.registered_as).identifier


def set_component_value(entity, component, field, value):
    """Sets the field value of an entities component to the specified value

    Args:
        entity: A :class:`fife_rpg.entities.rpg_entity.RPGEntity`

        component: The name of the component

        field: The field of the component

        value: The value to which the field is set
    """
    component_data = getattr(entity, component)
    setattr(component_data, field, value)


try:
    from fife_rpg.console_commands import register_command
    register_command(
        "SetComponentValue",
        lambda application, entity_name, *args: set_component_value(
            application.world.get_entity(entity_name), *args))
except AlreadyRegisteredError:
    pass