def remove_buff(sim_info: SimInfo, *buff_ids: Union[int, CommonBuffId]) -> bool: """remove_buff(sim_info, *buff_ids) Remove the specified buffs from a sim. :param sim_info: The sim to remove the specified buffs from. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of Buffs to remove. :type buff_ids: int :return: True, if all of the specified buffs were successfully removed. False, if not. :rtype: bool """ if sim_info is None: raise AssertionError('Argument sim_info was None') if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False success = True for buff_identifier in buff_ids: buff_instance = CommonBuffUtils.load_buff_by_id(buff_identifier) if buff_instance is None: continue if not sim_info.remove_buff_by_type(buff_instance): success = False return success
def has_buff(sim_info: SimInfo, *buff_ids: Union[int, CommonBuffId]) -> bool: """has_buff(sim_info, *buff_ids) Determine if any of the specified buffs are currently active on a sim. :param sim_info: The sim being checked. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of Buffs. :type buff_ids: int :return: True if the sim has any of the specified buffs. :rtype: int """ if sim_info is None: raise AssertionError('Argument sim_info was None') if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False if not buff_ids: return False sim_buffs = CommonBuffUtils.get_buffs(sim_info) for buff in sim_buffs: buff_id = CommonBuffUtils.get_buff_id(buff) if buff_id in buff_ids: return True return False
def remove_buff(sim_info: SimInfo, *buff_ids: int) -> bool: """remove_buff(sim_info, *buff_ids) Remove the specified buffs from a sim. :param sim_info: The sim to remove the specified buffs from. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of Buffs to remove. :type buff_ids: int :return: True, if all of the specified buffs were successfully removed. False, if not. :rtype: bool """ if sim_info is None: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.remove_buff.__name__, CommonBuffUtils.__name__)) return False if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False success = True for buff_identifier in buff_ids: buff_instance = CommonBuffUtils._load_buff_instance(buff_identifier) if buff_instance is None: continue if not sim_info.remove_buff_by_type(buff_instance): success = False return success
def add_buff( sim_info: SimInfo, *buff_ids: Union[int, CommonBuffId], buff_reason: Union[int, str, LocalizedString, CommonStringId] = None ) -> bool: """add_buff(sim_info, *buff_ids, buff_reason=None) Add the specified buffs to a sim. :param sim_info: The sim to add the specified buffs to. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of buffs to add. :type buff_ids: int :param buff_reason: The text that will display when the player hovers over the buffs. What caused the buffs to be added. :type buff_reason: Union[int, str, LocalizedString, CommonStringId], optional :return: True, if all of the specified buffs were successfully added. False, if not. :rtype: bool """ if sim_info is None: raise AssertionError('Argument sim_info was None') if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False localized_buff_reason = CommonLocalizationUtils.create_localized_string( buff_reason) success = True for buff_identifier in buff_ids: buff_instance = CommonBuffUtils.load_buff_by_id(buff_identifier) if buff_instance is None: continue if not sim_info.add_buff_from_op( buff_instance, buff_reason=localized_buff_reason): success = False return success
def has_buff(sim_info: SimInfo, *buff_ids: int) -> bool: """has_buff(sim_info, *buff_ids) Determine if any of the specified buffs are currently active on a sim. :param sim_info: The sim being checked. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of Buffs. :type buff_ids: int :return: True if the sim has any of the specified buffs. :rtype: int """ if sim_info is None: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.has_buff.__name__, CommonBuffUtils.__name__)) return False if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False if not buff_ids: return False sim_buffs = CommonBuffUtils.get_buffs(sim_info) for buff in sim_buffs: buff_id = getattr(buff, 'guid64', None) if buff_id in buff_ids: return True return False
def add_buff(sim_info: SimInfo, *buff_ids: int, buff_reason: Union[int, str, LocalizedString]=None) -> bool: """add_buff(sim_info, *buff_ids, buff_reason=None) Add the specified buffs to a sim. :param sim_info: The sim to add the specified buffs to. :type sim_info: SimInfo :param buff_ids: The decimal identifiers of buffs to add. :type buff_ids: int :param buff_reason: The text that will display when the player hovers over the buffs. What caused the buffs to be added. :type buff_reason: Union[int, str, LocalizedString], optional :return: True, if all of the specified buffs were successfully added. False, if not. :rtype: bool """ if sim_info is None: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\''.format(CommonBuffUtils.add_buff.__name__, CommonBuffUtils.__name__)) return False if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return False localized_buff_reason = CommonLocalizationUtils.create_localized_string(buff_reason) success = True for buff_identifier in buff_ids: buff_instance = CommonBuffUtils._load_buff_instance(buff_identifier) if buff_instance is None: continue if not sim_info.add_buff_from_op(buff_instance, buff_reason=localized_buff_reason): success = False return success
def get_buffs(sim_info: SimInfo) -> List[Buff]: """get_buffs(sim_info) Retrieve all buffs currently active on a Sim. :param sim_info: The Sim to retrieve the buffs of. :type sim_info: SimInfo :return: A collection of currently active buffs on the Sim. :rtype: Tuple[Buff] """ if sim_info is None: CommonExceptionHandler.log_exception( ModInfo.get_identity(), 'Argument \'sim_info\' was \'None\' for \'{}\' of class \'{}\'' .format(CommonBuffUtils.get_buffs.__name__, CommonBuffUtils.__name__)) return list() if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return list() from objects.components.buff_component import BuffComponent buff_component: BuffComponent = CommonComponentUtils.get_component( sim_info, CommonComponentType.BUFF) buffs = list() for buff in buff_component: if buff is None or not isinstance(buff, Buff): continue buffs.append(buff) return buffs
def get_gender_preference_amount(sim_info: SimInfo, gender: Gender) -> int: """get_gender_preference_value(sim_info, gender) Retrieve the amount a Sim prefers the specified gender. :param sim_info: An instance of a Sim. :type sim_info: SimInfo :param gender: A Gender. :type gender: Gender :return: The amount the Sim prefers the specified Gender. :rtype: int """ if not CommonComponentUtils.has_component( sim_info, CommonComponentType.STATISTIC): return 0 gender_preference = sim_info.get_gender_preference(gender) if gender_preference is None: return 0 return gender_preference.get_value()
def set_gender_preference_amount(sim_info: SimInfo, gender: Gender, amount: int) -> bool: """set_gender_preference_amount(sim_info, gender, amount) Set the amount a Sim prefers the specified Gender. :param sim_info: An instance of a Sim. :type sim_info: SimInfo :param gender: A Gender. :type gender: Gender :param amount: The amount the Sim prefers the specified Gender. :type amount: int :return: True, if successfully set. False, it not. :rtype: bool """ if not CommonComponentUtils.has_component( sim_info, CommonComponentType.STATISTIC): return False gender_preference = sim_info.get_gender_preference(gender) if gender_preference is None: return False gender_preference.set_value(amount) return True
def get_buff_ids(sim_info: SimInfo) -> List[int]: """get_buff_ids(sim_info) Retrieve decimal identifiers for all Buffs of a sim. :param sim_info: The sim to checked. :type sim_info: SimInfo :return: A collection of Buff identifiers on a Sim. :rtype: List[int] """ if sim_info is None: raise AssertionError('Argument sim_info was None') if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return list() buff_ids = list() sim_buffs = CommonBuffUtils.get_buffs(sim_info) for buff in sim_buffs: buff_id = CommonBuffUtils.get_buff_id(buff) if buff_id is None: continue buff_ids.append(buff_id) return buff_ids
def get_buffs(sim_info: SimInfo) -> List[Buff]: """get_buffs(sim_info) Retrieve all buffs currently active on a Sim. :param sim_info: The Sim to retrieve the buffs of. :type sim_info: SimInfo :return: A collection of currently active buffs on the Sim. :rtype: Tuple[Buff] """ if sim_info is None: raise AssertionError('Argument sim_info was None') if not CommonComponentUtils.has_component(sim_info, CommonComponentType.BUFF): return list() from objects.components.buff_component import BuffComponent buff_component: BuffComponent = CommonComponentUtils.get_component( sim_info, CommonComponentType.BUFF) buffs = list() for buff in buff_component: if buff is None or not isinstance(buff, Buff): continue buffs.append(buff) return buffs