private IEnumerator _WaitForSetFloatValueToBeLoaded(SetFloatValueData inputData) { // after this much time it will assume the set velocity 2d actually in fact has a magnitude of 0 // at which point it WILL NOT add it to the list. because: simply put, you can't speed up or slow down // a zero vector by any amount. float maxWaitTime = 5f; float defFloat = inputData.cachedFloatValue.floatValue.Value; while (Math.Abs(defFloat) < epsilon && maxWaitTime > 0.0f) { maxWaitTime -= Time.deltaTime; yield return(null); defFloat = inputData.cachedFloatValue.floatValue.Value; } if (maxWaitTime <= 0.0f) { Modding.Logger.LogError("[ModCommon] Unable to add setfloatvalue to CustomEnemySpeed because the float is " + "basically 0 which cannot have its value modified."); yield break; } inputData.SetDefaultFloat(defFloat); speedModifyFloatValues.Add(inputData); if (active && speedModActive) { _UpdateSingleSetFloatValue(inputData); } }
// Removes the SetFloatValue Data from the list, if it exists. Returns true if it found and removed it. public bool RemoveSetFloatValueData(SetFloatValueData inputData) { if (!speedModifyFloatValues.Contains(inputData)) { return(false); } _UpdateSingleSetFloatValue(inputData, true); speedModifyFloatValues.Remove(inputData); return(true); }
private void _UpdateSingleSetFloatValue(SetFloatValueData inputData, bool restoreOriginal = false) { if (inputData.cachedFloatValue == null) { throw new NullReferenceException("No SetFloatValue Action found on the FSM " + inputData.FSMName + " in state " + inputData.FSMStateName); } float realFactor = (float)(((danceSpeed - 1.0) * (inputData.Factor - 1.0)) + 1.0); if (!active || !speedModActive || restoreOriginal) { realFactor = 1.0f; } // Stop divide by zero. else if (realFactor <= epsilon) { throw new Exception("To prevent stupid looking, and broken behavior," + " your relative magnitude must be greater than " + epsilon + ". But a dance speed of " + danceSpeed + " set it to " + realFactor); } inputData.cachedFloatValue.floatValue.Value = (inputData.defaultValue * realFactor); }
// Adds a SetFloatValue to the list, stored in the struct format SetFloatValueData. Use a constructor to build it. public void AddSetFloatValueData(SetFloatValueData inputData) { if (inputData.CustomGameObject == null) { inputData.CustomGameObject = gameObject; } if (inputData.cachedFloatValue == null) { inputData.cachedFloatValue = _getOrCacheFSMSetFloatValue(inputData.FSMStateName, inputData.FSMName, inputData.CustomGameObject, inputData.ElementIndex); } if (inputData.cachedFloatValue == null) { throw new System.NullReferenceException("No SetFloatValue Action found on the FSM " + inputData.FSMName + " in state " + inputData.FSMStateName); } float mag = (float)Math.Abs(inputData.cachedFloatValue.floatValue.Value); if (mag <= epsilon) { StartCoroutine(_WaitForSetFloatValueToBeLoaded(inputData)); } else { inputData.SetDefaultFloat(inputData.cachedFloatValue.floatValue.Value); speedModifyFloatValues.Add(inputData); if (active && speedModActive) { _UpdateSingleSetFloatValue(inputData); } } }