private void SetUpBranch(TES4CodeBlock block, TES5EventCodeBlock newBlock, TES5FunctionScope blockFunctionScope, ITES5VariableOrProperty variable, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES4BlockParameterList parameterList = block.BlockParameterList;

            if (parameterList == null)
            {
                return;
            }
            List <TES4BlockParameter> parameterListVariableList = parameterList.Parameters;
            TES4BlockParameter        tesEquippedTarget         = parameterListVariableList[0];
            TES5LocalScope            localScope   = newBlock.CodeScope.LocalScope;
            ITES5Referencer           newContainer = this.referenceFactory.CreateReadReference(tesEquippedTarget.BlockParameter, globalScope, multipleScriptsScope, localScope);
            TES5ComparisonExpression  expression   = TES5ExpressionFactory.CreateComparisonExpression(TES5ReferenceFactory.CreateReferenceToVariable(variable), TES5ComparisonExpressionOperator.OPERATOR_EQUAL, newContainer);

            SetUpBranch(blockFunctionScope, newBlock, expression);
        }
        public void Modify(TES4CodeBlock block, TES5BlockList blockList, TES5EventCodeBlock newBlock, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES5FunctionScope blockFunctionScope = newBlock.FunctionScope;

            switch (block.BlockType.ToLower())
            {
            case "gamemode":
            case "scripteffectupdate":
            {
                TES5ObjectCall function = this.objectCallFactory.CreateRegisterForSingleUpdate(globalScope, multipleScriptsScope);
                newBlock.AddChunk(function);
                if (globalScope.ScriptHeader.BasicScriptType == TES5BasicType.T_QUEST)
                {
                    TES5EventCodeBlock onInitBlock = TES5BlockFactory.CreateOnInit();
                    onInitBlock.AddChunk(function);
                    blockList.Add(onInitBlock);
                }
                break;
            }

            case "onactivate":
            {
                TES5EventCodeBlock onInitBlock = TES5BlockFactory.CreateOnInit();
                TES5ObjectCall     function    = this.objectCallFactory.CreateObjectCall(TES5ReferenceFactory.CreateReferenceToSelf(globalScope), "BlockActivation", multipleScriptsScope);
                onInitBlock.AddChunk(function);
                blockList.Add(onInitBlock);
                break;
            }

            case "onactorequip":
            {
                SetUpBranch(block, newBlock, blockFunctionScope, TES5LocalVariableParameterMeaning.CONTAINER, globalScope, multipleScriptsScope);
                break;
            }

            case "ontriggeractor":
            {
                TES4BlockParameterList   parameterList                = block.BlockParameterList;
                TES5LocalScope           localScope                   = newBlock.CodeScope.LocalScope;
                TES5LocalVariable        activator                    = localScope.GetVariableWithMeaning(TES5LocalVariableParameterMeaning.ACTIVATOR);
                TES5LocalVariable        castedToActor                = new TES5LocalVariable("akAsActor", TES5BasicType.T_ACTOR);
                TES5Reference            referenceToCastedVariable    = TES5ReferenceFactory.CreateReferenceToVariable(castedToActor);
                TES5Reference            referenceToNonCastedVariable = TES5ReferenceFactory.CreateReferenceToVariable(activator);
                TES5ComparisonExpression expression                   = TES5ExpressionFactory.CreateComparisonExpression(referenceToCastedVariable, TES5ComparisonExpressionOperator.OPERATOR_NOT_EQUAL, new TES5None());
                TES5CodeScope            newCodeScope                 = TES5CodeScopeFactory.CreateCodeScopeRoot(blockFunctionScope);
                newCodeScope.LocalScope.AddVariable(castedToActor);
                newCodeScope.AddChunk(TES5VariableAssignationFactory.CreateAssignation(referenceToCastedVariable, referenceToNonCastedVariable));
                TES5CodeScope outerBranchCode;
                if (parameterList != null)
                {
                    //NOT TESTED
                    List <TES4BlockParameter> parameterListVariableList = parameterList.Parameters;
                    ITES5Referencer           targetActor     = this.referenceFactory.CreateReadReference(parameterListVariableList[0].BlockParameter, globalScope, multipleScriptsScope, localScope);
                    TES5ComparisonExpression  interExpression = TES5ExpressionFactory.CreateComparisonExpression(TES5ReferenceFactory.CreateReferenceToVariable(activator), TES5ComparisonExpressionOperator.OPERATOR_EQUAL, targetActor);
                    //TES5CodeScope interBranchCode = PHPFunction.Deserialize<TES5CodeScope>(PHPFunction.Serialize(newBlock.CodeScope));//WTM:  Change:  Why serialize and then deserialize?
                    TES5CodeScope interBranchCode = newBlock.CodeScope;
                    outerBranchCode = TES5CodeScopeFactory.CreateCodeScopeRoot(blockFunctionScope);
                    interBranchCode.LocalScope.ParentScope = outerBranchCode.LocalScope;
                    outerBranchCode.AddChunk(new TES5Branch(new TES5SubBranch(interExpression, interBranchCode)));
                }
                else
                {
                    //outerBranchCode = PHPFunction.Deserialize<TES5CodeScope>(PHPFunction.Serialize(newBlock.CodeScope));//WTM:  Change:  Why serialize and then deserialize?
                    outerBranchCode = newBlock.CodeScope;
                    outerBranchCode.LocalScope.ParentScope = newCodeScope.LocalScope;
                }

                newCodeScope.AddChunk(new TES5Branch(new TES5SubBranch(expression, outerBranchCode)));
                newBlock.CodeScope = newCodeScope;
                break;
            }

            case "onadd":
            {
                SetUpBranch(block, newBlock, blockFunctionScope, "akNewContainer", globalScope, multipleScriptsScope);
                break;
            }

            case "ondrop":
            {
                SetUpBranch(block, newBlock, blockFunctionScope, "akOldContainer", globalScope, multipleScriptsScope);
                break;
            }

            case "onpackagestart":
            {
                SetUpBranch(block, newBlock, blockFunctionScope, "akNewPackage", globalScope, multipleScriptsScope);
                break;
            }

            case "onpackagedone":
            case "onpackagechange":
            case "onpackageend":
            {
                SetUpBranch(block, newBlock, blockFunctionScope, "akOldPackage", globalScope, multipleScriptsScope);
                break;
            }

            case "onalarm":
            {
                //@INCONSISTENCE - We don"t account for alarm type.
                TES5ComparisonExpression expression = TES5ExpressionFactory.CreateComparisonExpression(this.objectCallFactory.CreateObjectCall(TES5ReferenceFactory.CreateReferenceToSelf(globalScope), "IsAlarmed", multipleScriptsScope), TES5ComparisonExpressionOperator.OPERATOR_EQUAL, new TES5Bool(true));
                SetUpBranch(blockFunctionScope, newBlock, expression);
                break;
            }

            /*
             *
             * case "onalarm":
             * {
             *
             * this.skyrimGroupEventName = "onhit";
             *
             * if (this.eventArgs[1] != 3) {
             *  //Nothing eelse is supported really..
             *  this.omit = true;
             *  break;
             * }
             *
             * branch = new TES4ConditionalBranch();
             * expression = new TES4Expression();
             * leftConstant = new TES4Constant("akAggressor", "ObjectReference");
             * //actionConstant        = new TES4Constant(this.eventArgs[1],"Package");
             * actionConstant = TES4Factories.createReference(this.eventArgs[2], this);
             *
             * expression.left_side = leftConstant;
             * expression.right_side = actionConstant;
             * expression.comparision_operator = TES4Expression.COMPARISION_OPERATOR_EQUAL;
             *
             * codeBlock = new TES4CodeBlock();
             * codeBlock.chunks = this.chunks;
             *
             * branch.ifs[] = array(
             *  "rawExpression" => "SCRIPT_GENERATED",
             *  "expression" => expression,
             *  "codeBlock" => codeBlock
             * );
             * this.chunks = new TES4ChunkContainer();
             * this.chunks.parent = this;
             * this.chunks.addChunk(branch);
             *
             * break;
             * }
             */
            case "onequip":
            case "onunequip":
            {
                SetUpBranch(block, newBlock, blockFunctionScope, "akActor", globalScope, multipleScriptsScope);
                break;
            }
            }
        }
Beispiel #3
0
        public TES4OBScriptGrammar()
            : base(false)
        {
            __invoke("Script").Is("ScriptHeader", "Block+").Call((TES4ScriptHeader header, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, null, blockList));
            }).

            Is("ScriptHeader", "VariableDeclaration+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList) =>
            {
                return(new TES4Script(header, variableList, null));
            }).

            Is("ScriptHeader", "VariableDeclaration+", "Block+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, variableList, blockList));
            })

            ;
            __invoke("ScriptHeader").Is("ScriptHeaderToken", "ScriptName").Call((System.Func <object, CommonToken, TES4ScriptHeader>)((object headerToken, CommonToken scriptName) =>
            {
                return(new TES4ScriptHeader((string)scriptName.Value));
            }))

            ;
            __invoke("VariableDeclaration+").Is("VariableDeclaration+", "VariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) =>
            {
                list.add(variableDeclaration);
                return(list);
            }).

            Is("VariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) =>
            {
                TES4VariableDeclarationList list = new TES4VariableDeclarationList();
                list.add(variableDeclaration);
                return(list);
            })

            ;
            __invoke("VariableDeclaration").Is("VariableDeclarationType", "VariableName").Call((System.Func <CommonToken, CommonToken, TES4VariableDeclaration>)((CommonToken variableDeclarationType, CommonToken variableName) =>
            {
                return(new TES4VariableDeclaration((string)variableName.Value, TES4Type.GetFirst((string)variableDeclarationType.Value.ToLower())));
            }))

            ;
            __invoke("Block+").Is("Block+", "Block").Call((TES4BlockList list, TES4CodeBlock blockDeclaration) =>
            {
                list.Add(blockDeclaration);
                return(list);
            }).

            Is("Block").Call((TES4CodeBlock blockDeclaration) =>
            {
                TES4BlockList list = new TES4BlockList();
                list.Add(blockDeclaration);
                return(list);
            })

            ;
            __invoke("Block").Is("BlockStart", "BlockType", "BlockParameter+", "Code+", "BlockEnd").Call((System.Func <object, CommonToken, TES4BlockParameterList, TES4CodeChunks, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, blockParameters, codeChunks));
            })).

            Is("BlockStart", "BlockType", "BlockParameter+", "BlockEnd").Call((System.Func <object, CommonToken, TES4BlockParameterList, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, blockParameters, null));
            }))  //rare empty block
            .

            Is("BlockStart", "BlockType", "Code+", "BlockEnd").Call((System.Func <object, CommonToken, TES4CodeChunks, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, null, codeChunks));
            })).

            Is("BlockStart", "BlockType", "BlockEnd").Call((System.Func <object, CommonToken, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, null, null));
            }))

            ; //rare empty block
            __invoke("BlockParameter+").Is("BlockParameter+", "BlockParameter").Call((TES4BlockParameterList list, TES4BlockParameter blockParameter) =>
            {
                list.Add(blockParameter);
                return(list);
            }).

            Is("BlockParameter").Call((TES4BlockParameter blockParameter) =>
            {
                TES4BlockParameterList block = new TES4BlockParameterList();
                block.Add(blockParameter);
                return(block);
            })

            ;
            __invoke("BlockParameter").Is("BlockParameterToken").Call((System.Func <CommonToken, TES4BlockParameter>)((CommonToken token) =>
            {
                return(new TES4BlockParameter((string)token.Value));
            }))

            ;
            this.createObscriptCodeParsingTree();
            this.Start("Script");
        }
Beispiel #4
0
        public TES4OBScriptGrammar()
            : base(false)
        {
            __invoke("Script").Is("ScriptHeader", "Block+").Call((TES4ScriptHeader header, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, null, blockList));
            }).

            Is("ScriptHeader", "VariableDeclaration+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList) =>
            {
                return(new TES4Script(header, variableList, null));
            }).

            Is("ScriptHeader", "VariableDeclaration+", "Block+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, variableList, blockList));
            })

#if NEWBT
            .
            Is("ScriptHeader").Call((TES4ScriptHeader header) =>//WTM:  Change:  I added this section to allow for a few more scripts to parsed (scripts that are just a header).
            {
                return(new TES4Script(header, null, null));
            })
#endif

            ;
            __invoke("ScriptHeader").Is("ScriptHeaderToken", "ScriptName").Call((object headerToken, CommonToken scriptName) =>
            {
                return(new TES4ScriptHeader(scriptName.Value));
            })

            ;
            __invoke("VariableDeclaration+").Is("VariableDeclaration+", "VariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) =>
            {
                list.Add(variableDeclaration);
                return(list);
            }).

            Is("VariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) =>
            {
                TES4VariableDeclarationList list = new TES4VariableDeclarationList();
                list.Add(variableDeclaration);
                return(list);
            })

            ;
            __invoke("VariableDeclaration").Is("VariableDeclarationType", "VariableName").Call((CommonToken variableDeclarationType, CommonToken variableName) =>
            {
                return(new TES4VariableDeclaration(variableName.Value, TES4Type.GetFirst(variableDeclarationType.Value.ToLower())));
            })

            ;
            __invoke("Block+").Is("Block+", "Block").Call((TES4BlockList list, TES4CodeBlock blockDeclaration) =>
            {
                list.Add(blockDeclaration);
                return(list);
            }).

            Is("Block").Call((TES4CodeBlock blockDeclaration) =>
            {
                TES4BlockList list = new TES4BlockList();
                list.Add(blockDeclaration);
                return(list);
            })

            ;
            __invoke("Block").Is("BlockStart", "BlockType", "BlockParameter+", "Code+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, blockParameters, codeChunks));
            }).

            Is("BlockStart", "BlockType", "BlockParameter+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, blockParameters, null));
            }) //rare empty block
            .

            Is("BlockStart", "BlockType", "Code+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, null, codeChunks));
            }).

            Is("BlockStart", "BlockType", "BlockEnd").Call((object blockStart, CommonToken blockType, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, null, null));
            })

            ; //rare empty block
            __invoke("BlockParameter+").Is("BlockParameter+", "BlockParameter").Call((TES4BlockParameterList list, TES4BlockParameter blockParameter) =>
            {
                list.Add(blockParameter);
                return(list);
            }).

            Is("BlockParameter").Call((TES4BlockParameter blockParameter) =>
            {
                TES4BlockParameterList block = new TES4BlockParameterList();
                block.Add(blockParameter);
                return(block);
            })

            ;
            __invoke("BlockParameter").Is("BlockParameterToken").Call((CommonToken token) =>
            {
                return(new TES4BlockParameter(token.Value));
            })

            ;
            this.CreateObscriptCodeParsingTree();
            this.Start("Script");
        }