示例#1
0
	def GenerateSpermArrivingPercentage (self, generationBaseSeed: typing.Optional[int] = None) -> float:
		"""
		Get the percentage of sperm that should get past the woohoo devices and make it from one sim to another. This will return a number from 0 to 1.
		:param generationBaseSeed: The seed being used to generate a random sperm reduction. This will be combined with other seeds unique to each
		woohoo safety method before being used.
		:type generationBaseSeed: typing.Optional[int]
		"""

		if generationBaseSeed is None:
			generationBaseSeed = random.randint(-1000000000, 1000000000)

		if not isinstance(generationBaseSeed, int):
			raise Exceptions.IncorrectTypeException(generationBaseSeed, "generationBaseSeed", (int,))

		if len(self) == 0:
			return 1
		else:
			arrivingPercentage = 1  # type: float

			for performanceSelectionIndex in range(len(self)):  # type: int
				performanceSelection = self[performanceSelectionIndex]  # type: MethodPerformanceSelection

				if not isinstance(performanceSelection, MethodPerformanceSelection):
					Debug.Log(Exceptions.GetIncorrectTypeExceptionText(performanceSelection, "performanceSelection[%s]" % performanceSelectionIndex, (MethodPerformanceSelection,)), This.Mod.Namespace, Debug.LogLevels.Error, group = This.Mod.Namespace, owner = __name__)
					continue

				woohooSafetyMethod = performanceSelection.WoohooSafetyMethod  # type: WoohooSafetyMethod
				performanceTypeInfo = performanceSelection.SelectedPerformanceTypeInfo  # type: WoohooSafetyMethod.PerformanceTypeInfo

				if performanceTypeInfo is None:
					Debug.Log("Performance selection had never selected a performance type.\n Woohoo Safety Method GUID: %s" % (str(woohooSafetyMethod.GUID)), This.Mod.Namespace, Debug.LogLevels.Error, group = This.Mod.Namespace, owner = __name__)
					continue

				safetyMethodSeed = woohooSafetyMethod.GetUniqueSeed()
				arrivingPercentage *= performanceTypeInfo.GenerateSpermArrivingPercentage(seed = generationBaseSeed + safetyMethodSeed)  # type: float

			return arrivingPercentage
示例#2
0
文件: Dot.py 项目: NeonOcean/S4.Cycle
	def Load (self, simsSection: SectionBranched.SectionBranched) -> bool:
		"""
		Load the reproductive system's data from this saving section. An exception will be raised if no valid sim has been set for this dot object.
		"""

		if self.TargetSimID is None or self.TargetSimInfo is None:
			raise Exception("Cannot load a dot information object with no target sim.")

		if not isinstance(simsSection, SectionBranched.SectionBranched):
			raise Exceptions.IncorrectTypeException(simsSection, "simsSection", (SectionBranched.SectionBranched,))

		operationInformation = self.SavableOperationInformation  # type: str
		operationSuccessful = True  # type: bool

		try:
			targetSimSavingKey = Saving.GetSimSimsSectionBranchKey(self.TargetSimInfo)  # type: str

			dotInformationData = simsSection.GetValue(targetSimSavingKey, DotSavingKey, default = None)

			if dotInformationData is None:
				Debug.Log("'%s' has had a dot information object created for the first time, or at least, they had no saved data in the loaded save file.\n%s" % (ToolsSims.GetFullName(self.TargetSimInfo), operationInformation), self.HostNamespace, Debug.LogLevels.Info, group = self.HostNamespace, owner = __name__)
				dotInformationData = dict()

			if not isinstance(dotInformationData, dict):
				Debug.Log("Incorrect type in dot information data with the section key.\n" + operationInformation + "\n" + Exceptions.GetIncorrectTypeExceptionText(dotInformationData, "DotInformationData", (dict,)), self.HostNamespace, Debug.LogLevels.Warning, group = self.HostNamespace, owner = __name__)
				dotInformationData = dict()
				operationSuccessful = False

			if simsSection.SavingObject.DataHostVersion is not None:
				lastVersion = Version.Version(simsSection.SavingObject.DataHostVersion)  # type: typing.Optional[Version.Version]
			else:
				lastVersion = None  # type: typing.Optional[Version.Version]

			loadSuccessful = self.LoadFromDictionary(dotInformationData, lastVersion = lastVersion)
		except:
			Debug.Log("Load operation in a dot information object aborted.\n" + operationInformation, self.HostNamespace, Debug.LogLevels.Exception, group = self.HostNamespace, owner = __name__)
			self.Reset()
			return False

		if not loadSuccessful:
			return False

		return operationSuccessful
示例#3
0
    def Load(self, persistentDataContainer: dict) -> bool:
        """
		Load persistent data from a persistent data container.
		:param persistentDataContainer: The persistent data container dictionary.
		:type persistentDataContainer: dict
		:return: True if this completed without incident, False if not.
		:rtype: bool
		"""

        operationSuccess = True  # type: bool

        if not isinstance(persistentDataContainer, dict):
            raise Exceptions.IncorrectTypeException(persistentDataContainer,
                                                    "persistentDataContainer",
                                                    (dict, ))

        persistentDataBranches = persistentDataContainer.get(
            self._branchesKey,
            dict())  # type: typing.Dict[str, typing.Dict[str, typing.Any]]

        if not isinstance(persistentDataBranches, dict):
            Debug.Log("Invalid type in persistent data container.\n" +
                      Exceptions.GetIncorrectTypeExceptionText(
                          persistentDataBranches,
                          "PersistentDataContainer[%s]" % self._branchesKey,
                          (dict, )),
                      self.HostNamespace,
                      Debug.LogLevels.Warning,
                      group=self.HostNamespace,
                      owner=__name__)
            persistentDataBranches = dict()
            operationSuccess = False

        lastVersionString = persistentDataContainer.get(
            self._lastVersionKey)  # type:

        if lastVersionString is None:
            lastVersion = None
        else:
            if not isinstance(lastVersionString, str):
                Debug.Log(
                    "Invalid type in persistent data container.\n" +
                    Exceptions.GetIncorrectTypeExceptionText(
                        lastVersionString,
                        "PersistentDataContainer[%s]" % self._lastVersionKey,
                        (dict, )),
                    self.HostNamespace,
                    Debug.LogLevels.Warning,
                    group=self.HostNamespace,
                    owner=__name__)
                lastVersion = None
                operationSuccess = False
            else:
                try:
                    lastVersion = Version.Version(lastVersionString)
                except Exception:
                    Debug.Log(
                        "Cannot convert persistent data's last version value '"
                        + lastVersionString + "' to a version number object",
                        self.HostNamespace,
                        Debug.LogLevels.Warning,
                        group=self.HostNamespace,
                        owner=__name__)
                    lastVersion = None
                    operationSuccess = False

        self.Reset(autoSave=False, autoUpdate=False)
        setDataSuccess = self._LoadSetData(
            persistentDataBranches, lastVersion=lastVersion)  # type: bool

        self._InvokeOnLoadEvent()

        if not setDataSuccess:
            return False

        return operationSuccess
示例#4
0
    def _LoadSetData(
            self,
            persistentDataBranches: dict,
            lastVersion: typing.Optional[Version.Version] = None) -> bool:
        """
		:param persistentDataBranches: The persistent data branches to be loaded.
		:type persistentDataBranches: dict
		:param lastVersion: The last version this data was saved successfully in.
		:type lastVersion: Version.Version
		:return: True if this completed without incident, False if not.
		:rtype: bool
		"""

        operationSuccess = True  # type: bool

        changed = False  # type: bool

        for persistentBranchKey in list(
                persistentDataBranches.keys()):  # type: str
            persistentBranchValues = persistentDataBranches[
                persistentBranchKey]  # type: typing.Dict[str, typing.Any]

            if not isinstance(persistentBranchKey, str):
                persistentDataBranches.pop(persistentBranchKey, None)
                Debug.Log(
                    "Invalid type in persistent data.\n" +
                    Exceptions.GetIncorrectTypeExceptionText(
                        persistentBranchKey, "PersistentDataBranches<Key>",
                        (str, )),
                    self.HostNamespace,
                    Debug.LogLevels.Warning,
                    group=self.HostNamespace,
                    owner=__name__)
                changed = True
                operationSuccess = False
                continue

            if not isinstance(persistentBranchValues, dict):
                persistentDataBranches.pop(persistentBranchKey, None)
                Debug.Log(
                    "Invalid type in persistent data.\n" +
                    Exceptions.GetIncorrectTypeExceptionText(
                        persistentBranchValues,
                        "PersistentDataBranches[%s]" % persistentBranchKey,
                        (dict, )),
                    self.HostNamespace,
                    Debug.LogLevels.Warning,
                    group=self.HostNamespace,
                    owner=__name__)
                changed = True
                operationSuccess = False
                continue

            for persistentKey in list(
                    persistentBranchValues.keys()):  # type: str
                persistentValue = persistentBranchValues[
                    persistentKey]  # type: typing.Any

                if not isinstance(persistentKey, str):
                    persistentBranchValues.pop(persistentKey, None)
                    Debug.Log(
                        "Invalid type in persistent data.\n" +
                        Exceptions.GetIncorrectTypeExceptionText(
                            persistentKey, "PersistentDataBranches[%s]<Key>" %
                            persistentBranchKey, (str, )),
                        self.HostNamespace,
                        Debug.LogLevels.Warning,
                        group=self.HostNamespace,
                        owner=__name__)
                    changed = True
                    operationSuccess = False
                    continue

                if not persistentKey in self._storage:
                    continue

                valueStorage = self._storage[
                    persistentKey]  # type: PersistentBranched.Value

                if not isinstance(persistentValue, valueStorage.ValueType):
                    Debug.Log(
                        "Invalid type in persistent data.\n" +
                        Exceptions.GetIncorrectTypeExceptionText(
                            persistentKey, "PersistentDataBranches[%s][%s]" %
                            (persistentBranchKey, persistentKey), (str, )),
                        self.HostNamespace,
                        Debug.LogLevels.Warning,
                        group=self.HostNamespace,
                        owner=__name__)
                    persistentBranchValues.pop(persistentKey, None)
                    changed = True
                    operationSuccess = False
                    continue

                try:
                    valueStorage.Set(persistentBranchKey, persistentValue,
                                     lastVersion)
                except Exception:
                    Debug.Log("Cannot set value '" + str(persistentValue) +
                              "' for persistent data '" + persistentKey + "'.",
                              self.HostNamespace,
                              Debug.LogLevels.Warning,
                              group=self.HostNamespace,
                              owner=__name__)
                    persistentBranchValues.pop(persistentKey, None)
                    changed = True
                    operationSuccess = False
                    continue

        self._loadedData = persistentDataBranches
        self._loadedLastVersion = lastVersion

        if changed:
            self.Save()

        self.Update()

        return operationSuccess
示例#5
0
    def _LoadSetData(
            self,
            persistentData: dict,
            lastVersion: typing.Optional[Version.Version] = None) -> bool:
        """
		:param persistentData: The persistent data to be loaded. This should just be a dictionary with every key paired with its value.
		:type persistentData: dict
		:param lastVersion: The last version this data was saved successfully in.
		:type lastVersion: Version.Version
		:return: True if this completed without incident, False if not.
		:rtype: bool
		"""

        operationSuccess = True  # type: bool

        persistenceInformation = self.PersistenceInformation  # type: str

        changed = False

        for persistentKey in list(persistentData.keys()):  # type: str
            persistentValue = persistentData[persistentKey]  # type: typing.Any

            if not isinstance(persistentKey, str):
                Debug.Log("Invalid type in persistent data.\n" +
                          Exceptions.GetIncorrectTypeExceptionText(
                              persistentKey, "PersistentData<Key>",
                              (str, )) + "\n" + persistenceInformation,
                          self.HostNamespace,
                          Debug.LogLevels.Warning,
                          group=self.HostNamespace,
                          owner=__name__)
                persistentData.pop(persistentKey, None)
                changed = True
                operationSuccess = False
                continue

            if not persistentKey in self._storage:
                continue

            valueStorage = self._storage[
                persistentKey]  # type: Persistent.Value

            if not isinstance(persistentValue, valueStorage.ValueType):
                Debug.Log(
                    "Invalid type in persistent data.\n" +
                    Exceptions.GetIncorrectTypeExceptionText(
                        persistentKey, "PersistentData[%s]" % persistentKey,
                        (valueStorage.ValueType, )) + "\n" +
                    persistenceInformation,
                    self.HostNamespace,
                    Debug.LogLevels.Warning,
                    group=self.HostNamespace,
                    owner=__name__)
                persistentData.pop(persistentKey, None)
                changed = True
                operationSuccess = False
                continue

            try:
                valueStorage.Set(persistentValue, lastVersion)
            except Exception:
                Debug.Log("Cannot set value '" + str(persistentValue) +
                          "' for persistent data '" + persistentKey + "'.\n" +
                          persistenceInformation,
                          self.HostNamespace,
                          Debug.LogLevels.Warning,
                          group=self.HostNamespace,
                          owner=__name__)
                persistentData.pop(persistentKey, None)
                changed = True
                operationSuccess = False
                continue

        self._loadedData = persistentData
        self._loadedLastVersion = lastVersion

        if changed:
            self.Save()

        self.Update()

        return operationSuccess
示例#6
0
    def Load(self, sectionData: dict) -> bool:
        operationInformation = "Save Identifier: %s | Section Identifier: %s" % (
            self.SavingObject.Identifier,
            self.Identifier,
        )
        operationSuccessful = True  # type: bool

        if not isinstance(sectionData, dict):
            Debug.Log("Incorrect type in section data.\n" +
                      Exceptions.GetIncorrectTypeExceptionText(
                          sectionData, "SectionData",
                          (dict, )) + "\n" + operationInformation,
                      self.SavingObject.Host.Namespace,
                      Debug.LogLevels.Warning,
                      group=self.SavingObject.Host.Namespace,
                      owner=__name__)
            sectionData = dict()
            operationSuccessful = False

        for branchKey in list(sectionData.keys()):  # type: str, dict
            if not isinstance(branchKey, str):
                Debug.Log("Incorrect type in section data.\n" +
                          Exceptions.GetIncorrectTypeExceptionText(
                              sectionData, "SectionData<Key>",
                              (str, )) + "\n" + operationInformation,
                          self.SavingObject.Host.Namespace,
                          Debug.LogLevels.Warning,
                          group=self.SavingObject.Host.Namespace,
                          owner=__name__)
                sectionData.pop(branchKey, None)
                operationSuccessful = False
                continue

            branchDictionary = sectionData[branchKey]  # type: dict

            if not isinstance(branchDictionary, dict):
                Debug.Log("Incorrect type in section data.\n" +
                          Exceptions.GetIncorrectTypeExceptionText(
                              sectionData, "SectionData[%s]" % branchKey,
                              (str, )) + "\n" + operationInformation,
                          self.SavingObject.Host.Namespace,
                          Debug.LogLevels.Warning,
                          group=self.SavingObject.Host.Namespace,
                          owner=__name__)
                sectionData.pop(branchKey, None)
                operationSuccessful = False
                continue

            for valueKey in list(branchDictionary.keys()):  # type: str
                if not isinstance(valueKey, str):
                    Debug.Log(
                        "Incorrect type in section data.\n" +
                        Exceptions.GetIncorrectTypeExceptionText(
                            sectionData, "SectionData[%s]<Key>" % branchKey,
                            (str, )) + "\n" + operationInformation,
                        self.SavingObject.Host.Namespace,
                        Debug.LogLevels.Warning,
                        group=self.SavingObject.Host.Namespace,
                        owner=__name__)
                    branchDictionary.pop(valueKey, None)
                    operationSuccessful = False
                    continue

        self._loadedData = sectionData

        callbackSuccessful = self._ActivateLoadCallbacks()  # type: bool

        if not callbackSuccessful:
            return False

        return operationSuccessful