示例#1
0
文件: Player.cs 项目: zrisher/ARMS
        private void Update()
        {
            IMyEntity controlled = myPlayer.Controller.ControlledEntity as IMyEntity;

            if (controlled != m_controlled)
            {
                m_controlled = controlled;

                if (controlled is IMyCharacter)
                {
                    m_soundEmitter = null;
                    m_threat       = null;
                    RelayNode charNode;
                    if (!Registrar.TryGetValue(controlled, out charNode))
                    {
                        Log.DebugLog("Failed to get node for character: " + controlled.getBestName(), Logger.severity.WARNING);
                        m_storage = null;
                        return;
                    }
                    m_storage = () => charNode.Storage;
                    Log.DebugLog("now controlling a character", Logger.severity.DEBUG);
                }
                else if (controlled is IMyCubeBlock)
                {
                    IRelayPart shipClient = RelayClient.GetOrCreateRelayPart((IMyCubeBlock)controlled);
                    m_storage      = shipClient.GetStorage;
                    m_soundEmitter = new MyEntity3DSoundEmitter((MyEntity)controlled);
                    Log.DebugLog("now controlling a ship", Logger.severity.DEBUG);
                }
                else
                {
                    Log.TraceLog("player controlling incompatible entity: " + controlled.getBestName(), Logger.severity.TRACE);
                    m_storage      = null;
                    m_soundEmitter = null;
                    m_threat       = null;
                    return;
                }
            }
            else if (m_storage == null || m_storage.Invoke() == null)
            {
                Log.TraceLog("no storage", Logger.severity.TRACE);
                m_threat = null;
                return;
            }

            if (UserSettings.GetSetting(UserSettings.BoolSettingName.MissileWarning))
            {
                UpdateMissileThreat();
            }
            else
            {
                m_threat = null;
            }
        }
示例#2
0
文件: Message.cs 项目: zrisher/ARMS
        private static void GetStorage(long entityId, out IMyCubeBlock block, out RelayStorage storage)
        {
            IMyEntity entity;

            if (!MyAPIGateway.Entities.TryGetEntityById(entityId, out entity))
            {
                Logger.AlwaysLog("Failed to get entity id for " + entityId, Logger.severity.WARNING);
                block   = null;
                storage = null;
                return;
            }

            block = entity as IMyCubeBlock;
            if (block == null)
            {
                Logger.AlwaysLog("Entity is not a block: " + entityId, Logger.severity.WARNING);
                storage = null;
                return;
            }

            storage = RelayClient.GetOrCreateRelayPart(block).GetStorage();
        }