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
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
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
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)
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)