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 MySandboxBot(MyPlayer botPlayer, MyBotDefinition botDefinition)
        {
            m_definition = botDefinition as MyAgentDefinition;

            m_player = botPlayer;
            m_navigation = new MyBotNavigation();
            m_respawnRequestSent = false;
            m_actionCollection = null;
            m_botMemory = new MyBotMemory(this);

            m_player.Controller.ControlledEntityChanged += Controller_ControlledEntityChanged;

            m_navigation.ChangeEntity(m_player.Controller.ControlledEntity);
        }
Пример #3
0
        public MyHumanoidBot(MyPlayer player, MyBotDefinition botDefinition)
            : base(player, botDefinition)
        {
            Debug.Assert(botDefinition is MyHumanoidBotDefinition, "Provided bot definition is not of humanoid type");
            if (m_player.Controller.ControlledEntity is MyCharacter) // when loaded player already controls entity
            {
                var character = m_player.Controller.ControlledEntity as MyCharacter;
                if (character.CurrentWeapon == null && StartingWeaponId.SubtypeId != MyStringHash.NullOrEmpty)
                {
                    AddItems(character);
                }
            }

            Sandbox.Game.Gui.MyCestmirDebugInputComponent.PlacedAction += DebugGoto;
        }
        private static MyCharacter CreateCharacterBase(MatrixD worldMatrix, ref Vector3 velocity, string characterName, string model, Vector3? colorMask, bool AIMode, bool useInventory = true, MyBotDefinition botDefinition = null)
        {
            MyCharacter character = new MyCharacter();
            MyObjectBuilder_Character objectBuilder = MyCharacter.Random();
            objectBuilder.CharacterModel = model ?? objectBuilder.CharacterModel;

            if (colorMask.HasValue)
                objectBuilder.ColorMaskHSV = colorMask.Value;

            objectBuilder.JetpackEnabled = MySession.Static.CreativeMode;
            objectBuilder.Battery = new MyObjectBuilder_Battery { CurrentCapacity = 1 };
            objectBuilder.AIMode = AIMode;
            objectBuilder.DisplayName = characterName;
            objectBuilder.LinearVelocity = velocity;
            objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
            character.Init(objectBuilder);

            MyEntities.RaiseEntityCreated(character);
            MyEntities.Add(character);

            System.Diagnostics.Debug.Assert(character.GetInventory() as MyInventory != null, "Null or unexpected inventory type returned!");
            if (useInventory)
                MyWorldGenerator.InitInventoryWithDefaults(character.GetInventory() as MyInventory);
            else if (botDefinition != null)
            {
                // use inventory from bot definition
                botDefinition.AddItems(character);
            }
            //character.PositionComp.SetWorldMatrix(worldMatrix);
            if (velocity.Length() > 0)
            {
                var jetpack = character.JetpackComp;

                if (jetpack != null)
                    jetpack.EnableDampeners(false, false);
            }

            return character;
        }
        /// <summary>
        /// This will just spawn new character, to take control, call respawn on player
        /// </summary>
        public static MyCharacter CreateCharacter(MatrixD worldMatrix, Vector3 velocity, string characterName, string model, Vector3? colorMask, MyBotDefinition botDefinition, bool findNearPos = true, bool AIMode = false, MyCockpit cockpit = null, bool useInventory = true, ulong playerSteamId = 0)
        {
            Vector3D? characterPos = null;
            if (findNearPos)
            {
                characterPos = MyEntities.FindFreePlace(worldMatrix.Translation, 2, 200, 5, 0.5f);

                // Extended search
                if (!characterPos.HasValue)
                {
                    characterPos = MyEntities.FindFreePlace(worldMatrix.Translation, 2, 200, 5, 5);
                }
            }

            // Use default position
            if (characterPos.HasValue)
            {
                worldMatrix.Translation = characterPos.Value;
            }

            MyCharacter character = CreateCharacterBase(worldMatrix, ref velocity, characterName, model, colorMask, AIMode, useInventory, botDefinition);

            if (cockpit == null && Sync.IsServer && MyPerGameSettings.BlockForVoxels == false)
            {
                MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(character), new EndpointId(playerSteamId));
            }
            return character;
        }
Пример #6
0
 private IMyBot CreateBot(Type botType, MyPlayer player, MyBotDefinition botDefinition)
 {
     return Activator.CreateInstance(botType, player, botDefinition) as IMyBot; // MW:TODO so far agent and humanoid have players so let's keep it like this
 }
Пример #7
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;
 }
Пример #8
0
 public MyAnimalBot(MyPlayer player, MyBotDefinition botDefinition)
     : base(player, botDefinition)
 {
 }
Пример #9
0
        public MyAgentBot(MyPlayer player, MyBotDefinition botDefinition)
        {
            m_player = player;
            m_navigation = new MyBotNavigation(); 
            m_actionCollection = null;
            m_botMemory = new MyBotMemory(this);
            m_botDefinition = botDefinition as MyAgentDefinition;

            m_removeAfterDeath = m_botDefinition.RemoveAfterDeath;
            m_respawnRequestSent = false;
            m_botRemoved = false;

            m_player.Controller.ControlledEntityChanged += Controller_ControlledEntityChanged;
            m_navigation.ChangeEntity(m_player.Controller.ControlledEntity);

            Sandbox.Game.Gui.MyCestmirDebugInputComponent.PlacedAction += DebugGoto;
        }
Пример #10
0
        public MyAgentBot(MyPlayer player, MyBotDefinition botDefinition)
        {
            m_player = player;
            m_navigation = new MyBotNavigation(); 
            m_actionCollection = null;
            m_botMemory = new MyBotMemory(this);
            m_botDefinition = botDefinition as MyAgentDefinition;

            m_player.Controller.ControlledEntityChanged += Controller_ControlledEntityChanged;
            m_navigation.ChangeEntity(m_player.Controller.ControlledEntity);
        }
Пример #11
0
        private void OnBotCreatedEvent(int botSerialNum, MyBotDefinition botDefinition)
        {
 	        var agentDefinition = botDefinition as MyAgentDefinition;
            if (agentDefinition != null && agentDefinition.FactionTag == "SPID")
            {
                MyPlayer player = null;
                if (Sync.Players.TryGetPlayerById(new MyPlayer.PlayerId(Sync.MyId, botSerialNum), out player))
                {
                    player.Controller.ControlledEntityChanged += OnBotControlledEntityChanged;
                    MyCharacter character = (player.Controller.ControlledEntity as MyCharacter);
                    if (character != null)
                    {
                        character.CharacterDied += BotCharacterDied;
                    }
                }
            }
        }
Пример #12
0
 public MyHumanoidBot(MyPlayer player, MyBotDefinition botDefinition)
     : base(player, botDefinition)
 {
     Debug.Assert(botDefinition is MyHumanoidBotDefinition, "Provided bot definition is not of humanoid type");
 }
Пример #13
0
        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;
        }