コード例 #1
0
        public TeamGroupType(ITypeSupplier typeSupplier, ElementEnum enumData) : base(enumData, typeSupplier, false)
        {
            Opposite = new InternalVar("Opposite", this, CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("The opposite team of the value. If the team value is ").Code("Team 1").Add(", Opposite will be ").Code("Team 2").Add(" and vice versa. If the value is ")
                                .Code("All").Add(", Opposite will still be ").Code("All").Add(".")
            };
            Score = new InternalVar("Score", typeSupplier.Number(), CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("The current score for the team. Results in 0 in free-for-all modes.")
            };
            OnDefense = new InternalVar("OnDefense", typeSupplier.Boolean(), CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("Whether the specified team is currently on defense. Results in False if the game mode is not Assault, Escort, or Assault/Escort.")
            };
            OnOffense = new InternalVar("OnOffense", typeSupplier.Boolean(), CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("Whether the specified team is currently on offense. Results in False if the game mode is not Assault, Escort, or Assault/Escort.")
            };

            _objectScope.AddNativeVariable(Opposite);
            _objectScope.AddNativeVariable(Score);
            _objectScope.AddNativeVariable(OnDefense);
            _objectScope.AddNativeVariable(OnOffense);
        }
コード例 #2
0
        public void GetMeta()
        {
            // Floor
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Floor",
                Documentation = "Rounds the provided number down to the nearest integer.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.RoundToInt(actionSet.CurrentObject, Rounding.Down)
            }.GetMethod());
            // Ceil
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Ceil",
                Documentation = "Return the ceiling of the provided number.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.RoundToInt(actionSet.CurrentObject, Rounding.Up)
            }.GetMethod());
            // Round
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Round",
                Documentation = "Returns the provided number rounded to the nearest integer.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.RoundToInt(actionSet.CurrentObject, Rounding.Nearest)
            }.GetMethod());
            // Absolute value
            _scope.AddNativeMethod(new FuncMethodBuilder()
            {
                Name          = "Abs",
                Documentation = "Returns the absolute value of the provided number. Also known as the value's distance to 0.",
                ReturnType    = this,
                Action        = (actionSet, methodCall) => Element.Abs(actionSet.CurrentObject)
            }.GetMethod());

            Operations.AddTypeOperation(new TypeOperation[] {
                new TypeOperation(TypeOperator.Add, this, this),                                  // Number + number
                new TypeOperation(TypeOperator.Subtract, this, this),                             // Number - number
                new TypeOperation(TypeOperator.Multiply, this, this),                             // Number * number
                new TypeOperation(TypeOperator.Divide, this, this),                               // Number / number
                new TypeOperation(TypeOperator.Modulo, this, this),                               // Number % number
                new TypeOperation(TypeOperator.Pow, this, this),
                new TypeOperation(TypeOperator.Multiply, _supplier.Vector(), _supplier.Vector()), // Number * vector
                new TypeOperation(TypeOperator.LessThan, this, _supplier.Boolean()),              // Number < number
                new TypeOperation(TypeOperator.LessThanOrEqual, this, _supplier.Boolean()),       // Number <= number
                new TypeOperation(TypeOperator.GreaterThanOrEqual, this, _supplier.Boolean()),    // Number >= number
                new TypeOperation(TypeOperator.GreaterThan, this, _supplier.Boolean()),           // Number > number
            });
            Operations.AddTypeOperation(AssignmentOperation.GetNumericOperations(this));
        }
コード例 #3
0
        public static CodeType DefaultTypeFromOperator(TypeOperator op, ITypeSupplier supplier)
        {
            switch (op)
            {
            case TypeOperator.And:
            case TypeOperator.Or:
            case TypeOperator.NotEqual:
            case TypeOperator.Equal:
            case TypeOperator.GreaterThan:
            case TypeOperator.GreaterThanOrEqual:
            case TypeOperator.LessThan:
            case TypeOperator.LessThanOrEqual:
                return(supplier.Boolean());

            case TypeOperator.Add:
            case TypeOperator.Divide:
            case TypeOperator.Modulo:
            case TypeOperator.Multiply:
            case TypeOperator.Pow:
            case TypeOperator.Subtract:
                return(supplier.Number());

            default: throw new NotImplementedException(op.ToString());
            }
        }
コード例 #4
0
 // String Contains function
 FuncMethod ContainsFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "Contains",
     Documentation = "Determines if the string contains the specified value.",
     ReturnType    = supplier.Boolean(),
     Parameters    = new CodeParameter[] {
         new CodeParameter("value", "The substring that will be searched for.", supplier.String())
     },
     Action = (actionSet, methodCall) => Element.Part("String Contains", actionSet.CurrentObject, methodCall.Get(0))
 };
 public ConstBoolParameter(string name, string documentation, ITypeSupplier typeSupplier, bool defaultValue)
     : base(name, documentation, typeSupplier.Boolean(), new ExpressionOrWorkshopValue(defaultValue ? Element.True() : Element.False()))
 {
 }
 public ConstBoolParameter(string name, string documentation, ITypeSupplier typeSupplier) : base(name, documentation, typeSupplier.Boolean())
 {
 }
コード例 #7
0
        void SetupScope()
        {
            if (_scopeInstance != null)
            {
                return;
            }

            _scopeInstance      = new Scope();
            _operationsInstance = new TypeOperatorInfo(this);

            Scope.AddNativeVariable(_length);
            Scope.AddNativeVariable(_last);
            Scope.AddNativeVariable(_first);

            var pipeType        = new PipeType(ArrayOfType, this);
            var functionHandler = ArrayOfType.ArrayHandler.GetFunctionHandler();

            // Filtered Array
            new GenericSortFunction()
            {
                Name                   = "FilteredArray",
                Documentation          = "A copy of the specified array with any values that do not match the specified condition removed.",
                ReturnType             = this,
                ArrayOfType            = ArrayOfType,
                FuncType               = _supplier.Boolean(),
                ParameterDocumentation = "The condition that is evaluated for each element of the copied array. If the condition is true, the element is kept in the copied array.",
                Function               = "Filtered Array",
                Executor               = functionHandler.FilteredArray()
            }.Add(Scope, _supplier);
            // Sorted Array
            new GenericSortFunction()
            {
                Name                   = "SortedArray",
                Documentation          = "A copy of the specified array with the values sorted according to the value rank that is evaluated for each element.",
                ReturnType             = this,
                ArrayOfType            = ArrayOfType,
                FuncType               = _supplier.Boolean(),
                ParameterDocumentation = "The value that is evaluated for each element of the copied array. The array is sorted by this rank in ascending order.",
                Function               = "Sorted Array",
                Executor               = functionHandler.SortedArray()
            }.Add(Scope, _supplier);
            // Is True For Any
            new GenericSortFunction()
            {
                Name                   = "IsTrueForAny",
                Documentation          = "Whether the specified condition evaluates to true for any value in the specified array.",
                ReturnType             = _supplier.Boolean(),
                ArrayOfType            = ArrayOfType,
                FuncType               = _supplier.Boolean(),
                ParameterDocumentation = "The condition that is evaluated for each element of the specified array.",
                Function               = "Is True For Any",
                Executor               = functionHandler.Any()
            }.Add(Scope, _supplier);
            // Is True For All
            new GenericSortFunction()
            {
                Name                   = "IsTrueForAll",
                Documentation          = "Whether the specified condition evaluates to true for every value in the specified array.",
                ReturnType             = _supplier.Boolean(),
                ArrayOfType            = ArrayOfType,
                FuncType               = _supplier.Boolean(),
                ParameterDocumentation = "The condition that is evaluated for each element of the specified array.",
                Function               = "Is True For All",
                Executor               = functionHandler.All()
            }.Add(Scope, _supplier);
            // Mapped
            var mapGenericParameter = new AnonymousType("T", new AnonymousTypeAttributes(false));
            var mapmethodInfo       = new MethodInfo(new[] { mapGenericParameter });

            mapGenericParameter.Context = mapmethodInfo.Tracker;
            new GenericSortFunction()
            {
                Name                   = "Map",
                Documentation          = "Whether the specified condition evaluates to true for every value in the specified array.",
                ReturnType             = new ArrayType(_supplier, mapGenericParameter),
                ArrayOfType            = ArrayOfType,
                FuncType               = mapGenericParameter,
                ParameterDocumentation = "The condition that is evaluated for each element of the specified array.",
                Function               = "Mapped Array",
                Executor               = functionHandler.Map(),
                MethodInfo             = mapmethodInfo
            }.Add(Scope, _supplier);
            // Contains
            Func(new FuncMethodBuilder()
            {
                Name          = "Contains",
                Documentation = "Whether the array contains the specified value.",
                ReturnType    = _supplier.Boolean(),
                Parameters    = new CodeParameter[] {
                    new CodeParameter("value", "The value that is being looked for in the array.", ArrayOfType)
                },
                Action = (actionSet, methodCall) => functionHandler.Contains(actionSet.CurrentObject, methodCall.ParameterValues[0])
            });
            // Random
            if (functionHandler.AllowUnhandled)
            {
                Func(new FuncMethodBuilder()
                {
                    Name          = "Random",
                    Documentation = "Gets a random value from the array.",
                    ReturnType    = ArrayOfType,
                    Action        = (actionSet, methodCall) => Element.Part("Random Value In Array", actionSet.CurrentObject)
                });
            }
            // Randomize
            if (functionHandler.AllowUnhandled)
            {
                Func(new FuncMethodBuilder()
                {
                    Name          = "Randomize",
                    Documentation = "Returns a copy of the array that is randomized.",
                    ReturnType    = this,
                    Action        = (actionSet, methodCall) => Element.Part("Randomized Array", actionSet.CurrentObject)
                });
            }
            // Append
            if (functionHandler.AllowUnhandled)
            {
                Func(new FuncMethodBuilder()
                {
                    Name          = "Append",
                    Documentation = "A copy of the array with the specified value appended to it.",
                    ReturnType    = this,
                    Parameters    = new CodeParameter[] {
                        new CodeParameter("value", "The value that is appended to the array. If the value is an array, it will be flattened.", pipeType)
                    },
                    Action = (actionSet, methodCall) => Element.Append(actionSet.CurrentObject, methodCall.ParameterValues[0])
                });
            }
            // Remove
            if (functionHandler.AllowUnhandled)
            {
                Func(new FuncMethodBuilder()
                {
                    Name          = "Remove",
                    Documentation = "A copy of the array with the specified value removed from it.",
                    ReturnType    = this,
                    Parameters    = new CodeParameter[] {
                        new CodeParameter("value", "The value that is removed from the array.", pipeType)
                    },
                    Action = (actionSet, methodCall) => Element.Part("Remove From Array", actionSet.CurrentObject, methodCall.ParameterValues[0])
                });
            }
            // Slice
            if (functionHandler.AllowUnhandled)
            {
                Func(new FuncMethodBuilder()
                {
                    Name          = "Slice",
                    Documentation = "A copy of the array containing only values from a specified index range.",
                    ReturnType    = this,
                    Parameters    = new CodeParameter[] {
                        new CodeParameter("startIndex", "The first index of the range.", _supplier.Number()),
                        new CodeParameter("count", "The number of elements in the resulting array. The resulting array will contain fewer elements if the specified range exceeds the bounds of the array.", _supplier.Number())
                    },
                    Action = (actionSet, methodCall) => Element.Part("Array Slice", actionSet.CurrentObject, methodCall.ParameterValues[0], methodCall.ParameterValues[1])
                });
            }
            // Index Of
            if (functionHandler.AllowUnhandled)
            {
                Func(new FuncMethodBuilder()
                {
                    Name          = "IndexOf",
                    Documentation = "The index of a value within an array or -1 if no such value can be found.",
                    ReturnType    = _supplier.Number(),
                    Parameters    = new CodeParameter[] {
                        new CodeParameter("value", "The value for which to search.", ArrayOfType)
                    },
                    Action = (actionSet, methodCall) => Element.IndexOfArrayValue(actionSet.CurrentObject, methodCall.ParameterValues[0])
                });
            }
            // Modify Append
            Func(new FuncMethodBuilder()
            {
                Name          = "ModAppend",
                Documentation = "Appends a value to the array. This will modify the array directly rather than returning a copy of the array. The source expression must be a variable.",
                Parameters    = new CodeParameter[] {
                    new CodeParameter("value", "The value that is pushed to the array.", pipeType)
                },
                OnCall     = SourceVariableResolver.GetSourceVariable,
                ReturnType = _supplier.Number(),
                Action     = (actionSet, methodCall) => SourceVariableResolver.Modify(actionSet, methodCall, Operation.AppendToArray)
            });
            // Modify Remove By Value
            Func(new FuncMethodBuilder()
            {
                Name          = "ModRemoveByValue",
                Documentation = "Removes an element from the array by a value. This will modify the array directly rather than returning a copy of the array. The source expression must be a variable.",
                Parameters    = new CodeParameter[] {
                    new CodeParameter("value", "The value that is removed from the array.", ArrayOfType)
                },
                OnCall     = SourceVariableResolver.GetSourceVariable,
                ReturnType = _supplier.Number(),
                Action     = (actionSet, methodCall) => SourceVariableResolver.Modify(actionSet, methodCall, Operation.RemoveFromArrayByValue)
            });
            // Modify Remove By Index
            Func(new FuncMethodBuilder()
            {
                Name          = "ModRemoveByIndex",
                Documentation = "Removes an element from the array by the index. This will modify the array directly rather than returning a copy of the array. The source expression must be a variable.",
                Parameters    = new CodeParameter[] {
                    new CodeParameter("index", "The index of the element that is removed from the array.", _supplier.Number())
                },
                OnCall     = SourceVariableResolver.GetSourceVariable,
                ReturnType = _supplier.Number(),
                Action     = (actionSet, methodCall) => SourceVariableResolver.Modify(actionSet, methodCall, Operation.RemoveFromArrayByIndex)
            });

            // Add type operations.
            Operations.AddTypeOperation(new[] {
                // + append
                new TypeOperation(TypeOperator.Add, pipeType, this, (l, r) => Element.Append(l, r)),
                // - remove
                new TypeOperation(TypeOperator.Subtract, pipeType, this, (l, r) => Element.Remove(l, r))
            });
            Operations.AddTypeOperation(new[] {
                // += mod append
                new AssignmentOperation(AssignmentOperator.AddEqual, pipeType, info => info.Modify(Operation.AppendToArray)),
                // -= mod remove
                new AssignmentOperation(AssignmentOperator.SubtractEqual, pipeType, info => info.Modify(Operation.RemoveFromArrayByValue))
            });

            ArrayOfType.ArrayHandler.OverrideArray(this);
        }
コード例 #8
0
        public void GetMeta()
        {
            _objectScope = PlayerVariableScope.Child();
            AddSharedFunctionsToScope(_objectScope);

            AddFunc(new FuncMethodBuilder()
            {
                Name          = "IsButtonHeld",
                Parameters    = new[] { new CodeParameter("button", _supplier.EnumType("Button")) },
                ReturnType    = _supplier.Boolean(),
                Action        = (set, call) => Element.Part("Is Button Held", set.CurrentObject, call.ParameterValues[0]),
                Documentation = "Determines if the target player is holding a button."
            });
            AddFunc(new FuncMethodBuilder()
            {
                Name          = "IsCommunicating",
                Parameters    = new[] { new CodeParameter("communication", _supplier.EnumType("Communication")) },
                ReturnType    = _supplier.Boolean(),
                Action        = (set, call) => Element.Part("Is Communicating", set.CurrentObject, call.ParameterValues[0]),
                Documentation = "Determines if the target player is communicating."
            });
            AddFunc(new FuncMethodBuilder()
            {
                Name          = "Stat",
                Parameters    = new[] { new CodeParameter("stat", _supplier.EnumType("PlayerStat")) },
                ReturnType    = _supplier.Number(),
                Action        = (set, call) => Element.Part("Player Stat", set.CurrentObject, call.ParameterValues[0]),
                Documentation = "Provides a statistic of the specified Player (limited to the current match). Statistics are only gathered when the game is in progress. Dummy bots do not gather statistics.",
            });
            AddFunc(new FuncMethodBuilder()
            {
                Name          = "HeroStat",
                Parameters    = new[] { new CodeParameter("hero", _supplier.Hero()), new CodeParameter("stat", _supplier.EnumType("PlayerHeroStat")) },
                ReturnType    = _supplier.Number(),
                Action        = (set, call) => Element.Part("Player Hero Stat", set.CurrentObject, call.ParameterValues[0], call.ParameterValues[1]),
                Documentation = "Provides a statistic of the specified Player's time playing a specific hero (limited to the current match). Statistics are only gathered when the game is in progress. Dummy bots do not gather statistics.",
            });
            AddFunc("Position", _supplier.Vector(), set => Element.PositionOf(set.CurrentObject), "The position of the player.");
            AddFunc("EyePosition", _supplier.Vector(), set => Element.EyePosition(set.CurrentObject), "The position of the player's head.");
            AddFunc("Team", _supplier.Any(), set => Element.Part("Team Of", set.CurrentObject), "The team of the player.");
            AddFunc("Health", _supplier.Number(), set => Element.Part("Health", set.CurrentObject), "The health of the player.");
            AddFunc("MaxHealth", _supplier.Number(), set => Element.Part("Max Health", set.CurrentObject), "The maximum health of the player.");
            AddFunc("FacingDirection", _supplier.Vector(), set => Element.FacingDirectionOf(set.CurrentObject), "The facing direction of the player.");
            AddFunc("Hero", _supplier.Any(), set => Element.Part("Hero Of", set.CurrentObject), "The hero of the player.");
            AddFunc("IsHost", _supplier.Boolean(), set => Element.Compare(set.CurrentObject, Operator.Equal, Element.Part("Host Player")), "Determines if the player is the host.");
            AddFunc("IsAlive", _supplier.Boolean(), set => Element.Part("Is Alive", set.CurrentObject), "Determines if the player is alive.");
            AddFunc("IsDead", _supplier.Boolean(), set => Element.Part("Is Dead", set.CurrentObject), "Determines if the player is dead.");
            AddFunc("IsCrouching", _supplier.Boolean(), set => Element.Part("Is Crouching", set.CurrentObject), "Determines if the player is crouching.");
            AddFunc("IsDummy", _supplier.Boolean(), set => Element.Part("Is Dummy Bot", set.CurrentObject), "Determines if the player is a dummy bot.");
            AddFunc("IsFiringPrimary", _supplier.Boolean(), set => Element.Part("Is Firing Primary", set.CurrentObject), "Determines if the player is firing their primary weapon.");
            AddFunc("IsFiringSecondary", _supplier.Boolean(), set => Element.Part("Is Firing Secondary", set.CurrentObject), "Determines if the player is using their secondary attack.");
            AddFunc("IsInAir", _supplier.Boolean(), set => Element.Part("Is In Air", set.CurrentObject), "Determines if the player is in the air.");
            AddFunc("IsOnGround", _supplier.Boolean(), set => Element.Part("Is On Ground", set.CurrentObject), "Determines if the player is on the ground.");
            AddFunc("IsInSpawnRoom", _supplier.Boolean(), set => Element.Part("Is In Spawn Room", set.CurrentObject), "Determines if the player is in the spawn room.");
            AddFunc("IsMoving", _supplier.Boolean(), set => Element.Part("Is Moving", set.CurrentObject), "Determines if the player is moving.");
            AddFunc("IsOnObjective", _supplier.Boolean(), set => Element.Part("Is On Objective", set.CurrentObject), "Determines if the player is on the objective.");
            AddFunc("IsOnWall", _supplier.Boolean(), set => Element.Part("Is On Wall", set.CurrentObject), "Determines if the player is on a wall.");
            AddFunc("IsPortraitOnFire", _supplier.Boolean(), set => Element.Part("Is Portrait On Fire", set.CurrentObject), "Determines if the player's portrait is on fire.");
            AddFunc("IsStanding", _supplier.Boolean(), set => Element.Part("Is Standing", set.CurrentObject), "Determines if the player is standing.");
            AddFunc("IsUsingAbility1", _supplier.Boolean(), set => Element.Part("Is Using Ability 1", set.CurrentObject), "Determines if the player is using their ability 1.");
            AddFunc("IsUsingAbility2", _supplier.Boolean(), set => Element.Part("Is Using Ability 2", set.CurrentObject), "Determines if the player is using their ability 2.");
        }