public IMyBot CreateBot(MyPlayer player, MyObjectBuilder_Bot botBuilder, MyBotDefinition botDefinition)
 {
     var output = new MySandboxBot(player, botDefinition);
     if (botBuilder != null)
         output.Init(botBuilder);
     return output;
 }
示例#2
0
 public IMyBot CreateBot(MyPlayer player, MyObjectBuilder_Bot botBuilder, MyBotDefinition botDefinition)
 {
     Debug.Assert(m_botDataByBehaviorType.ContainsKey(botDefinition.BehaviorType), "Undefined behavior type. Bot is not going to be created");
     if (!m_botDataByBehaviorType.ContainsKey(botDefinition.BehaviorType))
         return null;
     Debug.Assert(m_botTypeByDefinitionType.ContainsKey(botDefinition.TypeDefinitionId.TypeId), "Type not found. Bot is not going to be created!");
     if (!m_botTypeByDefinitionType.ContainsKey(botDefinition.TypeDefinitionId.TypeId))
         return null;
     var botData = m_botDataByBehaviorType[botDefinition.BehaviorType];
     var behaviorTypeData = m_botTypeByDefinitionType[botDefinition.TypeDefinitionId.TypeId];
     IMyBot output = CreateBot(behaviorTypeData.BotType, player, botDefinition);
     CreateActions(output, botData.BotActionsType);
     CreateLogic(output, botData.LogicType, botDefinition.BehaviorSubtype);
     if (botBuilder != null)
         output.Init(botBuilder);
     return output;
 }
示例#3
0
        public virtual void Init(MyObjectBuilder_Bot botBuilder)
        {
            var ob = botBuilder as MyObjectBuilder_AgentBot;
            if (ob == null)
                return;

            if (ob.AiTarget != null)
                AgentActions.AiTarget.Init(ob.AiTarget);
            if (botBuilder.BotMemory != null)
                m_botMemory.Init(botBuilder.BotMemory);
            BehaviorSubtypeName = ob.LastBehaviorTree;
        }
示例#4
0
        private void CreateBot(int playerNumber, MyObjectBuilder_Bot botBuilder)
        {
            Debug.Assert(BotFactory != null, "Bot factory is not set! Cannot create a new bot!");
            if (BotFactory == null) return;

            var newPlayer = Sync.Clients.LocalClient.GetPlayer(playerNumber);
            if (newPlayer == null) return;

            var isBotSpawned = m_agentsToSpawn.ContainsKey(playerNumber);
            var isLoading = botBuilder != null;
            var createdByPlayer = false;
            MyBotDefinition botDefinition = null;
            AgentSpawnData spawnData = default(AgentSpawnData);
            if (isBotSpawned)
            {
                spawnData = m_agentsToSpawn[playerNumber];
                createdByPlayer = spawnData.CreatedByPlayer;
                botDefinition = spawnData.AgentDefinition;
                m_agentsToSpawn.Remove(playerNumber);
            }
            else
            {
                Debug.Assert(botBuilder != null && !botBuilder.BotDefId.TypeId.IsNull, "Null or invalid bot builder. Bot is not going to be created");
                if (botBuilder == null || botBuilder.BotDefId.TypeId.IsNull)
                    return;

                botDefinition = MyDefinitionManager.Static.GetBotDefinition(botBuilder.BotDefId);
                Debug.Assert(botDefinition != null, "Bot definition could not be found.");
                if (botDefinition == null)
                    return;
            }

            if ((newPlayer.Character == null || !newPlayer.Character.IsDead)
                && BotFactory.CanCreateBotOfType(botDefinition.BehaviorType, isLoading) 
                || createdByPlayer)
            {
                IMyBot bot = null;
                if (isBotSpawned)
                    bot = BotFactory.CreateBot(newPlayer, botBuilder, spawnData.AgentDefinition);                
                else
                    bot = BotFactory.CreateBot(newPlayer, botBuilder, botDefinition);

                if (bot == null)
                {
                    MyLog.Default.WriteLine("Could not create a bot for player " + newPlayer + "!");
                }
                else
                {
                    m_botCollection.AddBot(playerNumber, bot);
                    if (isBotSpawned && bot is IMyEntityBot)
                        (bot as IMyEntityBot).Spawn(spawnData.SpawnPosition, createdByPlayer);
                }
            }
            else
            {
                // hack for removing uncontrolled bot players or saved dead characters
                var player = Sync.Players.TryGetPlayerById(new MyPlayer.PlayerId(MySteam.UserId, playerNumber));
                Sync.Players.RemovePlayer(player);
            }
        }
示例#5
0
 public void Init(MyObjectBuilder_Bot botBuilder)
 {
     var ob = (MyObjectBuilder_BarbarianBot)botBuilder; // MW:TODO replace with sandbox builder
 }
示例#6
0
        public virtual void Init(MyObjectBuilder_Bot botBuilder)
        {
            var ob = botBuilder as MyObjectBuilder_AgentBot;
            if (ob == null)
                return;

            m_removeAfterDeath = ob.RemoveAfterDeath;
            m_deathCountdownMs = ob.RespawnCounter;

            if (ob.AiTarget != null)
                AgentActions.AiTargetBase.Init(ob.AiTarget);
            if (botBuilder.BotMemory != null)
                m_botMemory.Init(botBuilder.BotMemory);
            MyAIComponent.Static.BehaviorTrees.SetBehaviorName(this, ob.LastBehaviorTree);
        }