Esempio n. 1
0
        public void Start()
        {
            eventManager = new EventManager();

            NetConfig.Init();
            TaskManger.CreateInstance().Init();
            TableManager.CreateInstance();
            TableManager.instance.getTypeFunc = (name) => { return(Type.GetType(name)); };
            TableManager.instance.Init();
            NetworkManager.CreateInstance().Init();
            ProxyManager.CreateInstance().Init();

            // start server
            NetworkManager.instance.forClient.server.Start();
            Logger.LogInfo("战场服务器已启动");
            // connect to main server
            ProxyManager.instance.GetProxy <MainServerProxy>().Connenct();


            m_updater.Start();
            m_updater.Add(this);
            m_updater.Add(ProxyManager.instance);

            Time.SetUpdater(m_updater);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var view  = new ConsoleViewer();
            var input = new ConsoleInput(view);

            var core = _LoadGame("Game.dll");

            var client = new Client <IUser>(view, input);

            client.ModeSelectorEvent += new ModeCreator(core, client.Command).Select;



            var updater = new Updater();

            updater.Add(client);
            updater.Add(core);

            while (client.Enable)
            {
                input.Update();
                updater.Working();
            }

            updater.Shutdown();
        }
Esempio n. 3
0
        void IBootable.Launch()
        {
            m_WiringOperator.JoinStreamEvent += CreatePeer;
            m_WiringOperator.LeftStreamEvent += DestroyPeer;

            m_Updater.Add(m_WiringOperator);
        }
Esempio n. 4
0
		public static void Main(string[] args)
		{
			var view = new ConsoleViewer();
			var input = new ConsoleInput(view);

			var core = _LoadGame("Game.dll");

			var client = new Client<IUser>(view, input);

			client.ModeSelectorEvent += new ModeCreator(core , client.Command ).Select;
			
            

            var updater = new Updater();
			updater.Add(client);
			updater.Add(core);

			while(client.Enable)
			{
				input.Update();
				updater.Working();
			}

			updater.Shutdown();
		}
Esempio n. 5
0
        private static void Main(string[] args)
        {
            var sw = new SpinWait();

            var botCount = 1;
            if(args.Length > 0)
            {
                botCount = int.Parse(args[0]);
            }

            if(args.Length > 1)
            {
                Program.IPAddress = args[1];
            }

            var clientHandler = new ClientHandler(Program.IPAddress, Program.Port, botCount);
            var view = new ConsoleViewer();
            Singleton<Log>.Instance.Initial(view);
            var input = new ConsoleInput(view);
            var client = new Client(view, input);
            var packetRegulator = new PacketRegulator();
            client.Command.Register(
                "si",
                () =>
                {
                    Console.WriteLine(
                        "Send Interval : {0}\nRequest Package Queue : {1}",
                        HitHandler.Interval,
                        packetRegulator.Sampling);
                });
            client.ModeSelectorEvent += clientHandler.Begin;

            var updater = new Updater();
            updater.Add(client);
            updater.Add(clientHandler);
            updater.Add(packetRegulator);

            while(client.Enable)
            {
                input.Update();
                updater.Working();
                sw.SpinOnce();
            }

            client.Command.Unregister("si");
            updater.Shutdown();
            clientHandler.End();
            Singleton<Log>.Instance.Final();
        }
Esempio n. 6
0
        void IBootable.Launch()
        {
            _Agent.ErrorMethodEvent += _ErrorMethod;

            _Updater.Add(_Agent);
            _ToOffline();
        }
Esempio n. 7
0
 void IStage.Enter()
 {
     _Updater.Add(_UserProvider);
     _Command.Register <string>("SpawnUser[UserName]", _Spawn);
     _Command.Register <string>("UnpawnUser[UserName]", _Unspawn);
     _Command.Register <string>("SelectUser[UserName]", _Select);
 }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            var sw = new SpinWait();
            Program._Enable = true;
            var updater = new Updater();
            var launcher = new Launcher();

            var server = new Server();
            var serverAppliction = new Regulus.Remoting.Soul.Native.Server(server, 12345);

            var client = new Proxy();
            Program.client_UserEvent(client.SpawnUser("user"));

            launcher.Push(serverAppliction);
            updater.Add(client);

            launcher.Launch();
            while(Program._Enable)
            {
                updater.Working();
                sw.SpinOnce();
            }

            updater.Shutdown();
            launcher.Shutdown();

            Console.ReadKey();
        }
Esempio n. 9
0
        private void Init()
        {
            RatAnimator = GetComponent <RatAnimator>();

            ratStateMachine.Init(this);

            idling     = new Idle();
            walking    = new Walk();
            jumping    = new Jump();
            climbing   = new Climb();
            jumpingOff = new JumpOff();

            idling.Init(this, ratStateMachine);
            walking.Init(this, ratStateMachine);
            jumping.Init(this, ratStateMachine);
            climbing.Init(this, ratStateMachine);
            jumpingOff.Init(this, ratStateMachine);

            ratStateMachine.AddState(idle, idling);
            ratStateMachine.AddState(walk, walking);
            ratStateMachine.AddState(jump, jumping);
            ratStateMachine.AddState(climb, climbing);
            ratStateMachine.AddState(jumpOff, jumpingOff);
            ratStateMachine.ChangeState(idle);

            //update helpers
            rotationUpdater.Add(UpdateRotation);
        }
Esempio n. 10
0
        public void JoinPlayer(Guid id, int character, bool main_player)
        {
            var player = new Player(_Binder, id, character, main_player);

            _Players.Add(player);

            _Updater.Add(player);
        }
Esempio n. 11
0
 public PingDeterminer(Server_ClientManager clientManager, Server_MessageSender sender, double miliSecondsPerTick, Clock clock, Updater updater)
 {
     this.miliSecondsPerTick = miliSecondsPerTick;
     this.messageSender      = sender;
     this.clock         = clock;
     this.clientManager = clientManager;
     updater.Add(this);
 }
Esempio n. 12
0
        internal void Push(ISoulBinder soulBinder, IUpdatable handler)
        {
            _RequesterHandlers.Add(handler);

            lock (_Binders)
            {
                _Binders.Enqueue(soulBinder);
            }
        }
Esempio n. 13
0
        public void Start()
        {
            eventManager = new EventManager();

            DBManager.CreateInstance().Init("mongodb://localhost:27017", "xiao_game");
            NetworkManager.CreateInstance().Init();
            ProxyManager.CreateInstance().Init();

            //
            NetworkManager.instance.serverForBattle.Start();
            Logger.LogInfo("网络监听(战场) 已启动");
            NetworkManager.instance.serverForClient.Start();
            Logger.LogInfo("网络监听(客户端) 已启动");


            m_updater.Start();
            m_updater.Add(this);
            m_updater.Add(ProxyManager.instance);

            Time.SetUpdater(m_updater);
        }
Esempio n. 14
0
            private TUser _SpawnController(string name)
            {
                var value      = new Value <TUser>();
                var controller = _ControllerProvider.Spawn();

                controller.Name = name;

                _Controlls.Add(controller);
                _Loops.Add(controller);

                _Viewer.WriteLine("控制者[" + name + "] 增加.");
                return(controller.GetUser());
            }
Esempio n. 15
0
        public void TestCenter()
        {
            var binder = Substitute.For<Remoting.ISoulBinder>();
            var finder = Substitute.For<IAccountFinder>();
            var record = Substitute.For<IGameRecorder>();

            var center = new Center(finder, record);

            Updater updater = new Updater();
            center.Join(binder);
            updater.Add(center);
            updater.Working();
            updater.Shutdown();
        }
Esempio n. 16
0
        private void _Update(object state)
        {
            var updater = new Updater();

            updater.Add(Read);
            updater.Add(Write);

            var counter = new TimeCounter();

            do
            {
                updater.Working();

                if (_Reset)
                {
                    counter.Reset();
                    _Reset = false;
                }

                Thread.Sleep(1000);
            }while(counter.Second <= 30);
            updater.Shutdown();
            _ThreadEnable = false;
        }
Esempio n. 17
0
        public void TestCenter()
        {
            var binder = Substitute.For <Remoting.ISoulBinder>();
            var finder = Substitute.For <IAccountFinder>();
            var record = Substitute.For <IGameRecorder>();

            var center = new Center(finder, record);

            Updater updater = new Updater();

            center.Join(binder);
            updater.Add(center);
            updater.Working();
            updater.Shutdown();
        }
Esempio n. 18
0
        private void Run()
        {
            AutoPowerRegulator wait = new AutoPowerRegulator(new PowerRegulator(30));

            Updater <Timestamp> updater = new Updater <Timestamp>();

            updater.Add(m_Agent);
            while (m_Enable)
            {
                m_Time.Sample();
                updater.Working(new Timestamp(m_Time.Now, m_Time.Delta));
                wait.Operate();
            }
            updater.Shutdown();
        }
Esempio n. 19
0
        private void Run(object State)
        {
            var updater = new Updater <Timestamp>();

            updater.Add(m_Host);

            var wait = new AutoPowerRegulator(new PowerRegulator());

            while (m_Enable)
            {
                m_Time.Sample();
                updater.Working(new Timestamp(m_Time.Now, m_Time.Delta));
                wait.Operate();
            }

            updater.Shutdown();
        }
Esempio n. 20
0
        public void PushUser(IUser user)
        {
            user.VerifySuccessEvent += id =>
            {
                if (NewUserEvent != null)
                {
                    NewUserEvent(id);
                }

                NewUserEvent += user.OnKick;
            };

            user.QuitEvent += () =>
            {
                NewUserEvent -= user.OnKick;
                _Users.Remove(user);
            };
            _Users.Add(user);
        }
Esempio n. 21
0
        private static void Main(string[] args)
        {
            var view = new ConsoleViewer();
            var input = new ConsoleInput(view);
            ICore core = null; // _LoadGame("Game.dll");

            var client = new Client(view, input);

            client.ModeSelectorEvent += new ModeCreator(core).OnSelect;

            var updater = new Updater();
            updater.Add(client);

            // updater.Add(core);
            while(client.Enable)
            {
                input.Update();
                updater.Working();
            }

            updater.Shutdown();
        }
Esempio n. 22
0
        public void TestFullFlow()
        {
            SocketMessageFactory spawner       = SocketMessageFactory.Instance;
            IPEndPoint           hostEndpoint  = new IPEndPoint(IPAddress.Parse("0.0.0.1"), 0);
            IPEndPoint           agentEndpoint = new IPEndPoint(IPAddress.Parse("0.0.0.2"), 0);

            FakeSocket hostSocket  = new FakeSocket(hostEndpoint);
            FakeSocket agentSocket = new FakeSocket(agentEndpoint);

            hostSocket.SendEvent += (pkg) =>
            {
                Package.SocketMessage package = spawner.Spawn();
                package.SetEndPoint(hostEndpoint);
                Buffer.BlockCopy(pkg.Package, 0, package.Package, 0, pkg.Package.Length);

                agentSocket.Receive(package);
            };
            agentSocket.SendEvent += (pkg) =>
            {
                Package.SocketMessage package = spawner.Spawn();
                package.SetEndPoint(agentEndpoint);
                Buffer.BlockCopy(pkg.Package, 0, package.Package, 0, pkg.Package.Length);

                hostSocket.Receive(package);
            };

            Host   host       = new Regulus.Network.Host(hostSocket, hostSocket);
            Agent  agent      = new Regulus.Network.Agent(agentSocket, agentSocket);
            Socket clientPeer = agent.Connect(hostEndpoint, (connect_result) => { });

            Updater <Timestamp> updater = new Updater <Timestamp>();

            updater.Add(hostSocket);
            updater.Add(agentSocket);
            updater.Add(host);
            updater.Add(agent);

            long ticks = 0;


            Socket rudpSocket = null;

            host.AcceptEvent += p => rudpSocket = p;

            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));

            Assert.AreNotEqual(null, rudpSocket);
            Assert.AreEqual(PeerStatus.Transmission, clientPeer.Status);


            byte[] sendBuffer = new byte[] { 1, 2, 3, 4, 5 };
            clientPeer.Send(sendBuffer, 0, sendBuffer.Length);


            int readCount = 0;

            byte[]     receivedBuffer = new byte[Config.Default.PackageSize];
            Task <int> task           = rudpSocket.Receive(receivedBuffer, 0, receivedBuffer.Length);



            Task waitTask = task.ContinueWith(t =>
            {
                readCount = t.Result;
            });

            while (readCount == 0)
            {
                updater.Working(new Timestamp(ticks++, 1));
            }

            Assert.AreEqual(sendBuffer.Length, readCount);

            clientPeer.Disconnect();



            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));
            updater.Working(new Timestamp(ticks++, 1));

            Assert.AreEqual(PeerStatus.Close, rudpSocket.Status);
        }
Esempio n. 23
0
        public override void Bind(Entity result, Main main, bool creating = false)
        {
            Factory.Get<DynamicMapFactory>().Bind(result, main);

            Transform transform = result.Get<Transform>();
            DynamicMap map = result.Get<DynamicMap>();
            PointLight light = result.Get<PointLight>();

            Sound blastFireSound = result.Get<Sound>("BlastFireSound");
            blastFireSound.Add(new Binding<Vector3>(blastFireSound.Position, transform.Position));
            blastFireSound.Add(new Binding<Vector3>(blastFireSound.Velocity, map.LinearVelocity));

            Sound blastChargeSound = result.Get<Sound>("BlastChargeSound");
            blastChargeSound.Add(new Binding<Vector3>(blastChargeSound.Position, transform.Position));
            blastChargeSound.Add(new Binding<Vector3>(blastChargeSound.Velocity, map.LinearVelocity));

            map.Add(new CommandBinding(map.CompletelyEmptied, delegate()
            {
                if (!main.EditorEnabled)
                    result.Delete.Execute();
            }));

            EntityRotator rotator = null;
            EntityMover mover = null;
            if (!main.EditorEnabled)
            {
                rotator = new EntityRotator(map.PhysicsEntity);
                main.Space.Add(rotator);

                mover = new EntityMover(map.PhysicsEntity);
                mover.TargetPosition = transform.Position;
                main.Space.Add(mover);
            }

            Map.Coordinate blastSource = map.GetCoordinate(0, 0, 0);
            Map.Coordinate blastPosition = blastSource;
            Map.CellState criticalMaterial = WorldFactory.StatesByName["Critical"];
            foreach (Map.Box box in map.Chunks.SelectMany(x => x.Boxes))
            {
                if (box.Type == criticalMaterial)
                {
                    blastSource = map.GetCoordinate(box.X, box.Y, box.Z);
                    blastPosition = map.GetCoordinate(box.X, box.Y, box.Z - 3);
                    break;
                }
            }

            Property<float> blastIntervalTime = result.GetProperty<float>("BlastInterval");
            float blastInterval = 0.0f;

            Property<float> playerPositionMemoryTime = result.GetProperty<float>("PlayerPositionMemoryTime");
            float timeSinceLastSpottedPlayer = playerPositionMemoryTime;

            Property<float> visibilityCheckInterval = result.GetProperty<float>("VisibilityCheckInterval");
            float timeSinceLastVisibilityCheck = 0.0f;

            Property<float> blastChargeTime = result.GetProperty<float>("BlastChargeTime");
            float blastCharge = 0.0f;

            Property<float> blastSpeed = result.GetProperty<float>("BlastSpeed");
            Property<float> playerDetectionRadius = result.GetProperty<float>("PlayerDetectionRadius");

            Updater update = new Updater();
            update.Add(delegate(float dt)
                {
                    if (map[blastSource].ID == 0)
                    {
                        update.Delete.Execute();
                        if (rotator != null)
                        {
                            main.Space.Remove(rotator);
                            main.Space.Remove(mover);
                        }
                        light.Delete.Execute();
                        return;
                    }
                    Entity player = PlayerFactory.Instance;
                    if (player != null)
                    {
                        Vector3 playerPosition = player.Get<Transform>().Position.Value;

                        Vector3 rayStart = map.GetAbsolutePosition(blastPosition);

                        Vector3 rayDirection = playerPosition - rayStart;
                        rayDirection.Normalize();

                        timeSinceLastVisibilityCheck += dt;
                        if (timeSinceLastVisibilityCheck > visibilityCheckInterval)
                        {
                            if ((playerPosition - transform.Position).Length() < playerDetectionRadius)
                                timeSinceLastSpottedPlayer = 0.0f;
                            else if (Vector3.Dot(rayDirection, map.GetAbsoluteVector(Vector3.Forward)) > 0)
                            {
                                RayCastResult hit;
                                if (main.Space.RayCast(new Ray(rayStart, rayDirection), out hit))
                                {
                                    EntityCollidable collidable = hit.HitObject as EntityCollidable;
                                    if (collidable != null && collidable.Entity.Tag is Player)
                                        timeSinceLastSpottedPlayer = 0.0f;
                                }
                            }
                            timeSinceLastVisibilityCheck = 0.0f;
                        }
                        timeSinceLastSpottedPlayer += dt;

                        light.Attenuation.Value = 0.0f;
                        if (timeSinceLastSpottedPlayer < playerPositionMemoryTime)
                        {
                            rotator.TargetOrientation = Quaternion.CreateFromRotationMatrix(Matrix.Invert(Matrix.CreateLookAt(rayStart, playerPosition, Vector3.Up)));
                            if (blastInterval > blastIntervalTime)
                            {
                                if (blastCharge < blastChargeTime)
                                {
                                    if (blastCharge == 0.0f)
                                        blastChargeSound.Play.Execute();
                                    blastCharge += dt;
                                    light.Position.Value = rayStart;
                                    light.Attenuation.Value = (blastCharge / blastChargeTime) * 30.0f;
                                }
                                else
                                {
                                    blastCharge = 0.0f;
                                    blastFireSound.Play.Execute();
                                    blastInterval = 0.0f;
                                    Entity blast = Factory.CreateAndBind(main, "Blast");

                                    PhysicsBlock physics = blast.Get<PhysicsBlock>();
                                    Transform blastTransform = blast.Get<Transform>();
                                    blastTransform.Position.Value = rayStart;
                                    physics.LinearVelocity.Value = (rayDirection * blastSpeed) + new Vector3(0.0f, 6.0f, 0.0f);
                                    main.Add(blast);
                                }
                            }
                            else
                            {
                                blastInterval += dt;
                                blastCharge = 0.0f;
                            }
                        }
                        else
                            blastCharge = 0.0f;
                    }
                });
            result.Add("Update", update);
        }
Esempio n. 24
0
        public override void Bind(Entity result, Main main, bool creating = false)
        {
            base.Bind(result, main);

            Transform transform = result.Get<Transform>();
            DynamicMap map = result.Get<DynamicMap>();

            Direction initialDirection = result.GetProperty<Direction>("Direction");
            Direction dir = initialDirection;

            Entity.Handle limit1 = result.GetProperty<Entity.Handle>("Limit 1");
            Entity.Handle limit2 = result.GetProperty<Entity.Handle>("Limit 2");

            Property<bool> isAtStart = new Property<bool> { Editable = false, Serialize = false };
            Property<bool> isAtEnd = new Property<bool> { Editable = false, Serialize = false };
            result.Add("IsAtStart", isAtStart);
            result.Add("IsAtEnd", isAtEnd);

            EntityMover mover = null;
            EntityRotator rotator = null;
            if (!main.EditorEnabled)
            {
                mover = new EntityMover(map.PhysicsEntity);
                mover.TargetPosition = transform.Position;
                main.Space.Add(mover);
                rotator = new EntityRotator(map.PhysicsEntity);
                rotator.TargetOrientation = transform.Quaternion;
                main.Space.Add(rotator);
            }

            Vector3 targetPosition = transform.Position;

            Property<float> speed = result.GetProperty<float>("Speed");
            Property<bool> stopOnEnd = result.GetProperty<bool>("StopOnEnd");

            Updater update = null;
            update = new Updater
            {
                delegate(float dt)
                {
                    if (!result.Active || limit1.Target == null || limit2.Target == null)
                        return;

                    float currentLocation = targetPosition.GetComponent(dir);

                    targetPosition = targetPosition.SetComponent(dir, currentLocation + dt * speed);

                    mover.TargetPosition = targetPosition;

                    float limit1Location = limit1.Target.Get<Transform>().Position.Value.GetComponent(dir);
                    float limit2Location = limit2.Target.Get<Transform>().Position.Value.GetComponent(dir);
                    float limitLocation = Math.Max(limit1Location, limit2Location);
                    if (currentLocation > limitLocation)
                    {
                        dir = dir.GetReverse();
                        if (limitLocation == limit1Location)
                        {
                            isAtStart.Value = true;
                            isAtEnd.Value = false;
                        }
                        else
                        {
                            isAtStart.Value = false;
                            isAtEnd.Value = true;
                        }
                        if (stopOnEnd)
                            update.Enabled.Value = false;
                    }
                }
            };
            update.Add(new TwoWayBinding<bool>(result.GetProperty<bool>("Enabled"), update.Enabled));

            result.Add(update);
        }
Esempio n. 25
0
 private void _Add(Controller <TUser> controller)
 {
     _Controllers.Add(controller);
     _Updater.Add(controller.User);
 }
Esempio n. 26
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Main.Config settings  = main.Settings;
            Transform   transform = entity.GetOrCreate <Transform>("Transform");

            entity.CannotSuspend = true;

            PlayerFactory.Instance = entity;

            this.SetMain(entity, main);

            FPSInput input = new FPSInput();

            input.EnabledWhenPaused = false;
            entity.Add("Input", input);

            Updater parkour = entity.Create <Updater>();
            Updater jumper  = entity.Create <Updater>();

            Player player = entity.GetOrCreate <Player>("Player");

            AnimatedModel firstPersonModel = entity.GetOrCreate <AnimatedModel>("FirstPersonModel");

            firstPersonModel.MapContent            = false;
            firstPersonModel.Serialize             = false;
            firstPersonModel.Filename.Value        = "Models\\joan-firstperson";
            firstPersonModel.CullBoundingBox.Value = false;

            AnimatedModel model = entity.GetOrCreate <AnimatedModel>("Model");

            model.MapContent            = false;
            model.Serialize             = false;
            model.Filename.Value        = "Models\\joan";
            model.CullBoundingBox.Value = false;

            AnimationController anim       = entity.GetOrCreate <AnimationController>("AnimationController");
            RotationController  rotation   = entity.GetOrCreate <RotationController>("Rotation");
            BlockPredictor      predictor  = entity.GetOrCreate <BlockPredictor>("BlockPredictor");
            Jump             jump          = entity.GetOrCreate <Jump>("Jump");
            RollKickSlide    rollKickSlide = entity.GetOrCreate <RollKickSlide>("RollKickSlide");
            Vault            vault         = entity.GetOrCreate <Vault>("Vault");
            WallRun          wallRun       = entity.GetOrCreate <WallRun>("WallRun");
            VoxelTools       voxelTools    = entity.GetOrCreate <VoxelTools>("VoxelTools");
            Footsteps        footsteps     = entity.GetOrCreate <Footsteps>("Footsteps");
            FallDamage       fallDamage    = entity.GetOrCreate <FallDamage>("FallDamage");
            CameraController cameraControl = entity.GetOrCreate <CameraController>("CameraControl");
            FPSCamera        fpsCamera     = entity.GetOrCreate <FPSCamera>("FPSCamera");

            fpsCamera.Enabled.Value = false;
            Rumble rumble = entity.GetOrCreate <Rumble>("Rumble");

            Property <Vector3> floor = new Property <Vector3>();

            transform.Add(new Binding <Vector3>(floor, () => transform.Position + new Vector3(0, player.Character.Height * -0.5f, 0), transform.Position, player.Character.Height));
            AkGameObjectTracker.Attach(entity, floor);

            predictor.Add(new Binding <Vector3>(predictor.FootPosition, floor));
            predictor.Add(new Binding <Vector3>(predictor.LinearVelocity, player.Character.LinearVelocity));
            predictor.Add(new Binding <float>(predictor.Rotation, rotation.Rotation));
            predictor.Add(new Binding <float>(predictor.MaxSpeed, player.Character.MaxSpeed));
            predictor.Add(new Binding <float>(predictor.JumpSpeed, player.Character.JumpSpeed));
            predictor.Add(new Binding <bool>(predictor.IsSupported, player.Character.IsSupported));

            jump.Add(new Binding <bool>(jump.Crouched, player.Character.Crouched));
            jump.Add(new TwoWayBinding <bool>(player.Character.IsSupported, jump.IsSupported));
            jump.Add(new TwoWayBinding <bool>(player.Character.HasTraction, jump.HasTraction));
            jump.Add(new TwoWayBinding <Vector3>(player.Character.LinearVelocity, jump.LinearVelocity));
            jump.Add(new TwoWayBinding <BEPUphysics.Entities.Entity>(jump.SupportEntity, player.Character.SupportEntity));
            jump.Add(new TwoWayBinding <Vector3>(jump.SupportVelocity, player.Character.SupportVelocity));
            jump.Add(new Binding <Vector2>(jump.AbsoluteMovementDirection, player.Character.MovementDirection));
            jump.Add(new Binding <WallRun.State>(jump.WallRunState, wallRun.CurrentState));
            jump.Add(new Binding <float>(jump.Rotation, rotation.Rotation));
            jump.Add(new Binding <Vector3>(jump.Position, transform.Position));
            jump.Add(new Binding <Vector3>(jump.FloorPosition, floor));
            jump.Add(new Binding <float>(jump.MaxSpeed, player.Character.MaxSpeed));
            jump.Add(new Binding <float>(jump.JumpSpeed, player.Character.JumpSpeed));
            jump.Add(new Binding <float>(jump.Mass, player.Character.Mass));
            jump.Add(new Binding <float>(jump.LastRollKickEnded, rollKickSlide.LastRollKickEnded));
            jump.Add(new Binding <Voxel>(jump.WallRunMap, wallRun.WallRunVoxel));
            jump.Add(new Binding <Direction>(jump.WallDirection, wallRun.WallDirection));
            jump.Add(new CommandBinding <Voxel, Voxel.Coord, Direction>(jump.WalkedOn, footsteps.WalkedOn));
            jump.Add(new CommandBinding(jump.DeactivateWallRun, (Action)wallRun.Deactivate));
            jump.Add(new CommandBinding <float>(jump.FallDamage, fallDamage.ApplyJump));
            jump.Predictor = predictor;
            jump.Bind(model);
            jump.Add(new TwoWayBinding <Voxel>(wallRun.LastWallRunMap, jump.LastWallRunMap));
            jump.Add(new TwoWayBinding <Direction>(wallRun.LastWallDirection, jump.LastWallDirection));
            jump.Add(new TwoWayBinding <bool>(rollKickSlide.CanKick, jump.CanKick));
            jump.Add(new TwoWayBinding <float>(player.Character.LastSupportedSpeed, jump.LastSupportedSpeed));

            wallRun.Add(new Binding <bool>(wallRun.IsSwimming, player.Character.IsSwimming));
            wallRun.Add(new TwoWayBinding <Vector3>(player.Character.LinearVelocity, wallRun.LinearVelocity));
            wallRun.Add(new TwoWayBinding <Vector3>(transform.Position, wallRun.Position));
            wallRun.Add(new TwoWayBinding <bool>(player.Character.IsSupported, wallRun.IsSupported));
            wallRun.Add(new CommandBinding(wallRun.LockRotation, (Action)rotation.Lock));
            wallRun.Add(new CommandBinding <float>(wallRun.UpdateLockedRotation, rotation.UpdateLockedRotation));
            vault.Add(new CommandBinding(wallRun.Vault, delegate() { vault.Go(true); }));
            wallRun.Predictor = predictor;
            wallRun.Add(new Binding <float>(wallRun.Height, player.Character.Height));
            wallRun.Add(new Binding <float>(wallRun.JumpSpeed, player.Character.JumpSpeed));
            wallRun.Add(new Binding <float>(wallRun.MaxSpeed, player.Character.MaxSpeed));
            wallRun.Add(new TwoWayBinding <float>(rotation.Rotation, wallRun.Rotation));
            wallRun.Add(new TwoWayBinding <bool>(player.Character.AllowUncrouch, wallRun.AllowUncrouch));
            wallRun.Add(new TwoWayBinding <bool>(player.Character.HasTraction, wallRun.HasTraction));
            wallRun.Add(new Binding <float>(wallRun.LastWallJump, jump.LastWallJump));
            player.Add(new Binding <WallRun.State>(player.Character.WallRunState, wallRun.CurrentState));

            input.Bind(rollKickSlide.RollKickButton, settings.RollKick);
            rollKickSlide.Add(new Binding <bool>(rollKickSlide.EnableCrouch, player.EnableCrouch));
            rollKickSlide.Add(new Binding <float>(rollKickSlide.Rotation, rotation.Rotation));
            rollKickSlide.Add(new Binding <bool>(rollKickSlide.IsSwimming, player.Character.IsSwimming));
            rollKickSlide.Add(new Binding <bool>(rollKickSlide.IsSupported, player.Character.IsSupported));
            rollKickSlide.Add(new Binding <Vector3>(rollKickSlide.FloorPosition, floor));
            rollKickSlide.Add(new Binding <float>(rollKickSlide.Height, player.Character.Height));
            rollKickSlide.Add(new Binding <float>(rollKickSlide.MaxSpeed, player.Character.MaxSpeed));
            rollKickSlide.Add(new Binding <float>(rollKickSlide.JumpSpeed, player.Character.JumpSpeed));
            rollKickSlide.Add(new Binding <Vector3>(rollKickSlide.SupportVelocity, player.Character.SupportVelocity));
            rollKickSlide.Add(new TwoWayBinding <bool>(wallRun.EnableEnhancedWallRun, rollKickSlide.EnableEnhancedRollSlide));
            rollKickSlide.Add(new TwoWayBinding <bool>(player.Character.AllowUncrouch, rollKickSlide.AllowUncrouch));
            rollKickSlide.Add(new TwoWayBinding <bool>(player.Character.Crouched, rollKickSlide.Crouched));
            rollKickSlide.Add(new TwoWayBinding <bool>(player.Character.EnableWalking, rollKickSlide.EnableWalking));
            rollKickSlide.Add(new TwoWayBinding <Vector3>(player.Character.LinearVelocity, rollKickSlide.LinearVelocity));
            rollKickSlide.Add(new TwoWayBinding <Vector3>(transform.Position, rollKickSlide.Position));
            rollKickSlide.Predictor = predictor;
            rollKickSlide.Bind(model);
            rollKickSlide.VoxelTools = voxelTools;
            rollKickSlide.Add(new CommandBinding(rollKickSlide.DeactivateWallRun, (Action)wallRun.Deactivate));
            rollKickSlide.Add(new CommandBinding(rollKickSlide.Footstep, footsteps.Footstep));
            rollKickSlide.Add(new CommandBinding(rollKickSlide.LockRotation, (Action)rotation.Lock));
            SoundKiller.Add(entity, AK.EVENTS.STOP_PLAYER_SLIDE_LOOP);

            vault.Add(new Binding <Vector3>(vault.Position, transform.Position));
            vault.Add(new Binding <Vector3>(vault.FloorPosition, floor));
            vault.Add(new Binding <float>(vault.MaxSpeed, player.Character.MaxSpeed));
            vault.Add(new Binding <WallRun.State>(vault.WallRunState, wallRun.CurrentState));
            vault.Add(new CommandBinding(vault.LockRotation, (Action)rotation.Lock));
            vault.Add(new CommandBinding(vault.DeactivateWallRun, (Action)wallRun.Deactivate));
            vault.Add(new TwoWayBinding <float>(player.Character.LastSupportedSpeed, vault.LastSupportedSpeed));
            vault.Add(new CommandBinding <float>(vault.FallDamage, fallDamage.Apply));
            vault.Bind(model);
            vault.Predictor = predictor;
            vault.Add(new TwoWayBinding <float>(rotation.Rotation, vault.Rotation));
            vault.Add(new TwoWayBinding <bool>(player.Character.IsSupported, vault.IsSupported));
            vault.Add(new TwoWayBinding <bool>(player.Character.HasTraction, vault.HasTraction));
            vault.Add(new TwoWayBinding <Vector3>(player.Character.LinearVelocity, vault.LinearVelocity));
            vault.Add(new TwoWayBinding <bool>(player.Character.EnableWalking, vault.EnableWalking));
            vault.Add(new TwoWayBinding <bool>(player.Character.AllowUncrouch, vault.AllowUncrouch));
            vault.Add(new TwoWayBinding <bool>(player.Character.Crouched, vault.Crouched));
            vault.Add(new Binding <float>(vault.Radius, player.Character.Radius));

            rotation.Add(new TwoWayBinding <Vector2>(rotation.Mouse, input.Mouse));
            rotation.Add(new Binding <bool>(rotation.Rolling, rollKickSlide.Rolling));
            rotation.Add(new Binding <bool>(rotation.Kicking, rollKickSlide.Kicking));
            rotation.Add(new Binding <Vault.State>(rotation.VaultState, vault.CurrentState));
            rotation.Add(new Binding <WallRun.State>(rotation.WallRunState, wallRun.CurrentState));

            voxelTools.Add(new Binding <float>(voxelTools.Height, player.Character.Height));
            voxelTools.Add(new Binding <float>(voxelTools.SupportHeight, player.Character.SupportHeight));
            voxelTools.Add(new Binding <Vector3>(voxelTools.Position, transform.Position));

            anim.Add(new Binding <bool>(anim.IsSupported, player.Character.IsSupported));
            anim.Add(new Binding <WallRun.State>(anim.WallRunState, wallRun.CurrentState));
            anim.Add(new Binding <bool>(anim.EnableWalking, player.Character.EnableWalking));
            anim.Add(new Binding <bool>(anim.Crouched, player.Character.Crouched));
            anim.Add(new Binding <Vector3>(anim.LinearVelocity, player.Character.LinearVelocity));
            anim.Add(new Binding <Vector2>(anim.Movement, input.Movement));
            anim.Add(new Binding <Vector2>(anim.Mouse, input.Mouse));
            anim.Add(new Binding <float>(anim.Rotation, rotation.Rotation));
            anim.Add(new Binding <Voxel>(anim.WallRunMap, wallRun.WallRunVoxel));
            anim.Add(new Binding <Direction>(anim.WallDirection, wallRun.WallDirection));
            anim.Add(new Binding <bool>(anim.IsSwimming, player.Character.IsSwimming));
            anim.Add(new Binding <bool>(anim.Kicking, rollKickSlide.Kicking));
            anim.Add(new Binding <Vector3>(anim.SupportVelocity, player.Character.SupportVelocity));
            anim.Add
            (
                new Binding <bool>
                (
                    anim.EnableLean,
                    () => player.Character.EnableWalking.Value && player.Character.IsSupported.Value && input.Movement.Value.Y > 0.5f,
                    player.Character.EnableWalking, player.Character.IsSupported, input.Movement
                )
            );
            anim.Bind(model);

            // Camera control
            model.UpdateWorldTransforms();

            cameraControl.Add(new Binding <Vector2>(cameraControl.Mouse, input.Mouse));
            cameraControl.Add(new Binding <float>(cameraControl.Lean, x => x * (float)Math.PI * 0.05f, anim.Lean));
            cameraControl.Add(new Binding <Vector3>(cameraControl.LinearVelocity, player.Character.LinearVelocity));
            cameraControl.Add(new Binding <float>(cameraControl.MaxSpeed, player.Character.MaxSpeed));
            cameraControl.Add(new Binding <Matrix>(cameraControl.CameraBone, model.GetBoneTransform("Camera")));
            cameraControl.Add(new Binding <Matrix>(cameraControl.HeadBone, model.GetBoneTransform("ORG-head")));
            cameraControl.Add(new Binding <Matrix>(cameraControl.ModelTransform, model.Transform));
            cameraControl.Add(new Binding <float>(cameraControl.BaseCameraShakeAmount, () => MathHelper.Clamp((player.Character.LinearVelocity.Value.Length() - (player.Character.MaxSpeed * 2.5f)) / (player.Character.MaxSpeed * 4.0f), 0, 1), player.Character.LinearVelocity, player.Character.MaxSpeed));
            cameraControl.Offset = model.GetBoneTransform("Camera").Value.Translation - model.GetBoneTransform("ORG-head").Value.Translation;

            float heightOffset = 0.1f;

#if VR
            if (main.VR)
            {
                heightOffset = 0.4f;
            }
#endif
            cameraControl.Offset += new Vector3(0, heightOffset, 0);

            rumble.Add(new Binding <float>(rumble.CameraShake, cameraControl.TotalCameraShake));
            rumble.Add(new CommandBinding <float>(fallDamage.Rumble, rumble.Go));
            rumble.Add(new CommandBinding <float>(player.Rumble, rumble.Go));
            rumble.Add(new CommandBinding <float>(rollKickSlide.Rumble, rumble.Go));

            firstPersonModel.Add(new Binding <bool>(firstPersonModel.Enabled, x => !x, cameraControl.ThirdPerson));

            model.Add(new ChangeBinding <bool>(cameraControl.ThirdPerson, delegate(bool old, bool value)
            {
                if (value && !old)
                {
                    model.UnsupportedTechniques.Remove(Technique.Clip);
                    model.UnsupportedTechniques.Remove(Technique.Render);
                }
                else if (old && !value)
                {
                    model.UnsupportedTechniques.Add(Technique.Clip);
                    model.UnsupportedTechniques.Add(Technique.Render);
                }
            }));

            Lemma.Console.Console.AddConCommand(new Console.ConCommand("third_person", "Toggle third-person view (WARNING: EXPERIMENTAL)", delegate(Console.ConCommand.ArgCollection args)
            {
                cameraControl.ThirdPerson.Value = !cameraControl.ThirdPerson;
            }));
            entity.Add(new CommandBinding(entity.Delete, delegate()
            {
                Lemma.Console.Console.RemoveConCommand("third_person");
            }));

#if DEVELOPMENT
            ModelAlpha debugCylinder = new ModelAlpha();
            debugCylinder.Filename.Value = "AlphaModels\\cylinder";
            debugCylinder.Add(new Binding <Matrix>(debugCylinder.Transform, transform.Matrix));
            debugCylinder.Serialize   = false;
            debugCylinder.Alpha.Value = 0.25f;
            debugCylinder.Add(new Binding <bool>(debugCylinder.Enabled, cameraControl.ThirdPerson));
            debugCylinder.Add(new Binding <Vector3>(debugCylinder.Scale, delegate()
            {
                return(new Vector3(player.Character.Radius * 2.0f, player.Character.Height, player.Character.Radius * 2.0f));
            }, player.Character.Height, player.Character.Radius));
            entity.Add(debugCylinder);
#endif

            // When rotation is locked, we want to make sure the player can't turn their head
            // 180 degrees from the direction they're facing

#if VR
            if (main.VR)
            {
                input.MaxY.Value = input.MinY.Value = 0;
            }
            else
#endif
            input.Add(new Binding <float>(input.MaxY, () => rotation.Locked ? (float)Math.PI * 0.3f : (float)Math.PI * 0.4f, rotation.Locked));

            input.Add(new Binding <float>(input.MinX, () => rotation.Locked ? rotation.Rotation + ((float)Math.PI * -0.4f) : 0.0f, rotation.Rotation, rotation.Locked));
            input.Add(new Binding <float>(input.MaxX, () => rotation.Locked ? rotation.Rotation + ((float)Math.PI * 0.4f) : 0.0f, rotation.Rotation, rotation.Locked));
            input.Add(new NotifyBinding(delegate() { input.Mouse.Changed(); }, rotation.Locked));             // Make sure the rotation locking takes effect even if the player doesn't move the mouse

            // Setup rendering properties

            model.Materials = firstPersonModel.Materials = new Model.Material[3];

            // Hoodie and shoes
            model.Materials[0] = new Model.Material
            {
                SpecularIntensity = 0.0f,
                SpecularPower     = 1.0f,
            };

            // Hands
            model.Materials[1] = new Model.Material
            {
                SpecularIntensity = 0.3f,
                SpecularPower     = 2.0f,
            };

            // Pants and skin
            model.Materials[2] = new Model.Material
            {
                SpecularIntensity = 0.5f,
                SpecularPower     = 20.0f,
            };

            firstPersonModel.Bind(model);

            // Third person model only gets rendered for shadows. No regular rendering or reflections.
            model.UnsupportedTechniques.Add(Technique.Clip);
            model.UnsupportedTechniques.Add(Technique.Render);

            // First-person model only used for regular rendering. No shadows or reflections.
            firstPersonModel.UnsupportedTechniques.Add(Technique.Shadow);
            firstPersonModel.UnsupportedTechniques.Add(Technique.Clip);

            // Build UI
            UIRenderer ui = new UIRenderer();
            ui.DrawOrder.Value   = -1;
            ui.EnabledWhenPaused = true;
            ui.EnabledInEditMode = false;
            entity.Add("UI", ui);

            input.Add(new Binding <float>(input.MouseSensitivity, settings.MouseSensitivity));
            input.Add(new Binding <bool>(input.InvertMouseX, settings.InvertMouseX));
            input.Add(new Binding <bool>(input.InvertMouseY, settings.InvertMouseY));
            input.Add(new Binding <PCInput.PCInputBinding>(input.LeftKey, settings.Left));
            input.Add(new Binding <PCInput.PCInputBinding>(input.RightKey, settings.Right));
            input.Add(new Binding <PCInput.PCInputBinding>(input.BackwardKey, settings.Backward));
            input.Add(new Binding <PCInput.PCInputBinding>(input.ForwardKey, settings.Forward));

            model.StartClip("Idle", 0, true, AnimatedModel.DefaultBlendTime);

            // Set up AI agent
            Agent agent = entity.GetOrCreate <Agent>();
            agent.Add(new TwoWayBinding <float>(player.Health, agent.Health));
            agent.Add(new Binding <Vector3>(agent.Position, () => transform.Position.Value + new Vector3(0, player.Character.Height * -0.5f, 0), transform.Position, player.Character.Height));
            agent.Add(new Binding <bool>(agent.Loud, () => player.Character.MovementDirection.Value.LengthSquared() > 0 && !player.Character.Crouched, player.Character.Crouched));

            // Blocks
            BlockCloud blockCloud = entity.GetOrCreate <BlockCloud>("BlockCloud");
            blockCloud.Scale.Value = 0.5f;
            blockCloud.Add(new Binding <Vector3>(blockCloud.Position, () => transform.Position.Value + new Vector3(0, player.Character.Height + player.Character.LinearVelocity.Value.Y, 0), transform.Position, player.Character.Height, player.Character.LinearVelocity));
            blockCloud.Blocks.ItemAdded += delegate(int index, Entity.Handle block)
            {
                Entity e = block.Target;
                if (e != null)
                {
                    e.Serialize = false;
                    PhysicsBlock.CancelPlayerCollisions(e.Get <PhysicsBlock>());
                }
            };

            PointLight blockLight = entity.Create <PointLight>();
            blockLight.Add(new Binding <Vector3>(blockLight.Position, blockCloud.AveragePosition));
            blockLight.Add(new Binding <bool, int>(blockLight.Enabled, x => x > 0, blockCloud.Blocks.Length));
            blockLight.Attenuation.Value = 30.0f;
            blockLight.Add(new Binding <Vector3, Voxel.t>(blockLight.Color, delegate(Voxel.t t)
            {
                switch (t)
                {
                case Voxel.t.GlowBlue:
                    return(new Vector3(0.7f, 0.7f, 0.9f));

                case Voxel.t.GlowYellow:
                    return(new Vector3(0.9f, 0.9f, 0.7f));

                default:
                    return(new Vector3(0.8f, 0.8f, 0.8f));
                }
            }, blockCloud.Type));

            // Death
            entity.Add(new CommandBinding(player.Die, blockCloud.Clear));
            entity.Add(new CommandBinding(player.Die, delegate()
            {
                Session.Recorder.Event(main, "Die");
                if (agent.Killed || Agent.Query(transform.Position, 0.0f, 10.0f, x => x != agent) != null)
                {
                    Session.Recorder.Event(main, "Killed");
                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_PLAYER_DEATH, entity);
                    main.Spawner.RespawnDistance = Spawner.KilledRespawnDistance;
                    main.Spawner.RespawnInterval = Spawner.KilledRespawnInterval;
                }
                entity.Add(new Animation(new Animation.Execute(entity.Delete)));
            }));

            player.EnabledInEditMode = false;

            Action updateFallSound = delegate()
            {
                float speed    = player.Character.LinearVelocity.Value.Length();
                float maxSpeed = player.Character.MaxSpeed * 1.25f;
                float value;
                if (speed > maxSpeed)
                {
                    value = (speed - maxSpeed) / (maxSpeed * 2.0f);
                }
                else
                {
                    value = 0.0f;
                }
                AkSoundEngine.SetRTPCValue(AK.GAME_PARAMETERS.SFX_PLAYER_FALL, value);
            };
            updateFallSound();
            AkSoundEngine.PostEvent(AK.EVENTS.PLAY_PLAYER_FALL, entity);
            player.Add(new NotifyBinding(updateFallSound, player.Character.LinearVelocity));
            SoundKiller.Add(entity, AK.EVENTS.STOP_PLAYER_FALL);

            player.Add(new TwoWayBinding <Matrix>(transform.Matrix, player.Character.Transform));

            model.Add(new Binding <Matrix>(model.Transform, delegate()
            {
                const float leanAmount = (float)Math.PI * 0.1f;
                return(Matrix.CreateTranslation(0, (player.Character.Height * -0.5f) - player.Character.SupportHeight, 0) * Matrix.CreateRotationZ(anim.Lean * leanAmount) * Matrix.CreateRotationY(rotation.Rotation) * transform.Matrix);
            }, transform.Matrix, rotation.Rotation, player.Character.Height, player.Character.SupportHeight, anim.Lean));

            firstPersonModel.Add(new Binding <Matrix>(firstPersonModel.Transform, model.Transform));
            firstPersonModel.Add(new Binding <Vector3>(firstPersonModel.Scale, model.Scale));

            WallRun.State[] footstepWallrunStates = new[]
            {
                WallRun.State.Left,
                WallRun.State.Right,
                WallRun.State.Straight,
                WallRun.State.None,
            };
            footsteps.Add(new Binding <bool>(footsteps.SoundEnabled, () => !player.Character.Crouched && footstepWallrunStates.Contains(wallRun.CurrentState) || (player.Character.IsSupported && player.Character.EnableWalking), player.Character.IsSupported, player.Character.EnableWalking, wallRun.CurrentState, player.Character.Crouched));
            footsteps.Add(new Binding <Vector3>(footsteps.Position, transform.Position));
            footsteps.Add(new Binding <float>(footsteps.Rotation, rotation.Rotation));
            footsteps.Add(new Binding <float>(footsteps.CharacterHeight, player.Character.Height));
            footsteps.Add(new Binding <float>(footsteps.SupportHeight, player.Character.SupportHeight));
            footsteps.Add(new Binding <bool>(footsteps.IsSupported, player.Character.IsSupported));
            footsteps.Add(new Binding <bool>(footsteps.IsSwimming, player.Character.IsSwimming));
            footsteps.Add(new CommandBinding <float>(footsteps.Damage, agent.Damage));
            footsteps.Add(new CommandBinding <Voxel, Voxel.Coord, Direction>(wallRun.WalkedOn, footsteps.WalkedOn));
            model.Trigger("Run", 0.16f, footsteps.Footstep);
            model.Trigger("Run", 0.58f, footsteps.Footstep);
            model.Trigger("WallRunLeft", 0.16f, footsteps.Footstep);
            model.Trigger("WallRunLeft", 0.58f, footsteps.Footstep);
            model.Trigger("WallRunRight", 0.16f, footsteps.Footstep);
            model.Trigger("WallRunRight", 0.58f, footsteps.Footstep);
            model.Trigger("WallRunStraight", 0.16f, footsteps.Footstep);
            model.Trigger("WallRunStraight", 0.58f, footsteps.Footstep);
            model.Trigger("TurnLeft", 0.15f, footsteps.Footstep);
            model.Trigger("TurnRight", 0.15f, footsteps.Footstep);
            model.Trigger("TopOut", 1.0f, new Command
            {
                Action = delegate()
                {
                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_PLAYER_GRUNT, entity);
                }
            });

            main.UI.IsMouseVisible.Value = false;

            SkinnedModel.Clip sprintAnimation = model["Sprint"], runAnimation = model["Run"];

            // Movement binding
            player.Add(new Binding <Vector2>(player.Character.MovementDirection, delegate()
            {
                Vector2 movement = input.Movement;
                if (movement.LengthSquared() == 0.0f)
                {
                    return(Vector2.Zero);
                }

                Matrix matrix = Matrix.CreateRotationY(rotation.Rotation);

                Vector2 forwardDir = new Vector2(matrix.Forward.X, matrix.Forward.Z);
                Vector2 rightDir   = new Vector2(matrix.Right.X, matrix.Right.Z);
                return(-(forwardDir * movement.Y) - (rightDir * movement.X));
            }, input.Movement, rotation.Rotation));

            player.Character.Crouched.Value      = true;
            player.Character.AllowUncrouch.Value = true;

            // Fall damage
            fallDamage.Add(new Binding <bool>(fallDamage.IsSupported, player.Character.IsSupported));
            fallDamage.Add(new TwoWayBinding <Vector3>(player.Character.LinearVelocity, fallDamage.LinearVelocity));
            fallDamage.Add(new TwoWayBinding <float>(player.Health, fallDamage.Health));
            fallDamage.Add(new CommandBinding <BEPUphysics.BroadPhaseEntries.Collidable, ContactCollection>(player.Character.Collided, fallDamage.Collided));
            fallDamage.Add(new TwoWayBinding <bool>(player.Character.EnableWalking, fallDamage.EnableWalking));
            fallDamage.Add(new TwoWayBinding <bool>(player.EnableMoves, fallDamage.EnableMoves));
            fallDamage.Add(new TwoWayBinding <bool>(fallDamage.Landing, rotation.Landing));
            fallDamage.Add(new CommandBinding(fallDamage.LockRotation, (Action)rotation.Lock));
            fallDamage.Add(new CommandBinding <float>(fallDamage.PhysicsDamage, agent.Damage));
            fallDamage.Bind(model);

            // Swim up
            input.Bind(player.Character.SwimUp, settings.Jump);

            float       parkourTime = 0;
            float       jumpTime    = 0;
            const float gracePeriod = 1.0f;
            jumper.Action = delegate(float dt)
            {
                if (player.EnableMoves && player.Character.EnableWalking &&
                    vault.CurrentState.Value == Vault.State.None &&
                    !rollKickSlide.Rolling && !rollKickSlide.Kicking &&
                    jumpTime < gracePeriod)
                {
                    if (jump.Go())
                    {
                        parkour.Enabled.Value = false;
                        jumper.Enabled.Value  = false;
                    }
                    jumpTime += dt;
                }
                else
                {
                    jumper.Enabled.Value = false;
                }
            };
            jumper.Add(new CommandBinding(jumper.Enable, delegate() { jumpTime = 0; }));
            jumper.Enabled.Value = false;
            entity.Add(jumper);

            // Jumping
            input.Bind(settings.Jump, PCInput.InputState.Down, delegate()
            {
                jumper.Enabled.Value = true;
            });

            input.Bind(settings.Jump, PCInput.InputState.Up, delegate()
            {
                jumper.Enabled.Value = false;
            });

            // Wall-run, vault, predictive
            parkour.Action = delegate(float dt)
            {
                if (player.EnableMoves &&
                    player.Character.EnableWalking &&
                    !(player.Character.Crouched && player.Character.IsSupported) &&
                    vault.CurrentState.Value == Vault.State.None &&
                    !rollKickSlide.Kicking &&
                    !rollKickSlide.Rolling &&
                    wallRun.CurrentState.Value == WallRun.State.None &&
                    parkourTime < gracePeriod)
                {
                    bool didSomething = false;

                    bool parkourBeganThisFrame = parkourTime == 0;
                    if (predictor.PossibilityCount > 0)
                    {
                        // In slow motion, prefer left and right wall-running
                        if (!(didSomething = wallRun.Activate(WallRun.State.Left, parkourBeganThisFrame)))
                        {
                            if (!(didSomething = wallRun.Activate(WallRun.State.Right, parkourBeganThisFrame)))
                            {
                                if (!(didSomething = vault.Go(parkourBeganThisFrame)))
                                {
                                    didSomething = wallRun.Activate(WallRun.State.Straight, parkourBeganThisFrame);
                                }
                            }
                        }
                    }
                    else
                    {
                        // In normal mode, prefer straight wall-running
                        if (!(didSomething = vault.Go(parkourBeganThisFrame)))
                        {
                            if (!(didSomething = wallRun.Activate(WallRun.State.Straight, parkourBeganThisFrame)))
                            {
                                if (!(didSomething = wallRun.Activate(WallRun.State.Left, parkourBeganThisFrame)))
                                {
                                    didSomething = wallRun.Activate(WallRun.State.Right, parkourBeganThisFrame);
                                }
                            }
                        }
                    }

                    if (didSomething)
                    {
                        jumper.Enabled.Value    = false;
                        player.SlowMotion.Value = false;
                        parkour.Enabled.Value   = false;
                    }
                    else if (parkourBeganThisFrame)
                    {
                        if (blockCloud.Blocks.Length > 0)
                        {
                            player.SlowMotion.Value = true;
                            predictor.ClearPossibilities();
                            predictor.PredictPlatforms();
                            predictor.PredictWalls();
                        }
                        else if (player.EnableSlowMotion)
                        {
                            player.SlowMotion.Value = true;
                        }
                    }

                    parkourTime += dt;
                }
                else
                {
                    parkour.Enabled.Value = false;
                }
            };
            parkour.Add(new CommandBinding(parkour.Enable, delegate()
            {
                parkourTime = 0;
            }));
            entity.Add(parkour);
            parkour.Enabled.Value = false;

            input.Bind(settings.Parkour, PCInput.InputState.Down, delegate()
            {
                parkour.Enabled.Value = true;
            });

            input.Bind(settings.Parkour, PCInput.InputState.Up, delegate()
            {
                parkour.Enabled.Value = false;
                wallRun.Deactivate();
                if (player.SlowMotion)
                {
                    player.SlowMotion.Value = false;
                }
            });

            input.Bind(settings.RollKick, PCInput.InputState.Down, delegate()
            {
                if (player.EnableMoves && player.Character.EnableWalking)
                {
                    rollKickSlide.Go();
                    parkour.Enabled.Value = false;
                    jumper.Enabled.Value  = false;
                }
            });

            input.Bind(settings.RollKick, PCInput.InputState.Up, delegate()
            {
                if (!rollKickSlide.Rolling && !rollKickSlide.Kicking)
                {
                    player.Character.AllowUncrouch.Value = true;
                }
            });

            // Special ability

            /*
             * input.Bind(settings.SpecialAbility, PCInput.InputState.Down, delegate()
             * {
             *      Voxel.GlobalRaycastResult hit = Voxel.GlobalRaycast(main.Camera.Position, main.Camera.Forward, main.Camera.FarPlaneDistance, null);
             *      if (hit.Voxel != null && hit.Voxel.GetType() != typeof(DynamicVoxel))
             *      {
             *              VoxelRip.Go(hit.Voxel, hit.Coordinate.Value, 7, delegate(List<DynamicVoxel> results)
             *              {
             *                      foreach (DynamicVoxel v in results)
             *                      {
             *                              v.IsAffectedByGravity.Value = false;
             *                              v.LinearVelocity.Value = hit.Voxel.GetAbsoluteVector(hit.Normal.GetVector()) * 7.0f
             + new Vector3((float)this.random.NextDouble() * 2.0f - 1.0f, (float)this.random.NextDouble() * 2.0f - 1.0f, (float)this.random.NextDouble() * 2.0f - 1.0f);
             +                      }
             +              });
             +      }
             + });
             */

            // Player data bindings

            entity.Add(new PostInitialization
            {
                delegate()
                {
                    Entity dataEntity     = PlayerDataFactory.Instance;
                    PlayerData playerData = dataEntity.Get <PlayerData>();

                    // HACK. Overwriting the property rather than binding the two together. Oh well.
                    // This is because I haven't written a two-way list binding.
                    footsteps.RespawnLocations = playerData.RespawnLocations;

                    // Bind player data properties
                    entity.Add(new TwoWayBinding <float>(WorldFactory.Instance.Get <World>().CameraShakeAmount, cameraControl.CameraShakeAmount));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableRoll, rollKickSlide.EnableRoll));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableCrouch, player.EnableCrouch));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableKick, rollKickSlide.EnableKick));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableWallRun, wallRun.EnableWallRun));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableWallRunHorizontal, wallRun.EnableWallRunHorizontal));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableEnhancedWallRun, wallRun.EnableEnhancedWallRun));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableMoves, player.EnableMoves));
                    entity.Add(new TwoWayBinding <float>(playerData.MaxSpeed, player.Character.MaxSpeed));
                    entity.Add(new TwoWayBinding <Voxel.t>(playerData.CloudType, blockCloud.Type));
                    entity.Add(new TwoWayBinding <bool>(playerData.ThirdPerson, cameraControl.ThirdPerson));
                    entity.Add(new TwoWayBinding <bool>(playerData.EnableSlowMotion, player.EnableSlowMotion));

                    Phone phone = dataEntity.GetOrCreate <Phone>("Phone");

                    entity.Add
                    (
                        new Binding <bool>
                        (
                            phone.CanReceiveMessages,
                            () => player.Character.IsSupported && !player.Character.IsSwimming && !player.Character.Crouched,
                            player.Character.IsSupported,
                            player.Character.IsSwimming,
                            player.Character.Crouched
                        )
                    );

                    PhoneNote.Attach(main, entity, player, model, input, phone, player.Character.EnableWalking, playerData.PhoneActive, playerData.NoteActive);

                    PlayerUI.Attach(main, entity, ui, player.Health, rotation.Rotation, playerData.NoteActive, playerData.PhoneActive);
                }
            });

            fpsCamera.Add(new Binding <Vector2>(fpsCamera.Mouse, input.Mouse));
            fpsCamera.Add(new Binding <Vector2>(fpsCamera.Movement, input.Movement));
            input.Bind(fpsCamera.SpeedMode, settings.Parkour);
            input.Bind(fpsCamera.Up, settings.Jump);
            fpsCamera.Add(new Binding <bool>(fpsCamera.Down, input.GetKey(Keys.LeftControl)));
            Lemma.Console.Console.AddConCommand(new ConCommand("noclip", "Toggle free camera mode", delegate(ConCommand.ArgCollection args)
            {
                bool freeCameraMode            = !fpsCamera.Enabled;
                fpsCamera.Enabled.Value        = freeCameraMode;
                cameraControl.Enabled.Value    = !freeCameraMode;
                firstPersonModel.Enabled.Value = !freeCameraMode;
                model.Enabled.Value            = !freeCameraMode;
                ui.Enabled.Value = !freeCameraMode;
                player.Character.EnableWalking.Value      = !freeCameraMode;
                player.EnableMoves.Value                  = !freeCameraMode;
                player.Character.Body.IsAffectedByGravity = !freeCameraMode;
                if (freeCameraMode)
                {
                    AkSoundEngine.PostEvent(AK.EVENTS.STOP_PLAYER_BREATHING_SOFT, entity);
                }
                else
                {
                    transform.Position.Value = main.Camera.Position;
                }
            }));

            entity.Add(new CommandBinding(entity.Delete, delegate()
            {
                Lemma.Console.Console.RemoveConCommand("noclip");
                if (fpsCamera.Enabled)                 // Movement is disabled. Re-enable it.
                {
                    player.Character.EnableWalking.Value = true;
                    player.EnableMoves.Value             = true;
                }
                PlayerFactory.Instance = null;
            }));
        }
 void IBootable.Launch()
 {
     _Updater.Add(_Center);
 }
Esempio n. 28
0
 public static void SubscribeUpdate(Action <float> listener) => mUpdater.Add(listener);
Esempio n. 29
0
 void IBootable.Launch()
 {
     _Update.Add(_Hall);
 }
Esempio n. 30
0
        public static void Run(Entity script)
        {
            Updater         updater = script.Create <Updater>();
            Command         enable  = command(script, "Enable");
            Command         disable = command(script, "Disable");
            Property <bool> enabled = property <bool>(script, "Enabled");

            updater.Add(new Binding <bool>(updater.Enabled, enabled));

            script.Add(new CommandBinding(enable, () => !enabled, delegate()
            {
                enabled.Value = true;
            }));

            script.Add(new CommandBinding(disable, () => enabled, delegate()
            {
                enabled.Value = false;
            }));

            AmbientSound sound = script.Create <AmbientSound>();

            sound.PlayCue.Value = AK.EVENTS.PLAY_MONOLITH_LOOP;
            sound.StopCue.Value = AK.EVENTS.STOP_ALL_OBJECT;
            sound.Add(new Binding <bool>(sound.Enabled, enabled));

            script.Add(new Binding <float, bool>(WorldFactory.Instance.Get <World>().CameraShakeAmount, x => x ? 0.02f : 0.0f, enabled));

            script.Add(new ChangeBinding <bool>(enabled, delegate(bool old, bool value)
            {
                if (!old && value)
                {
                    enable.Execute();
                }
                else if (old && !value)
                {
                    disable.Execute();
                }
            }));

            RiftFactory riftFactory = Factory.Get <RiftFactory>();
            const float minInterval = 3.0f;
            const float maxInterval = 8.0f;
            float       interval    = minInterval + (float)random.NextDouble() * (maxInterval - minInterval);

            updater.Action = delegate(float dt)
            {
                Entity player = PlayerFactory.Instance;
                if (player != null)
                {
                    interval -= dt;
                    if (interval < 0.0f)
                    {
                        Vector3 pos = player.Get <Transform>().Position;
                        Vector3 dir = Vector3.Normalize(new Vector3((float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f));
                        Voxel.GlobalRaycastResult hit = default(Voxel.GlobalRaycastResult);
                        int  radius  = random.Next(4, 10);
                        int  tries   = 30;
                        bool success = false;
                        while (tries > 0)
                        {
                            hit = Voxel.GlobalRaycast(pos, dir, 50.0f);

                            if (hit.Voxel != null &&
                                hit.Distance > radius &&
                                Rift.Query(hit.Position) == null &&
                                Zone.CanSpawnRift(hit.Position) &&
                                MapExit.Query(hit.Position, 5 + radius) == null)
                            {
                                success = true;
                                break;
                            }

                            tries--;
                        }

                        if (success)
                        {
                            Entity rift = riftFactory.CreateAndBind(main);
                            rift.Get <Transform>().Position.Value = hit.Position;
                            VoxelAttachable attachment = rift.Get <VoxelAttachable>();
                            attachment.AttachedVoxel.Value = hit.Voxel.Entity;
                            attachment.Coord.Value         = hit.Coordinate.Value;
                            Rift riftComponent = rift.Get <Rift>();
                            riftComponent.Radius.Value = radius;
                            main.Add(rift);
                            riftComponent.Enabled.Value = true;
                            interval = minInterval + (float)random.NextDouble() * (maxInterval - minInterval);
                        }
                    }
                }
            };
            script.Add(updater);
        }