public virtual void Init(MyObjectBuilder_Bot botBuilder) { var ob = botBuilder as MyObjectBuilder_AgentBot; if (ob == null) return; m_deathCountdownMs = ob.RespawnCounter; if (AgentDefinition.FactionTag != null) { var faction = MySession.Static.Factions.TryGetOrCreateFactionByTag(AgentDefinition.FactionTag); if (faction != null) { MyFactionCollection.SendJoinRequest(faction.FactionId, Player.Identity.IdentityId); m_joinRequestSent = true; } } 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); }
public IMyBot CreateBot(MyPlayer player, MyObjectBuilder_Bot botBuilder, MyBotDefinition botDefinition) { MyObjectBuilderType obType = MyObjectBuilderType.Invalid; if (botBuilder == null) { obType = botDefinition.Id.TypeId; botBuilder = m_objectFactory.CreateObjectBuilder<MyObjectBuilder_Bot>(m_objectFactory.GetProducedType(obType)); } else { obType = botBuilder.TypeId; Debug.Assert(botDefinition.Id == botBuilder.BotDefId, "Bot builder type does not match bot definition type!"); } 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; var botData = m_botDataByBehaviorType[botDefinition.BehaviorType]; IMyBot output = CreateBot(m_objectFactory.GetProducedType(obType), player, botDefinition); CreateActions(output, botData.BotActionsType); CreateLogic(output, botData.LogicType, botDefinition.BehaviorSubtype); output.Init(botBuilder); return output; }