public static MyCharacter SpawnAgent(ulong steamId, string name, Color color, MatrixD startPosition, long identityId = 1000) { var character = MyCharacter.CreateCharacter( startPosition, Vector3.Zero, name, "", color, null, identityId: identityId); character.SwitchJetpack(); var playerId = new MyPlayer.PlayerId(steamId); var identityBuilder = new MyObjectBuilder_Identity { DisplayName = name, CharacterEntityId = character.EntityId, ColorMask = color.ToVector3() }; var identity = new MyAgentIdentity().CreateNewIdentity(identityBuilder); var myPlayer = new MyPlayer(Sync.Clients.LocalClient, playerId) { Identity = identity }; var characterController = new MyEntityController(myPlayer); characterController.TakeControl(character); return(character); }
public static MyCharacter SpawnAgent( ulong steamId, string name, Color color, MatrixD startPosition, long identityId ) { var identityBuilder = new MyObjectBuilder_Identity { DisplayName = name, ColorMask = color.ToVector3(), IdentityId = identityId, }; var identity = MySession.Static.Players.CreateNewIdentity(identityBuilder); var character = MyCharacter.CreateCharacter( startPosition, Vector3.Zero, name, "", color, null, identityId: identityId); var client = new MyNetworkClient(steamId, name); //client.SetInstanceProperty("IsLocal", true); var player = MySession.Static.Players.CreateNewPlayer( identity: identity, steamClient: client, playerName: name, realPlayer: true ); var characterController = new MyEntityController(player); characterController.TakeControl(character); return(player.Character); }
protected override void OnControlReleased(MyEntityController controller) { base.OnControlReleased(controller); if (controller.Player.IsLocalPlayer()) { if (m_pilot != null) { m_pilot.RadioReceiver.Clear(); } } }
protected override void OnControlReleased(MyEntityController controller) { base.OnControlReleased(controller); if (controller.Player.IsLocalPlayer()) { if (m_pilot != null) { m_pilot.RadioReceiver.Clear(); } } // to turn on/off sound in dependence of distance from listener NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; }
public override List <MyHudEntityParams> GetHudParams(bool allowBlink) { base.m_hudParams.Clear(); if ((((base.CubeGrid != null) && !base.CubeGrid.MarkedForClose) && !base.CubeGrid.Closed) && base.IsWorking) { List <MyHudEntityParams> hudParams = this.GetHudParams(allowBlink && base.HasLocalPlayerAccess()); StringBuilder hudText = this.HudText; if (this.ShowShipName || (hudText.Length > 0)) { StringBuilder text = hudParams[0].Text; text.Clear(); if (!string.IsNullOrEmpty(base.GetOwnerFactionTag())) { text.Append(base.GetOwnerFactionTag()); text.Append("."); } if (this.ShowShipName) { text.Append(base.CubeGrid.DisplayName); text.Append(" - "); } text.Append(hudText); } base.m_hudParams.AddList <MyHudEntityParams>(hudParams); if (base.HasLocalPlayerAccess() && (base.SlimBlock.CubeGrid.GridSystems.TerminalSystem != null)) { base.SlimBlock.CubeGrid.GridSystems.TerminalSystem.NeedsHudUpdate = true; foreach (MyTerminalBlock block in base.SlimBlock.CubeGrid.GridSystems.TerminalSystem.HudBlocks) { if (!ReferenceEquals(block, this)) { base.m_hudParams.AddList <MyHudEntityParams>(block.GetHudParams(true)); } } } MyEntityController entityController = MySession.Static.Players.GetEntityController(base.CubeGrid); if (entityController != null) { MyCockpit controlledEntity = entityController.ControlledEntity as MyCockpit; if ((controlledEntity != null) && (controlledEntity.Pilot != null)) { base.m_hudParams.AddList <MyHudEntityParams>(controlledEntity.GetHudParams(true)); } } } return(base.m_hudParams); }
protected override void ComponentStack_IsFunctionalChanged() { MyCharacter pilot = base.m_pilot; MyEntityController controller = base.ControllerInfo.Controller; base.ComponentStack_IsFunctionalChanged(); if ((!base.IsFunctional && (pilot != null)) && (controller == null)) { if (MySession.Static.CreativeMode) { pilot.Close(); } else { pilot.DoDamage(1000f, MyDamageType.Destruction, false, 0L); } } }
protected void OnCryoChamberControlAcquired(MyEntityController controller) { m_currentPlayerId = controller.Player.Id; }
public void OnControlReleased(MyEntityController controller) { }
public void OnControlAcquired(MyEntityController controller) { }
public static void ReportPlayerDeath(bool isLocallyControlled, ulong playerSteamId) { if (!Sandbox.Engine.Platform.Game.IsDedicated) { try { if (isLocallyControlled) { int isVanilla; string deathCause = m_lastDamageInformation.Type.String; bool flag = false; bool flag2 = false; if ((m_lastDamageInformation.Type != MyStringHash.NullOrEmpty) && (m_lastDamageInformation.AttackerId != 0)) { if (m_lastDamageInformation.Type == MyDamageType.Suicide) { flag2 = true; } else { MyEntity entity = null; MyEntities.TryGetEntityById(m_lastDamageInformation.AttackerId, out entity, false); IMyControllableEntity entity2 = entity as IMyControllableEntity; if (entity2 == null) { if (((entity is IMyGunBaseUser) || (entity is IMyHandheldGunObject <MyToolBase>)) || (entity is IMyHandheldGunObject <MyGunBase>)) { flag = true; } } else { MyEntityController controller = entity2.ControllerInfo.Controller; if (controller != null) { if (controller.Player.Id.SteamId != playerSteamId) { flag = true; } else { flag2 = true; } } } } } string deathType = !flag ? (!flag2 ? (!(m_lastDamageInformation.Type == MyDamageType.Destruction) ? ((m_lastDamageInformation.Type == MyDamageType.Environment) ? "environment" : "unknown") : "cockpit_destruction") : "self_inflicted") : "pvp"; MyPlanetNamesData planetNames = GetPlanetNames(MySession.Static.LocalCharacter.PositionComp.GetPosition()); bool campaign = (MyCampaignManager.Static != null) && MyCampaignManager.Static.IsCampaignRunning; if (!campaign || (MyCampaignManager.Static.ActiveCampaign == null)) { isVanilla = 0; } else { isVanilla = (int)MyCampaignManager.Static.ActiveCampaign.IsVanilla; } MyAnalyticsManager.Instance.ReportPlayerDeath(deathType, deathCause, planetNames.planetName, planetNames.planetType, campaign, (bool)isVanilla, MySession.Static.Settings.GameMode.ToString(), GetModList(), MySession.Static.Mods.Count); } } catch (Exception exception) { MyLog.Default.WriteLine(exception); } } }
public void TurnOnJetpack(bool newState, bool fromInit = false, bool fromLoad = false) { int num1; int num2; MyEntityController controller = base.Character.ControllerInfo.Controller; newState = newState && MySession.Static.Settings.EnableJetpack; newState = newState && (base.Character.Definition.Jetpack != null); if (!newState) { num1 = 0; } else if ((!MySession.Static.SurvivalMode || MyFakes.ENABLE_JETPACK_IN_SURVIVAL) || (controller == null)) { num1 = 1; } else { num1 = (int)MySession.Static.CreativeToolsEnabled(controller.Player.Id.SteamId); } newState = (bool)num2; bool flag = this.TurnedOn != newState; this.TurnedOn = newState; this.ThrustComp.Enabled = newState; this.ThrustComp.ControlThrust = Vector3.Zero; this.ThrustComp.MarkDirty(false); this.ThrustComp.UpdateBeforeSimulation(true, base.Character.RelativeDampeningEntity); if (!this.ThrustComp.Enabled) { this.ThrustComp.SetRequiredFuelInput(ref this.FuelDefinition.Id, 0f, null); } this.ThrustComp.ResourceSink(base.Character).Update(); if ((base.Character.ControllerInfo.IsLocallyControlled() || fromInit) || Sync.IsServer) { MyCharacterMovementEnum currentMovementState = base.Character.GetCurrentMovementState(); if (currentMovementState != MyCharacterMovementEnum.Sitting) { if (this.TurnedOn) { base.Character.StopFalling(); } bool flag2 = false; bool flag3 = newState; if ((!this.IsPowered & flag3) && (((base.Character.ControllerInfo.Controller != null) && !MySession.Static.CreativeToolsEnabled(base.Character.ControllerInfo.Controller.Player.Id.SteamId)) || (!ReferenceEquals(MySession.Static.LocalCharacter, base.Character) && !Sync.IsServer))) { flag3 = false; flag2 = true; } if (flag3) { if (base.Character.IsOnLadder) { base.Character.GetOffLadder(); } base.Character.IsUsing = null; } if (flag && !base.Character.IsDead) { base.Character.UpdateCharacterPhysics(false); } if ((ReferenceEquals(MySession.Static.ControlledEntity, base.Character) & flag) && !fromLoad) { if (flag3) { MyAnalyticsHelper.ReportActivityStart(base.Character, "jetpack", "character", string.Empty, string.Empty, true); } else { MyAnalyticsHelper.ReportActivityEnd(base.Character, "jetpack"); } if (flag2) { MyGuiAudio.PlaySound(MyGuiSounds.HudUnable); this.TurnedOn = false; this.ThrustComp.Enabled = false; this.ThrustComp.ControlThrust = Vector3.Zero; this.ThrustComp.MarkDirty(false); this.ThrustComp.UpdateBeforeSimulation(true, base.Character.RelativeDampeningEntity); this.ThrustComp.SetRequiredFuelInput(ref this.FuelDefinition.Id, 0f, null); this.ThrustComp.ResourceSink(base.Character).Update(); } } MyCharacterProxy characterProxy = base.Character.Physics.CharacterProxy; if (characterProxy == null) { if (this.Running && (currentMovementState != MyCharacterMovementEnum.Died)) { base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0f, 1f, false, null, false); base.Character.SetLocalHeadAnimation(0f, 0f, 0.3f); } } else { MatrixD worldMatrix = base.Character.WorldMatrix; characterProxy.SetForwardAndUp((Vector3)worldMatrix.Forward, (Vector3)worldMatrix.Up); characterProxy.EnableFlyingState(this.Running); if ((currentMovementState != MyCharacterMovementEnum.Died) && !base.Character.IsOnLadder) { if (!this.Running && ((characterProxy.GetState() == HkCharacterStateType.HK_CHARACTER_IN_AIR) || (characterProxy.GetState() == ((HkCharacterStateType)5)))) { base.Character.StartFalling(); } else if ((currentMovementState != MyCharacterMovementEnum.Standing) && !newState) { base.Character.PlayCharacterAnimation("Idle", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f, false, null, false); base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Standing); currentMovementState = base.Character.GetCurrentMovementState(); } } if (this.Running && (currentMovementState != MyCharacterMovementEnum.Died)) { base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0f, 1f, false, null, false); base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying); base.Character.SetLocalHeadAnimation(0f, 0f, 0.3f); characterProxy.PosX = 0f; characterProxy.PosY = 0f; } if ((!fromLoad && !newState) && (base.Character.Physics.Gravity.LengthSquared() <= 0.1f)) { this.CurrentAutoEnableDelay = -1f; } } } } }
protected void OnCryoChamberControlAcquired(MyEntityController controller) { this.m_currentPlayerId = new MyPlayer.PlayerId?(controller.Player.Id); }