Exemplo n.º 1
0
 public void RefreshParameters()
 {
     for (int num = conditionals.Count - 1; num >= 0; num--)
     {
         ConditionalObject conditionalObject = conditionals[num];
         if (conditionalObject.gameObject == null)
         {
             conditionals.RemoveAt(num);
         }
         else if (conditionalObject.restrictOnHealth)
         {
             conditionalObject.healthRestrictionMin = Mathf.Clamp01(conditionalObject.healthRestrictionMin);
             conditionalObject.healthRestrictionMax = Mathf.Clamp01(conditionalObject.healthRestrictionMax);
         }
         conditionalObject.gibId = -1;
         if (conditionalObject.gameObject != null)
         {
             Gibbable component = conditionalObject.gameObject.GetComponent <Gibbable>();
             if (component != null)
             {
                 component.uniqueId      = num;
                 conditionalObject.gibId = num;
             }
         }
     }
 }
Exemplo n.º 2
0
        public void GetState_ShouldEvaluateLessThanOrEqualToCorrectly()
        {
            foreach (var input in new List <Tuple <string, string, string, bool, bool> >()
            {
                Tuple.Create("1", ConditionalOperator.LessThanOrEqualTo, "10", true, true),
                Tuple.Create("20", ConditionalOperator.LessThanOrEqualTo, "20", true, true),
                Tuple.Create("300", ConditionalOperator.LessThanOrEqualTo, "30", true, false),
                Tuple.Create("bar", ConditionalOperator.LessThanOrEqualTo, "bar", false, false)
            })
            {
                var conditionalObject = new ConditionalObject
                {
                    String    = input.Item1 + input.Item2 + input.Item3,
                    LeftSide  = input.Item1,
                    Operator  = input.Item2,
                    RightSide = input.Item3,
                };

                var actual = _service.Evaluate(conditionalObject);

                Assert.AreEqual(input.Item4, actual.IsSuccess, conditionalObject.String);
                if (actual.IsSuccess)
                {
                    Assert.AreEqual(input.Item5, actual.Value, conditionalObject.String);
                }
            }
        }
Exemplo n.º 3
0
        public void GetState_ShouldEvaluateGreaterThanCorrectly()
        {
            foreach (var input in new List <Tuple <string, string, string, bool, bool> >()
            {
                Tuple.Create("1", ConditionalOperator.GreaterThan, "10", true, false),
                Tuple.Create("300", ConditionalOperator.GreaterThan, "30", true, true),
                Tuple.Create("bar", ConditionalOperator.GreaterThan, "bar", false, false)
            })
            {
                var conditionalObject = new ConditionalObject
                {
                    String    = input.Item1 + input.Item2 + input.Item3,
                    LeftSide  = input.Item1,
                    Operator  = input.Item2,
                    RightSide = input.Item3,
                };

                var actual = _service.Evaluate(conditionalObject);

                Assert.AreEqual(input.Item4, actual.IsSuccess, conditionalObject.String);
                if (actual.IsSuccess)
                {
                    Assert.AreEqual(input.Item5, actual.Value, conditionalObject.String);
                }
                if (actual.IsFailure)
                {
                    Assert.IsTrue(actual.Error.Message.EndsWith(ConditionalObjectLogic.UnknownOperatorError), conditionalObject.String);
                }
            }
        }
Exemplo n.º 4
0
        public Result <bool> Evaluate(ConditionalObject conditionalObject)
        {
            var leftVar        = 0m;
            var rightVar       = 0m;
            var isLeftNumeric  = decimal.TryParse(conditionalObject.LeftSide, out leftVar);
            var isRightNumeric = decimal.TryParse(conditionalObject.RightSide, out rightVar);

            if (isLeftNumeric != isRightNumeric)
            {
                return(Result.Fail <bool>(TypeMismatchError));
            }

            if (isLeftNumeric && isRightNumeric)
            {
                return(TestNumerics(leftVar, conditionalObject.Operator, rightVar));
            }
            return(TestStrings(conditionalObject.LeftSide, conditionalObject.Operator, conditionalObject.RightSide));
        }
Exemplo n.º 5
0
        public void GetState_ShouldFail_WhenComparingStringAndNumeric()
        {
            foreach (var input in new List <Tuple <string, string> >()
            {
                Tuple.Create("1", "test"),
                Tuple.Create("foo", "3000")
            })
            {
                var conditionalObject = new ConditionalObject
                {
                    LeftSide  = input.Item1,
                    RightSide = input.Item2,
                };

                var actual = _service.Evaluate(conditionalObject);

                Assert.IsTrue(actual.IsFailure, input.Item1 + " " + input.Item2);
                Assert.AreEqual(ConditionalObjectLogic.TypeMismatchError, actual.Error.Message, input.Item1 + " " + input.Item2);
            }
        }
Exemplo n.º 6
0
    private void RefreshConditional(ConditionalObject conditional, bool canGib)
    {
        if (conditional.gameObject == null)
        {
            return;
        }
        bool flag = true;

        if (conditional.restrictOnHealth)
        {
            flag = ((!Mathf.Approximately(conditional.healthRestrictionMin, conditional.healthRestrictionMax)) ? (base.healthFraction > conditional.healthRestrictionMin && base.healthFraction <= conditional.healthRestrictionMax) : Mathf.Approximately(base.healthFraction, conditional.healthRestrictionMin));
            if (!canGib)
            {
            }
        }
        if (flag && IsOnAVehicle && conditional.restrictOnLockable)
        {
            flag = Vehicle.IsLockable == conditional.lockableRestriction;
        }
        if (flag && conditional.restrictOnAdjacent)
        {
            bool flag2 = false;
            bool flag3 = false;
            BaseVehicleModule result;
            if (TryGetAdjacentModuleInFront(out result))
            {
                flag2 = InSameVisualGroupAs(result, conditional.adjacentMatch);
            }
            if (TryGetAdjacentModuleBehind(out result))
            {
                flag3 = InSameVisualGroupAs(result, conditional.adjacentMatch);
            }
            switch (conditional.adjacentRestriction)
            {
            case ConditionalObject.AdjacentCondition.BothDifferent:
                flag = !flag2 && !flag3;
                break;

            case ConditionalObject.AdjacentCondition.SameInFront:
                flag = flag2;
                break;

            case ConditionalObject.AdjacentCondition.SameBehind:
                flag = flag3;
                break;

            case ConditionalObject.AdjacentCondition.DifferentInFront:
                flag = !flag2;
                break;

            case ConditionalObject.AdjacentCondition.DifferentBehind:
                flag = !flag3;
                break;

            case ConditionalObject.AdjacentCondition.BothSame:
                flag = flag2 && flag3;
                break;
            }
        }
        if (flag)
        {
            if (!IsOnAVehicle)
            {
                for (int i = 0; i < conditional.socketSettings.Length; i++)
                {
                    flag = !conditional.socketSettings[i].HasSocketRestrictions;
                    if (!flag)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int j = 0; j < conditional.socketSettings.Length; j++)
                {
                    flag = Vehicle.GetSocket(FirstSocketIndex + j).ShouldBeActive(conditional.socketSettings[j]);
                    if (!flag)
                    {
                        break;
                    }
                }
            }
        }
        bool activeInHierarchy = conditional.gameObject.activeInHierarchy;

        conditional.SetActive(flag);
    }