コード例 #1
0
 public void AddObject(ThnObject obj)
 {
     sceneObjects[obj.Name] = obj;
     if (obj.Object != null) {
         World?.AddObject(obj.Object);
     }
 }
コード例 #2
0
ファイル: ServerWorld.cs プロジェクト: Regenhardt/Librelancer
 public void SpawnPlayer(Player player, Vector3 position, Quaternion orientation)
 {
     Interlocked.Increment(ref PlayerCount);
     actions.Enqueue(() =>
     {
         foreach (var p in Players)
         {
             player.SpawnPlayer(p.Key);
             p.Key.SpawnPlayer(player);
         }
         player.SendSolars(SpawnedSolars);
         foreach (var npc in spawnedNPCs)
         {
             SpawnShip(npc, player);
         }
         var obj = new GameObject(player.Character.Ship, Server.Resources, false, true)
         {
             World = GameWorld
         };
         obj.Components.Add(new SPlayerComponent(player, obj));
         obj.Components.Add(new SHealthComponent(obj)
         {
             CurrentHealth = player.Character.Ship.Hitpoints,
             MaxHealth     = player.Character.Ship.Hitpoints
         });
         obj.Components.Add(new SEngineComponent(obj));
         foreach (var item in player.Character.Items.Where(x => !string.IsNullOrEmpty(x.Hardpoint)))
         {
             EquipmentObjectManager.InstantiateEquipment(obj, Server.Resources, EquipmentType.Server, item.Hardpoint, item.Equipment);
         }
         obj.NetID = player.ID;
         GameWorld.AddObject(obj);
         obj.Register(GameWorld.Physics);
         Players[player] = obj;
         Players[player].SetLocalTransform(Matrix4x4.CreateFromQuaternion(orientation) *
                                           Matrix4x4.CreateTranslation(position));
     });
 }
コード例 #3
0
        void FinishLoad()
        {
            Game.Saves.Selected = -1;
            ui.OpenScene("hud");
            var shp = Game.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            player       = new GameObject(shp.ModelFile.LoadFile(Game.ResourceManager), Game.ResourceManager);
            control      = new ShipPhysicsComponent(player);
            control.Ship = shp;
            shipInput    = new ShipInputComponent(player);
            player.Components.Add(shipInput);
            player.Components.Add(control);
            weapons = new WeaponControlComponent(player);
            player.Components.Add(weapons);
            player.Components.Add(new CDamageFuseComponent(player, shp.Fuses));

            player.SetLocalTransform(session.PlayerOrientation * Matrix4x4.CreateTranslation(session.PlayerPosition));
            player.PhysicsComponent.Mass = shp.Mass;
            playerHealth               = new CHealthComponent(player);
            playerHealth.MaxHealth     = shp.Hitpoints;
            playerHealth.CurrentHealth = shp.Hitpoints;
            player.Components.Add(playerHealth);
            if (shp.Mass < 0)
            {
                FLLog.Error("Ship", "Mass < 0");
            }

            player.Tag = GameObject.ClientPlayerTag;
            foreach (var equipment in session.Items.Where(x => !string.IsNullOrEmpty(x.Hardpoint)))
            {
                EquipmentObjectManager.InstantiateEquipment(player, Game.ResourceManager, EquipmentType.LocalPlayer, equipment.Hardpoint, equipment.Equipment);
            }
            powerCore = player.GetComponent <PowerCoreComponent>();
            if (powerCore == null)
            {
                throw new Exception("Player launched without a powercore equipped!");
            }
            camera = new ChaseCamera(Game.RenderContext.CurrentViewport, Game.GameData.Ini.Cameras);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = player.LocalTransform.ClearTranslation();
            var offset = shp.ChaseOffset;

            camera.DesiredPositionOffset = offset;
            if (shp.CameraHorizontalTurnAngle > 0)
            {
                camera.HorizontalTurnAngle = shp.CameraHorizontalTurnAngle;
            }
            if (shp.CameraVerticalTurnUpAngle > 0)
            {
                camera.VerticalTurnUpAngle = shp.CameraVerticalTurnUpAngle;
            }
            if (shp.CameraVerticalTurnDownAngle > 0)
            {
                camera.VerticalTurnDownAngle = shp.CameraVerticalTurnDownAngle;
            }
            camera.Reset();

            sysrender           = new SystemRenderer(camera, Game.GameData, Game.ResourceManager, Game);
            sysrender.ZOverride = true; //Draw all with regular Z
            world = new GameWorld(sysrender);
            world.LoadSystem(sys, Game.ResourceManager, false, session.SpawnTime);
            session.WorldReady();
            player.World = world;
            world.AddObject(player);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            player.Register(world.Physics);
            Game.Sound.PlayMusic(sys.MusicSpace);
            //world.Physics.EnableWireframes(debugphysics);
            cur_arrow                = Game.ResourceManager.GetCursor("arrow");
            cur_cross                = Game.ResourceManager.GetCursor("cross");
            cur_reticle              = Game.ResourceManager.GetCursor("fire_neutral");
            current_cur              = cur_cross;
            Game.Keyboard.TextInput += Game_TextInput;
            Game.Keyboard.KeyDown   += Keyboard_KeyDown;
            Game.Mouse.MouseDown    += Mouse_MouseDown;
            Game.Mouse.MouseUp      += Mouse_MouseUp;
            input = new InputManager(Game);
            input.ToggleActivated += Input_ToggleActivated;
            input.ToggleUp        += Input_ToggleUp;
            pilotcomponent         = new AutopilotComponent(player);
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
            Game.Sound.ResetListenerVelocity();
            FadeIn(0.5, 0.5);
        }