Example #1
0
 public DelayedEvent(MicroscriptNode ev, DelayTimeType delayType, double delayTime, bool delayAbsolute)
 {
     Event         = ev;
     DelayType     = delayType;
     DelayTime     = delayTime;
     DelayAbsolute = delayAbsolute;
 }
Example #2
0
 public MicroscriptNode(MicroscriptType type, string target, MicroscriptAction action, object value,
                        DelayTimeType delayType, double delayTime, bool delayAbsolute)
 {
     Type          = type;
     Target        = target;
     Action        = action;
     Value         = value;
     DelayType     = delayType;
     DelayTime     = delayTime;
     DelayAbsolute = delayAbsolute;
 }
Example #3
0
 public static void ScheduleEvent(MicroscriptNode action, DelayTimeType timeType, double delayTime, bool delayAbsolute)
 {
     ScheduleEvent(new DelayedEvent(action, timeType, delayTime, delayAbsolute));
 }
Example #4
0
        public static MicroscriptNode ParseMicroscript(JToken jt)
        {
            //parse type and target
            MicroscriptType   type;
            string            target;
            MicroscriptAction action;
            object            value = 0;

            if (jt["flag"] != null)
            {
                type   = MicroscriptType.Flag;
                target = jt["flag"].Value <string>();
            }
            else if (jt["item"] != null)
            {
                type   = MicroscriptType.Item;
                target = jt["item"].Value <string>();
            }
            else if (jt["variable"] != null)
            {
                type   = MicroscriptType.Variable;
                target = jt["variable"].Value <string>();
            }
            else if (jt["affinity"] != null)
            {
                type   = MicroscriptType.Affinity;
                target = jt["affinity"].Value <string>();
            }
            else if (jt["quest"] != null)
            {
                type   = MicroscriptType.Quest;
                target = jt["quest"].Value <string>();
            }
            else if (jt["actorvalue"] != null)
            {
                type   = MicroscriptType.ActorValue;
                target = jt["actorvalue"].Value <string>();
            }
            else if (jt["exec"] != null)
            {
                type   = MicroscriptType.Exec;
                target = jt["exec"].Value <string>();
                if (jt["arg"] != null)
                {
                    value = TypeUtils.StringToNumericAuto(jt["arg"].Value <string>());
                }
            }
            else
            {
                throw new NotSupportedException();
            }

            //parse action/value
            if (jt["set"] != null)
            {
                action = MicroscriptAction.Set;
                if (type == MicroscriptType.Flag) //parse as boolean
                {
                    value = Convert.ToInt32(jt["set"].Value <bool>());
                }
                else //otherwise parse as number
                {
                    value = jt["set"].Value <int>();
                }
            }
            else if (jt["toggle"] != null)
            {
                action = MicroscriptAction.Toggle;
            }
            else if (jt["add"] != null)
            {
                action = MicroscriptAction.Add;
                value  = TypeUtils.StringToNumericAuto(jt["add"].Value <string>());
            }
            else if (jt["give"] != null)
            {
                action = MicroscriptAction.Give;
                value  = TypeUtils.StringToNumericAuto(jt["give"].Value <string>());
            }
            else if (jt["take"] != null)
            {
                action = MicroscriptAction.Take;
                value  = TypeUtils.StringToNumericAuto(jt["take"].Value <string>());
            }
            else if (jt["start"] != null)
            {
                action = MicroscriptAction.Start;
                value  = TypeUtils.StringToNumericAuto(jt["start"].Value <string>());
            }
            else if (jt["finish"] != null)
            {
                action = MicroscriptAction.Finish;
                value  = TypeUtils.StringToNumericAuto(jt["finish"].Value <string>());
            }
            else
            {
                throw new NotSupportedException();
            }

            //parse delay, if applicable
            DelayTimeType delayType     = DelayTimeType.None;
            double        delayTime     = default(double);
            bool          delayAbsolute = false;

            if (jt["delay"] != null)
            {
                delayType = DelayTimeType.Game;
                delayTime = double.Parse(jt["delay"].Value <string>());
                if (jt["delayType"] != null)
                {
                    string delayTypeString = jt["delayType"].Value <string>();
                    switch (delayTypeString)
                    {
                    case "real":
                        delayType = DelayTimeType.Real;
                        break;

                    case "world":
                        delayType = DelayTimeType.World;
                        break;

                    case "game":
                        delayType = DelayTimeType.Game;
                        break;
                    }
                }
                if (jt["delayAbsolute"] != null)
                {
                    delayAbsolute = jt["delayAbsolute"].Value <bool>();
                }
            }

            return(new MicroscriptNode(type, target, action, value, delayType, delayTime, delayAbsolute));
        }