示例#1
0
        public TriggerObject Dupe()
        {
            TriggerObject output = new TriggerObject();

            output.TrigName   = TrigName;
            output.This       = This;
            output.TrigMob    = TrigMob;
            output.TrigItem   = TrigItem;
            output.Spell      = Spell;
            output.Damage     = Damage;
            output.Speech     = Speech;
            output.Targeted   = Targeted;
            output.SkillName  = SkillName;
            output.SkillValue = SkillValue;
            output.Script     = Script;
            output.GumpID     = GumpID;
            foreach (KeyValuePair <string, int> pair in ints)
            {
                output.ints.Add(pair.Key, pair.Value);
            }
            foreach (KeyValuePair <string, string> pair in strings)
            {
                output.strings.Add(pair.Key, pair.Value);
            }
            foreach (KeyValuePair <string, double> pair in doubles)
            {
                output.doubles.Add(pair.Key, pair.Value);
            }
            foreach (KeyValuePair <string, object> pair in objs)
            {
                output.objs.Add(pair.Key, pair.Value);
            }
            return(output);
        }
示例#2
0
        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 spawnentry statement, so just keep going
                    return(ProcessChildren(trigObject));
                }
            }

            lastResult = ProcessChildren(trigObject);
            if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue)
            {
                return(lastResult);
            }
            return(ProcessResult.None);
        }
示例#3
0
 public Object Calculate(TriggerObject trigObj)
 {
     if (Children.Count == 0 || Children.Count > 1)
     {
         throw new Exception("Bad number of children in MathTree!:" + Children.Count + " ScriptString: " + ScriptString);
     }
     return(MathNode.Calculate(trigObj, (MathNode)Children[0]));
 }
示例#4
0
 public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject)
 {
     if (Override)
     {
         return(ProcessResult.ReturnOverride);
     }
     return(ProcessResult.Return);
 }
示例#5
0
 public PausedUberScript(TriggerObject trigObject, bool triggersOnly, double milliseconds)
     : base(TimeSpan.FromMilliseconds(milliseconds))
 {
     TriggersOnly    = triggersOnly;
     TrigObject      = trigObject;
     ExpectedEndTime = DateTime.UtcNow + TimeSpan.FromMilliseconds(milliseconds);
     Start();
 }
		public PausedUberScript(TriggerObject trigObject, bool triggersOnly, double milliseconds)
			: base(TimeSpan.FromMilliseconds(milliseconds))
		{
			TriggersOnly = triggersOnly;
			TrigObject = trigObject;
			ExpectedEndTime = DateTime.UtcNow + TimeSpan.FromMilliseconds(milliseconds);
			Start();
		}
        override public ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject)
        {
            trigObject.CurrentNodeExecutionChain.Add(this);

            ProcessResult result = UserDefinedFunction.Execute(trigObject);

            trigObject.CurrentNodeExecutionChain.Remove(this);
            return result;
        }
        override public ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject)
        {
            trigObject.CurrentNodeExecutionChain.Add(this);

            ProcessResult result = UserDefinedFunction.Execute(trigObject);

            trigObject.CurrentNodeExecutionChain.Remove(this);
            return(result);
        }
示例#9
0
        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;
        }
示例#10
0
        public static string GetStringValue(TriggerObject trigObject, object o, string name, out Type ptype)
        {
            object value = GetObject(trigObject, o, name, out ptype);
            string ToString;
            if (value == null)
                ToString = "null";
            else
                ToString = value.ToString();

            return ToString;
        }
示例#11
0
        /// <summary>
        ///     Checks for any triggers existing on "thisMob", returns true if a trigger signalled to override the
        ///     handler that it came from
        /// </summary>
        /// <returns>true if a trigger execution signalled to override the handler that called Trigger</returns>
        public static bool Trigger(
            IEntity thisObj,
            Mobile trigMob,
            TriggerName trigName,
            Item item           = null,
            string spoken       = null,
            Spell spell         = null,
            int damage          = 0,
            object targeted     = null,
            SkillName skillName = SkillName.Spellweaving,
            double skillValue   = 0.0)           // spellweaving is just a placeholder
        {
            var  scripts = XmlAttach.GetScripts(thisObj);
            bool result  = false;

            if (scripts != null)
            {
                TriggerObject trigObject = new TriggerObject
                {
                    TrigName   = trigName,
                    This       = thisObj,
                    TrigMob    = trigMob,
                    TrigItem   = item,
                    Spell      = spell,
                    Damage     = damage,
                    Speech     = spoken,
                    Targeted   = targeted,
                    SkillName  = skillName,
                    SkillValue = skillValue
                };

                int count = 0;

                foreach (XmlScript script in scripts)
                {
                    count++;

                    // make sure each script has its own TriggerObjects
                    if (script.Execute(count < scripts.Count ? trigObject.Dupe() : trigObject, true))
                    {
                        // returns true if there is an override
                        result = true;
                    }
                }
            }

            return(result);
        }
示例#12
0
        public static string GetStringValue(TriggerObject trigObject, object o, string name, out Type ptype)
        {
            object value = GetObject(trigObject, o, name, out ptype);
            string ToString;

            if (value == null)
            {
                ToString = "null";
            }
            else
            {
                ToString = value.ToString();
            }

            return(ToString);
        }
示例#13
0
        protected override void OnTarget(Mobile from, object targeted)
        {
            if (m_Script == null)
            {
                return;
            }

            TriggerObject trigObject = new TriggerObject {
                This     = m_Source,
                TrigMob  = @from,
                TrigName = TriggerName.onTarget,
                Targeted = targeted
            };

            m_Script.Execute(trigObject, true);
        }
示例#14
0
        private Object GetReturnObject(UberNode node, TriggerObject trigObject)
        {
            if (node is RootNode)
            {
                // it's a spawn node, execute it
                return(((RootNode)Children[1]).SpawnAndReturnObject(ProcessResult.None, trigObject));
            }

            if (node is MathTree)
            {
                return(((MathTree)Children[1]).Calculate(trigObject));
            }

            throw new UberScriptException(
                      "Line " + LineNumber + ": " + ScriptString + "\nStatement node did not have MathTree second child!");
        }
示例#15
0
		protected override void OnTarget(Mobile from, object targeted)
		{
			if (m_Script == null)
			{
				return;
			}

			TriggerObject trigObject = new TriggerObject {
				This = m_Source,
				TrigMob = @from,
				TrigName = TriggerName.onTarget,
				Targeted = targeted
			};

			m_Script.Execute(trigObject, true);
		}
示例#16
0
        public static bool SendGump(TriggerObject trigObject, Mobile target, string GumpFile, bool closeGump)
        {
            if (GumpFile == null || target == null)
            {
                return(false);
            }

            string path;

            GumpFileMap.TryGetValue(GumpFile.ToLower(), out path);
            if (path == null)
            {
                //path = Path.GetFullPath(ScriptFile);
                path = Path.Combine(Core.BaseDirectory, "UberScripts", GumpFile);
                if (!File.Exists(path))
                {
                    throw new UberScriptException("Script file did not exist at " + path);
                }
                GumpFileMap.Add(GumpFile.ToLower(), path);
            }

            UberGumpBase parsedGump;
            XmlDocument  parsedXml;

            if (!Gumps.ContainsKey(path))
            {
                parsedXml = new XmlDocument(); //* create an xml document object.
                parsedXml.Load(path);          //* load the XML document from the specified file.
                if (parsedXml == null)
                {
                    return(false);
                }
                parsedGump = new UberGumpBase(parsedXml.FirstChild);
                Gumps.Add(path, parsedGump);
            }
            else
            {
                parsedGump = Gumps[path];
            }

            if (closeGump && target.HasGump(typeof(UberScriptGump)))
            {
                target.CloseGump(typeof(UberScriptGump));
            }
            target.SendGump(new UberScriptGump(target, trigObject, parsedGump, GumpFile));
            return(true);
        }
示例#17
0
 public TriggerObject Dupe()
 {
     TriggerObject output = new TriggerObject();
     output.TrigName = TrigName;
     output.This = This;
     output.TrigMob = TrigMob;
     output.TrigItem = TrigItem;
     output.Spell = Spell;
     output.Damage = Damage;
     output.Speech = Speech;
     output.Targeted = Targeted;
     output.SkillName = SkillName;
     output.SkillValue = SkillValue;
     output.Script = Script;
     output.GumpID = GumpID;
     foreach (KeyValuePair<string, int> pair in ints) { output.ints.Add(pair.Key, pair.Value); }
     foreach (KeyValuePair<string, string> pair in strings) { output.strings.Add(pair.Key, pair.Value); }
     foreach (KeyValuePair<string, double> pair in doubles) { output.doubles.Add(pair.Key, pair.Value); }
     foreach (KeyValuePair<string, object> pair in objs) { output.objs.Add(pair.Key, pair.Value); }
     return output;
 }
示例#18
0
        public static bool TryExecuteScript(string ScriptFile, TriggerObject trigObject, List <int> rootNodeIndeces, bool triggerScriptsOnly)
        {
            bool signalToOverride = false;

            RootNode parsedScriptRoot = GetRootNode(ScriptFile, rootNodeIndeces);

            if (parsedScriptRoot == null)
            {
                return(false);
            }

            if (triggerScriptsOnly)
            {
                foreach (TriggerNode trigNode in parsedScriptRoot.TriggerNodes)
                {
                    if (trigNode.TrigName == trigObject.TrigName)
                    {
                        ProcessResult result = trigNode.Process(ProcessResult.None, trigObject);
                        if (result == ProcessResult.ReturnOverride)
                        {
                            signalToOverride = true;
                        }
                    }
                }
            }
            else if (trigObject.Script.ProceedToNextStage)
            {
                // NOTE: signalToOverride is overloaded--it works for both NEXTSTAGE function (sequences)
                // AND triggers
                if (parsedScriptRoot.Process(ProcessResult.None, trigObject) == ProcessResult.EndOfSequence)
                {
                    signalToOverride = true;
                }
            }
            else
            {
                parsedScriptRoot.Process(ProcessResult.None, trigObject);
            }
            return(signalToOverride);
        }
示例#19
0
        public override void OnAttach()
        {
            base.OnAttach();
            AllScripts.Add(this, true);

            /*
             * List<string> timerTriggers = ParsedScripts.GetTimerTriggers(ScriptFile, RootNodeIndeces);
             * if (timerTriggers != null)
             * {
             *  // subscribe to timers
             *  UberScriptTimedScripts.SubscribeScript(this, timerTriggers);
             * }
             * */

            UpdateScriptTriggerLookup();

            if (XmlScript.HasTrigger(AttachedTo, TriggerName.onCreate))
            {
                TriggerObject trigObject = new TriggerObject();
                trigObject.TrigName = TriggerName.onCreate;
                trigObject.This     = AttachedTo;
                this.Execute(trigObject, true);
            }

            if (AttachedTo is BaseCreature)
            {
                if (XmlScript.HasTrigger(AttachedTo, TriggerName.onActivate))
                {
                    BaseCreature bc = (BaseCreature)AttachedTo;
                    if (bc.AIObject.m_Timer != null && bc.AIObject.m_Timer.Running)
                    {
                        UberScriptTriggers.Trigger(bc, bc, TriggerName.onActivate);
                    }
                }
            }
        }
示例#20
0
        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 spawnentry statement, so just keep going
                    return ProcessChildren(trigObject);
                }
            }

            lastResult = ProcessChildren(trigObject);
            if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue)
            {
                return lastResult;
            }
            return ProcessResult.None;
        }
示例#21
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return new Rectangle2D();
			}

			int x = originX + GetX(trigObject);
			int y = originY + GetY(trigObject);

			gump.CurrentList = GetListSource(trigObject);

			string objName = GetObjsVarName(trigObject);
			ArrayList prevList = gump.CurrentList;
			object prevListObject = gump.CurrentListObject;

			gump.CurrentListObject = trigObject.objs.ContainsKey(objName) ? trigObject.objs[objName] : null;

			foreach (UberGumpElement child in Children)
			{
				child.GenerateGump(trigObject, gump, x, y);
			}

			gump.CurrentList = prevList;
			gump.CurrentListObject = prevListObject;

			return new Rectangle2D(GetX(trigObject), GetY(trigObject), GetWidth(trigObject), GetHeight(trigObject));
		}
示例#22
0
		public bool GetCondition(TriggerObject trigObject)
		{
			object output = m_Condition.Calculate(trigObject);

			if (!(output is bool))
			{
				throw new UberScriptException(
					GetType() + " GetCondition did not resolve to an bool: " + output + " from " + m_Condition.ScriptString);
			}

			return (bool)output;
		}
示例#23
0
		public virtual int GetHeight(TriggerObject trigObject)
		{
			return 0;
		}
示例#24
0
        public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject)
        {
            // will always have 2 children, either function nodes or MathTree nodes
            Object o        = null;
            string propname = null;
            Object value;
            string globalObjsString;
            string localObjsString;

            // 1st child is the property that will be set
            if (Children[0] is FunctionNode)
            {
                // this presumes that it is a function like THIS() or TRIGMOB()
                FunctionNode fn = Children[0] as FunctionNode;
                o        = fn.Execute(trigObject, true);
                propname = fn.Property;
            }
            else             // Children[0] is argument node
            {
                string scriptString = Children[0].ScriptString;
                int    dotIndex     = scriptString.IndexOf('.');

                if (dotIndex > -1)
                {
                    if (scriptString.StartsWith("global_"))
                    {
                        if (scriptString.StartsWith("global_ints."))
                        {
                            UberTreeParser.global_ints[scriptString.Substring(12)] = (int)((MathTree)Children[1]).Calculate(trigObject);

                            value = ((MathTree)Children[1]).Calculate(trigObject);

                            switch (AssignType)
                            {
                            case AssignmentType.Plus:
                                UberTreeParser.global_ints[scriptString.Substring(12)] =
                                    UberTreeParser.global_ints[scriptString.Substring(12)] + Convert.ToInt32(value);
                                break;

                            case AssignmentType.Minus:
                                UberTreeParser.global_ints[scriptString.Substring(12)] =
                                    UberTreeParser.global_ints[scriptString.Substring(12)] - Convert.ToInt32(value);
                                break;

                            case AssignmentType.Mult:
                                UberTreeParser.global_ints[scriptString.Substring(12)] =
                                    UberTreeParser.global_ints[scriptString.Substring(12)] * Convert.ToInt32(value);
                                break;

                            case AssignmentType.Divide:
                                UberTreeParser.global_ints[scriptString.Substring(12)] =
                                    Convert.ToInt32(UberTreeParser.global_ints[scriptString.Substring(12)] / Convert.ToDouble(value));
                                break;

                            default:
                                UberTreeParser.global_ints[scriptString.Substring(12)] = Convert.ToInt32(value);
                                break;
                            }

                            return(ProcessResult.None);
                        }

                        if (scriptString.StartsWith("global_strings."))
                        {
                            value = GetReturnObject(Children[1], trigObject);

                            if (value != null)
                            {
                                value = value.ToString();

                                switch (AssignType)
                                {
                                case AssignmentType.Plus:
                                    UberTreeParser.global_strings[scriptString.Substring(15)] =
                                        UberTreeParser.global_strings[scriptString.Substring(15)] + (string)value;
                                    break;

                                case AssignmentType.Regular:
                                    UberTreeParser.global_strings[scriptString.Substring(15)] = (string)value;
                                    break;
                                }

                                throw new UberScriptException(
                                          "Line " + LineNumber + ": " + ScriptString + "\nTried to use +=, -=, *=, or /= but this is only supported for " +
                                          value.GetType() + "! It is only supported for int, double, and UInt64");
                                //return ProcessResult.None;
                            }

                            throw new UberScriptException(
                                      "Line " + LineNumber + ": " + ScriptString +
                                      "\nTried to add null value to strings dictionary... this is not allowed!");
                        }

                        if (scriptString.StartsWith("global_doubles."))
                        {
                            value = ((MathTree)Children[1]).Calculate(trigObject);

                            switch (AssignType)
                            {
                            case AssignmentType.Plus:
                                UberTreeParser.global_doubles[scriptString.Substring(15)] =
                                    UberTreeParser.global_doubles[scriptString.Substring(15)] + Convert.ToDouble(value);
                                break;

                            case AssignmentType.Minus:
                                UberTreeParser.global_doubles[scriptString.Substring(15)] =
                                    UberTreeParser.global_doubles[scriptString.Substring(15)] - Convert.ToDouble(value);
                                break;

                            case AssignmentType.Mult:
                                UberTreeParser.global_doubles[scriptString.Substring(15)] =
                                    UberTreeParser.global_doubles[scriptString.Substring(15)] * Convert.ToDouble(value);
                                break;

                            case AssignmentType.Divide:
                                UberTreeParser.global_doubles[scriptString.Substring(15)] =
                                    UberTreeParser.global_doubles[scriptString.Substring(15)] / Convert.ToDouble(value);
                                break;

                            default:
                                UberTreeParser.global_doubles[scriptString.Substring(15)] = Convert.ToDouble(value);
                                break;
                            }

                            return(ProcessResult.None);
                        }

                        if (scriptString.StartsWith("global_objs."))
                        {
                            globalObjsString = scriptString.Substring(12);

                            int secondDotIndex = globalObjsString.IndexOf('.');

                            if (secondDotIndex > -1)                             // we are trying to set a property on an existing object
                            {
                                // will throw error if it doesn't exist yet
                                o        = UberTreeParser.global_objs[globalObjsString.Substring(0, secondDotIndex)];
                                propname = globalObjsString.Substring(secondDotIndex + 1);
                            }
                            else
                            {
                                UberTreeParser.global_objs[globalObjsString] = GetReturnObject(Children[1], trigObject);
                                return(ProcessResult.None);
                            }
                        }
                    }
                    else if (scriptString.StartsWith("ints."))
                    {
                        value = ((MathTree)Children[1]).Calculate(trigObject);

                        switch (AssignType)
                        {
                        case AssignmentType.Plus:
                            trigObject.ints[scriptString.Substring(5)] = trigObject.ints[scriptString.Substring(5)] + Convert.ToInt32(value);
                            break;

                        case AssignmentType.Minus:
                            trigObject.ints[scriptString.Substring(5)] = trigObject.ints[scriptString.Substring(5)] - Convert.ToInt32(value);
                            break;

                        case AssignmentType.Mult:
                            trigObject.ints[scriptString.Substring(5)] = trigObject.ints[scriptString.Substring(5)] * Convert.ToInt32(value);
                            break;

                        case AssignmentType.Divide:
                            trigObject.ints[scriptString.Substring(5)] =
                                Convert.ToInt32(trigObject.ints[scriptString.Substring(5)] / Convert.ToDouble(value));
                            break;

                        default:
                            trigObject.ints[scriptString.Substring(5)] = Convert.ToInt32(value);
                            break;
                        }

                        return(ProcessResult.None);
                    }
                    else if (scriptString.StartsWith("strings."))
                    {
                        value = GetReturnObject(Children[1], trigObject);

                        if (value != null)
                        {
                            value = value.ToString();

                            switch (AssignType)
                            {
                            case AssignmentType.Plus:
                                trigObject.strings[scriptString.Substring(8)] = trigObject.strings[scriptString.Substring(8)] + (string)value;
                                break;

                            case AssignmentType.Regular:
                                trigObject.strings[scriptString.Substring(8)] = (string)value;
                                break;

                            default:
                                throw new UberScriptException(
                                          "Line " + LineNumber + ": " + ScriptString +
                                          "\nTried to use +=, -=, *=, or /= but this is only supported for " + value.GetType() +
                                          "! It is only supported for int, double, and UInt64");
                            }
                            return(ProcessResult.None);
                        }

                        throw new UberScriptException(
                                  "Line " + LineNumber + ": " + ScriptString +
                                  "\nTried to add null value to strings dictionary... this is not allowed!");
                    }
                    else if (scriptString.StartsWith("doubles."))
                    {
                        value = ((MathTree)Children[1]).Calculate(trigObject);

                        switch (AssignType)
                        {
                        case AssignmentType.Plus:
                            trigObject.doubles[scriptString.Substring(8)] = trigObject.doubles[scriptString.Substring(8)] +
                                                                            Convert.ToDouble(value);
                            break;

                        case AssignmentType.Minus:
                            trigObject.doubles[scriptString.Substring(8)] = trigObject.doubles[scriptString.Substring(8)] -
                                                                            Convert.ToDouble(value);
                            break;

                        case AssignmentType.Mult:
                            trigObject.doubles[scriptString.Substring(8)] = trigObject.doubles[scriptString.Substring(8)] *
                                                                            Convert.ToDouble(value);
                            break;

                        case AssignmentType.Divide:
                            trigObject.doubles[scriptString.Substring(8)] = trigObject.doubles[scriptString.Substring(8)] /
                                                                            Convert.ToDouble(value);
                            break;

                        default:
                            trigObject.doubles[scriptString.Substring(8)] = Convert.ToDouble(value);
                            break;
                        }

                        return(ProcessResult.None);
                    }
                    else if (scriptString.StartsWith("objs."))
                    {
                        localObjsString = scriptString.Substring(5);

                        int secondDotIndex = localObjsString.IndexOf('.');

                        if (secondDotIndex > -1)                         // we are trying to set a property on an existing object
                        {
                            if (!trigObject.objs.TryGetValue(localObjsString.Substring(0, secondDotIndex), out o))
                            {
                                // will throw error if it doesn't exist yet
                                throw new UberScriptException(
                                          "local objs dictionary did not have entry: " + localObjsString.Substring(0, secondDotIndex));
                            }

                            propname = localObjsString.Substring(secondDotIndex + 1);
                        }
                        else
                        {
                            trigObject.objs[localObjsString] = GetReturnObject(Children[1], trigObject);
                            return(ProcessResult.None);
                        }
                    }
                }

                // only makes it here if we aren't editing global variables directly
                // (or if the we are returning a global object, e.g. global_objs.goober.hits
                if (o == null)
                {
                    o        = trigObject.Spawn ?? trigObject.This;
                    propname = scriptString;
                }
            }

            // 2nd child is the value, but could have an operation in it and needs to be parsed
            try
            {
                if (AssignType == AssignmentType.Regular)
                {
                    value = GetReturnObject(Children[1], trigObject);
                }
                else
                {
                    Type ptype;

                    value = PropertyGetters.GetObject(trigObject, o, propname, out ptype);

                    if (value is int)
                    {
                        switch (AssignType)
                        {
                        case AssignmentType.Plus:
                            value = (int)value + Convert.ToInt32(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Minus:
                            value = (int)value - Convert.ToInt32(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Mult:
                            value = Convert.ToInt32((int)value * Convert.ToDouble(GetReturnObject(Children[1], trigObject)));
                            break;

                        case AssignmentType.Divide:
                            value = Convert.ToInt32((int)value / Convert.ToDouble(GetReturnObject(Children[1], trigObject)));
                            break;
                        }
                    }
                    else if (value is double)
                    {
                        switch (AssignType)
                        {
                        case AssignmentType.Plus:
                            value = (double)value + Convert.ToDouble(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Minus:
                            value = (double)value - Convert.ToDouble(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Mult:
                            value = (double)value * Convert.ToDouble(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Divide:
                            value = (double)value / Convert.ToDouble(GetReturnObject(Children[1], trigObject));
                            break;
                        }
                    }
                    else if (value is UInt64)
                    {
                        switch (AssignType)
                        {
                        case AssignmentType.Plus:
                            value = (UInt64)value + Convert.ToUInt64(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Minus:
                            value = (UInt64)value - Convert.ToUInt64(GetReturnObject(Children[1], trigObject));
                            break;

                        case AssignmentType.Mult:
                            value = Convert.ToUInt64((UInt64)value * Convert.ToDouble(GetReturnObject(Children[1], trigObject)));
                            break;

                        case AssignmentType.Divide:
                            value = Convert.ToUInt64((UInt64)value / Convert.ToDouble(GetReturnObject(Children[1], trigObject)));
                            break;
                        }
                    }
                    else if (value is string)
                    {
                        if (AssignType == AssignmentType.Plus)
                        {
                            value = (string)value + GetReturnObject(Children[1], trigObject);
                        }
                        else
                        {
                            throw new UberScriptException(
                                      "Tried to use +=, -=, *=, or /= but this is only supported for " + value.GetType() +
                                      "! It is only supported for int, double, and UInt64");
                        }
                    }
                    else
                    {
                        //throw new UberScriptException("Tried to use +=, -=, *=, or /= on a non-numeric left-hand side!");
                        throw new UberScriptException(
                                  "Tried to use +=, -=, *=, or /= but this is only supported for " + value.GetType() +
                                  "! It is only supported for int, double, and UInt64");
                    }
                }
            }
            catch (Exception e)
            {
                throw new UberScriptException("Line " + LineNumber + ": " + ScriptString + "\nGetReturnObject Error:", e);
            }

            try
            {
                PropertySetters.SetPropertyValue(trigObject, o, propname, value);
            }
            catch (Exception e)
            {
                throw new UberScriptException("Line " + LineNumber + ": " + ScriptString + "\nError setting value:", e);
            }

            return(ProcessResult.None);
        }
示例#25
0
        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);
        }
示例#26
0
		public string GetName(TriggerObject trigObject)
		{
			object output = m_Name.Calculate(trigObject);

			if (output == null)
			{
				return "null";
			}

			return output.ToString();
		}
示例#27
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return new Rectangle2D();
			}

			int backgroundID = GetBackgroundID(trigObject);
			int padding = GetPadding(trigObject);
			int x = originX + GetX(trigObject);
			int y = originY + GetY(trigObject);
			int width = GetWidth(trigObject);
			int height = GetHeight(trigObject);
			int horizontalGap = GetHorizontalGap(trigObject);

			if (backgroundID != 0)
			{
				gump.AddBackground(x, y, width, height, backgroundID);
			}

			x += padding;
			y += padding;

			foreach (UberGumpElement child in Children)
			{
				child.GenerateGump(trigObject, gump, x, y);
				x += child.GetWidth(trigObject) + horizontalGap;
			}

			return new Rectangle2D(GetX(trigObject), GetY(trigObject), GetWidth(trigObject), GetHeight(trigObject));
		}
示例#28
0
		public override int GetWidth(TriggerObject trigObject)
		{
			return m_Condition != null && GetCondition(trigObject) == false ? 0 : GetWidthFromString(GetLabel(trigObject));
		}
示例#29
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return new Rectangle2D();
			}

			gump.AddLabel(originX + GetX(trigObject), originY + GetY(trigObject), GetHue(trigObject), GetLabel(trigObject));

			return new Rectangle2D(GetX(trigObject), GetY(trigObject), GetWidth(trigObject), GetHeight(trigObject));
		}
示例#30
0
		protected MathTree m_Height = new MathTree(null, "10"); // 44 is default tile size

		public override int GetHeight(TriggerObject trigObject)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return 0;
			}

			object output = m_Height.Calculate(trigObject);

			if (!(output is int))
			{
				throw new UberScriptException(
					GetType() + " GetHeight did not resolve to an integer: " + output + " from " + m_Height.ScriptString);
			}

			return (int)output;
		}
示例#31
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return new Rectangle2D();
			}

			gump.X = GetX(trigObject);
			gump.Y = GetY(trigObject);
			gump.Closable = Closable;
			gump.Disposable = Disposable;
			gump.Dragable = Dragable;
			gump.Resizable = Resizable;

			gump.AddPage(0);

			foreach (UberGumpElement child in Children)
			{
				child.GenerateGump(trigObject, gump, gump.X, gump.Y);
			}

			return new Rectangle2D();
		}
示例#32
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return new Rectangle2D();
			}

			int backgroundID = GetBackgroundID(trigObject);
			int padding = GetPadding(trigObject);
			int x = originX + GetX(trigObject);
			int y = originY + GetY(trigObject);
			int width = GetWidth(trigObject);
			int height = GetHeight(trigObject);
			int verticalGap = GetVerticalGap(trigObject);

			if (backgroundID != 0)
			{
				gump.AddBackground(x, y, width, height, backgroundID);
			}

			x += padding;
			y += padding;

			foreach (UberGumpElement child in Children)
			{
				if (child is UberGumpList)
				{
					UberGumpList list = (UberGumpList)child;
					ArrayList actualList = list.GetListSource(trigObject);

					if (actualList != null)
					{
						string key = list.GetObjsVarName(trigObject);
						string functionName = list.GetLoopFunction(trigObject);

						foreach (object element in actualList)
						{
							trigObject.objs[key] = element;
							child.GenerateGump(trigObject, gump, x, y);
							y += child.GetHeight(trigObject) + verticalGap;

							// check the script to execute in between
							if (functionName == null)
							{
								continue;
							}

							RootNode scriptNode = trigObject.Script.ScriptRootNode;

							if (scriptNode != null)
							{
								foreach (UserDefinedFunctionNode node in
									scriptNode.UserDefinedFunctionNodes.Where(node => node.ScriptString == functionName))
								{
									node.Execute(trigObject);
									break;
								}
							}
						}
					}
				}
				else
				{
					child.GenerateGump(trigObject, gump, x, y);
					y += child.GetHeight(trigObject) + verticalGap;
				}
			}
			return new Rectangle2D(GetX(trigObject), GetY(trigObject), GetWidth(trigObject), GetHeight(trigObject));
		}
示例#33
0
		public override int GetWidth(TriggerObject trigObject)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return 0;
			}

			if (FitToContents)
			{
				int padding = GetPadding(trigObject);
				int width = padding * 2;

				foreach (UberGumpElement child in Children)
				{
					int childX = child.GetX(trigObject);
					int childWidth = childX + child.GetWidth(trigObject) + padding * 2;

					if (childWidth > width)
					{
						width = childWidth;
					}
				}

				return width;
			}

			object output = m_Width.Calculate(trigObject);

			if (!(output is int))
			{
				throw new UberScriptException(
					GetType() + " GetWidth did not resolve to an integer: " + output + " from " + m_Width.ScriptString);
			}

			return (int)output;
		}
示例#34
0
        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);
        }
示例#35
0
		public override int GetHeight(TriggerObject trigObject)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return 0;
			}

			if (FitToContents)
			{
				int padding = GetPadding(trigObject);
				int height = padding * 2;

				foreach (UberGumpElement child in Children)
				{
					int childY = child.GetY(trigObject);
					int childHeight = childY + child.GetHeight(trigObject) + padding * 2;

					if (childHeight > height)
					{
						height = childHeight;
					}
				}

				return height;
			}

			object output = m_Height.Calculate(trigObject);

			if (!(output is int))
			{
				throw new UberScriptException(
					GetType() + " GetHeight did not resolve to an integer: " + output + " from " + m_Height.ScriptString);
			}

			return (int)output;
		}
示例#36
0
        // These functions are borrowed heavily from ArteGordon's BaseXmlSpawner class

        // set property values with support for nested attributes
        public static void SetPropertyValue(TriggerObject trigObj, object o, string name, object value)
        {
            if (o == null)
            {
                throw new UberScriptException("Null object");
            }

            //Type ptype = null;
            object po   = null;
            Type   type = o.GetType();

            PropertyInfo[] props = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

            // parse the strings of the form property.attribute into two parts
            // first get the property
            List <string> arglist = PropertyGetters.PropSplitter(name);

            string propname = arglist[0];

            if (propname.Length == 0)
            {
                throw new UberScriptException("Empty string property!");
            }

            // Check whether they are trying to set an xml attachment through the
            // shortcut e.g. TRIGMOB().xmlints.score = TRIGMOB().xmlints.score + 1

            if (arglist.Count > 1 && (propname[0] == 'x' || propname[0] == 'X'))
            {
                // NEED TO HANDLE SETTING PROPERTIES ON THE ATTACHMENTS!
                string lowerPropName = propname.ToLower();
                if (lowerPropName == "xmlints")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmlints on anything but Mobile or Item");
                    }
                    // check for existing xmlValue attachment or create a new one
                    XmlValue xmlValue = XmlAttach.GetValueAttachment(entity, arglist[1]);
                    if (xmlValue == null)
                    {
                        // arglist should only have [xmlints, name], nothing more
                        if (arglist.Count > 2)
                        {
                            throw new UberScriptException("Attempted to set property on a not-yet-existant attachment!:" + name);
                        }
                        xmlValue = new XmlValue(arglist[1], (int)value);
                        XmlAttach.AttachTo(null, entity, xmlValue);
                    }
                    else if (arglist.Count == 2)
                    {
                        if (value == null)
                        {
                            xmlValue.Delete();
                        }
                        else
                        {
                            xmlValue.Value = (int)value;
                        }
                    }
                    else if (arglist.Count > 2)
                    {
                        // could be setting a property on an existing XmlAttachment!
                        // e.g. xmlints.test.expiration = 0:0:1
                        SetPropertyValue(trigObj, xmlValue, arglist[2], value);
                    }
                    return;
                }
                else if (lowerPropName == "xmlstrings")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmlstrings on anything but Mobile or Item");
                    }
                    XmlLocalVariable xmlLocalVariable = XmlAttach.GetStringAttachment(entity, arglist[1]);
                    if (xmlLocalVariable == null)
                    {
                        // arglist should only have [xmlints, name], nothing more
                        if (arglist.Count > 2)
                        {
                            throw new UberScriptException("Attempted to set property on a not-yet-existant attachment!:" + name);
                        }
                        xmlLocalVariable = new XmlLocalVariable(arglist[1], (string)value);
                        XmlAttach.AttachTo(null, entity, xmlLocalVariable);
                    }
                    else if (arglist.Count == 2)
                    {
                        if (value == null)
                        {
                            xmlLocalVariable.Delete();
                        }
                        else
                        {
                            xmlLocalVariable.Data = (string)value;
                        }
                    }
                    else if (arglist.Count > 2)
                    {
                        // could be setting a property on an existing XmlAttachment!
                        // e.g. xmlints.test.expiration = 0:0:1
                        SetPropertyValue(trigObj, xmlLocalVariable, arglist[2], value);
                    }
                    return;
                }
                else if (lowerPropName == "xmldoubles")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmldoubles on anything but Mobile or Item");
                    }
                    XmlDouble xmlDouble = XmlAttach.GetDoubleAttachment(entity, arglist[1]);
                    if (xmlDouble == null)
                    {
                        // arglist should only have [xmlints, name], nothing more
                        if (arglist.Count > 2)
                        {
                            throw new UberScriptException("Attempted to set property on a not-yet-existant attachment!:" + name);
                        }
                        xmlDouble = new XmlDouble(arglist[1], (double)value);
                        XmlAttach.AttachTo(null, entity, xmlDouble);
                    }
                    else if (arglist.Count == 2)
                    {
                        if (value == null)
                        {
                            xmlDouble.Delete();
                        }
                        else
                        {
                            xmlDouble.Value = (double)value;
                        }
                    }
                    else if (arglist.Count > 2)
                    {
                        // could be setting a property on an existing XmlAttachment!
                        // e.g. xmlints.test.expiration = 0:0:1
                        SetPropertyValue(trigObj, xmlDouble, arglist[2], value);
                    }
                    return;
                }
                else if (lowerPropName == "xmlobjs")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmlobjs on anything but Mobile or Item");
                    }
                    XmlObject xmlObject = XmlAttach.GetObjectAttachment(entity, arglist[1]);
                    if (xmlObject == null)
                    {
                        // arglist should only have [xmlints, name], nothing more
                        if (arglist.Count > 2)
                        {
                            throw new UberScriptException("Attempted to set property on a not-yet-existant attachment!:" + name);
                        }
                        xmlObject = new XmlObject(arglist[1], value);
                        XmlAttach.AttachTo(null, entity, xmlObject);
                    }
                    else if (arglist.Count == 2)
                    {
                        if (value == null)
                        {
                            xmlObject.Delete();
                        }
                        else
                        {
                            xmlObject.Value = value;
                        }
                    }
                    else if (arglist.Count > 2)
                    {
                        // XmlObject only contains a few properties that
                        // can be accessed through statements like THIS().xmlobjs.test._____
                        // since there is a potential conflict between the developer wanting access
                        // to the properties on the object contained in the XmlObject.Value (most likely)
                        // or the properties on the XmlObject itself (far less likely)
                        string testPropName = arglist[2].ToLower();
                        // to access properties on the xmlobject itself (e.g. expiration), one must do this:
                        //  THIS().xmlobjs.test.xmlobject.expiration
                        if (testPropName == "xmlobject")
                        {
                            if (arglist.Count < 4)
                            {
                                throw new UberScriptException("Can't set an xmlobject directly, use ATTACH function!");
                            }
                            else
                            {
                                string propLookup = arglist[3]; // add this first so later additions all prepended with '.'
                                for (int i = 4; i < arglist.Count; i++)
                                {
                                    propLookup += "." + arglist[i];
                                }
                                SetPropertyValue(trigObj, xmlObject, propLookup, value);
                            }
                        }
                        else
                        {
                            string propLookup = arglist[2]; // add this first so later additions all prepended with '.'
                            for (int i = 3; i < arglist.Count; i++)
                            {
                                propLookup += "." + arglist[i];
                            }
                            SetPropertyValue(trigObj, xmlObject.Value, propLookup, value);
                        }
                    }

                    //else if (arglist.Count > 2)
                    //{
                    // could be setting a property on an existing XmlAttachment!
                    // e.g. xmlints.test.expiration = 0:0:1
                    //    SetPropertyValue(trigObject, xmlObject, arglist[2], value);
                    //}
                    return;
                }
            }

            /*
             * string[] keywordargs = ParseString(propname, 4, ",");
             *
             * // check for special keywords
             * if (keywordargs[0] == "ATTACHMENT")
             * {
             *  if (keywordargs.Length < 4)
             *  {
             *      return "Invalid ATTACHMENT format";
             *  }
             *  // syntax is ATTACHMENT,type,name,propname
             *
             *  string apropname = keywordargs[3];
             *  string aname = keywordargs[2];
             *  Type attachtype = SpawnerType.GetType(keywordargs[1]);
             *
             *  // allow empty string specifications to be used to indicate a null string which will match any name
             *  if (aname == "") aname = null;
             *
             *  ArrayList attachments = XmlAttach.FindAttachments(o, attachtype, aname);
             *
             *  if (attachments != null && attachments.Count > 0)
             *  {
             *      // change the object, object type, and propname to refer to the attachment
             *      o = attachments[0];
             *      propname = apropname;
             *
             *      if (o == null)
             *      {
             *          return "Null object";
             *      }
             *
             *      type = o.GetType();
             *      props = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);
             *  }
             *  else
             *      return "Attachment not found";
             *
             * }
             * else if (keywordargs[0] == "SKILL")
             * {
             *  if (keywordargs.Length < 2)
             *  {
             *      return "Invalid SKILL format";
             *  }
             *  bool found = true;
             *  try
             *  {
             *      SkillName skillname = (SkillName)Enum.Parse(typeof(SkillName), keywordargs[1], true);
             *      if (o is Mobile)
             *      {
             *
             *          Skill skill = ((Mobile)o).Skills[skillname];
             *
             *          skill.Base = double.Parse(value);
             *
             *          return "Property has been set.";
             *      }
             *      else
             *          return "Object is not mobile";
             *  }
             *  catch { found = false; }
             *
             *  if (!found)
             *      return "Invalid SKILL reference.";
             * }
             * else if (keywordargs[0] == "STEALABLE")
             * {
             *
             *  bool found = true;
             *  try
             *  {
             *      if (o is Item)
             *      {
             *
             *          ItemFlags.SetStealable(o as Item, bool.Parse(value));
             *
             *          return "Property has been set.";
             *      }
             *      else
             *          return "Object is not an item";
             *  }
             *  catch { found = false; }
             *
             *  if (!found)
             *      return "Invalid Stealable assignment.";
             * }
             * */

            // do a bit of parsing to handle array references
            string[] arraystring = propname.Split('[');
            int      index       = 0;

            if (arraystring.Length > 1)
            {
                // parse the property name from the indexing
                propname = arraystring[0];

                // then parse to get the index value
                string[] arrayvalue = arraystring[1].Split(']');

                if (arrayvalue.Length > 0)
                {
                    try
                    {
                        index = int.Parse(arrayvalue[0]);
                    }
                    catch
                    {
                        try
                        {
                            index = (int)(new MathTree(null, arrayvalue[0])).Calculate(trigObj);
                        }
                        catch
                        {
                            throw new UberScriptException("Could not get int array value from: " + arrayvalue[0] + " for prop of " + name + " on object " + o);
                        }
                    }
                }
            }
            PropertyInfo propInfoToSet     = null;
            string       lowerCasePropName = propname.ToLower();

            // optimization to find propertyInfo without looping through
            if (o is BaseCreature)
            {
                if (BaseCreatureProperties.ContainsKey(lowerCasePropName))
                {
                    propInfoToSet = BaseCreatureProperties[lowerCasePropName];
                }
            }
            else if (o is PlayerMobile)
            {
                if (PlayerMobileProperties.ContainsKey(lowerCasePropName))
                {
                    propInfoToSet = PlayerMobileProperties[lowerCasePropName];
                }
            }
            else if (o is Item)
            {
                if (ItemProperties.ContainsKey(lowerCasePropName))
                {
                    propInfoToSet = ItemProperties[lowerCasePropName];
                }
            }
            // is a nested property with attributes so first get the property
            if (propInfoToSet == null)
            {
                foreach (PropertyInfo p in props)
                {
                    if (Insensitive.Equals(p.Name, propname))
                    {
                        propInfoToSet = p;
                        break;
                    }
                }
            }
            if (propInfoToSet != null)
            {
                //if (IsProtected(type, propname))
                //    return "Property is protected.";

                if (arglist.Count > 1)
                {
                    //ptype = propInfoToSet.PropertyType;
                    po = propInfoToSet.GetValue(o, null);
                    // now set the nested attribute using the new property list
                    string propLookup = arglist[1];
                    for (int i = 2; i < arglist.Count; i++)
                    {
                        propLookup += "." + arglist[i];
                    }
                    SetPropertyValue(trigObj, po, propLookup, value);
                    return;
                    // otherwise let it roll through and throw an exception
                }
                else // arglist.Count == 1
                {
                    //if (IsProtected(type, propname))
                    //    return "Property is protected.";
                    if (!propInfoToSet.CanWrite)
                    {
                        throw new UberScriptException("Property is read only.");
                    }

                    InternalSetValue(o, propInfoToSet, value, false, index);
                    return;
                }
            }

            throw new UberScriptException("Property " + name + " not found on " + o + ".");
        }
示例#37
0
		public override int GetHeight(TriggerObject trigObject)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return 0;
			}

			if (FitToContents)
			{
				int padding = GetPadding(trigObject);
				int height = 0;
				int verticalGap = GetVerticalGap(trigObject);

				int count = 0;

				foreach (UberGumpElement child in Children)
				{
					int childHeight = child.GetHeight(trigObject);
					int childY = child.GetY(trigObject);

					// list--assume they are all as tall as the first one
					if (child is UberGumpList)
					{
						UberGumpList list = (UberGumpList)child;
						ArrayList actualList = list.GetListSource(trigObject);

						if (actualList != null)
						{
							if (actualList.Count > 1)
							{
								height += (childHeight) * (actualList.Count - 1);
							}
						}
					}

					height += childHeight + childY;
					count += 1;
				}

				return height + padding * 2 + ((count - 1) * verticalGap);
			}

			object output = m_Height.Calculate(trigObject);

			if (!(output is int))
			{
				throw new UberScriptException(
					GetType() + " GetHeight did not resolve to an integer: " + output + " from " + m_Width.ScriptString);
			}

			return (int)output;
		}
示例#38
0
        public static object GetObject(TriggerObject trigObj, object o, string name, out Type ptype) // used for all comparisons
        {
            // ALL EXCEPTIONS CAUGHT OUTSIDE OF THIS FUNCTION (so that a useful error can be displayed)
            // trigobject used in case there are array indeces with a function [THIS().x]
            ptype = null;
            if (o == null || name == null)
            {
                return(null);
            }

            Type   type = o.GetType();
            object po   = null;

            PropertyInfo[] props = null;
            try
            {
                props = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);
            }
            catch (Exception e)
            {
                throw new UberScriptException("GetProperties Error!", e);
            }

            // parse the strings of the form property.attribute into two parts
            // first get the property
            List <string> arglist  = PropSplitter(name);
            string        propname = arglist[0];

            if (propname.Length == 0)
            {
                throw new UberScriptException("Empty string property!");
            }
            if (arglist.Count > 1 && (propname[0] == 'x' || propname[0] == 'X'))
            {
                if (propname.ToLower() == "xmlints")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmlints on anything but Mobile or Item");
                    }
                    // check for existing xmlValue attachment or create a new one
                    XmlValue xmlValue = XmlAttach.GetValueAttachment(o as IEntity, arglist[1]);
                    if (xmlValue == null)
                    {
                        return(null);      //throw new UberScriptException("Could not find XmlValue named " + name + " on " + o);
                    }
                    if (arglist.Count > 2) // must be trying to get a property on the xmlValue (e.g. xmlints.test.expiration)
                    {
                        return(GetObject(trigObj, xmlValue, arglist[2], out ptype));
                    }
                    ptype = typeof(int);
                    return(xmlValue.Value);
                }
                else if (propname.ToLower() == "xmlstrings")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmlstrings on anything but Mobile or Item");
                    }
                    XmlLocalVariable xmlLocalVariable = XmlAttach.GetStringAttachment(o as IEntity, arglist[1]);
                    if (xmlLocalVariable == null)
                    {
                        return(null);      // throw new UberScriptException("Could not find XmlLocalVariable named " + name + " on " + o);
                    }
                    if (arglist.Count > 2) // must be trying to get a property on the xmlValue (e.g. xmlints.test.expiration)
                    {
                        return(GetObject(trigObj, xmlLocalVariable, arglist[2], out ptype));
                    }
                    ptype = typeof(string);
                    return(xmlLocalVariable.Data);
                }
                else if (propname.ToLower() == "xmldoubles")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmldoubles on anything but Mobile or Item");
                    }
                    XmlDouble xmlDouble = XmlAttach.GetDoubleAttachment(entity, arglist[1]);
                    if (xmlDouble == null)
                    {
                        return(null);      //  throw new UberScriptException("Could not find XmlDouble named " + name + " on " + o);
                    }
                    if (arglist.Count > 2) // must be trying to get a property on the xmlValue (e.g. xmlints.test.expiration)
                    {
                        return(GetObject(trigObj, xmlDouble, arglist[2], out ptype));
                    }
                    ptype = typeof(double);
                    return(xmlDouble.Value);
                }
                else if (propname.ToLower() == "xmlobjs")
                {
                    IEntity entity = o as IEntity;
                    if (entity == null)
                    {
                        throw new UberScriptException("Can't set xmlobjs on anything but Mobile or Item");
                    }
                    // since the object might be a list of some kind, need to check for the [] indexing first
                    string objName          = arglist[1];
                    int    openBracketIndex = objName.IndexOf('[');
                    int    listindex        = -1; // for lists / arrays
                    if (openBracketIndex > 0)
                    {
                        int closingBracketIndex = objName.IndexOf(']');
                        if (closingBracketIndex < openBracketIndex + 1)
                        {
                            throw new UberScriptException("xmlobjs." + objName + " [] indexing error: must have at least 1 character between the []");
                        }

                        listindex = (int)(new MathTree(null, objName.Substring(openBracketIndex + 1, closingBracketIndex - openBracketIndex - 1))).Calculate(trigObj);
                        objName   = objName.Substring(0, openBracketIndex);
                    }

                    XmlObject xmlObject = XmlAttach.GetObjectAttachment(entity, objName);
                    if (xmlObject == null)
                    {
                        return(null);                   // throw new UberScriptException("Could not find XmlObject named " + name + " on " + o);
                    }
                    //if (arglist.Count > 2) // must be trying to get a property on the xmlValue (e.g. xmlints.test.expiration)
                    //    return GetObject(trigObject, xmlObject, arglist[2], out ptype);


                    //=====
                    if (arglist.Count > 2)
                    {
                        // XmlObject only contains a few properties that
                        // can be accessed through statements like THIS().xmlobjs.test._____
                        // since there is a potential conflict between the developer wanting access
                        // to the properties on the object contained in the XmlObject.Value (most likely)
                        // or the properties on the XmlObject itself (far less likely)
                        string testPropName = arglist[2].ToLower();
                        // to access properties on the xmlobject itself (e.g. expiration), one must do this:
                        //  THIS().xmlobjs.test.xmlobject.expiration
                        if (testPropName == "xmlobject")
                        {
                            if (arglist.Count < 4)
                            {
                                return(xmlObject);
                            }

                            string propLookup = arglist[3]; // add this first so later additions all prepended with '.'
                            for (int i = 4; i < arglist.Count; i++)
                            {
                                propLookup += "." + arglist[i];
                            }
                            return(PropertyGetters.GetObject(trigObj, xmlObject, propLookup, out ptype));
                        }
                        else
                        {
                            if (xmlObject.Value == null)
                            {
                                return(null);
                            }
                            string propLookup = arglist[2]; // add this first so later additions all prepended with '.'
                            for (int i = 3; i < arglist.Count; i++)
                            {
                                propLookup += "." + arglist[i];
                            }

                            if (listindex >= 0)
                            {
                                ptype = xmlObject.Value.GetType();
                                if (ptype.GetInterface("IList") != null)
                                {
                                    try
                                    {
                                        return(PropertyGetters.GetObject(trigObj, ((IList)xmlObject.Value)[listindex], propLookup, out ptype));
                                        //return ((IList)xmlObject.Value)[listindex];
                                    }
                                    catch (Exception e)
                                    {
                                        throw new UberScriptException("Get Array value error!", e);
                                    }
                                }
                                else
                                {
                                    throw new UberScriptException("xmlobj." + objName + " was indexed with [] indexer, but did not contain a list!");
                                }
                            }

                            return(PropertyGetters.GetObject(trigObj, xmlObject.Value, propLookup, out ptype));
                        }
                    }
                    else if (listindex >= 0)
                    {
                        // no properties afterward but has a list index (e.g. xmlobjs.spawnedPlatforms[0])
                        ptype = xmlObject.Value.GetType();
                        if (ptype.GetInterface("IList") != null)
                        {
                            try
                            {
                                return(((IList)xmlObject.Value)[listindex]);
                            }
                            catch (Exception e)
                            {
                                throw new UberScriptException("Get Array value error!", e);
                            }
                        }
                        else
                        {
                            throw new UberScriptException("xmlobj." + objName + " was indexed with [] indexer, but did not contain a list!");
                        }
                    }
                    //====


                    ptype = typeof(object);
                    return(xmlObject.Value);
                }
            }
            // parse up to 4 comma separated args for special keyword properties

            /*
             * string[] keywordargs = ParseString(propname, 4, ",");
             *
             * // check for special keywords
             * if (keywordargs[0] == "ATTACHMENT")
             * {
             *  // syntax is ATTACHMENT,type,name,property
             *  if (keywordargs.Length < 4)
             *  {
             *      return "Invalid ATTACHMENT format";
             *  }
             *
             *  string apropname = keywordargs[3];
             *  string aname = keywordargs[2];
             *  Type attachtype = SpawnerType.GetType(keywordargs[1]);
             *
             *  // allow empty string specifications to be used to indicate a null string which will match any name
             *  if (aname == "") aname = null;
             *
             *  ArrayList attachments = XmlAttach.FindAttachments(o, attachtype, aname);
             *
             *  if (attachments != null && attachments.Count > 0)
             *  {
             *      string getvalue = GetPropertyValue(spawner, attachments[0], apropname, out ptype);
             *
             *      return getvalue;
             *  }
             *  else
             *      return "Attachment not found";
             * }
             * */

            // I REALLY OUGHT TO IMPLEMENT GETTING TYPE SOME TIME
            // do a bit of parsing to handle array references
            string[] arraystring = arglist[0].Split('[');
            int      index       = -1;

            if (arraystring.Length > 1)
            {
                // parse the property name from the indexing
                propname = arraystring[0];

                // then parse to get the index value
                string[] arrayvalue = arraystring[1].Split(']');

                if (arrayvalue.Length > 0)
                {
                    try
                    {
                        index = int.Parse(arrayvalue[0]);
                    }
                    catch
                    {
                        try
                        {
                            index = (int)(new MathTree(null, arrayvalue[0])).Calculate(trigObj);
                        }
                        catch
                        {
                            throw new UberScriptException("Could not get int array value from: " + arrayvalue[0] + " for prop of " + name + " on object " + o);
                        }
                    }
                }
            }

            PropertyInfo propInfoToGet     = null;
            string       lowerCasePropName = propname.ToLower();

            // optimization to find propertyInfo without looping through
            if (o is BaseCreature)
            {
                if (PropertySetters.BaseCreatureProperties.ContainsKey(lowerCasePropName))
                {
                    propInfoToGet = PropertySetters.BaseCreatureProperties[lowerCasePropName];
                }
            }
            else if (o is PlayerMobile)
            {
                if (PropertySetters.PlayerMobileProperties.ContainsKey(lowerCasePropName))
                {
                    propInfoToGet = PropertySetters.PlayerMobileProperties[lowerCasePropName];
                }
            }
            else if (o is Item)
            {
                if (PropertySetters.ItemProperties.ContainsKey(lowerCasePropName))
                {
                    propInfoToGet = PropertySetters.ItemProperties[lowerCasePropName];
                }
            }
            // is a nested property with attributes so first get the property
            if (propInfoToGet == null)
            {
                foreach (PropertyInfo p in props)
                {
                    if (Insensitive.Equals(p.Name, propname))
                    {
                        propInfoToGet = p;
                        break;
                    }
                }
            }
            if (propInfoToGet != null)
            {
                if (!propInfoToGet.CanRead)
                {
                    throw new UberScriptException("Property " + propname + " is write only.");
                }
                //if (IsProtected(type, propname))
                //    return "Property is protected.";
                ptype = propInfoToGet.PropertyType;
                if (arglist.Count > 1)
                {
                    if (ptype.IsPrimitive)
                    {
                        po = propInfoToGet.GetValue(o, null);
                    }
                    else if ((ptype.GetInterface("IList") != null) && index >= 0)
                    {
                        try
                        {
                            object arrayvalue = propInfoToGet.GetValue(o, null);
                            po = ((IList)arrayvalue)[index];
                        }
                        catch (Exception e)
                        {
                            throw new UberScriptException("Get Array value error!", e);
                        }
                    }
                    else
                    {
                        po = propInfoToGet.GetValue(o, null);
                    }
                    // now set the nested attribute using the new property list
                    string propLookup = arglist[1];
                    for (int i = 2; i < arglist.Count; i++)
                    {
                        propLookup += "." + arglist[i];
                    }
                    return(GetObject(trigObj, po, propLookup, out ptype));
                }
                else
                {
                    // its just a simple single property
                    return(InternalGetValue(o, propInfoToGet, index));
                }
            }

            throw new UberScriptException("Could not find property on " + o + ": " + name);
        }
示例#39
0
		// returns the width and height of the element
		public virtual Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			throw new NotImplementedException();
		}
示例#40
0
        public virtual bool Execute(TriggerObject trigObject, bool triggersOnly, UberNode pauseNode = null)
        {
            if (!Enabled || Deleted)
            {
                return(false);
            }
            if (AttachedTo != null && AttachedTo.Deleted)
            {
                Delete(); return(false);
            }

            trigObject.Script = this;
            // true IF there was a trigger override
            bool returnOverride = false;

            try
            {
                returnOverride = ParsedScripts.TryExecuteScript(ScriptFile, trigObject, RootNodeIndeces, triggersOnly);
            }
            catch (UberScriptException e)
            {
                if (m_SendDebugMessageTo != null && !m_SendDebugMessageTo.Deleted)
                {
                    m_SendDebugMessageTo.SendMessage(36, "Error Executing script file: " + ScriptFile);
                    Exception innerMostException = e;
                    m_SendDebugMessageTo.SendMessage(36, e.Message);
                    int level = 0;
                    while (true)
                    {
                        if (innerMostException.InnerException == null)
                        {
                            break;
                        }
                        level++;
                        innerMostException = innerMostException.InnerException;
                        string msg = "";
                        for (int i = 0; i < level; i++)
                        {
                            msg += "--";
                        }
                        msg += ">" + innerMostException.Message;
                        m_SendDebugMessageTo.SendMessage(36, msg);
                    }
                }
                if (ParsedScripts.DebugLevel >= (int)ParsedScripts.DebugLevels.ScriptDebugMessages)
                {
                    Console.WriteLine("Error Executing script file: " + ScriptFile);
                    Exception innerMostException = e;
                    Console.WriteLine(e.Message);
                    int level = 0;
                    while (true)
                    {
                        if (innerMostException.InnerException == null)
                        {
                            break;
                        }
                        level++;
                        innerMostException = innerMostException.InnerException;
                        for (int i = 0; i < level; i++)
                        {
                            Console.Write("\t");
                        }
                        Console.WriteLine(innerMostException.Message);
                    }
                    if (ParsedScripts.DebugLevel >= (int)ParsedScripts.DebugLevels.ScriptDebugMessagesAndStackTrace)
                    {
                        Console.WriteLine(innerMostException.StackTrace);
                    }
                }
            }
            catch (Exception general)
            {
                if (m_SendDebugMessageTo != null && !m_SendDebugMessageTo.Deleted)
                {
                    m_SendDebugMessageTo.SendMessage(36, "GENERAL UNCAUGHT ERROR Executing script file: " + ScriptFile);
                    m_SendDebugMessageTo.SendMessage(36, general.Message);
                }
                Console.WriteLine("Error Executing script file: " + ScriptFile);
                Console.WriteLine("GENERAL UNCAUGHT ERROR: this should never happen!");
                Console.WriteLine(general.Message);
                Console.WriteLine(general.StackTrace);
            }
            return(returnOverride);
        }
示例#41
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return new Rectangle2D();
			}

			int x = originX + GetX(trigObject);
			int y = originY + GetY(trigObject);
			int width = GetWidth(trigObject);
			int height = GetHeight(trigObject);

			if (HTMLMath != null)
			{
				object toSend = HTMLMath.Calculate(trigObject);

				gump.AddHtml(x, y, width, height, toSend == null ? HTMLString : toSend.ToString(), Background, ScrollBar);
			}
			else
			{
				gump.AddHtml(x, y, width, height, HTMLString, Background, ScrollBar);
			}

			return new Rectangle2D(GetX(trigObject), GetY(trigObject), GetWidth(trigObject), GetHeight(trigObject));
		}
示例#42
0
        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);
        }
示例#43
0
		public override Rectangle2D GenerateGump(TriggerObject trigObject, UberScriptGump gump, int originX, int originY)
		{
			return m_Condition != null && GetCondition(trigObject) == false
					   ? new Rectangle2D()
					   : new Rectangle2D(GetX(trigObject), GetY(trigObject), GetWidth(trigObject), GetHeight(trigObject));
		}
示例#44
0
 public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject)
 {
     Execute(trigObject);
     return(ProcessResult.None);
 }
示例#45
0
		public override int GetHeight(TriggerObject trigObject)
		{
			return m_Condition != null && GetCondition(trigObject) == false ? 0 : 20;
		}
示例#46
0
        override public ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject) // lastSiblingResult used for conditionals
        {
            // IF YOU EDIT THIS FUNCTION, BE SURE TO MAKE THE CORRESPONDING CHANGE TO THE SpawnAndReturnObject FUNCTION!
            Object prevSpawnedObject = trigObject.Spawn;
            Object callingObj        = trigObject.Spawn != null ? trigObject.Spawn : trigObject.This;

            if (this.ScriptString != null)
            {
                // it's a spawn node, so we need to spawn an object here
                Object caller = trigObject.Spawn != null ? trigObject.Spawn : trigObject.This;
                trigObject.Spawn = SpawnHandlers.Spawn(ScriptString, caller);
            }
            if (this.Children.Count > 0)                                // there is a special script assoctiated with the spawn
            {
                ProcessResult lastResult = ProcessChildren(trigObject); // ignore any returns in spawn definition
                if (lastResult == ProcessResult.EndOfSequence)
                {
                    return(lastResult); // we are processing a sequence
                }
                IEntity spawnedObject = trigObject.Spawn as IEntity;
                if (spawnedObject != null && this.TriggerNodes.Count > 0)
                {
                    XmlScript script = new XmlScript(UberTreeParser.CurrentFileBeingParsed);
                    // script.RootNodeIndeces.Add(0); // NO DON'T DO THIS// always has the initial 0 for the top root node (which always exists)
                    AddRootNodeIndeces(this, script.RootNodeIndeces);
                    XmlAttach.AttachTo(spawnedObject, script);
                }
            }
            // if it was already given a location in it's children, then don't give it one... otherwise place it
            // on the caller
            Item   callerItem = null;
            Mobile callerMob  = null;

            if (callingObj is Item)
            {
                callerItem = callingObj as Item;
            }
            else if (callingObj is Mobile)
            {
                callerMob = callingObj as Mobile;
            }

            Object o    = trigObject.Spawn;
            Mobile m    = null;
            Item   item = null;

            if (o is Mobile)
            {
                m = (Mobile)o;
            }
            else if (o is Item)
            {
                item = (Item)o;
            }

            if ((m != null && m.Location == Point3D.Zero && m.Map == Map.Internal) || (item != null && item.Location == Point3D.Zero && item.Map == Map.Internal && item.RootParentEntity == null))
            {
                try
                {
                    if (m != null)
                    {
                        if (callerItem != null)
                        {
                            if (callerItem.RootParentEntity != null)
                            {
                                m.MoveToWorld(callerItem.RootParentEntity.Location, callerItem.RootParentEntity.Map);
                            }
                            else
                            {
                                m.MoveToWorld(callerItem.Location, callerItem.Map);
                            }
                        }
                        else if (callerMob != null)
                        {
                            m.MoveToWorld(callerMob.Location, callerMob.Map);
                        }
                        else if (callingObj is IPoint3D)
                        {
                            m.MoveToWorld(new Point3D((IPoint3D)callingObj), Map.Felucca);
                        }
                        else
                        {
                            throw new UberScriptException("Spawn caller (the thing XmlScript is attached to) was neither mobile or item! It was: " + callingObj);
                        }
                        //loc = GetSpawnPosition(requiresurface, packrange, packcoord, spawnpositioning, m);

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;
                            c.Home = c.Location;
                        }
                        trigObject.Spawn = prevSpawnedObject;
                        return(ProcessResult.None);
                    }
                    else if (item != null)
                    {
                        if (callerItem != null)
                        {
                            item.MoveToWorld(callerItem.Location, callerItem.Map);
                        }
                        else if (callerMob != null)
                        {
                            item.MoveToWorld(callerMob.Location, callerMob.Map);
                        }
                        else if (callingObj is IPoint3D)
                        {
                            item.MoveToWorld(new Point3D((IPoint3D)callingObj), Map.Felucca);
                        }
                        else
                        {
                            throw new UberScriptException("Spawn caller (the thing XmlScript is attached to) was neither mobile or item! It was: " + callingObj);
                        }
                        trigObject.Spawn = prevSpawnedObject;
                        return(ProcessResult.None);
                    }
                }
                catch (Exception ex) { throw new UberScriptException(String.Format("When spawning {0}", o), ex); }
            }
            else if (m != null && m is BaseCreature)
            {
                BaseCreature c = (BaseCreature)m;
                c.Home = c.Location;
            }
            trigObject.Spawn = prevSpawnedObject;
            return(ProcessResult.None);
        }
示例#47
0
		public int GetPressedID(TriggerObject trigObject)
		{
			object output = m_PressedID.Calculate(trigObject);

			if (!(output is int))
			{
				throw new UberScriptException(
					GetType() + " GetPressedID did not resolve to an integer: " + output + " from " + m_PressedID.ScriptString);
			}

			return (int)output;
		}
示例#48
0
        public Object SpawnAndReturnObject(ProcessResult lastSiblingResult, TriggerObject trigObject)
        {
            // IF YOU EDIT THIS FUNCTION, BE SURE TO MAKE THE CORRESPONDING CHANGE TO THE Process FUNCTION!
            // this is just like Process, except it returns the spawned object (useful only in StatementNodes such that the object
            // can be assigned to the lefthand side of the statement node
            // e.g.
            // objs.test = orc
            // {
            //    name = goober
            // }
            Object prevSpawnedObject = trigObject.Spawn;
            Object callingObj        = trigObject.Spawn != null ? trigObject.Spawn : trigObject.This;

            if (this.ScriptString != null)
            {
                // it's a spawn node, so we need to spawn an object here
                trigObject.Spawn = SpawnHandlers.Spawn(ScriptString, callingObj);
            }
            if (this.Children.Count > 0)     // there is a special script associated with the spawn
            {
                ProcessChildren(trigObject); // ignore any overrides within spawn definitions
                IEntity spawnedObject = trigObject.Spawn as IEntity;
                if (spawnedObject != null && this.TriggerNodes.Count > 0)
                {
                    XmlScript script = new XmlScript(UberTreeParser.CurrentFileBeingParsed);
                    AddRootNodeIndeces(this, script.RootNodeIndeces);
                    XmlAttach.AttachTo(spawnedObject, script);
                }
            }
            // if it was already given a location in it's children, then don't give it one... otherwise place it
            // on the caller
            Item   callerItem = null;
            Mobile callerMob  = null;

            if (callingObj is Item)
            {
                callerItem = callingObj as Item;
            }
            else if (callingObj is Mobile)
            {
                callerMob = callingObj as Mobile;
            }

            Object o    = trigObject.Spawn;
            Mobile m    = null;
            Item   item = null;

            if (o is Mobile)
            {
                m = (Mobile)o;
            }
            else if (o is Item)
            {
                item = (Item)o;
            }

            if ((m != null && m.Location == Point3D.Zero && m.Map == Map.Internal) || (item != null && item.Location == Point3D.Zero && item.Map == Map.Internal && item.RootParentEntity == null))
            {
                try
                {
                    if (m != null)
                    {
                        if (callerItem != null)
                        {
                            if (callerItem.RootParentEntity != null)
                            {
                                m.MoveToWorld(callerItem.RootParentEntity.Location, callerItem.RootParentEntity.Map);
                            }
                            else
                            {
                                m.MoveToWorld(callerItem.Location, callerItem.Map);
                            }
                        }
                        else if (callerMob != null)
                        {
                            m.MoveToWorld(callerMob.Location, callerMob.Map);
                        }
                        else if (callingObj is IPoint3D)
                        {
                            m.MoveToWorld(new Point3D((IPoint3D)callingObj), Map.Felucca);
                        }
                        else
                        {
                            throw new UberScriptException("Spawn caller (the thing XmlScript is attached to) was neither mobile or item! It was: " + callingObj);
                        }
                        //loc = GetSpawnPosition(requiresurface, packrange, packcoord, spawnpositioning, m);

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;
                            c.Home = c.Location;
                        }
                        trigObject.Spawn = prevSpawnedObject;
                        return(o);
                    }
                    else if (item != null)
                    {
                        if (callerItem != null)
                        {
                            item.MoveToWorld(callerItem.Location, callerItem.Map);
                        }
                        else if (callerMob != null)
                        {
                            item.MoveToWorld(callerMob.Location, callerMob.Map);
                        }
                        else if (callingObj is IPoint3D)
                        {
                            item.MoveToWorld(new Point3D((IPoint3D)callingObj), Map.Felucca);
                        }
                        else
                        {
                            throw new UberScriptException("Spawn caller (the thing XmlScript is attached to) was neither mobile or item! It was: " + callingObj);
                        }
                        trigObject.Spawn = prevSpawnedObject;
                        return(o);
                    }
                }
                catch (Exception ex) { throw new UberScriptException(String.Format("When spawning {0}", o), ex); }
            }
            else if (m != null && m is BaseCreature)
            {
                BaseCreature c = (BaseCreature)m;
                c.Home = c.Location;
            }

            trigObject.Spawn = prevSpawnedObject;
            return(o);
        }
示例#49
0
		public override int GetHeight(TriggerObject trigObject)
		{
			return m_Condition != null && GetCondition(trigObject) == false
					   ? 0
					   : GumpIndexData.GetGumpData(GetNormalID(trigObject)).Height;
		}
示例#50
0
 public override ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject)
 {
     return(ProcessChildren(trigObject));
     //return ProcessResult.None;
 }
示例#51
0
 override public ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject) // lastSiblingResult used for conditionals
 {
     return(ProcessResult.Pause);
 }
示例#52
0
        protected ProcessResult ProcessChildren(TriggerObject trigObject)
        {
            ProcessResult lastResult = ProcessResult.None;
            PauseNode     newPause   = null;

            if (trigObject.PausedNodeChain != null)
            {
                if (trigObject.PausedNodeChain.Peek() != this)
                {
                    return(ProcessResult.None);
                }

                trigObject.PausedNodeChain.Dequeue();
            }

            trigObject.CurrentNodeExecutionChain.Add(this);

            foreach (UberNode child in Children)
            {
                if (trigObject.PausedNodeChain != null)
                {
                    if (trigObject.PausedNodeChain.Peek() != child)
                    {
                        continue;
                    }
                    if (!(child is ConditionalNode)) // Conditional node handles it's own processChildren
                    {
                        trigObject.PausedNodeChain.Dequeue();
                    }

                    if (trigObject.PausedNodeChain.Count == 0)
                    {
                        // if we got here, we found the node that we need to start execution on
                        trigObject.PausedNodeChain = null;
                    }
                }

                if (newPause != null) // just passed a pause node, time to stop execution
                {
                    trigObject.CurrentNodeExecutionChain.Add(child);
                    trigObject.PausedNodeChain = new Queue <UberNode>();
                    foreach (UberNode node in trigObject.CurrentNodeExecutionChain)
                    {
                        trigObject.PausedNodeChain.Enqueue(node);
                    }
                    trigObject.CurrentNodeExecutionChain = new List <UberNode>();
                    PausedUberScript paused = new PausedUberScript(trigObject, (trigObject != null && trigObject.TrigName != TriggerName.NoTrigger), newPause.PauseMS);
                    return(ProcessResult.Return);
                }
                if (child is PauseNode)
                {
                    newPause = child as PauseNode;
                    continue;
                }
                if (child is BreakNode)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return(ProcessResult.Break);
                }
                if (child is ContinueNode)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return(ProcessResult.Continue);
                }
                if (trigObject.Script.ProceedToNextStage)
                {
                    // only execute the proper sequence node
                    if (child is SequenceNode)
                    {
                        SequenceNode sequenceNode = child as SequenceNode;
                        if (trigObject.Script.Stage < sequenceNode.Stage)
                        {
                            // found the next stage
                            trigObject.Script.Stage = sequenceNode.Stage;
                            trigObject.Script.ProceedToNextStage = false;
                            lastResult = child.Process(lastResult, trigObject);
                            trigObject.CurrentNodeExecutionChain.Remove(this);
                            return(lastResult);
                        }
                    }
                    continue;
                }
                else
                {
                    if (child is TriggerNode)
                    {
                        continue;                                                            // triggernodes execute only in response to events
                    }
                    else if (child is ConditionalNode && trigObject.PausedNodeChain == null) // if PausedNodeChain not null and it reached here, then it is the right node, don't depend on past conditionals--execute it
                    {
                        ConditionalNode conditionalNode = child as ConditionalNode;
                        if (conditionalNode.IfType == ConditionalNode.ConditionalType.Elif || conditionalNode.IfType == ConditionalNode.ConditionalType.Else)
                        {
                            if (lastResult == ProcessResult.FailedIf)
                            {
                                lastResult = child.Process(lastResult, trigObject);
                                if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride)
                                {
                                    trigObject.CurrentNodeExecutionChain.Remove(this);
                                    return(lastResult);
                                }
                            }
                            continue;
                        }
                    }
                }

                lastResult = child.Process(lastResult, trigObject);
                if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return(lastResult);
                }
            }
            if (trigObject.Script.ProceedToNextStage)
            {
                lastResult = ProcessResult.EndOfSequence;
                trigObject.Script.ProceedToNextStage = false;
            }
            trigObject.CurrentNodeExecutionChain.Remove(this);
            if (lastResult == ProcessResult.FailedIf || lastResult == ProcessResult.SucceedIf && !(this is ConditionalNode))
            {
                lastResult = ProcessResult.None; // don't percolate the result up
            }
            return(lastResult);
        }
示例#53
0
		public string GetLoopFunction(TriggerObject trigObject)
		{
			object output = m_LoopFunction.Calculate(trigObject);

			if (output == null)
			{
				return null;
			}

			return output.ToString();
		}
示例#54
0
 public ProcessResult Execute(TriggerObject trigObject)
 {
     return(ProcessChildren(trigObject));
 }
示例#55
0
 virtual public ProcessResult Process(ProcessResult lastSiblingResult, TriggerObject trigObject) // lastSiblingResult used for conditionals
 {
     throw new NotImplementedException();
 }
示例#56
0
		public override int GetWidth(TriggerObject trigObject)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return 0;
			}

			int maxWidth = 0;

			foreach (UberGumpElement child in Children)
			{
				/*
				// int labelWidthModifier = 0;
                // I was thinking of automatically calculating label widths but i don't think it's worth it 
				// (the gump maker is on the hook to make it the right width)
                if (child is UberGumpLabel)
                {
                    // test to see if we can estimate the width based on the elements
                    UberGumpLabel label = (UberGumpLabel)child;
                    ArrayList actualList = GetListSource(trigObject);
                    if (actualList != null && actualList.Count > 1)
                    {
                        string objsVarName = GetObjsVarName(trigObject);
                        trigObject.objs[objsVarName] = actualList[0];
                        // now that we have the item in the list, get the label width as normal (but add some extra space)
                        labelWidthModifier = 10;
                    }
                }
                */

				int childWidth = 0;
				int childX = 0;

				// have to go through the elements and "test" them with real list data to see what their 
				// actual widths will be (also this allows for conditions on objects in the list)
				ArrayList actualList = GetListSource(trigObject);

				if (actualList != null)
				{
					string key = GetObjsVarName(trigObject);
					//string functionName = GetLoopFunction(trigObject); 
					// don't execute this function in between; it's too dangerous in the width calc!

					foreach (object element in actualList)
					{
						trigObject.objs[key] = element;

						int testX = child.GetX(trigObject);
						int testWidth = child.GetWidth(trigObject); // + labelWidthModifier;

						if (testWidth + testX <= childWidth + childX)
						{
							continue;
						}

						childWidth = testWidth;
						childX = testX;
					}
				}

				if (childWidth + childX > maxWidth)
				{
					maxWidth = childWidth;
				}
			}

			return maxWidth;
		}
示例#57
0
        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);
        }
示例#58
0
		public virtual int GetWidth(TriggerObject trigObject)
		{
			return 0;
		}
示例#59
0
		public override int GetHeight(TriggerObject trigObject)
		{
			if (m_Condition != null && GetCondition(trigObject) == false)
			{
				return 0;
			}

			int maxHeight = 0;

			foreach (UberGumpElement child in Children)
			{
				int childHeight = 0;
				int childY = 0;

				// have to go through the elements and "test" them with real list data to see what their actual widths will be (also this allows for conditions on objects in the list)
				ArrayList actualList = GetListSource(trigObject);
				if (actualList != null)
				{
					string key = GetObjsVarName(trigObject);

					//string functionName = GetLoopFunction(trigObject); // don't execute this function in between; it's too dangerous in the width calc!
					foreach (object element in actualList)
					{
						trigObject.objs[key] = element;

						int testY = child.GetY(trigObject);
						int testHeight = child.GetHeight(trigObject); // + labelWidthModifier;

						if (testHeight + testY <= childHeight + childY)
						{
							continue;
						}

						childHeight = testHeight;
						childY = testY;
					}
				}

				if (childHeight + childY > maxHeight)
				{
					maxHeight = childHeight;
				}
			}

			return maxHeight;
		}
示例#60
0
        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);
        }