Esempio n. 1
0
        // Assume this is triggered when sensor detects player
        public void playerDetected()
        {
            //Echo("Player detected!");

            for (int i = 0; i < doors.Count; i++)
            {
                IMyDoor door           = doors[i];
                Boolean anyoneNearDoor = false;
                for (int j = 0; j < sensors.Count; j++)
                {
                    VRage.ModAPI.IMyEntity player = sensors[j].LastDetectedEntity;
                    if (player == null)
                    {
                        continue;
                    }
                    //Echo("Checking player at " + player.GetPosition().ToString() + " against door " + door.CustomName);

                    if ((player.GetPosition() - door.GetPosition()).Length() <= triggerDist)
                    {
                        anyoneNearDoor = true;
                        break;
                    }
                }
                if (anyoneNearDoor)
                {
                    door.ApplyAction("Open_On");
                }
                else
                {
                    door.ApplyAction("Open_Off");
                }
            }
        }
Esempio n. 2
0
        public static string PrintTerminalActions(IMyEntity block)
        {
            IMyTerminalBlock myTerminalBlock = block as IMyTerminalBlock;

            if (myTerminalBlock == null)
            {
                return("");
            }
            List <ITerminalAction> results = new List <ITerminalAction>();

            myTerminalBlock.GetActions(results);
            StringBuilder sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine();
            sb.AppendFormat("{0,-2}Terminal Actions", " ");
            sb.AppendLine();
            foreach (ITerminalAction terminalAction in results)
            {
                sb.AppendFormat("{0,-4}[{1}]{2}", " ", terminalAction.Id, terminalAction.Name);
                sb.AppendLine();
            }
            sb.AppendLine();
            return(sb.ToString());
        }
Esempio n. 3
0
 public static bool IsEntityFracturedTree(VRage.ModAPI.IMyEntity entity)
 {
     return((entity is MyFracturedPiece) && ((MyFracturedPiece)entity).OriginalBlocks != null && ((MyFracturedPiece)entity).OriginalBlocks.Count > 0 &&
            (((MyFracturedPiece)entity).OriginalBlocks[0].TypeId == typeof(MyObjectBuilder_Tree) ||
             ((MyFracturedPiece)entity).OriginalBlocks[0].TypeId == typeof(MyObjectBuilder_DestroyableItem) ||
             ((MyFracturedPiece)entity).OriginalBlocks[0].TypeId == typeof(MyObjectBuilder_TreeDefinition)) && ((MyFracturedPiece)entity).Physics != null);
 }
Esempio n. 4
0
        public void AddBlocksFromIds(long[] blockIds)
        {
            foreach (long blockId in blockIds)
            {
                VRage.ModAPI.IMyEntity ent = MyAPIGateway.Entities.GetEntityById(blockId);

                if (ent == null)
                {
                    Log.Write("problem finding entity with Id");
                }

                IMyFunctionalBlock block = ent as IMyFunctionalBlock;

                if (block == null)
                {
                    Log.Write("the block isn't a functional one");
                }

                if (block != null && !_blocks.Contains(block))
                {
                    block.EnabledChanged += AssertValidActive;
                    _blocks.Add(ent as IMyFunctionalBlock);
                    Log.Write("added block successfully!");
                }
                else
                {
                    Log.Write("the block is already there");
                }
            }
        }
Esempio n. 5
0
 private void Entities_OnEntityRemove(VRage.ModAPI.IMyEntity obj)
 {
     if (obj != null)
     {
         IMyCubeGrid grid = obj as IMyCubeGrid;
         if (obj != null)
         {
             gridList.Remove(grid);
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Handles the deactivation and decommissioning of the extension.
        /// </summary>
        /// <param name="e">The entity whose closure this method needs to unsubscribe from.</param>
        private void ShutdownSequence(VRage.ModAPI.IMyEntity e)
        {
            // Set this to true/false to enabled/disable debug-logging in this method...
            bool watchMe = true;

            Note(watchMe, "Disconnecting Extension...");
            e.OnClose -= ShutdownSequence;
            Note(watchMe, "Terminating Extension...");
            debugLogger.CloseLog();
            extensionSet.Remove(host.EntityId);
        }
Esempio n. 7
0
 private void Entities_OnEntityAdd(VRage.ModAPI.IMyEntity obj)
 {
     if (obj != null)
     {
         IMyCubeGrid grid = obj as IMyCubeGrid;
         if (obj != null)
         {
             //MyVisualScriptLogicProvider.SendChatMessage(grid.CustomName + " grids: " + gridList.Count.ToString());
             gridList.Add(grid);
         }
     }
 }
Esempio n. 8
0
        private void Assembler_OnClosing(VRage.ModAPI.IMyEntity obj)
        {
            var asm = obj as Sandbox.ModAPI.IMyAssembler;

            if (asm == null)
            {
                return;
            }

            asm.CurrentModeChanged -= Assembler_OnModeChanged;
            asm.OnClosing          -= Assembler_OnClosing;
        }
Esempio n. 9
0
        public static void PrintTerminalActions(IMyEntity block)
        {
            IMyTerminalBlock myTerminalBlock = block as IMyTerminalBlock;

            if (myTerminalBlock == null)
            {
                return;
            }
            List <ITerminalAction> results = new List <ITerminalAction>();

            myTerminalBlock.GetActions(results);
            foreach (ITerminalAction terminalAction in results)
            {
                StaticLog.WriteToLog("PrintTerminalActions", $"Actions: {terminalAction.Id} | {terminalAction.Name}", LogType.General);
            }
        }
        /// <summary>
        /// When entity is being closed, we need to clean it's records for events
        /// </summary>
        /// <param name="entity">entity being removed</param>
        private static void RegisteredEntityOnClose(VRage.ModAPI.IMyEntity entity)
        {
            entity.OnClose -= RegisteredEntityOnClose;

            if (RegisteredListeners.ContainsKey(entity.EntityId))
            {
                if (ProcessingEvents)
                {
                    AddPostponedListenerRemoval(entity.EntityId);
                }
                else
                {
                    RegisteredListeners.Remove(entity.EntityId);
                }
            }

            // Worst case, this entity is registered also elsewheree
            if (ExternalyListenedEntities.Contains(entity.EntityId))
            {
                ExternalyListenedEntities.Remove(entity.EntityId);

                m_tmpCompList.Clear();

                foreach (var entry in ExternalListeners)
                {
                    entry.Value.Remove(entity.EntityId);
                    if (entry.Value.Count == 0)
                    {
                        m_tmpCompList.Add(entry.Key);
                    }
                }

                foreach (var removing in m_tmpCompList)
                {
                    ExternalListeners.Remove(removing);
                }
            }
        }
Esempio n. 11
0
 public static Sandbox.ModAPI.Ingame.IMyGridTerminalSystem getGridTerminal(VRage.ModAPI.IMyEntity Entity)
 {
     return(Sandbox.ModAPI.MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((Entity as IMyCubeBlock).CubeGrid));
 }
Esempio n. 12
0
 private void myBlock_OnClose(VRage.ModAPI.IMyEntity obj)
 {
     (myBlock as IMyTerminalBlock).CustomNameChanged -= Solar_CustomNameChanged;
     myBlock.OnClose -= myBlock_OnClose;
 }
Esempio n. 13
0
 public EntitySync(VRage.ModAPI.IMyEntity Entity, string DataDescription) : base(DataDescription)
 {
     SenderName = $"EntitySyncer {DataDescription} for {Entity.EntityId}";
 }
Esempio n. 14
0
 private void CubeBlock_OnClosing(VRage.ModAPI.IMyEntity obj)
 {
     m_block.CubeBlock.OnClosing -= CubeBlock_OnClosing;
     m_state = State.Closed;
 }