コード例 #1
0
            public bool Run(Cutscene cs, double delta)
            {
                time += delta;
                if (time >= Duration)
                {
                    Renderer.SParam = EndSParam;
                    return(false);
                }
                var pct = (float)(time / Duration);

                if (ParamCurve != null)
                {
                    pct = ParamCurve.GetValue((float)time, (float)Duration);
                }
                Renderer.SParam = MathHelper.Lerp(StartSParam, EndSParam, pct);
                return(true);
            }
コード例 #2
0
ファイル: MainMenu.cs プロジェクト: TRBlount/Librelancer
 void Keyboard_KeyDown(KeyEventArgs e)
 {
     if (e.Key >= Keys.D1 && e.Key <= Keys.D9)
     {
         var i = (int)e.Key - (int)Keys.D1;
         var r = Game.GameData.GetIntroSceneSpecific(i);
         if (r == null)
         {
             return;
         }
         intro = r;
         scene = new Cutscene(intro.Scripts, Game);
         scene.Update(TimeSpan.FromSeconds(1f / 60f)); //Do all the setup events - smoother entrance
         Game.Sound.PlayMusic(intro.Music);
         GC.Collect();                                 //crap
     }
 }
コード例 #3
0
ファイル: LuaMenu.cs プロジェクト: lyzardiar/Librelancer
        public LuaMenu(FreelancerGame g) : base(g)
        {
            api = new LuaAPI(this);
            ui  = new XmlUIManager(g, "menu", api, g.GameData.GetInterfaceXml("mainmenu"));
            ui.OnConstruct();
            ui.Enter();
            g.GameData.PopulateCursors();
            g.CursorKind = CursorKind.None;
            intro        = g.GameData.GetIntroScene();
            scene        = new Cutscene(intro.Scripts, Game);
            scene.Update(TimeSpan.FromSeconds(1f / 60f)); //Do all the setup events - smoother entrance
            cur = g.ResourceManager.GetCursor("arrow");
            GC.Collect();                                 //crap
            g.Sound.PlayMusic(intro.Music);
#if DEBUG
            g.Keyboard.KeyDown += Keyboard_KeyDown;
#endif
            FadeIn(0.1, 0.3);
        }
コード例 #4
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            var obj   = cs.Objects[(string)ev.Targets[0]];
            var path  = cs.Objects[(string)ev.Targets[1]];
            var start = (float)ev.Properties["start_percent"];
            var stop  = (float)ev.Properties["stop_percent"];
            var flags = ThnEnum.Check <AttachFlags>(ev.Properties["flags"]);

            cs.Coroutines.Add(new ObjectPathAnimation()
            {
                Duration     = ev.Duration,
                StartPercent = start,
                StopPercent  = stop,
                Flags        = flags,
                Curve        = ev.ParamCurve,
                Path         = path,
                Object       = obj
            });
        }
コード例 #5
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            //How to tie this in with .anm files?
            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Object != null && obj.Object.AnimationComponent != null) //Check if object has Cmp animation
            {
                object o;
                bool   loop = true;
                if (ev.Properties.TryGetValue("event_flags", out o))
                {
                    if (((int)(float)o) == 3)
                    {
                        loop = false; //Play once?
                    }
                }
                obj.Object.AnimationComponent.StartAnimation((string)ev.Properties["animation"], loop);
            }
        }
コード例 #6
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Sound != null)
            {
                var    flags = (SoundFlags)0;
                object tmp;
                if (ev.Properties.TryGetValue("flags", out tmp))
                {
                    flags = ThnEnum.Check <SoundFlags>(tmp);
                }
                obj.Sound.Play(flags == SoundFlags.Loop);
                cs.Coroutines.Add(new SoundRoutine()
                {
                    Sound = obj.Sound, Duration = ev.Duration
                });
            }
        }
コード例 #7
0
            public bool Run(Cutscene cs, double delta)
            {
                Time += delta;
                Time  = MathHelper.Clamp(Time, 0, Duration);

                if (HasPos)
                {
                    This.Translate = GetPosition(delta);
                }
                if (HasQuat)
                {
                    This.Rotate = Matrix4x4.CreateFromQuaternion(GetOrientation(delta));
                }
                if (AxisRot != null)
                {
                    This.Rotate = AxisRot.OriginalRotate *
                                  Matrix4x4.CreateFromAxisAngle(AxisRot.Axis, AxisRot.GetRads((float)(Time / Duration)));
                }
                return(Time != Duration);
            }
コード例 #8
0
        public LuaMenu(FreelancerGame g) : base(g)
        {
            api        = new MenuAPI(this);
            ui         = new UiContext(g);
            ui.GameApi = new MenuAPI(this);
            widget     = ui.CreateAll("mainmenu.xml");
            g.GameData.PopulateCursors();
            g.CursorKind = CursorKind.None;
            intro        = g.GameData.GetIntroScene();
            scene        = new Cutscene(new ThnScriptContext(intro.Scripts), Game.GameData, Game.Viewport, Game);
            scene.Update(TimeSpan.FromSeconds(1f / 60f)); //Do all the setup events - smoother entrance
            FLLog.Info("Thn", "Playing " + intro.ThnName);
            cur = g.ResourceManager.GetCursor("arrow");
            GC.Collect(); //crap
            g.Sound.PlayMusic(intro.Music);
#if DEBUG
            g.Keyboard.KeyDown += Keyboard_KeyDown;
#endif
            FadeIn(0.1, 0.3);
        }
コード例 #9
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            //How to tie this in with .anm files?
            float start_time = 0;
            float duration   = 0;
            float time_scale = 1;

            if (ev.Properties.TryGetValue("start_time", out object of))
            {
                start_time = (float)of;
            }
            if (ev.Properties.TryGetValue("time_scale", out of))
            {
                time_scale = (float)of;
            }
            if (ev.Properties.TryGetValue("duration", out of))
            {
                duration = (float)of;
            }

            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Object != null && obj.Object.AnimationComponent != null) //Check if object has Cmp animation
            {
                object o;
                bool   loop = false;
                if (ev.Properties.TryGetValue("event_flags", out o))
                {
                    if (((int)(float)o) == 2)
                    {
                        loop = true; //Play once?
                    }
                }
                obj.Object.AnimationComponent.StartAnimation(
                    (string)ev.Properties["animation"],
                    loop,
                    start_time,
                    time_scale,
                    duration);
            }
        }
コード例 #10
0
        void SwitchToRoom()
        {
            if (currentRoom.Music == null)
            {
                Game.Sound.StopMusic();
            }
            else
            {
                Game.Sound.PlayMusic(currentRoom.Music);
            }
            scene = new Cutscene(currentRoom.OpenScripts(), Game);
            if (currentRoom.Camera != null)
            {
                scene.SetCamera(currentRoom.Camera);
            }

            /*foreach (var npc in currentRoom.Npcs)
             * {
             *      var obj = scene.Objects[npc.StandingPlace];
             *      var child = new GameObject();
             *      child.RenderComponent = new CharacterRenderer(
             *              Game.ResourceManager.GetDfm(npc.HeadMesh),
             *              Game.ResourceManager.GetDfm(npc.BodyMesh),
             *              Game.ResourceManager.GetDfm(npc.LeftHandMesh),
             *              Game.ResourceManager.GetDfm(npc.RightHandMesh)
             *      );
             *      child.Register(scene.Renderer, scene.World.Physics);
             *      child.Transform = Matrix4.CreateTranslation(0, 3, 0);
             *      obj.Object.Children.Add(child);
             * }*/
            if (currentRoom.PlayerShipPlacement != null)
            {
                var shp = Game.GameData.GetShip(session.PlayerShip);
                var obj = new GameObject(shp.Drawable, Game.ResourceManager);
                obj.PhysicsComponent = null;
                var place = scene.Objects[currentRoom.PlayerShipPlacement];
                obj.Register(scene.Renderer, scene.World.Physics);
                obj.Transform = obj.GetHardpoint("HpMount").Transform.Inverted();
                place.Object.Children.Add(obj);
            }
        }
コード例 #11
0
            public bool Run(Cutscene cs, double delta)
            {
                t += delta;
                var amount = MathHelper.Clamp((float)(t / Event.Duration), 0, 1);

                if (t > Event.Duration)
                {
                    return(false);
                }
                if (FogColor != null)
                {
                    var f    = FogColor.Value;
                    var c2   = new Color3f(f.X / 255f, f.Y / 255f, f.Z / 255f);
                    var c1   = new Color3f(OrigFogColor.R, OrigFogColor.G, OrigFogColor.B);
                    var cend = Utf.Ale.AlchemyEasing.EaseColorRGB(Utf.Ale.EasingTypes.Linear, amount, 0, 1, c1, c2);
                    cs.Renderer.SystemLighting.FogColor = new Color4(cend, 1);
                }
                if (FogStart != null)
                {
                    var f = FogStart.Value;
                    cs.Renderer.SystemLighting.FogRange.X =
                        MathHelper.Lerp(OrigFogStart, f, amount);
                }
                if (FogEnd != null)
                {
                    var f = FogEnd.Value;
                    cs.Renderer.SystemLighting.FogRange.Y =
                        MathHelper.Lerp(OrigFogEnd, f, amount);
                }
                if (FogDensity != null)
                {
                    var f = FogDensity.Value;
                    cs.Renderer.SystemLighting.FogDensity =
                        MathHelper.Lerp(OrigFogDensity, f, amount);
                }

                return(true);
            }
コード例 #12
0
            public bool Run(Cutscene cs, double delta)
            {
                Vector3   translate = Parent.Translate;
                Matrix4x4 rotate    = Parent.Rotate;

                if (Part != null && (Position || Orientation))
                {
                    var tr = Part.GetTransform();
                    if (Position)
                    {
                        translate = tr.Translation;
                    }
                    if (Orientation)
                    {
                        rotate = Matrix4x4.CreateFromQuaternion(tr.ExtractRotation());
                    }
                }
                if (Orientation && OrientationRelative)
                {
                    var qCurrent = rotate.ExtractRotation();
                    var diff     = qCurrent * Quaternion.Inverse(LastRotate);
                    var qChild   = Child.Rotate.ExtractRotation();
                    rotate     = Matrix4x4.CreateFromQuaternion(qChild * diff);
                    LastRotate = qCurrent;
                }
                t += delta;
                if (LookAt)
                {
                    if (lookFunc == null)
                    {
                        //offset does not affect LOOK_AT flags
                        if (Part != null)
                        {
                            lookFunc = () => Vector3.Transform(Vector3.Zero, Part.Transform);
                        }
                        else
                        {
                            lookFunc = () => Parent.Translate;
                        }
                    }
                    if (Child.Camera != null)
                    {
                        Child.Camera.LookAt = lookFunc;
                    }
                }

                if (t > Duration)
                {
                    if (LookAt && Child.Camera != null)
                    {
                        Child.Camera.LookAt = null;
                    }
                }
                if (Offset != Vector3.Zero)  //TODO: This can be optimised
                {
                    var off = Offset;
                    if (EntityRelative)
                    {
                        off = Vector3.Transform(Offset, rotate.ExtractRotation());
                    }
                    var tr = rotate * Matrix4x4.CreateTranslation(translate) * Matrix4x4.CreateTranslation(off);
                    translate = tr.Translation;
                    rotate    = Matrix4x4.CreateFromQuaternion(tr.ExtractRotation());
                }
                if (Position)
                {
                    Child.Translate = translate;
                }
                if (Orientation)
                {
                    Child.Rotate = rotate;
                }
                return(t <= Duration);
            }
コード例 #13
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            ThnObject objA;
            ThnObject objB;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[1]);
                return;
            }
            var    targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var    flags      = AttachFlags.Position | AttachFlags.Orientation;
            object tmp;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            //Attach GameObjects to eachother
            GameObject part = null;
            string     tgt_part;

            ev.Properties.TryGetValue("target_part", out tmp);
            tgt_part = (tmp as string);
            if (targetType == TargetTypes.Hardpoint && !string.IsNullOrEmpty(tgt_part))
            {
                if (objB.Object == null)
                {
                    FLLog.Error("Thn", "Could not get hardpoints on " + objB.Name);
                }
                else
                {
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
                }
            }
            if (targetType == TargetTypes.Part && !string.IsNullOrEmpty(tgt_part))
            {
                if (objB.Object == null || objB.Object.RigidModel == null || objB.Object.RigidModel.Parts == null)
                {
                    FLLog.Error("Thn", "Could not get parts on " + objB.Name);
                }
                else
                {
                    if (objB.Object.RigidModel.Parts.TryGetValue((string)ev.Properties["target_part"], out var tgtpart))
                    {
                        var hp = new Hardpoint(null, tgtpart);
                        part            = new GameObject();
                        part.Parent     = objB.Object;
                        part.Attachment = hp;
                    }
                }
            }
            Vector3 offset = Vector3.Zero;

            if (ev.Properties.TryGetValue("offset", out tmp))
            {
                offset = ((LuaTable)tmp).ToVector3();
            }
            Quaternion lastRotate = Quaternion.Identity;

            if ((flags & AttachFlags.Orientation) == AttachFlags.Orientation &&
                (flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative)
            {
                if (part != null)
                {
                    lastRotate = part.GetTransform().ExtractRotation();
                }
                else
                {
                    lastRotate = objB.Rotate.ExtractRotation();
                }
            }
            cs.Coroutines.Add(new AttachRoutine()
            {
                Duration            = ev.Duration,
                Child               = objA,
                Parent              = objB,
                Part                = part,
                Position            = ((flags & AttachFlags.Position) == AttachFlags.Position),
                Orientation         = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                OrientationRelative = ((flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative),
                EntityRelative      = ((flags & AttachFlags.EntityRelative) == AttachFlags.EntityRelative),
                LookAt              = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt),
                LastRotate          = lastRotate,
                Offset              = offset
            });
        }
コード例 #14
0
            public bool Run(Cutscene cs, double delta)
            {
                Vector3 translate = Parent.Translate;
                Matrix4 rotate    = Parent.Rotate;

                if (Part != null && (Position || Orientation))
                {
                    var tr = Part.GetTransform();
                    if (Position)
                    {
                        translate = tr.ExtractTranslation();
                    }
                    if (Orientation)
                    {
                        rotate = Matrix4.CreateFromQuaternion(tr.ExtractRotation());
                    }
                }
                t += delta;
                if (LookAt)
                {
                    if (lookFunc == null)
                    {
                        if (Part != null)
                        {
                            lookFunc = () => Part.Transform.Transform(Vector3.Zero);
                        }
                        else
                        {
                            lookFunc = () => Parent.Translate;
                        }
                    }
                    if (Child.Camera != null)
                    {
                        Child.Camera.LookAt = lookFunc;
                    }
                }
                else
                if (Child.Camera != null)
                {
                    Child.Camera.LookAt = null;
                }

                if (t > Duration)
                {
                    if (LookAt)
                    {
                        Child.Camera.LookAt = null;
                    }
                }
                if (Offset != Vector3.Zero)  //TODO: This can be optimised
                {
                    var tr = rotate * Matrix4.CreateTranslation(translate) * Matrix4.CreateTranslation(Offset);
                    translate = tr.ExtractTranslation();
                    rotate    = Matrix4.CreateFromQuaternion(tr.ExtractRotation());
                }
                if (Position)
                {
                    Child.Translate = translate;
                }
                if (Orientation)
                {
                    Child.Rotate = rotate;
                }
                return(true);
            }
コード例 #15
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (!cs.Objects.ContainsKey((string)ev.Targets[0]))
            {
                FLLog.Error("Thn", $"Entity {ev.Targets[0]} does not exist");
                return;
            }
            var obj = cs.Objects[(string)ev.Targets[0]];

            if (obj.Light == null)
            {
                FLLog.Error("Thn", $"Entity {ev.Targets[0]} is not a light");
                return;
            }

            object   tmp;
            LuaTable lightprops;

            if (ev.Properties.TryGetValue("lightprops", out tmp))
            {
                lightprops = (LuaTable)tmp;
            }
            else
            {
                FLLog.Warning("Thn", "Light prop animation with no properties");
                return;
            }

            Vector3 vtmp;
            Color3f?targetDiffuse = null;
            Color3f?targetAmbient = null;

            if (lightprops.TryGetValue("on", out tmp))
            {
                obj.Light.Active = ThnEnum.Check <bool>(tmp);
            }
            if (lightprops.TryGetVector3("diffuse", out vtmp))
            {
                targetDiffuse = new Color3f(vtmp);
                if (ev.Duration <= 0)
                {
                    obj.Light.Light.Color = new Color3f(vtmp);
                }
            }
            if (lightprops.TryGetVector3("ambient", out vtmp))
            {
                targetAmbient = new Color3f(vtmp);
                if (ev.Duration <= 0)
                {
                    obj.Light.Light.Ambient = new Color3f(vtmp);
                }
            }
            if (ev.Duration > 0)
            {
                cs.Coroutines.Add(new AnimLightProp()
                {
                    Source        = obj.Light.Light,
                    Target        = obj.Light,
                    TargetDiffuse = targetDiffuse,
                    TargetAmbient = targetAmbient,
                    Duration      = ev.Duration,
                    ParamCurve    = ev.ParamCurve
                });
            }
        }
コード例 #16
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (ev.Targets.Capacity == 0)
            {
                return;
            }
            ThnObject objA;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[0]);
                return;
            }

            bool       hasPos   = false;
            Quaternion?q_orient = null;

            if (ev.Targets.Capacity >= 1)
            {
                var     props = (LuaTable)ev.Properties["spatialprops"];
                Vector3 pos;
                object  tmp;
                if (props.TryGetValue("q_orient", out tmp))
                {
                    var tb = (LuaTable)tmp;
                    q_orient = new Quaternion((float)tb[1], (float)tb[2], (float)tb[3], (float)tb[0]);
                }

                if (props.TryGetValue("orient", out tmp))
                {
                    var orient = ThnScript.GetMatrix((LuaTable)tmp);
                    q_orient = orient.ExtractRotation();
                }

                AxisRotation axisRotation = null;
                if (props.TryGetValue("axisrot", out tmp))
                {
                    var axisRot_Table = (LuaTable)tmp;
                    axisRotation = new AxisRotation();
                    if (!axisRot_Table.TryGetVector3(1, out axisRotation.Axis))
                    {
                        FLLog.Error("Thn", "invalid axisrot");
                        return;
                    }
                    axisRotation.Axis           = Vector3.TransformNormal(axisRotation.Axis, objA.Rotate);
                    axisRotation.Degrees        = (float)axisRot_Table[0];
                    axisRotation.OriginalRotate = objA.Rotate;
                }

                hasPos = props.TryGetVector3("pos", out pos);
                if (ev.Targets.Capacity > 1)
                {
                    ThnObject objB;
                    if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
                    {
                        FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[1]);
                        return;
                    }
                    if (ev.Duration < float.Epsilon)
                    {
                        objA.Translate = objB.Translate;
                        objA.Rotate    = objB.Rotate;
                    }
                    else
                    {
                        cs.Coroutines.Add(new FollowSpatialRoutine()
                        {
                            Duration = ev.Duration,
                            HasPos   = hasPos,
                            HasQuat  = q_orient != null,
                            This     = objA,
                            Follow   = objB
                        });
                    }
                }
                else
                {
                    if (ev.Duration < float.Epsilon)
                    {
                        if (hasPos)
                        {
                            objA.Translate = pos;
                        }
                        if (q_orient != null)
                        {
                            objA.Rotate = Matrix4x4.CreateFromQuaternion(q_orient.Value);
                        }
                    }
                    else
                    {
                        cs.Coroutines.Add(new StaticSpatialRoutine()
                        {
                            Duration = ev.Duration,
                            HasPos   = hasPos,
                            HasQuat  = q_orient != null,
                            EndPos   = pos,
                            EndQuat  = q_orient ?? Quaternion.Identity,
                            This     = objA,
                            AxisRot  = axisRotation
                        });
                    }
                }
            }
        }
コード例 #17
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            //fogmode is ignored.
            //fogdensity is ignored.
            var fogprops = (LuaTable)ev.Properties["fogprops"];

            object  tmp;
            Vector3 tmp2;

            //Nullable since we are animating
            bool?    fogon      = null;
            Vector3? fogColor   = null;
            float?   fogstart   = null;
            float?   fogend     = null;
            float?   fogDensity = null;
            FogModes fogMode    = FogModes.Linear;

            //Get values
            if (fogprops.TryGetValue("fogon", out tmp))
            {
                fogon = ThnEnum.Check <bool>(tmp);
            }
            if (fogprops.TryGetValue("fogmode", out tmp))
            {
                fogMode = ThnEnum.Check <FogModes>(tmp);
            }
            if (fogprops.TryGetValue("fogdensity", out tmp))
            {
                fogDensity = (float)tmp;
            }
            if (fogprops.TryGetVector3("fogcolor", out tmp2))
            {
                fogColor = tmp2;
            }
            if (fogprops.TryGetValue("fogstart", out tmp))
            {
                fogstart = (float)tmp;
            }
            if (fogprops.TryGetValue("fogend", out tmp))
            {
                fogend = (float)tmp;
            }

            if (fogon.HasValue) //i'm pretty sure this can't be animated
            {
                cs.Renderer.SystemLighting.FogMode = fogon.Value ? fogMode : FogModes.None;
            }

            //Set fog
            if (Math.Abs(ev.Duration) < float.Epsilon) //just set it
            {
                if (fogColor.HasValue)
                {
                    var v = fogColor.Value;
                    v *= (1 / 255f);
                    cs.Renderer.SystemLighting.FogColor = new Color4(v.X, v.Y, v.Z, 1);
                }
                if (fogstart.HasValue)
                {
                    cs.Renderer.SystemLighting.FogRange.X = fogstart.Value;
                }
                if (fogend.HasValue)
                {
                    cs.Renderer.SystemLighting.FogRange.Y = fogend.Value;
                }
                if (fogDensity.HasValue)
                {
                    cs.Renderer.SystemLighting.FogDensity = fogDensity.Value;
                }
            }
            else
            {
                cs.Coroutines.Add(new FogPropAnimRoutine() //animate it!
                {
                    Event          = ev,
                    FogDensity     = fogDensity,
                    FogColor       = fogColor,
                    FogStart       = fogstart,
                    FogEnd         = fogend,
                    OrigFogColor   = cs.Renderer.SystemLighting.FogColor,
                    OrigFogStart   = cs.Renderer.SystemLighting.FogRange.X,
                    OrigFogEnd     = cs.Renderer.SystemLighting.FogRange.Y,
                    OrigFogDensity = cs.Renderer.SystemLighting.FogDensity
                });
            }
        }
コード例 #18
0
        void SwitchToRoom(bool dolanding)
        {
            Game.Saves.Selected = -1;
            session.RoomEntered(virtualRoom ?? currentRoom.Nickname, currentBase.Nickname);
            if (currentRoom.Music == null)
            {
                Game.Sound.StopMusic();
            }
            else
            {
                Game.Sound.PlayMusic(currentRoom.Music, currentRoom.MusicOneShot);
            }
            var shp = Game.GameData.GetShip(session.PlayerShip);

            playerShip = new GameObject(shp.ModelFile.LoadFile(Game.ResourceManager), Game.ResourceManager);
            playerShip.PhysicsComponent = null;
            CreatePlayerEquipment();
            session.OnUpdatePlayerShip = CreatePlayerEquipment;
            var ctx = new ThnScriptContext(currentRoom.OpenSet());

            ctx.PlayerShip = playerShip;
            if (currentBase.TerrainTiny != null)
            {
                ctx.Substitutions.Add("$terrain_tiny", currentBase.TerrainTiny);
            }
            if (currentBase.TerrainSml != null)
            {
                ctx.Substitutions.Add("$terrain_sml", currentBase.TerrainSml);
            }
            if (currentBase.TerrainMdm != null)
            {
                ctx.Substitutions.Add("$terrain_mdm", currentBase.TerrainMdm);
            }
            if (currentBase.TerrainLrg != null)
            {
                ctx.Substitutions.Add("$terrain_lrg", currentBase.TerrainLrg);
            }
            if (currentBase.TerrainDyna1 != null)
            {
                ctx.Substitutions.Add("$terrain_dyna_01", currentBase.TerrainDyna1);
            }
            if (currentBase.TerrainDyna2 != null)
            {
                ctx.Substitutions.Add("$terrain_dyna_02", currentBase.TerrainDyna2);
            }
            scene = new Cutscene(ctx, Game.GameData, Game.RenderContext.CurrentViewport, Game);
            scene.ScriptFinished += SceneOnScriptFinished;
            sceneScripts          = currentRoom.OpenScene().ToArray();
            if (dolanding && !string.IsNullOrEmpty(currentRoom.LandScript))
            {
                RoomDoSceneScript(new ThnScript(currentRoom.LandScript), ScriptState.Enter);
            }
            else if (!string.IsNullOrEmpty(currentRoom.StartScript))
            {
                RoomDoSceneScript(new ThnScript(currentRoom.StartScript), ScriptState.Enter);
            }
            else
            {
                RoomDoSceneScript(null, ScriptState.None);
            }
        }
コード例 #19
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            if (ev.Targets.Capacity == 0)
            {
                return;
            }
            ThnObject objA;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[0]);
                return;
            }
            if (ev.Targets.Capacity == 1)
            {
                var        props    = (LuaTable)ev.Properties["spatialprops"];
                Quaternion?q_orient = null;
                Vector3    pos;
                object     tmp;
                if (props.TryGetValue("q_orient", out tmp))
                {
                    var tb = (LuaTable)tmp;
                    q_orient = new Quaternion((float)tb[1], (float)tb[2], (float)tb[3], (float)tb[0]);
                }
                if (props.TryGetValue("orient", out tmp))
                {
                    var orient = ThnScript.GetMatrix((LuaTable)tmp);
                    q_orient = orient.ExtractRotation();
                }
                bool hasPos = props.TryGetVector3("pos", out pos);
                if (ev.Duration < float.Epsilon)
                {
                    if (hasPos)
                    {
                        objA.Translate = pos;
                    }
                    if (q_orient != null)
                    {
                        objA.Rotate = Matrix4.CreateFromQuaternion(q_orient.Value);
                    }
                }
                else
                {
                    cs.Coroutines.Add(new StaticSpatialRoutine()
                    {
                        Duration = ev.Duration,
                        HasPos   = hasPos,
                        HasQuat  = q_orient != null,
                        EndPos   = pos,
                        EndQuat  = q_orient ?? Quaternion.Identity,
                        This     = objA
                    });
                }
            }
            else
            {
                ThnObject objB;
                if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
                {
                    FLLog.Error("Thn", "Object does not exist " + (string)ev.Targets[1]);
                    return;
                }
                if (ev.Duration < float.Epsilon)
                {
                    objA.Translate = objB.Translate;
                    objA.Rotate    = objB.Rotate;
                }
                else
                {
                    cs.Coroutines.Add(new FollowSpatialRoutine()
                    {
                        Duration = ev.Duration,
                        HasPos   = true,
                        HasQuat  = true,
                        This     = objA,
                        Follow   = objB
                    });
                }
            }
        }