public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject) { ProcessResult lastResult = ProcessResult.None; // NOTE: I commented out the try here because if (trigObject.PausedNodeChain != null) { if (trigObject.PausedNodeChain.Count == 1 && trigObject.PausedNodeChain.Peek() == this) { trigObject.PausedNodeChain = null; } else { // it was paused inside of the if statement, so just keep going return(ProcessChildren(trigObject)); } } Object result; if (this.IfType == ConditionalType.If) { try { result = ConditionalMathTree.Calculate(trigObject); } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + ScriptString + "\nConditionalNode Error:", e); } if (result is bool && (bool)result) { lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue) { return(lastResult); } return(ProcessResult.SucceedIf); } else { return(ProcessResult.FailedIf); } } else if (this.IfType == ConditionalType.Elif) { try { result = ConditionalMathTree.Calculate(trigObject); } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + ScriptString + "\nConditionalNode Error:", e); } if (result is bool && (bool)result) { lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue) { return(lastResult); } return(ProcessResult.SucceedIf); } else { return(ProcessResult.FailedIf); } } else // this.IfType == ConditionalType.Else { lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue) { return(lastResult); } } return(ProcessResult.None); }
public Object Execute(TriggerObject trigObject, bool tryReturnObject = false) { if (trigObject == null) { throw new UberScriptException("Execute: trigObject reference is null"); } var args = new List <Object> { trigObject }; // the args of the function are actually // stored in nodes--either function or argument... e.g. // EFFECT(14000,25, THIS().x, THIS().y, THIS().z) // has 2 argument nodes and 3 function nodes // each child of a FunctionNode is an argument represented by a MathTree foreach (UberNode child in Children) { if (!(child is MathTree)) { throw new UberScriptException( String.Format("Execute: MathTree child expected at line {0}:\n{1}", LineNumber, OriginalString)); } MathTree mathTree = child as MathTree; if (!mathTree.IsEmpty()) { args.Add(mathTree.Calculate(trigObject)); } } Object obj; try { // FunctionNode scriptstring contains function name obj = UberScriptFunctions.Invoke(ScriptString, args.ToArray()); } catch (Exception x) { throw new UberScriptException( String.Format("Execute: an exception was thrown during invocation at line {0}:\n{1}", LineNumber, OriginalString), x); } if (Property == null || tryReturnObject) { return(obj); } Type ptype; try { obj = PropertyGetters.GetObject(trigObject, obj, Property, out ptype); if (obj == null) { return(null); // it's ok to be null here } } catch (Exception x) { throw new UberScriptException( String.Format( "Execute: value could not be set on function '{0}' output object at line {1}:\n{2}", ScriptString, LineNumber, OriginalString), x); } if (ptype == null) { throw new UberScriptException( String.Format( "Execute: property '{0}' does not exist on function '{1}' output object at line {2}:\n{3}", Property, ScriptString, LineNumber, OriginalString)); } if (NegateOutput) { if (obj is sbyte) { obj = -(sbyte)obj; } else if (obj is short) { obj = -(short)obj; } else if (obj is int) { obj = -(int)obj; } else if (obj is long) { obj = -(long)obj; } else { throw new UberScriptException( String.Format( "Execute: output negation failed on function '{0}' output object type '{1}' at line {2}:\n{3}", ScriptString, obj.GetType(), LineNumber, OriginalString)); } } return(obj); }
public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject) { if (InfiniteLoopRisk == true) { throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nAttempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } int maxLoopNumber = 10000; int loopCount = 0; // first try to execute the initial statement if (InitialStatement != null) { InitialStatement.Process(ProcessResult.None, trigObject); } Object result = ConditionalMathTree.Calculate(trigObject); while (result is bool && (bool)result) { //execute the child code ProcessResult lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Break) // exit out of this for loop { return(ProcessResult.None); } if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride) { return(lastResult); } // ProcessResult.Continue--just keep going //execute the next part of the loop (often ints.i++) try { RepeatedStatement.Process(ProcessResult.None, trigObject); } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nForLoop Repeated Statement execution error: ", e); } try { // see whether we still meet our condition result = ConditionalMathTree.Calculate(trigObject); } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nForLoop Conditional Statement execution error: ", e); } loopCount++; if (loopCount > maxLoopNumber) { InfiniteLoopRisk = true; throw new UberScriptException("Attempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } } return(ProcessResult.None); }
public Object Execute(TriggerObject trigObject, bool tryReturnObject = false) { List <Object> args = new List <Object>(); args.Add(trigObject); // every function takes this as a parameter // the args of the function are actually // stored in nodes--either function or argument... e.g. // EFFECT(14000,25, THIS().x, THIS().y, THIS().z) // has 2 argument nodes and 3 function nodes // each child of a ListAccessNode is an argument represented by a MathTree foreach (UberNode child in Children) { if (child is MathTree) { MathTree mathTree = child as MathTree; if (!mathTree.IsEmpty()) { args.Add(mathTree.Calculate(trigObject)); } //Execute(trigObject, tryReturnObject = false)); } else { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nListAccessNode had children other than MathTree... something is broken!"); } } object[] reflectionArgs = new object[args.Count]; int count = 0; foreach (Object arg in args) { reflectionArgs[count] = arg; count++; } Object outputObject; /* * if (ScriptString == "THIS") { outputObject = trigObject.This; } * else if (ScriptString == "TRIGMOB") { outputObject = trigObject.TrigMob; } * else if (ScriptString == "GIVENTOTHIS") { outputObject = trigObject.DroppedOnThis; } * else if (ScriptString == "GIVENBYTHIS") { outputObject = trigObject.DroppedOnThis; } * else if (ScriptString == "TARGETTEDBY") { outputObject = trigObject.TargettedBy; } * else if (ScriptString == "TARGETTED") { outputObject = trigObject.Targetted; } * else if (ScriptString == "DAMAGE") { outputObject = trigObject.Damage; } * else*/ try { outputObject = UberScriptFunctions.Invoke(this.ScriptString, reflectionArgs); // ListAccessNode scriptstring contains function name } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nError invoking function:", e); } if (Property == null || tryReturnObject) { return(outputObject); } Type ptype; try { outputObject = PropertyGetters.GetObject(trigObject, outputObject, Property, out ptype); if (outputObject == null) { return(null); // it's ok to be null here } } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nError setting value:", e); } if (ptype == null) { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nListAccessNode function " + ScriptString + " output object did not have property: " + Property); } if (NegateOutput) { Type outputType = outputObject.GetType(); if (outputType == typeof(SByte)) { outputObject = -((SByte)outputObject); } else if (outputType == typeof(Int16)) { outputObject = -((Int16)outputObject); } else if (outputType == typeof(Int32)) { outputObject = -((Int32)outputObject); } else if (outputType == typeof(Int64)) { outputObject = -((Int64)outputObject); } else { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nCould not negate output of " + this.ScriptString + " output object of type: " + outputType); } } return(outputObject); }
public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject) { if (InfiniteLoopRisk == true) { throw new UberScriptException("Attempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } int maxLoopNumber = 1000000; int loopCount = 0; Object list = ListObject.Calculate(trigObject); // currently only supports these 3 types of lists IPooledEnumerable pooledEnum = list as IPooledEnumerable; List <Mobile> mobList = list as List <Mobile>; List <Item> itemList = list as List <Item>; ArrayList arrayList = list as ArrayList; if (pooledEnum != null) { foreach (Object obj in pooledEnum) { trigObject.objs[ObjectLookup] = obj; // execute the child nodes ProcessResult lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Break) // exit out of this for loop { trigObject.CurrentNodeExecutionChain.Remove(this); return(ProcessResult.None); } if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride) { return(lastResult); } loopCount++; if (loopCount > maxLoopNumber) { InfiniteLoopRisk = true; throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nAttempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } if (lastResult == ProcessResult.Continue) { continue; } } pooledEnum.Free(); } else if (mobList != null) { foreach (Mobile mob in mobList) { trigObject.objs[ObjectLookup] = mob; // execute the child nodes ProcessResult lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Break) // exit out of this for loop { trigObject.CurrentNodeExecutionChain.Remove(this); return(ProcessResult.None); } if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride) { return(lastResult); } loopCount++; if (loopCount > maxLoopNumber) { InfiniteLoopRisk = true; throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nAttempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } if (lastResult == ProcessResult.Continue) { continue; } } } else if (itemList != null) { foreach (Item item in itemList) { trigObject.objs[ObjectLookup] = item; // execute the child nodes ProcessResult lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Break) // exit out of this for loop { trigObject.CurrentNodeExecutionChain.Remove(this); return(ProcessResult.None); } if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride) { return(lastResult); } loopCount++; if (loopCount > maxLoopNumber) { InfiniteLoopRisk = true; throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nAttempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } if (lastResult == ProcessResult.Continue) { continue; } } } else if (arrayList != null) { foreach (Object obj in arrayList) { trigObject.objs[ObjectLookup] = obj; // execute the child nodes ProcessResult lastResult = ProcessChildren(trigObject); if (lastResult == ProcessResult.Break) // exit out of this for loop { trigObject.CurrentNodeExecutionChain.Remove(this); return(ProcessResult.None); } if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride) { return(lastResult); } loopCount++; if (loopCount > maxLoopNumber) { InfiniteLoopRisk = true; throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nAttempted to execute ForLoop with InfiniteLoop risk! Skipping for loop!"); } if (lastResult == ProcessResult.Continue) { continue; } } } else { throw new UberScriptException("Line " + LineNumber + ": " + base.ScriptString + "\nDid not have IPooledEnumerable, Mobile List, or Item List to iterate over!"); } return(ProcessResult.None); }