Пример #1
0
        public void TryRemoveBot(int botHandler)
        {
            IMyBot bot = null;

            this.m_allBots.TryGetValue(botHandler, out bot);
            if (bot != null)
            {
                string behaviorType = bot.BotDefinition.BehaviorType;
                bot.Cleanup();
                if (this.m_botIndex != -1)
                {
                    if (ReferenceEquals(this.m_behaviorTreeCollection.DebugBot, bot))
                    {
                        this.m_behaviorTreeCollection.DebugBot = null;
                    }
                    int index = this.m_botsQueue.IndexOf(botHandler);
                    if (index < this.m_botIndex)
                    {
                        this.m_botIndex--;
                    }
                    else if (index == this.m_botIndex)
                    {
                        this.m_botIndex = -1;
                    }
                }
                this.m_allBots.Remove(botHandler);
                this.m_botsQueue.Remove(botHandler);
                string str2 = behaviorType;
                this.m_botsCountPerBehavior[str2] -= 1;
            }
        }
Пример #2
0
        public void TryRemoveBot(int botHandler)
        {
            Debug.Assert(m_allBots.ContainsKey(botHandler), "Bot with the given handler does not exist!");

            IMyBot bot = null;

            m_allBots.TryGetValue(botHandler, out bot);
            if (bot == null)
            {
                return;
            }

            var botBehaviorType = bot.BotDefinition.BehaviorType;

            bot.Cleanup();

            if (m_botIndex != -1)
            {
                if (m_behaviorTreeCollection.DebugBot == bot)
                {
                    m_behaviorTreeCollection.DebugBot = null;
                }
                int removedBotIndex = m_botsQueue.IndexOf(botHandler);
                if (removedBotIndex < m_botIndex)
                {
                    m_botIndex--;
                }
                else if (removedBotIndex == m_botIndex)
                {
                    m_botIndex = -1;
                }
            }
            m_allBots.Remove(botHandler);
            m_botsQueue.Remove(botHandler);

            Debug.Assert(m_botsCountPerBehavior[botBehaviorType] > 0, "Bots count of this type is equal to zero. Invalid state");
            m_botsCountPerBehavior[botBehaviorType]--;
        }