Beispiel #1
0
        private void GridSearch_Friend()
        {
            int          bestNameLength = int.MaxValue;
            RelayStorage store          = m_netStore;

            if (store == null)
            {
                Log.DebugLog("no storage", Logger.severity.DEBUG);
                return;
            }

            store.SearchLastSeen(seen => {
                IMyCubeGrid grid = seen.Entity as IMyCubeGrid;
                if (grid != null && grid.DisplayName.Length < bestNameLength && grid.DisplayName.LowerRemoveWhitespace().Contains(m_targetGridName) && CanTarget(seen))
                {
                    Grid           = seen;
                    bestNameLength = grid.DisplayName.Length;
                    if (bestNameLength == m_targetGridName.Length)
                    {
                        Log.DebugLog("perfect match LastSeen: " + seen.Entity.getBestName());
                        return(true);
                    }
                }
                return(false);
            });

            if (Grid != null)
            {
                Log.DebugLog("Best match LastSeen: " + Grid.Entity.getBestName());
            }
        }
Beispiel #2
0
        private void UpdateLastSeen()
        {
            RelayStorage store = m_controlBlock.NetworkStorage;

            if (store == null)
            {
                Log.DebugLog("failed to get storage", Logger.severity.INFO);
                m_character = null;
                return;
            }

            if (m_character != null)
            {
                if (store.TryGetLastSeen(m_character.Entity.EntityId, out m_character))
                {
                    Log.DebugLog("got updated last seen");
                    return;
                }
                else
                {
                    Log.DebugLog("failed to update last seen", Logger.severity.WARNING);
                    m_character = null;
                    m_timeoutAt = Globals.ElapsedTime + timeout;
                }
            }

            store.SearchLastSeen((LastSeen seen) => {
                Log.DebugLog("seen: " + seen.Entity.getBestName());
                if (seen.Entity is IMyCharacter && seen.Entity.DisplayName.LowerRemoveWhitespace().Contains(m_charName))
                {
                    Log.DebugLog("found a last seen for character");
                    m_character = seen;
                    return(true);
                }
                return(false);
            });

            Log.DebugLog("failed to find a character from last seen", condition: m_character == null);
        }
Beispiel #3
0
        private void GridSearch_Enemy()
        {
            RelayStorage store = m_netStore;

            if (store == null)
            {
                Log.DebugLog("no storage", Logger.severity.DEBUG);
                return;
            }

            if (m_targetEntityId != 0L)
            {
                LastSeen target;
                if (store.TryGetLastSeen(m_targetEntityId, out target) && CanTarget(target))
                {
                    Grid = target;
                    Log.DebugLog("found target: " + target.Entity.getBestName());
                }
                else
                {
                    Grid = null;
                }
                return;
            }

            List <LastSeen> enemies = ResourcePool <List <LastSeen> > .Get();

            Vector3D position = m_controlBlock.CubeBlock.GetPosition();

            store.SearchLastSeen(seen => {
                if (!seen.IsValid || !seen.isRecent())
                {
                    return(false);
                }

                IMyCubeGrid asGrid = seen.Entity as IMyCubeGrid;
                if (asGrid == null)
                {
                    return(false);
                }
                if (!m_controlBlock.CubeBlock.canConsiderHostile(asGrid))
                {
                    return(false);
                }

                enemies.Add(seen);
                Log.DebugLog("enemy: " + asGrid.DisplayName);
                return(false);
            });

            Log.DebugLog("number of enemies: " + enemies.Count);
            IOrderedEnumerable <LastSeen> enemiesByDistance = enemies.OrderBy(OrderValue != null ? OrderValue : seen => Vector3D.DistanceSquared(position, seen.GetPosition()));

            m_reason = ReasonCannotTarget.None;
            foreach (LastSeen enemy in enemiesByDistance)
            {
                if (CanTarget(enemy))
                {
                    Grid = enemy;
                    Log.DebugLog("found target: " + enemy.Entity.getBestName());
                    enemies.Clear();
                    ResourcePool <List <LastSeen> > .Return(enemies);

                    return;
                }
            }

            Grid = null;
            Log.DebugLog("nothing found");
            enemies.Clear();
            ResourcePool <List <LastSeen> > .Return(enemies);
        }