private void OnComponentRemoved(MyEntityComponent obj) { if (StateComponent != obj) { return; } StateComponent = null; }
private void ComponentAdded(MyEntityComponent obj) { var p = obj as IPowerProvider; if (p == null) { return; } _providers.Add(p); p.OnPowerChanged += PowerStateChanged; }
private void OnBeforeRemovedFromContainer(MyEntityComponent component) { if (component != _sourceInventory) { return; } _sourceInventory.ContentsChanged -= OnSourceItemsChanged; _sourceInventory.BeforeRemovedFromContainer -= OnBeforeRemovedFromContainer; _sourceInventory = null; }
private void OnComponentAdded(MyEntityComponent obj) { // ReSharper disable once SuspiciousTypeConversion.Global var cc = obj as MyEntityStateComponent; if (cc == null) { return; } StateComponent = cc; }
private void ComponentRemoved(MyEntityComponent obj) { var p = obj as IPowerProvider; if (p == null) { return; } _providers.Remove(p); p.OnPowerChanged -= PowerStateChanged; MarkForUpdate(); }
private void OnComponentRemoved(MyEntityComponent obj) { var cast = obj as TComp; if (cast == null) { return; } if (_components.Remove(cast)) { ComponentRemoved?.Invoke(cast); } }
public static bool IsTrusted(MyEntityComponent target, Vector3D?overrideLocation = null) { if (!MyMultiplayerModApi.Static.IsServer) { return(true); } if (MyEventContext.Current.IsLocallyInvoked) { return(true); } if (target?.Entity == null) { return(true); } if (MyAPIGateway.Session.IsAdminModeEnabled(MyEventContext.Current.Sender.Value)) { return(true); } var player = MyPlayers.Static.GetPlayer(new MyPlayer.PlayerId(MyEventContext.Current.Sender.Value, 0)); var playerEntity = player?.ControlledEntity; if (playerEntity == null) { return(false); } var loc = overrideLocation ?? target.Entity.WorldMatrix.Translation; if (Vector3D.DistanceSquared(playerEntity.WorldMatrix.Translation, loc) > TrustedDistance * TrustedDistance) { return(false); } var access = target.Container.Get <MyAccessPermissionComponent>(); if (access != null && !access.Permissions.HasPermission(player.Identity.Id)) { return(false); } var areaOwnership = MySession.Static.Components.Get <MyAreaOwnershipSystem>()?.GetAreaPermissions(loc); if (areaOwnership.HasValue && !areaOwnership.Value.HasPermission(player.Identity.Id)) { return(false); } return(true); }
public override void Activate(MyEntityStatComponent owner) { base.Activate(owner); if (owner.Entity == null || _activatedComponentDefinition == null) { return; // can't do anything about this } // Component exists? { MyEntityComponent existingComponent; MyMultiComponent existingMulti; if (owner.Entity.Components.TryGet(_definition.AddedComponent.TypeId, _definition.AddedComponent.SubtypeId, out existingComponent)) { return; } if (owner.Entity.Components.TryGet(_definition.AddedComponent.TypeId, out existingComponent)) { existingMulti = existingComponent as MyMultiComponent; if (existingMulti == null || existingMulti.SubtypeId == _definition.AddedComponent.SubtypeId) { return; } } } if (_activatedComponent == null) { // _activatedComponent = MyEntityComponent.Factory.CreateInstance(_definition.AddedComponent.TypeId); if (_definition.AddedComponent.TypeId == typeof(MyObjectBuilder_PhantomEffectComponent)) { _activatedComponent = new MyPhantomEffectComponent(); } else { throw new Exception("Invalid component type " + _definition.AddedComponent.TypeId); } var def = MyDefinitionManager.Get <MyEntityComponentDefinition>(_definition.AddedComponent); if (def != null) { _activatedComponent.Init(def); } } if (_activatedComponent.Entity == null) { owner.Entity.Components.Add(_activatedComponent); } }
private void OnComponentRemoved(MyEntityComponent obj) { // ReSharper disable once SuspiciousTypeConversion.Global var cc = obj as IConditionComponent; if (cc == null || cc.Id != _key) { return; } _components.Remove(cc); cc.StateChanged -= ComponentChanged; if (!_blockedUpdate) { Calculate(); } }
private void OnComponentRemoved(MyEntityComponent obj) { // ReSharper disable once SuspiciousTypeConversion.Global var cc = obj as IMyPowerProvider; if (cc == null) { return; } _components.Remove(cc); cc.PowerStateChanged -= ComponentChanged; if (!_blockedUpdate) { Calculate(); } }
private static TComponentDef ComponentDefinition <TComponentDef>(MyEntityComponent vic) where TComponentDef : MyEntityComponentDefinition { var def = vic.Entity?.Definition?.Components; if (def == null) { return(null); } foreach (var k in def) { var definition = k.Definition as TComponentDef; if (definition != null) { return(definition); } } return(null); }
/// <summary> /// Gets all components of type specified on the same entity. /// </summary> /// <typeparam name="TComp"></typeparam> /// <param name="comp"></param> /// <returns></returns> public static IEnumerable <TComp> GetAll <TComp>(this MyEntityComponent comp) where TComp : MyEntityComponent { return(comp.Entity?.Components?.GetComponents <TComp>()); }
/// <summary> /// Gets a component of type and subtype specified on the same entity. /// </summary> /// <typeparam name="TComp"></typeparam> /// <param name="comp"></param> /// <param name="subtype"></param> /// <returns></returns> public static TComp Get <TComp>(this MyEntityComponent comp, MyStringHash subtype) where TComp : MyMultiComponent { return(comp.Entity?.Get <TComp>(subtype) ?? null); }
/// <summary> /// Gets a component of type specified on the same entity. /// </summary> /// <typeparam name="TComp"></typeparam> /// <param name="comp"></param> /// <returns></returns> public static TComp Get <TComp>(this MyEntityComponent comp) where TComp : MyEntityComponent { return(comp.Entity?.Get <TComp>() ?? null); }
private void CheckSkeleton(MyEntityComponent e) { CheckSkeleton(); }
public RailPhysicsNode(MyEntityComponent target) { _rootParentChanged = RootRefChanged; _target = target; }