Beispiel #1
0
            public override void ExecuteTrigger(int Index)
            {
                Dictionary <string, CutsceneScript> DicScripts = LoadAllScripts();

                string[] Content = new string[] { "" };
                foreach (string Line in Content)
                {
                    string[] LineContent = Line.Split(new string[1] {
                        " "
                    }, StringSplitOptions.RemoveEmptyEntries);
                    string         ScriptName = LineContent[0];
                    CutsceneScript LineScript = DicScripts[ScriptName];
                    System.Reflection.PropertyInfo[] ScriptProperties = LineScript.GetType().GetProperties();
                    for (int i = 0; i < ScriptProperties.Length; ++i)
                    {
                        ScriptProperties[i].SetValue(LineScript, Convert.ChangeType(LineContent[i + 1], ScriptProperties[i].PropertyType));
                    }
                }
            }
        private void Load(BinaryReader BR)
        {
            DicActionScript.Clear();
            int            ScriptCount = BR.ReadInt32();
            CutsceneScript NewScript = null;
            int            PosX, PosY;
            uint           ID = 0;
            string         NewScriptType;
            Cutscene       ScriptOwner;

            if (IsInEditor)
            {
                ScriptOwner = null;
            }
            else
            {
                ScriptOwner = this;
            }

            #region Action Scripts

            NextActionScriptID = ScriptCount;
            for (int S = 0; S < ScriptCount; S++)
            {
                NewScriptType = BR.ReadString();
                PosX          = BR.ReadInt32();
                PosY          = BR.ReadInt32();
                NewScript     = DicCutsceneScript[NewScriptType].CopyScript(ScriptOwner);

                switch (NewScriptType)
                {
                case "Cutscene Behavior":
                    ListCutsceneBehavior.Add((ScriptCutsceneBehavior)NewScript);
                    break;
                }

                NewScript.Load(BR);

                if (NewScript is CutsceneActionScript)
                {
                    ((CutsceneActionScript)NewScript).ExecuteEvent         = ExecuteEvent;
                    ((CutsceneActionScript)NewScript).GetDataContainerByID = GetDataContainerByID;
                    int ArrayEventCount;
                    //Load the Events
                    for (int E = 0; E < ((CutsceneActionScript)NewScript).ArrayEvents.Count(); E++)
                    {
                        ArrayEventCount = BR.ReadInt32();//Number of Scripts linked to the Event.
                        for (int i = 0; i < ArrayEventCount; i++)
                        {
                            ((CutsceneActionScript)NewScript).ArrayEvents[E].Add(new EventInfo(BR.ReadInt32(), BR.ReadInt32()));
                        }
                    }
                    DicActionScript.Add(S, (CutsceneActionScript)NewScript);
                }
                else
                {
                    throw new Exception("The cutscene failed to load. " + NewScript.Name + "didn't load properly.");
                }

                NewScript.ScriptSize.X = PosX;
                NewScript.ScriptSize.Y = PosY;
            }

            #endregion

            #region Data Container

            int ScriptDataContainer = BR.ReadInt32();
            for (int D = 0; D < ScriptDataContainer; D++)
            {
                NewScriptType = BR.ReadString();
                ID            = BR.ReadUInt32();
                PosX          = BR.ReadInt32();
                PosY          = BR.ReadInt32();
                NewScript     = DicCutsceneScript[NewScriptType].CopyScript(this);

                if (NewScript is CutsceneDataContainer)
                {
                    ((CutsceneDataContainer)NewScript).ID = ID;
                    ListDataContainer.Add(((CutsceneDataContainer)NewScript));
                }
                else
                {
                    throw new Exception("The cutscene failed to load. " + NewScript.Name + "didn't load properly.");
                }

                NewScript.Load(BR);
                NewScript.ScriptSize.X = PosX;
                NewScript.ScriptSize.Y = PosY;
            }

            #endregion

            for (int S = 0; S < ScriptCount; S++)
            {
                DicActionScript[S].AfterCutsceneLoad();
            }

            for (int D = 0; D < ScriptDataContainer; D++)
            {
                ListDataContainer[D].AfterCutsceneLoad();
            }
        }
            public override void AfterCutsceneLoad()
            {
                Dictionary <string, CutsceneScript> DicScripts;

                if (Owner == null)
                {
                    DicScripts = LoadAllScripts();
                }
                else
                {
                    DicScripts = Owner.DicCutsceneScript;
                }
                string[] Content = _Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                string PreviousEvent = null;
                CutsceneActionScript LastActionScript = null;

                foreach (string Line in Content)
                {
                    string[] LineContent = Line.Split(new string[1] {
                        ", "
                    }, StringSplitOptions.None);
                    string         ScriptName = LineContent[0];
                    CutsceneScript LineScript = DicScripts[ScriptName].CopyScript(Owner);
                    System.Reflection.PropertyInfo[] ScriptProperties = LineScript.GetType().GetProperties();

                    int i = 1;
                    foreach (System.Reflection.PropertyInfo Property in ScriptProperties)
                    {
                        if (Property.CanWrite)
                        {
                            string Value = "";
                            if (i < LineContent.Length)
                            {
                                Value = LineContent[i];
                            }

                            string[] ArrayLineContent = Value.Split(new string[1] {
                                ","
                            }, StringSplitOptions.RemoveEmptyEntries);
                            if (Property.PropertyType­.IsArray)
                            {
                                Property.SetValue(LineScript, Convert.ChangeType(ArrayLineContent, Property.PropertyType, CultureInfo.InvariantCulture));
                            }
                            else if (Property.PropertyType­.IsEnum)
                            {
                                object EnumValue = Enum.Parse(Property.PropertyType, Value);
                                Property.SetValue(LineScript, Convert.ChangeType(EnumValue, Property.PropertyType, CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                Property.SetValue(LineScript, Convert.ChangeType(Value, Property.PropertyType, CultureInfo.InvariantCulture));
                            }

                            ++i;
                        }
                    }

                    CutsceneActionScript LineActionScript = LineScript as CutsceneActionScript;

                    if (LineActionScript != null)
                    {
                        int CurrentScriptCount = 0;
                        if (Owner != null)
                        {
                            LineActionScript.ExecuteEvent         = Owner.ExecuteEvent;
                            LineActionScript.GetDataContainerByID = Owner.GetDataContainerByID;
                            CurrentScriptCount = Owner.DicActionScript.Count;
                            Owner.AddActionScript(LineActionScript);
                        }

                        if (PreviousEvent == null)
                        {
                            ListTextScriptToTrigger.Add(LineActionScript);
                        }
                        else
                        {
                            int EventIndex = Array.IndexOf(LastActionScript.NameEvents, PreviousEvent);
                            LastActionScript.ArrayEvents[EventIndex].Add(new EventInfo(CurrentScriptCount, 0));
                        }

                        PreviousEvent = null;
                        if (LineContent.Length > i)
                        {
                            PreviousEvent    = LineContent[i];
                            LastActionScript = LineActionScript;
                        }
                        else
                        {
                            LastActionScript = null;
                        }
                    }
                    else
                    {
                        CutsceneDataContainer LineDataContainer = LineScript as CutsceneDataContainer;
                        if (LineDataContainer != null && Owner != null)
                        {
                            Owner.ListDataContainer.Add(LineDataContainer);
                        }
                    }
                }
            }