public bool TryGetCameraSettings(PlayerId pid, long entityId, out MyEntityCameraSettings cameraSettings) { MyPlayer client = null; if (MySandboxGame.IsDedicated) { client = MySession.Static.Players.GetPlayerById(pid); } else { client = MySession.Static.LocalHumanPlayer; } if (m_characterCameraSettings != null && client != null && client.Character != null && client.Character.EntityId == entityId) { cameraSettings = m_characterCameraSettings; return(true); } if (ContainsPlayer(pid) && m_entityCameraSettings[pid].ContainsKey(entityId)) { return(m_entityCameraSettings[pid].TryGetValue(entityId, out cameraSettings)); } cameraSettings = null; return(false); }
private void AddCharacterCameraData(PlayerId pid, bool isFirstPerson, double distance, Vector2 headAngle) { if (m_characterCameraSettings == null) { m_characterCameraSettings = new MyEntityCameraSettings(); } m_characterCameraSettings.IsFirstPerson = isFirstPerson; if (!isFirstPerson) { m_characterCameraSettings.Distance = distance; m_characterCameraSettings.HeadAngle = headAngle; } }
private void AddCameraData(PlayerId pid, long entityId, MyEntityCameraSettings data) { if (!ContainsPlayer(pid)) { m_entityCameraSettings[pid] = new Dictionary <long, MyEntityCameraSettings>(); } if (m_entityCameraSettings[pid].ContainsKey(entityId)) { m_entityCameraSettings[pid][entityId] = data; } else { m_entityCameraSettings[pid].Add(entityId, data); } }
private void AddCameraData(PlayerId pid, long entityId, bool isFirstPerson, double distance, Vector2 headAngle) { MyEntityCameraSettings cameraSettings = null; if (TryGetCameraSettings(pid, entityId, out cameraSettings)) { cameraSettings.IsFirstPerson = isFirstPerson; if (!isFirstPerson) { cameraSettings.Distance = distance; cameraSettings.HeadAngle = headAngle; } } else { cameraSettings = new MyEntityCameraSettings() { Distance = distance, IsFirstPerson = isFirstPerson, HeadAngle = headAngle, }; AddCameraData(pid, entityId, cameraSettings); } }
public void LoadCameraCollection(MyObjectBuilder_Checkpoint checkpoint) { m_entityCameraSettings = new Dictionary <PlayerId, Dictionary <long, MyEntityCameraSettings> >(); var allPlayers = checkpoint.AllPlayersData; if (allPlayers != null) { foreach (var playerData in allPlayers.Dictionary) { PlayerId pid = new PlayerId(playerData.Key.ClientId, playerData.Key.SerialId); m_entityCameraSettings[pid] = new Dictionary <long, MyEntityCameraSettings>(); foreach (var cameraSettings in playerData.Value.EntityCameraData) { MyEntityCameraSettings data = new MyEntityCameraSettings() { Distance = cameraSettings.Distance, HeadAngle = (Vector2?)cameraSettings.HeadAngle, IsFirstPerson = cameraSettings.IsFirstPerson }; m_entityCameraSettings[pid][cameraSettings.EntityId] = data; } if (playerData.Value.CharacterCameraData != null) { m_characterCameraSettings = new MyEntityCameraSettings() { Distance = playerData.Value.CharacterCameraData.Distance, HeadAngle = playerData.Value.CharacterCameraData.HeadAngle, IsFirstPerson = playerData.Value.CharacterCameraData.IsFirstPerson }; } } } }
void DieInternal() { if (!CharacterCanDie && !MyPerGameSettings.CharacterSuicideEnabled) return; if (MySession.Static.LocalCharacter == this) m_localCharacterWasInThirdPerson = !IsInFirstPersonView; MyHud.CharacterInfo.HealthRatio = 0f; SoundComp.PlayDeathSound(StatComp != null ? StatComp.LastDamage.Type : MyStringHash.NullOrEmpty); if (UseNewAnimationSystem) AnimationController.Variables.SetValue(MyAnimationVariableStorageHints.StrIdDead, 1.0f); if (m_InventoryScreen != null) { m_InventoryScreen.CloseScreen(); } if (StatComp != null && StatComp.Health != null) StatComp.Health.OnStatChanged -= StatComp.OnHealthChanged; if (m_breath != null) m_breath.CurrentState = MyCharacterBreath.State.NoBreath; if (CurrentRemoteControl != null) { //This will happen when character is killed without being destroyed var remoteControl = CurrentRemoteControl as MyRemoteControl; if (remoteControl != null) { remoteControl.ForceReleaseControl(); } else { var turretControl = CurrentRemoteControl as MyLargeTurretBase; if (turretControl != null) { turretControl.ForceReleaseControl(); } } } if (ControllerInfo != null && ControllerInfo.IsLocallyHumanControlled()) { if (MyGuiScreenTerminal.IsOpen) { MyGuiScreenTerminal.Hide(); } if (MyGuiScreenGamePlay.ActiveGameplayScreen != null) { MyGuiScreenGamePlay.ActiveGameplayScreen.CloseScreen(); MyGuiScreenGamePlay.ActiveGameplayScreen = null; } if (MyGuiScreenGamePlay.TmpGameplayScreenHolder != null) { MyGuiScreenGamePlay.TmpGameplayScreenHolder.CloseScreen(); MyGuiScreenGamePlay.TmpGameplayScreenHolder = null; } } if (Parent is MyCockpit) { var cockpit = Parent as MyCockpit; if (cockpit.Pilot == this) cockpit.RemovePilot(); //needed to be done localy otherwise client wont see respawn message } if (MySession.Static.ControlledEntity is MyRemoteControl) { //This will happen when character is killed without being destroyed var remoteControl = MySession.Static.ControlledEntity as MyRemoteControl; if (remoteControl.PreviousControlledEntity == this) { remoteControl.ForceReleaseControl(); } } //TODO(AF) Create a shared RemoteControl component if (MySession.Static.ControlledEntity is MyLargeTurretBase) { //This will happen when character is killed without being destroyed var turret = MySession.Static.ControlledEntity as MyLargeTurretBase; turret.ForceReleaseControl(); } if (m_currentMovementState == MyCharacterMovementEnum.Died) { StartRespawn(0.1f); return; } ulong playerId = 0; if (ControllerInfo.Controller != null && ControllerInfo.Controller.Player != null) { playerId = ControllerInfo.Controller.Player.Id.SteamId; if (!MySession.Static.Cameras.TryGetCameraSettings(ControllerInfo.Controller.Player.Id, EntityId, out m_cameraSettingsWhenAlive)) { if (ControllerInfo.IsLocallyHumanControlled()) { m_cameraSettingsWhenAlive = new MyEntityCameraSettings() { Distance = MyThirdPersonSpectator.Static.GetViewerDistance(), IsFirstPerson = IsInFirstPersonView, HeadAngle = new Vector2(HeadLocalXAngle, HeadLocalYAngle) }; } } } MyAnalyticsHelper.ReportPlayerDeath(ControllerInfo.IsLocallyHumanControlled(), playerId); MySandboxGame.Log.WriteLine("Player character died. Id : " + playerId); EndShootAll(); // If it is the local player who died, give this player a death location coordinate if (GetPlayerIdentityId() == MySession.Static.LocalPlayerId) { m_isDeathPlayer = true; string bodyLocationName = MyTexts.Get(MySpaceTexts.GPS_Body_Location_Name).ToString(); MyGps deathLocation = MySession.Static.Gpss.GetGpsByName(MySession.Static.LocalPlayerId, bodyLocationName) as MyGps; if (deathLocation != null) { deathLocation.Coords = new Vector3D(MySession.Static.LocalHumanPlayer.GetPosition()); deathLocation.Coords.X = Math.Round(deathLocation.Coords.X, 2); deathLocation.Coords.Y = Math.Round(deathLocation.Coords.Y, 2); deathLocation.Coords.Z = Math.Round(deathLocation.Coords.Z, 2); MySession.Static.Gpss.SendModifyGps(MySession.Static.LocalPlayerId, deathLocation); } else { deathLocation = new MyGps(); deathLocation.Name = bodyLocationName; deathLocation.Description = MyTexts.Get(MySpaceTexts.GPS_Body_Location_Desc).ToString(); deathLocation.Coords = new Vector3D(MySession.Static.LocalHumanPlayer.GetPosition()); deathLocation.Coords.X = Math.Round(deathLocation.Coords.X, 2); deathLocation.Coords.Y = Math.Round(deathLocation.Coords.Y, 2); deathLocation.Coords.Z = Math.Round(deathLocation.Coords.Z, 2); deathLocation.ShowOnHud = true; deathLocation.DiscardAt = null; MySession.Static.Gpss.SendAddGps(MySession.Static.LocalPlayerId, ref deathLocation); } } if (Sync.IsServer && m_currentWeapon != null && m_currentWeapon.PhysicalObject != null) { var inventoryItem = new MyPhysicalInventoryItem() { Amount = 1, Scale = 1f, Content = m_currentWeapon.PhysicalObject, }; // Guns if (inventoryItem.Content is MyObjectBuilder_PhysicalGunObject) { (inventoryItem.Content as MyObjectBuilder_PhysicalGunObject).GunEntity.EntityId = 0; } MyFloatingObjects.Spawn(inventoryItem, ((MyEntity)m_currentWeapon).PositionComp.GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, Physics); this.GetInventory().RemoveItemsOfType(1, m_currentWeapon.PhysicalObject); } IsUsing = null; m_isFalling = false; SetCurrentMovementState(MyCharacterMovementEnum.Died); UnequipWeapon(); //Inventory.Clear(false); StopUpperAnimation(0.5f); //SoundComp.StartSecondarySound(Definition.DeathSoundName, sync: false); m_animationCommandsEnabled = true; if (m_isInFirstPerson) PlayCharacterAnimation("DiedFps", MyBlendOption.Immediate, MyFrameOption.PlayOnce, 0.5f); else PlayCharacterAnimation("Died", MyBlendOption.Immediate, MyFrameOption.PlayOnce, 0.5f); //InitBoxPhysics(MyMaterialType.METAL, ModelLod0, 900, 0, MyPhysics.DefaultCollisionFilter, RigidBodyFlag.RBF_DEFAULT); //InitSpherePhysics(MyMaterialType.METAL, ModelLod0, 900, 0, 0, 0, RigidBodyFlag.RBF_DEFAULT); InitDeadBodyPhysics(); StartRespawn(RESPAWN_TIME); m_currentLootingCounter = m_characterDefinition.LootingTime; if (CharacterDied != null) CharacterDied(this); foreach (var component in Components) { var characterComponent = component as MyCharacterComponent; if (characterComponent != null) { characterComponent.OnCharacterDead(); } } SoundComp.CharacterDied(); JetpackComp = null; // m_jetpackEnabled = false; // Syncing dead bodies only when the ragdoll is disabled if (!Components.Has<MyCharacterRagdollComponent>()) { SyncFlag = true; } }
public void LoadCameraCollection(MyObjectBuilder_Checkpoint checkpoint) { m_entityCameraSettings = new Dictionary<PlayerId, Dictionary<long, MyEntityCameraSettings>>(); var allPlayers = checkpoint.AllPlayersData; if (allPlayers != null) { foreach (var playerData in allPlayers.Dictionary) { PlayerId pid = new PlayerId(playerData.Key.ClientId, playerData.Key.SerialId); m_entityCameraSettings[pid] = new Dictionary<long, MyEntityCameraSettings>(); foreach (var cameraSettings in playerData.Value.EntityCameraData) { MyEntityCameraSettings data = new MyEntityCameraSettings() { Distance = cameraSettings.Distance, HeadAngle = (Vector2?)cameraSettings.HeadAngle, IsFirstPerson = cameraSettings.IsFirstPerson }; m_entityCameraSettings[pid][cameraSettings.EntityId] = data; } if (playerData.Value.CharacterCameraData != null) { m_characterCameraSettings = new MyEntityCameraSettings() { Distance = playerData.Value.CharacterCameraData.Distance, HeadAngle = playerData.Value.CharacterCameraData.HeadAngle, IsFirstPerson = playerData.Value.CharacterCameraData.IsFirstPerson }; } } } }
public bool TryGetCameraSettings(PlayerId pid, long entityId, out MyEntityCameraSettings cameraSettings) { MyPlayer client = null; if (MySandboxGame.IsDedicated) client = MySession.Static.Players.TryGetPlayerById(pid); else client = MySession.LocalHumanPlayer; if (m_characterCameraSettings != null && client != null && client.Character != null && client.Character.EntityId == entityId) { cameraSettings = m_characterCameraSettings; return true; } if (ContainsPlayer(pid) && m_entityCameraSettings[pid].ContainsKey(entityId)) { return m_entityCameraSettings[pid].TryGetValue(entityId, out cameraSettings); } cameraSettings = null; return false; }
private void AddCameraData(PlayerId pid, long entityId, MyEntityCameraSettings data) { if (!ContainsPlayer(pid)) { m_entityCameraSettings[pid] = new Dictionary<long, MyEntityCameraSettings>(); } if (m_entityCameraSettings[pid].ContainsKey(entityId)) m_entityCameraSettings[pid][entityId] = data; else m_entityCameraSettings[pid].Add(entityId, data); }
private void AddCharacterCameraData(PlayerId pid, bool isFirstPerson, double distance, Vector2 headAngle) { if (m_characterCameraSettings == null) m_characterCameraSettings = new MyEntityCameraSettings(); m_characterCameraSettings.IsFirstPerson = isFirstPerson; if (!isFirstPerson) { m_characterCameraSettings.Distance = distance; m_characterCameraSettings.HeadAngle = headAngle; } }
public Multiplayer.MyEntityCameraSettings GetCameraEntitySettings() { ulong playerId = 0; if (ControllerInfo.Controller != null && ControllerInfo.Controller.Player != null) { playerId = ControllerInfo.Controller.Player.Id.SteamId; if (!MySession.Static.Cameras.TryGetCameraSettings(ControllerInfo.Controller.Player.Id, EntityId, out m_cameraSettings)) { if (ControllerInfo.IsLocallyHumanControlled()) { m_cameraSettings = new MyEntityCameraSettings() { Distance = 0, IsFirstPerson = true, HeadAngle = new Vector2(HeadLocalXAngle, HeadLocalYAngle) }; } } } return m_cameraSettings; }