/// <summary> /// Processes the provided entity, and if applicable processes the existing blocks and registers it for automatic processing of new blocks. /// </summary> /// <param name="obj">The entity being processed for grid-block processing and registration.</param> private void AttemptGridInclusion(VRage.ModAPI.IMyEntity obj) { // Set this to true/false to enabled/disable debug-logging in this method... bool watchMe = true; Note(watchMe, "Attempting inclusion of entity " + obj.EntityId.ToString() + " as grid..."); VRage.Game.ModAPI.IMyCubeGrid grid = obj as VRage.Game.ModAPI.IMyCubeGrid; if (grid != null && grid.Physics != null && grid.Physics.Enabled) { List <VRage.Game.ModAPI.IMySlimBlock> blocks = new List <VRage.Game.ModAPI.IMySlimBlock>(); Note(watchMe, "Collecting terminal block references..."); grid.GetBlocks(blocks, block => block.FatBlock != null && block.FatBlock is Sandbox.ModAPI.IMyTerminalBlock); Note(watchMe, "Iterating over identified references"); foreach (VRage.Game.ModAPI.IMySlimBlock block in blocks) { AttemptExtension(block); } Note(watchMe, "Subscribing AttemptExtension to grid's block-added event..."); grid.OnBlockAdded += AttemptExtension; } else { Note(watchMe, "Entity cast-to-grid operation failed..."); } }
void IMyUseObject.Use(UseActionEnum actionEnum, VRage.ModAPI.IMyEntity entity) { MyCharacter thisEntity = entity as MyCharacter; if (!base.MarkedForClose) { MyFixedPoint amount = MyFixedPoint.Min(this.Item.Amount, thisEntity.GetInventory(0).ComputeAmountThatFits(this.Item.Content.GetId(), 0f, 0f)); if (amount == 0) { if ((MySandboxGame.TotalGamePlayTimeInMilliseconds - this.m_lastTimePlayedSound) > 0x9c4) { MyGuiAudio.PlaySound(MyGuiSounds.HudVocInventoryFull); this.m_lastTimePlayedSound = MySandboxGame.TotalGamePlayTimeInMilliseconds; } MyHud.Stats.GetStat <MyStatPlayerInventoryFull>().InventoryFull = true; } else { if (amount > 0) { if (ReferenceEquals(MySession.Static.ControlledEntity, thisEntity) && ((this.lastTimeSound == DateTime.MinValue) || ((DateTime.UtcNow - this.lastTimeSound).TotalMilliseconds > 500.0))) { MyGuiAudio.PlaySound(MyGuiSounds.PlayTakeItem); this.lastTimeSound = DateTime.UtcNow; } thisEntity.GetInventory(0).PickupItem(this, amount); } MyHud.Notifications.ReloadTexts(); } } }
void IMyUseObject.Use(UseActionEnum actionEnum, IMyEntity entity) { var user = entity as MyCharacter; if (!MarkedForClose) { System.Diagnostics.Debug.Assert((user.GetInventory() as MyInventory) != null, "Null or unexpected inventory type returned!"); MyFixedPoint amount = MyFixedPoint.Min(Item.Amount, (user.GetInventory() as MyInventory).ComputeAmountThatFits(Item.Content.GetId())); if (amount == 0) { if (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastTimePlayedSound > 2500) { MyGuiAudio.PlaySound(MyGuiSounds.HudVocInventoryFull); m_lastTimePlayedSound = MySandboxGame.TotalGamePlayTimeInMilliseconds; } MyHud.Notifications.Add(MyNotificationSingletons.InventoryFull); return; } if (amount > 0) { if (MySession.Static.ControlledEntity == user && (lastTimeSound == DateTime.MinValue || (DateTime.UtcNow - lastTimeSound).TotalMilliseconds > 500)) { MyGuiAudio.PlaySound(MyGuiSounds.PlayTakeItem); lastTimeSound = DateTime.UtcNow; } System.Diagnostics.Debug.Assert((user.GetInventory() as MyInventory) != null, "Null or unexpected inventory type returned"); (user.GetInventory() as MyInventory).PickupItem(this, amount); } MyHud.Notifications.ReloadTexts(); } }
private void OnEntityClosing(VRage.ModAPI.IMyEntity obj) { var entity = obj as MyEntity; if (entity.HasInventory && entity.InScene) { SpawnInventoryContainer(); } }
private void RigidBody_ContactPointCallback(ref HkContactPointEvent value) { if (Sync.IsServer) { VRage.ModAPI.IMyEntity otherEntity = value.GetOtherEntity(this); if (otherEntity is MyFloatingObject) { this.m_entitiesToTake.Add(otherEntity as MyFloatingObject); MySandboxGame.Static.Invoke(() => base.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME, "MyCollector::NeedsUpdate"); } } }
private void OnModelClosing(IMyEntity obj) { Logger.Instance.LogMessage("Block: " + obj.EntityId + " Model Closing"); if (m_light_emmitter != null) { m_light_emmitter.Clear(); } // close the child grid attached to the subpart NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.EACH_FRAME; (obj as MyEntitySubpart).OnClose -= OnClosing; (obj as MyEntitySubpart).PositionComp.OnPositionChanged -= OnModelPositionChanged; }
private void OnClosing(IMyEntity obj) { NeedsUpdate = MyEntityUpdateEnum.NONE; (obj as IMyFunctionalBlock).OnClosing -= OnClosing; if (PlayerInput.Instance.isServer) { (obj as IMyFunctionalBlock).OnMarkForClose -= OnMarkForClose; } (obj as IMyFunctionalBlock).EnabledChanged -= OnEnabledChanged; (obj as IMyFunctionalBlock).PropertiesChanged -= OnPropertiesChanged; (obj as IMyFunctionalBlock).IsWorkingChanged -= OnIsWorkingChanged; PlayerInput.Instance.DeleteTerminalValues(obj.EntityId); }
public static bool UnregisterHandler(VRage.ModAPI.IMyEntity Entity, string SenderFilter, ReceivedMessageHandler Handler) { long EntityID = Entity.EntityId; if (!EntityHandlersCollection.ContainsKey(EntityID)) { return(false); } if (!EntityHandlersCollection[EntityID].ContainsKey(SenderFilter)) { return(false); } return(EntityHandlersCollection[EntityID][SenderFilter].Remove(Handler)); }
/// <summary> /// Subscribes an entity-level handler to the message received event from given sender about the given entity. /// <para /> /// Useful for entity gamelogic components. Absolutely not useful for entity components. /// </summary> /// <param name="SenderName">A DataMessage.SenderName on which the handler will be invoked.</param> public static bool RegisterHandler(VRage.ModAPI.IMyEntity Entity, string SenderName, ReceivedMessageHandler Handler) { long EntityID = Entity.EntityId; if (!EntityHandlersCollection.ContainsKey(EntityID)) { EntityHandlersCollection.Add(EntityID, new Dictionary <string, HashSet <ReceivedMessageHandler> >()); } var EntityHandlers = EntityHandlersCollection[EntityID]; if (!EntityHandlers.ContainsKey(SenderName)) { EntityHandlers.Add(SenderName, new HashSet <ReceivedMessageHandler>()); } return(EntityHandlers[SenderName].Add(Handler)); }
private bool CanInteractWith(IMyEntity entity) { if (entity == null) { return(false); } if ((entity == this.CubeGrid && !CanInteractWithSelf)) { return(false); } if (!(entity is MyCubeGrid) && !(entity is MyCharacter)) { return(false); } return(true); }
private void Beacon_CheckThermal(VRage.ModAPI.IMyEntity obj) { var subtype = Beacon.Name; if (obj is IMyBeacon) { var output = calculateRadius(GetThermalOutput(Beacon)); var beacon = obj as IMyBeacon; if (lastOutput > output) { output = lastOutput * 0.90f; } lastOutput = output; beacon.Radius = output; beacon.Enabled = true; beacon.HudText = "Thermal Signature"; } }
// Closing Event Callbacks private void OnMarkForClose(IMyEntity obj) { var ammo = new MyObjectBuilder_AmmoMagazine() { SubtypeName = "SpotlightTurretAmmoMagazine" }; IMyInventory inv = obj.GameLogic.GetAs <TurretSpotlight>().m_inventory; List <MyInventoryItem> items = new List <MyInventoryItem>(); inv.GetItems(items); MyFixedPoint amount = 0; foreach (var item in items) { amount += item.Amount; } obj.GameLogic.GetAs <TurretSpotlight>().m_inventory.RemoveItemsOfType(amount, ammo); }
static public int GetPlayerState() { int PlayerState = 1; //check to see if player is solo = 0, in a cockpit = 1, chair = 2 or Cryopod = 3 //doing this in case we want a different output set depending on the situation (ex: we won't allow block/ship control for player in cryopod) VRage.ModAPI.IMyEntity controlled = null; string state = string.Empty; try { controlled = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity; } catch { if (EntityStash != null) { controlled = EntityStash; } } // var controlled = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity; if (controlled is VRage.Game.ModAPI.IMyCharacter) { state = "character"; PlayerState = 0; } else if (controlled is Sandbox.ModAPI.Ingame.IMyCockpit) { state = "cockpit"; PlayerState = 1; } else if (!(controlled is VRage.Game.ModAPI.IMyCharacter) && (!(controlled is Sandbox.ModAPI.Ingame.IMyCockpit))) { state = controlled.ToString(); PlayerState = 3; } return(PlayerState); }
protected override void AddProducedItemToInventory(MyBlueprintDefinitionBase definition, MyFixedPoint amountMult) { if (Sync.IsServer) { MyInventory inventory = null; MyInventory inventory2 = (base.Entity as MyEntity).GetInventory(0); if (this.m_lastEntityInteraction == null) { if (inventory2 == null) { return; } foreach (MyBlueprintDefinitionBase.Item item3 in definition.Results) { MyFixedPoint amount = item3.Amount * amountMult; IMyInventoryItem item = base.CreateInventoryItem(item3.Id, amount); inventory2.Add(item, item.Amount); } } else { inventory = (this.m_lastEntityInteraction as MyEntity).GetInventory(0); if (inventory != null) { foreach (MyBlueprintDefinitionBase.Item item in definition.Results) { MyFixedPoint amount = item.Amount * amountMult; IMyInventoryItem item2 = base.CreateInventoryItem(item.Id, amount); if (!inventory.Add(item2, item2.Amount)) { inventory2.Add(item2, item2.Amount); } } } } this.m_lastEntityInteraction = null; } }
/// <summary> /// Uses object by specified action /// Caller calls this method only on supported actions /// </summary> void IMyUseObject.Use(UseActionEnum actionEnum, IMyEntity entity) { var user = entity as MyCharacter; if (MyPerGameSettings.TerminalEnabled) { MyGuiScreenTerminal.Show(MyTerminalPageEnum.Inventory, user, this); } if (MyPerGameSettings.GUI.InventoryScreen != null && IsDead) { var inventory = Components.Get<MyInventoryAggregate>(); if (inventory != null) { var screen = user.ShowAggregateInventoryScreen(inventory); } } }
void UpdateShadowIgnoredObjects(IMyEntity parent) { Render.UpdateShadowIgnoredObjects(parent); foreach (var child in parent.Hierarchy.Children) { UpdateShadowIgnoredObjects(child.Container.Entity); } }
private void Beacon_CheckThermal(VRage.ModAPI.IMyEntity obj) { if (Beacon != null) { var subtype = Beacon.Name; if (obj is IMyBeacon && obj != null) { var output = calculateRadius(GetThermalOutput(Beacon)); var beacon = obj as IMyBeacon; if (lastOutput > output) { delay = 0; output = lastOutput * 0.95f; } if (output <= 1.0f) { output = 1.0f; } if (GetBeaconRadius() < output && output != 0.0f && (GetBeaconRadius() != lastOutput)) { delay += 1; CubeGrid_UpdatePowerGrid(Beacon.SlimBlock); if (delay == 5) { //ApplyDamagePower(Beacon); if (output <= 500000)// && output <= 5) { TogglePower(Beacon); } } } lastOutput = output; beacon.Radius = output; //MyAPIGateway.Utilities.ShowMessage("ThermalBeacon_Debug", "beacon.Radius Output Range:" + output.ToString()); beacon.Enabled = true; if (beacon.Radius <= 8000) { beacon.HudText = "Small Signature"; } if (beacon.Radius >= 8001 && beacon.Radius <= 100000) { beacon.HudText = "Medium Signature"; } if (beacon.Radius >= 100001 && beacon.Radius <= 250000) { beacon.HudText = "Large Signature"; } if (beacon.Radius >= 250001 && beacon.Radius <= 400000) { beacon.HudText = "Huge Signature"; } if (beacon.Radius >= 400001) { beacon.HudText = "Massive Signature"; } } } }
private void AddEntityInternal(IMyEntity ientity, bool blockManipulatedEntity = true) { MyEntity entity = ientity as MyEntity; if (entity == null) { return; } MyCubeBlock block; Vector3D? hitPosition = null; MyCharacterDetectorComponent detectorComponent = Owner.Components.Get<MyCharacterDetectorComponent>(); if (detectorComponent != null) hitPosition = detectorComponent.HitPosition; MyDefinitionId dummy; // this code checks if this entity can be used as component for building, we want add only those cubegrids to inventories entity = TestEntityForPickup(entity, hitPosition, out dummy, blockManipulatedEntity); if (entity is MyCubeGrid) { if (!AddGrid(entity as MyCubeGrid)) { MyHud.Notifications.Add(MyNotificationSingletons.InventoryFull); } } else if (entity is MyCubeBlock) { if (!AddBlockAndRemoveFromGrid((entity as MyCubeBlock).SlimBlock)) { MyHud.Notifications.Add(MyNotificationSingletons.InventoryFull); } } else if (entity is MyFloatingObject) { TakeFloatingObject(entity as MyFloatingObject); } }
public void AddEntity(IMyEntity entity, bool blockManipulatedEntity = true) { MyMultiplayer.RaiseEvent(this, x => x.AddEntity_Implementation, entity.EntityId, blockManipulatedEntity); }
public void SetLastEntityInteraction(VRage.ModAPI.IMyEntity entity) { this.m_lastEntityInteraction = entity; }