public override void GenerateAttributes(ProceduralLevel level) { //check if attribute from tag or random float minAttributeCount = m_MinimumAttributeCount.Evaluate(level.Difficulty); float maxAttributeCount = m_MaximumAttributeCount.Evaluate(level.Difficulty); int attributeCount = (int)Math.Round(Random.Range(minAttributeCount, maxAttributeCount)); List <ValueMod> attributes = new List <ValueMod>(); for (int i = 0; i < attributeCount; i++) { float roll = Random.Range(0.0f, 1.0f); Mod[] rollableMods = null; string tag = ""; if (roll <= m_ChanceToPickAttributeFromTag) { if (level.TagList.Count > 0) { int tagRoll = Random.Range(0, level.TagList.Count); rollableMods = ModifierManager.GetModifiersForDomainAndTag(2, level.TagList[tagRoll].Identifier); tag = level.TagList[tagRoll].Identifier; } if (rollableMods == null || rollableMods.Length == 0) { rollableMods = ModifierManager.GetModifiersForDomain(2); tag = m_DefaultTag.Identifier; } } else { rollableMods = ModifierManager.GetModifiersForDomain(2); tag = m_DefaultTag.Identifier; } if (rollableMods == null) { continue; } ValueMod valueMod = ModUtils.Roll(rollableMods.ToArray(), tag); if (valueMod == null) { continue; } attributes.Add(valueMod); } level.Attributes = attributes.ToArray(); }
public override void Invoke(ItemStack itemStack) { Mod[] availableMods = ModifierManager.GetModifiersForDomainAndTag(1, itemStack.Item.Tags.ToArray()); List <ValueMod> valueMods = new List <ValueMod>(); foreach (ValueMod explicitMod in itemStack.ExplicitMods) { valueMods.Add(explicitMod); } availableMods = ModUtils.Filter(availableMods, itemStack.ItemLevel); availableMods = ModUtils.Filter(availableMods, valueMods.ToArray()); ValueMod valueMod = ModUtils.Roll(availableMods, itemStack.Item.Tags.ToArray()); if (valueMod == null) { return; } valueMods.Add(valueMod); itemStack.ExplicitMods = valueMods.ToArray(); }
public override void Invoke(ItemStack itemStack) { if (itemStack == null) { return; } int count = (int)m_ExplicitCount.Evaluate(UnityEngine.Random.Range(0.0f, 1.0f)); Mod[] availableMods = ModifierManager.GetModifiersForDomainAndTag(1, itemStack.Item.Tags.ToArray()); availableMods = ModUtils.Filter(availableMods, itemStack.ItemLevel); List <ValueMod> valueMods = new List <ValueMod>(); for (int i = 0; i < count; i++) { availableMods = ModUtils.Filter(availableMods, valueMods.ToArray()); ValueMod valueMod = ModUtils.Roll(availableMods, itemStack.Item.Tags.ToArray()); if (valueMod != null) { valueMods.Add(valueMod); } } itemStack.ExplicitMods = valueMods.ToArray(); }
private void ApplyMod(ValueMod mod) { var inputLastInd = mInputs.Count - 1; double val; if (inputLastInd != -1 && mInputs[inputLastInd].type == InputType.Numeric) { val = mInputs[inputLastInd].value; } else { val = mCurValue; } string strFormat; double newVal; switch (mod) { case ValueMod.Square: strFormat = "({0})²"; newVal = val * val; break; case ValueMod.SquareRoot: strFormat = "√({0})"; newVal = System.Math.Sqrt(val); break; case ValueMod.Invert: strFormat = "1/({0})"; newVal = 1.0 / val; break; case ValueMod.Negate: strFormat = "-({0})"; newVal = -val; break; case ValueMod.Cos: strFormat = "cos({0})"; newVal = System.Math.Cos(val * (System.Math.PI / 180.0)); break; case ValueMod.Sin: strFormat = "sin({0})"; newVal = System.Math.Sin(val * (System.Math.PI / 180.0)); break; case ValueMod.Tan: strFormat = "tan({0})"; newVal = System.Math.Tan(val * (System.Math.PI / 180.0)); break; default: strFormat = "{0}"; newVal = 0f; break; } //check for last value from input and modify it if (inputLastInd != -1 && mInputs[inputLastInd].type == InputType.Numeric) { //encapsulate value var inputVal = mInputs[inputLastInd]; ModifyInput(inputLastInd, InputType.Numeric, string.Format(strFormat, inputVal.displayText), newVal); } else { //apply to current input and add to input AddInput(InputType.Numeric, string.Format(strFormat, mCurValue), newVal); } //clear input and apply value ApplyCurrentValue(newVal); }