void CreatePlayerEquipment() { playerShip.Children.Clear(); foreach (var mount in session.Items.Where(x => !string.IsNullOrEmpty(x.Hardpoint))) { if (mount.Hardpoint != "internal") { EquipmentObjectManager.InstantiateEquipment(playerShip, Game.ResourceManager, EquipmentType.Cutscene, mount.Hardpoint, mount.Equipment); } } }
public GameObject DoSpawn(string nickname, Loadout loadout, GameData.Pilot pilot, Vector3 position, Quaternion orient) { NetShipLoadout netLoadout = new NetShipLoadout(); netLoadout.Items = new List <NetShipCargo>(); var ship = World.Server.GameData.GetShip(loadout.Archetype); netLoadout.ShipCRC = ship.CRC; var obj = new GameObject(ship, World.Server.Resources, false, true); obj.Name = $"Bob NPC - {loadout.Nickname}"; obj.Nickname = nickname; obj.SetLocalTransform(Matrix4x4.CreateFromQuaternion(orient) * Matrix4x4.CreateTranslation(position)); obj.Components.Add(new SHealthComponent(obj) { CurrentHealth = ship.Hitpoints, MaxHealth = ship.Hitpoints }); foreach (var equipped in loadout.Equip) { var e = World.Server.GameData.GetEquipment(equipped.Nickname); if (e == null) { continue; } EquipmentObjectManager.InstantiateEquipment(obj, World.Server.Resources, EquipmentType.Server, equipped.Hardpoint, e); var hp = equipped.Hardpoint == null ? NetShipCargo.InternalCrc : CrcTool.FLModelCrc(equipped.Hardpoint); netLoadout.Items.Add(new NetShipCargo(0, e.CRC, hp, 255, 1)); } obj.Components.Add(new SNPCComponent(obj, this) { Loadout = netLoadout, Pilot = pilot }); obj.Components.Add(new ShipPhysicsComponent(obj) { Ship = ship }); obj.Components.Add(new ShipInputComponent(obj)); obj.Components.Add(new AutopilotComponent(obj)); obj.Components.Add(new WeaponControlComponent(obj)); World.OnNPCSpawn(obj); if (nickname != null) { missionNPCs[nickname] = obj; } return(obj); }
public void SetLoadout(Dictionary <string, Equipment> equipment, List <Equipment> nohp) { foreach (var k in equipment.Keys) { EquipmentObjectManager.InstantiateEquipment(this, Resources, RenderComponent != null, k, equipment[k]); } foreach (var eq in nohp) { if (eq is AnimationEquipment) { var anm = (AnimationEquipment)eq; if (anm.Animation != null) { AnimationComponent?.StartAnimation(anm.Animation); } } } }
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)); }); }
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); }
void FinishLoad() { var shp = Game.GameData.GetShip(session.PlayerShip); //Set up player object + camera player = new GameObject(shp.ModelFile.LoadFile(Game.ResourceManager), Game.ResourceManager, true, false); 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.Transform = session.PlayerOrientation * Matrix4x4.CreateTranslation(session.PlayerPosition); player.PhysicsComponent.Mass = shp.Mass; if (shp.Mass < 0) { FLLog.Error("Ship", "Mass < 0"); } player.Nickname = "player"; foreach (var equipment in session.Mounts) { var equip = Game.GameData.GetEquipment(equipment.Item); if (equip == null) { continue; } EquipmentObjectManager.InstantiateEquipment(player, Game.ResourceManager, true, equipment.Hardpoint, equip); } powerCore = player.GetComponent <PowerCoreComponent>(); if (powerCore == null) { throw new Exception("Player launched without a powercore equipped!"); } camera = new ChaseCamera(Game.Viewport); camera.ChasePosition = session.PlayerPosition; camera.ChaseOrientation = player.Transform.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); world = new GameWorld(sysrender); world.LoadSystem(sys, Game.ResourceManager); session.WorldReady(); player.World = world; world.Objects.Add(player); world.RenderUpdate += World_RenderUpdate; world.PhysicsUpdate += World_PhysicsUpdate; player.Register(world.Physics); Game.Sound.PlayMusic(sys.MusicSpace); debugphysics = new PhysicsDebugRenderer(); //world.Physics.EnableWireframes(debugphysics); cur_arrow = Game.ResourceManager.GetCursor("cross"); cur_reticle = Game.ResourceManager.GetCursor("fire_neutral"); current_cur = cur_arrow; Game.Keyboard.TextInput += Game_TextInput; Game.Keyboard.KeyDown += Keyboard_KeyDown; Game.Mouse.MouseDown += Mouse_MouseDown; input = new InputManager(Game); input.ToggleActivated += Input_ToggleActivated; input.ToggleUp += Input_ToggleUp; pilotcomponent = new AutopilotComponent(player); pilotcomponent.DockComplete += Pilotcomponent_DockComplete; player.Components.Add(pilotcomponent); player.World = world; world.MessageBroadcasted += World_MessageBroadcasted; Game.Sound.ResetListenerVelocity(); FadeIn(0.5, 0.5); }