public static IMyEntity GetMissileTargetForGrid(IMyEntity grid) { try { MyEntityComponentContainer componentContainer = grid.Components; GuidedMissileTargetGridHook targetGridHook = null; foreach (MyComponentBase comp in componentContainer) { var hook = comp as GuidedMissileTargetGridHook; if (hook != null) { targetGridHook = hook; } if (comp is MyCompositeGameLogicComponent) { // Log.Info("we got a composite component!"); targetGridHook = comp.GetAs <GuidedMissileTargetGridHook>(); } } if (targetGridHook != null) { return(targetGridHook.GetMissileTarget()); } } catch (Exception e) { Log.Info("Error during GetMissileTargetForGrid: " + e); return(null); } return(null); }
protected MyMultiplayerServerBase(MySyncLayer syncLayer, EndpointId localClientEndpoint) : base(syncLayer) { this.m_factory = new MyReplicableFactory(); MyReplicationServer layer = new MyReplicationServer(this, localClientEndpoint, Thread.CurrentThread); base.SetReplicationLayer(layer); base.ClientLeft += (steamId, e) => MySandboxGame.Static.Invoke(() => this.ReplicationLayer.OnClientLeft(new EndpointId(steamId)), "P2P Client left"); base.ClientJoined += steamId => this.ReplicationLayer.OnClientJoined(new EndpointId(steamId), base.CreateClientState()); MyEntities.OnEntityCreate += new Action <MyEntity>(this.CreateReplicableForObject); MyEntityComponentBase.OnAfterAddedToContainer += new Action <MyEntityComponentBase>(this.CreateReplicableForObject); MyExternalReplicable.Destroyed += new Action <MyExternalReplicable>(this.DestroyReplicable); foreach (MyEntity entity in MyEntities.GetEntities()) { this.CreateReplicableForObject(entity); MyEntityComponentContainer components = entity.Components; if (components != null) { foreach (MyComponentBase base2 in components) { this.CreateReplicableForObject(base2); } } } syncLayer.TransportLayer.Register(MyMessageId.RPC, 0xff, new Action <MyPacket>(this.ReplicationLayer.OnEvent)); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, 0xff, new Action <MyPacket>(this.ReplicationLayer.ReplicableReady)); syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_REQUEST, 0xff, new Action <MyPacket>(this.ReplicationLayer.ReplicableRequest)); syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, 0xff, new Action <MyPacket>(this.ReplicationLayer.OnClientUpdate)); syncLayer.TransportLayer.Register(MyMessageId.CLIENT_ACKS, 0xff, new Action <MyPacket>(this.ReplicationLayer.OnClientAcks)); syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, 0xff, new Action <MyPacket>(this.ClientReady)); }
/// <summary> /// Initializes a new instance of the <see cref="MyEntity"/> class. /// </summary> public MyEntity(bool initComponents = true) { Components = new MyEntityComponentContainer(this); Components.ComponentAdded += Components_ComponentAdded; Components.ComponentRemoved += Components_ComponentRemoved; this.Flags = EntityFlags.Visible | EntityFlags.SkipIfTooSmall | EntityFlags.Save | EntityFlags.NeedsResolveCastShadow | EntityFlags.InvalidateOnMove; if (initComponents) { this.m_hudParams = new List <MyHudEntityParams>(1); this.Hierarchy = new MyHierarchyComponentBase(); this.GameLogic = new MyNullGameLogicComponent(); this.PositionComp = new MyPositionComponent(); PositionComp.LocalMatrix = Matrix.Identity; this.Render = new MyRenderComponent(); AddDebugRenderComponent(new MyDebugRenderComponent(this)); } }
internal void <GetRemoveEntityOnTimerEvent> b__21_0(MyEntityComponentContainer container) { if (!container.Entity.MarkedForClose) { container.Entity.Close(); } }
public void OnRemovedFromContainer() { _container.ComponentAdded -= _registerComponent; _container.ComponentRemoved -= _unregisterComponent; foreach (var k in _container) { _unregisterComponent(k); } _container = null; }
public void OnAddedToContainer(MyEntityComponentContainer container) { _container = container; container.ComponentAdded += _registerComponent; container.ComponentRemoved += _unregisterComponent; foreach (var k in container) { _registerComponent(k); } }
public static bool SetMissileTargetForGrid(IMyEntity grid, IMyEntity target) { if (grid == null) { Log.Info("The grid seems to be null, no target could be assigned."); return(false); } if (target == null) { Log.Info("The target seems to be null, no target could be assigned."); return(false); } MyEntityComponentContainer componentContainer = grid.Components; if (componentContainer == null) { // Log.Info("The grid.Components are null. Could not assign a target!"); return(false); } GuidedMissileTargetGridHook targetGridHook = null; foreach (MyComponentBase comp in componentContainer) { var hook = comp as GuidedMissileTargetGridHook; if (hook != null) { targetGridHook = hook; } if (comp is MyCompositeGameLogicComponent) { // Log.Info("we got a composite component!"); targetGridHook = comp.GetAs <GuidedMissileTargetGridHook>(); } } if (targetGridHook == null) { // Log.Info("We did not found our TargetGridHook. A target could not be assigned!"); // Log.Info("This is what we had: "); foreach (MyComponentBase comp in componentContainer) { Log.Info(comp.ToString()); } return(false); } return(targetGridHook.SetMissileTarget(target)); }
public GuidedMissileControlStationHook GetControlStationHook(IMyEntity turret) { MyEntityComponentContainer componentContainer = turret.Components; GuidedMissileControlStationHook controlStationHook = null; foreach (MyComponentBase comp in componentContainer) { var hook = comp as GuidedMissileControlStationHook; if (hook != null) { controlStationHook = hook; } } return(controlStationHook); }
private void characterEntity_MovementStateChanged(IMyCharacter currentcharacter, MyCharacterMovementEnum oldState, MyCharacterMovementEnum newState) { if (skipNextActivation > 0) { skipNextActivation--; } if (oldState == MyCharacterMovementEnum.Sitting) { } if (newState == MyCharacterMovementEnum.Died) { characterEntity.MovementStateChanged -= characterEntity_MovementStateChanged; handlerAdded = false; skipNextActivation = 0; } if ((oldState == MyCharacterMovementEnum.Flying) || (newState == MyCharacterMovementEnum.Flying)) { MyEntityComponentContainer playercontainer = characterEntity.Components; MyCharacterJetpackComponent JetpackComp = playercontainer.Get <MyCharacterJetpackComponent>(); if (JetpackComp != null) { if ((oldState == MyCharacterMovementEnum.Flying) && (newState == MyCharacterMovementEnum.Sitting)) { skipNextActivation = activationskippingdelay; } else { if (!MyAPIGateway.Input.IsNewGameControlPressed(MyControlsSpace.THRUSTS)) { if (JetpackComp.TurnedOn) { if (skipNextActivation > 0) { skipNextActivation = 0; } else { JetpackComp.TurnOnJetpack(false); //turn the jetpack off } } } } } } // if ((newState != MyCharacterMovementEnum.Sitting) || (oldState != MyCharacterMovementEnum.Sitting)) skipNextActivation = false; }
public void AddToContainer(MyEntityComponentContainer container, bool includeParent, bool includeChildren) { _includeParent = includeParent; _includeChildren = includeChildren; _container = container; _container.ComponentAdded += OnComponentAdded; _container.ComponentRemoved += OnComponentAdded; foreach (var c in _container.GetComponents <TComp>()) { OnComponentAdded(c); } if (_includeParent) { _hierarchy = container.Get <MyHierarchyComponent>(); _hierarchy.ParentChanged += ParentChanged; ParentChanged(_hierarchy, null, _hierarchy.Parent); } if (_includeChildren) { _modelAttachment = container.Get <MyModelAttachmentComponent>(); if (_modelAttachment != null) { _modelAttachment.OnEntityAttached += OnEntityAttached; _modelAttachment.OnEntityDetached += OnEntityDetached; var h = container.Get <MyHierarchyComponent>(); if (h != null) { foreach (var e in h.Children) { if (e.Entity != null && _modelAttachment.GetEntityAttachmentPoint(e.Entity) != MyStringHash.NullOrEmpty) { OnEntityAttached(_modelAttachment, e.Entity); } } } } } }
public void RemoveFromContainer() { if (_includeParent) { _hierarchy.ParentChanged -= ParentChanged; ParentChanged(_hierarchy, _hierarchy.Parent, null); _hierarchy = null; } if (_modelAttachment != null) { _modelAttachment.OnEntityAttached -= OnEntityAttached; _modelAttachment.OnEntityDetached -= OnEntityDetached; var h = _container.Get <MyHierarchyComponent>(); if (h != null) { foreach (var e in h.Children) { if (e.Entity != null && _modelAttachment.GetEntityAttachmentPoint(e.Entity) != MyStringHash.NullOrEmpty) { OnEntityDetached(_modelAttachment, e.Entity); } } } _modelAttachment = null; } _container.ComponentAdded -= OnComponentAdded; _container.ComponentRemoved -= OnComponentAdded; foreach (var c in _components) { ComponentRemoved?.Invoke(c); } _components.Clear(); _container = null; }
private void characterEntity_OnMovementStateChanged(MyCharacterMovementEnum oldState, MyCharacterMovementEnum newState) { if (oldState == MyCharacterMovementEnum.Sitting) { } if ((oldState == MyCharacterMovementEnum.Flying) || (newState == MyCharacterMovementEnum.Flying)) { MyEntityComponentContainer playercontainer = characterEntity.Components; MyCharacterJetpackComponent JetpackComp = playercontainer.Get <MyCharacterJetpackComponent>(); if (JetpackComp != null) { if ((oldState == MyCharacterMovementEnum.Flying) && (newState == MyCharacterMovementEnum.Sitting)) { skipNextActivation = true; } else { if (!MyAPIGateway.Input.IsNewGameControlPressed(MyControlsSpace.THRUSTS)) { if (JetpackComp.TurnedOn) { if (skipNextActivation) { skipNextActivation = false; } else { JetpackComp.TurnOnJetpack(false); //turn the jetpack off } } } } } } }
public override void UpdateAfterSimulation() { try { tick++; if (MyAPIGateway.Session == null) { return; } if (!init) //reinit just to be save { Init(); } if (isDedicatedHost) { return; //there is no jetpack or even a player on the dedicated host itself } if (tick % 3 == 0) //better performance if the code is executed less - only do it every 3 ticks will work until you play below 4 FPS { if ((skipNextActivation > 0) && (skipNextActivation < activationskippingdelay)) { skipNextActivation--; } var camera = MyAPIGateway.Session.CameraController; if (camera == null) { return; } if (characterEntity != null && (characterEntity.MarkedForClose || characterEntity.Closed)) { characterEntity = null; //remove the stored character } if (camera is IMyCharacter) { if (camera as IMyCharacter != characterEntity) { if (characterEntity != null) { characterEntity.MovementStateChanged -= characterEntity_MovementStateChanged; } handlerAdded = false; } characterEntity = ((IMyCharacter)camera); MyEntityComponentContainer playercontainer = ((IMyCharacter)camera).Components; MyCharacterJetpackComponent JetpackComp = playercontainer.Get <MyCharacterJetpackComponent>(); if (JetpackComp != null) { if (JetpackComp.CurrentAutoEnableDelay > 0) //The coundown is running so deactivate it { JetpackComp.CurrentAutoEnableDelay = -1; //now it is deactivated again } } } } if (!handlerAdded) //only once { var camera = MyAPIGateway.Session.CameraController; if (camera == null) { return; } if (camera is IMyCharacter) { characterEntity = ((IMyCharacter)camera); //store the character Entity characterEntity.MovementStateChanged += characterEntity_MovementStateChanged; //add the handler handlerAdded = true; skipNextActivation = activationskippingdelay; } } } catch (Exception e) { //Lazy lazy... still no logging... } }
public static T GetAny <T>(this MyEntityComponentContainer container) where T : MyGameLogicComponent { return(container.Get <T>() ?? (container.Get <MyGameLogicComponent>() ?? container.Get <MyCompositeGameLogicComponent>()) ?.GetAs <T>()); }