Пример #1
0
	def IsAvailable (self, targetSimInfo: sim_info.SimInfo) -> bool:
		"""
		Get whether or not the target sim can use this safety method. This may incorrectly return false for non-instanced sims; we cannot read the inventory
		of sims not instanced.
		"""

		if not isinstance(targetSimInfo, sim_info.SimInfo):
			raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

		if not self.HasRequirement:
			return True

		if not targetSimInfo.is_instanced():
			return False

		targetSim = targetSimInfo.get_sim_instance()  # type: sim.Sim

		for requirementGroup in self.Requirements:  # type: typing.Tuple[WoohooSafetyMethod.Requirement, ...]
			if len(requirementGroup) == 0:
				continue

			groupRequirementsMet = True  # type: bool

			for requirement in requirementGroup:  # type: WoohooSafetyMethod.Requirement
				if not requirement.RequirementMet(targetSim):
					groupRequirementsMet = False
					break

			if groupRequirementsMet:
				return True

		return False
Пример #2
0
	def RemoveUse (self, targetSimInfo: sim_info.SimInfo) -> bool:
		"""
		Remove one or more uses from this woohoo safety method.
		:param targetSimInfo: The sim who we are removing a use of this safety method for.
		:type targetSimInfo: sim_info.SimInfo
		:return: Whether or not we could remove a use from the target sim. This will return false if no matching object was found in the sim's
		inventory or all match objects found were out of uses. This will always return false if the sim is not instanced; we cannot read the
		inventory of sims not instanced.
		:rtype: bool
		"""

		if not isinstance(targetSimInfo, sim_info.SimInfo):
			raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

		if self.TargetObject is None or self.TargetStatistic is None:
			return False

		if not targetSimInfo.is_instanced():
			return False

		targetSim = targetSimInfo.get_sim_instance()  # type: sim.Sim

		inventoryComponent = targetSim.get_component(ComponentsTypes.INVENTORY_COMPONENT)  # type: ComponentsInventory.InventoryComponent

		if not inventoryComponent.has_item_with_definition(self.TargetObject):
			return False

		for matchingObject in inventoryComponent.get_items_with_definition_gen(self.TargetObject):  # type: game_object.GameObject
			matchingStatistic = matchingObject.statistic_tracker.get_statistic(self.TargetStatistic, add = True)  # type: statistic.BaseStatistic
			matchingStatisticValue = int(matchingStatistic.get_value())  # type: int

			if matchingStatisticValue <= 0:
				continue

			matchingStatistic.set_value(matchingStatisticValue - 1)
			break

		return True
Пример #3
0
	def GetUseCount (self, targetSimInfo: sim_info.SimInfo) -> int:
		"""
		Get the number of uses of this woohoo safety method the target sim has left.
		:param targetSimInfo: The sim who we are getting the use count of this safety method for.
		:type targetSimInfo: sim_info.SimInfo
		:return: The number of uses of this woohoo safety method the target sim has left. This will always return 0 if the sim is not instanced; we
		cannot read the inventory of sims not instanced.
		:rtype: bool
		"""

		if not isinstance(targetSimInfo, sim_info.SimInfo):
			raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

		if self.TargetObject is None or self.TargetStatistic is None:
			return 0

		if not targetSimInfo.is_instanced():
			return 0

		targetSim = targetSimInfo.get_sim_instance()  # type: sim.Sim

		inventoryComponent = targetSim.get_component(ComponentsTypes.INVENTORY_COMPONENT)  # type: ComponentsInventory.InventoryComponent

		if not inventoryComponent.has_item_with_definition(self.TargetObject):
			return 0

		useCount = 0  # type: int

		for matchingObject in inventoryComponent.get_items_with_definition_gen(self.TargetObject):  # type: game_object.GameObject
			matchingStatistic = matchingObject.statistic_tracker.get_statistic(self.TargetStatistic, add = True)  # type: statistic.BaseStatistic
			matchingStatisticValue = int(matchingStatistic.get_value())  # type: int

			if matchingStatisticValue <= 0:
				continue

			useCount += matchingStatisticValue

		return useCount
Пример #4
0
	def GetUseCount (self, targetSimInfo: sim_info.SimInfo) -> int:
		"""
		Get the number of uses of this woohoo safety method the target sim has left.
		:param targetSimInfo: The sim who we are getting the use count of this safety method for.
		:type targetSimInfo: sim_info.SimInfo
		:return: The number of uses of this woohoo safety method the target sim has left. This will always return 0 if the sim is not instanced; we
		cannot read the inventory of sims not instanced.
		:rtype: bool
		"""

		if not isinstance(targetSimInfo, sim_info.SimInfo):
			raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

		if self.TargetObject is None:
			return 0

		if not targetSimInfo.is_instanced():
			return 0

		targetSim = targetSimInfo.get_sim_instance()  # type: sim.Sim

		inventoryComponent = targetSim.get_component(ComponentsTypes.INVENTORY_COMPONENT)  # type: ComponentsInventory.InventoryComponent
		return inventoryComponent.get_item_quantity_by_definition(self.TargetObject)
Пример #5
0
	def RemoveUse (self, targetSimInfo: sim_info.SimInfo) -> bool:
		"""
		Remove one or more uses from this woohoo safety method.
		:param targetSimInfo: The sim who we are removing a use of this safety method for.
		:type targetSimInfo: sim_info.SimInfo
		:return: Whether or not we could remove a use from the target sim. This will return false if no matching object was found in the sim's
		inventory or all match objects found were out of uses. This will always return false if the sim is not instanced; we cannot read the
		inventory of sims not instanced.
		:rtype: bool
		"""

		if not isinstance(targetSimInfo, sim_info.SimInfo):
			raise Exceptions.IncorrectTypeException(targetSimInfo, "targetSimInfo", (sim_info.SimInfo,))

		if self.TargetObject is None:
			return False

		if not targetSimInfo.is_instanced():
			return False

		targetSim = targetSimInfo.get_sim_instance()  # type: sim.Sim

		inventoryComponent = targetSim.get_component(ComponentsTypes.INVENTORY_COMPONENT)  # type: ComponentsInventory.InventoryComponent
		return inventoryComponent.try_destroy_object_by_definition(self.TargetObject)
 def _is_instanced(_sim_info: SimInfo) -> bool:
     return _sim_info.get_sim_instance(allow_hidden_flags=ALL_HIDDEN_REASONS) is not None
Пример #7
0
    def move_sim_to_household(sim_info: SimInfo,
                              household_id: int = None,
                              destroy_if_empty_household: bool = True) -> bool:
        """move_sim_to_household(sim_info, household_id=None, destroy_if_empty_household=True)

        Move a Sim to the specified household or a new household if no Household is specified.

        :param sim_info: The Sim to add.
        :type sim_info: SimInfo
        :param household_id: The identifier of the Household to add the Sim to.
        :type household_id: int
        :param destroy_if_empty_household: If True, if the Sim comes from a household containing only them, then it will be destroyed after they are moved.
        :type destroy_if_empty_household: bool, optional
        :return: True, if the Sim was added to the Household successfully. False, if not.
        :rtype: bool
        """
        active_household = services.active_household()
        starting_household = sim_info.household
        log.format_info('Moving a Sim to a new household.',
                        sim=CommonSimNameUtils.get_full_name(sim_info),
                        household_id=household_id,
                        starting_household=starting_household)
        if household_id is None:
            log.info(
                'No destination household specified, creating a household for the sim.'
            )
            destination_household = services.household_manager(
            ).create_household(sim_info.account)
        else:
            log.info('Household was specified, getting household of the sim.')
            destination_household = services.household_manager().get(
                household_id)
        if destination_household is None:
            raise AssertionError('Destination Household not specified!')
        log.format_info('Destination household acquired',
                        destination_household=destination_household)
        if CommonSimStateUtils.is_hidden(sim_info):
            log.info('Making hidden Sim visible.')
            services.hidden_sim_service().unhide(sim_info.id)
        if starting_household is destination_household:
            raise AssertionError(
                'The Sim being moved is already in the destination household.')
        if not destination_household.can_add_sim_info(sim_info):
            raise AssertionError(
                'The destination household has no room for additions.')
        log.info('Removing Sim from the starting household.')
        starting_household.remove_sim_info(
            sim_info, destroy_if_empty_household=destroy_if_empty_household)
        log.info('Adding Sim to the destination household.')
        destination_household.add_sim_info_to_household(sim_info)
        client = services.client_manager().get_first_client()
        if destination_household is active_household:
            log.info(
                'The destination household is the active household. Changing the Sim to be selectable.'
            )
            client.add_selectable_sim_info(sim_info)
        else:
            log.info(
                'The destination household is different from the active household. Removing the selectability of the sim.'
            )
            client.remove_selectable_sim_info(sim_info)
        if sim_info.career_tracker is not None:
            log.info('Removing invalid careers.')
            sim_info.career_tracker.remove_invalid_careers()
            log.info('Invalid careers removed.')
        sim = sim_info.get_sim_instance()
        if sim is not None:
            log.info('Updating sims intended position on the active Lot.')
            sim.update_intended_position_on_active_lot(update_ui=True)
            situation_manager = services.get_zone_situation_manager()
            log.info('Removing Sim from currently active situations.')
            for situation in situation_manager.get_situations_sim_is_in(sim):
                if destination_household is active_household and situation.is_user_facing:
                    pass
                else:
                    log.format_info('Removing situation',
                                    situation_id=situation.id)
                    situation_manager.remove_sim_from_situation(
                        sim, situation.id)
            log.info(
                'Done removing situations. Updating daycare service information.'
            )
            services.daycare_service().on_sim_spawn(sim_info)
        log.info('Done moving Sim to household.')
        return True