Example #1
0
        public override void PreloadForDraw()
        {
            base.PreloadForDraw();

            foreach (Bot bot in m_botShips)
            {
                MySmallShipBot ship = CreateBotFromBuilder(bot.Builder, Vector3.Zero);
                ship.PreloadForDraw();
                ship.Physics.Enabled = false;
                ship.MarkForClose();
            }
        }
        public override void Load()
        {
            if (!IsMainSector)
            {
                return;
            }

            //add biochem ammo
            //MyScriptWrapper.GetPlayerInventory().AddInventoryItem(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_BioChem, 100f, true);
            //MyScriptWrapper.GetPlayerInventory().AddInventoryItem(MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Universal_Launcher_Mine_BioChem, 100, true);
            MyScriptWrapper.AddInventoryItem(MyScriptWrapper.GetPlayerInventory(), MyMwcObjectBuilderTypeEnum.SmallShip_Ammo, (int)MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Autocannon_BioChem, 100);
            MyScriptWrapper.AddInventoryItem(MyScriptWrapper.GetCentralInventory(), MyMwcObjectBuilderTypeEnum.SmallShip_HackingTool, (int)MyMwcObjectBuilder_SmallShip_HackingTool_TypesEnum.Level_2, 1f, true);

            MyScriptWrapper.DeactivateSpawnPoint((uint)EntityID.SpawnpointAtWeHaveCompany);

            /*
             * MyMwcObjectBuilder_SmallShip_Player originalBuilder = MySession.PlayerShip.GetObjectBuilder(true) as MyMwcObjectBuilder_SmallShip_Player;
             * originalBuilder.ShipType = MyMwcObjectBuilder_SmallShip_TypesEnum.GETTYSBURG;
             * MySession.PlayerShip.Close();
             * MyEntities.CreateFromObjectBuilderAndAdd(null, originalBuilder, originalBuilder.PositionAndOrientation.GetMatrix());
             */
            m_panelsLeft = GetPanelsLeft((uint)EntityID.PanelsPrefabContainer);
            //MyAudio.ApplyTransition(MyMusicTransitionEnum.HeavyFight);

            MyScriptWrapper.SetPlayerFaction(MyMwcObjectBuilder_FactionEnum.Rainiers);
            MyScriptWrapper.SetFactionRelation(MyMwcObjectBuilder_FactionEnum.Rainiers, MyMwcObjectBuilder_FactionEnum.FourthReich, MyFactions.RELATION_BEST);
            MyScriptWrapper.SetFactionRelation(MyMwcObjectBuilder_FactionEnum.Rainiers, MyMwcObjectBuilder_FactionEnum.Euroamerican, MyFactions.RELATION_WORST);
            MyScriptWrapper.FixBotNames();

            MyEntityDetector startDetector = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.StartDetector));

            startDetector.OnEntityEnter += StartDummyDetector;
            startDetector.On();

            MyEntityDetector Security01Detector = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.SecurityDetector));

            Security01Detector.OnEntityEnter += StartSecurity01Detector;
            Security01Detector.On();

            MyEntityDetector Security02Detector = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.SecurityDetector2));

            Security02Detector.OnEntityEnter += StartSecurity02Detector;
            Security02Detector.On();

            MyScriptWrapper.EntityClosing += EntityClosing;

            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.DestroyPanelsEnable1), false);
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.CargoExitDoor), false);
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.Doors1), false);
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.DestroyPanelsEnable2), false);
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.Doors3), false);
            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((uint)EntityID.Doors4), false);

            MyScriptWrapper.OnSpawnpointBotSpawned += OnSpawnpointSpawned;

            MyScriptWrapper.OnSentenceStarted += MyScriptWrapper_OnSentenceStarted;



            m_marcus = MyScriptWrapper.GetEntity("Marcus") as MySmallShipBot;

            //disable marcus
            if (m_marcus != null)
            {
                //MyScriptWrapper.DisableShip(m_ma);
                m_marcus.Enabled  = false;
                m_marcus.Visible  = false;
                m_marcus.ActiveAI = false;
                MyScriptWrapper.StopFollow(m_marcus);
                m_marcusInventory.Clear();
                m_marcusInventory.AddRange(m_marcus.Inventory.GetInventoryItems());
                m_marcus.Inventory.ClearInventoryItems();
            }

            //disable ships for marcus
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.MarcusFakeShip1));
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.MarcusFakeShip2));
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.MarcusPlaceholder));
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.MarcusFakeShip3));


            m_marcusPlacHolder = MyScriptWrapper.GetEntity((uint)EntityID.MarcusPlaceholder);

            MyScriptWrapper.SetEntityEnabled(MyScriptWrapper.GetEntity((int)EntityID.SecurityHub), false);

            InitDetector((uint)75094, StartEACDetector);

            //add Raven Girl and Raven Guy
            //We need to replace old vitolino+tanja, because they have deutch smallships from doppelburg

            m_ravenguyBot = MyScriptWrapper.GetEntity("RavenGuy") as MySmallShipBot;
            m_ravenguyBot.SetName("Disabled_vitolino");
            m_ravenguyBot.MarkForClose();

            m_ravenguyBot = MyScriptWrapper.InsertFriend(MyActorEnum.VALENTIN);
            m_ravenguyBot.LeaderLostEnabled = true;
            m_ravenguyBot.Follow(MySession.PlayerShip);
            Matrix ravenguyPosition = Matrix.CreateWorld(MySession.PlayerShip.GetPosition() - Vector3.Right * 15, MySession.PlayerShip.WorldMatrix.Forward, MySession.PlayerShip.WorldMatrix.Up);

            m_ravenguyBot.SetWorldMatrix(ravenguyPosition);

            m_ravengirlBot = MyScriptWrapper.GetEntity("RavenGirl") as MySmallShipBot;
            m_ravengirlBot.SetName("Disabled_tanja");
            m_ravengirlBot.MarkForClose();

            m_ravengirlBot = MyScriptWrapper.InsertFriend(MyActorEnum.TARJA);
            m_ravengirlBot.LeaderLostEnabled = true;
            m_ravenguyBot.Follow(MySession.PlayerShip);
            Matrix ravengirlPosition = Matrix.CreateWorld(MySession.PlayerShip.GetPosition() + Vector3.Right * 15, MySession.PlayerShip.WorldMatrix.Forward, MySession.PlayerShip.WorldMatrix.Up);

            m_ravengirlBot.SetWorldMatrix(ravengirlPosition);

            base.Load();
        }
        public override void OnOkClick(MyGuiControlButton sender)
        {
            base.OnOkClick(sender);

            if (m_botBuilder != null)
            {
                m_botBuilder.Faction      = (MyMwcObjectBuilder_FactionEnum)m_selectShipFactionCombobox.GetSelectedKey();
                m_botBuilder.AITemplate   = (MyAITemplateEnum)m_selectAITemplateCombobox.GetSelectedKey();
                m_botBuilder.Aggressivity = m_aggresivitySlider.GetValue();
                m_botBuilder.SeeDistance  = m_seeDistanceSlider.GetValue();
                var  templateBuilder = m_templatesBuilders[m_selectSmallShipCombobox.GetSelectedKey()];
                bool isTemplate      = templateBuilder.UserData != null;
                if (isTemplate)
                {
                    var template = templateBuilder.UserData as MySmallShipTemplate;
                    if (m_botBuilder.ShipTemplateID == null)
                    {
                        if (m_inventoryBuilder == null)
                        {
                            m_botBuilder.Inventory = null;
                            m_botBuilder.Weapons   = null;
                            m_botBuilder.Engine    = null;
                            m_botBuilder.Armor     = null;
                            m_botBuilder.Radar     = null;
                        }
                        else
                        {
                            m_botBuilder.Inventory = m_inventoryBuilder.Inventory;
                            m_botBuilder.Weapons   = m_inventoryBuilder.Weapons;
                            m_botBuilder.Engine    = m_inventoryBuilder.Engine;
                            m_botBuilder.Armor     = m_inventoryBuilder.Armor;
                            m_botBuilder.Radar     = m_inventoryBuilder.Radar;
                        }
                    }
                    m_botBuilder.ShipTemplateID = template.ID;
                }
                else
                {
                    var builderWithAllItems = MyMwcObjectBuilder_SmallShip_Bot.CreateObjectBuilderWithAllItems(templateBuilder.Builder.ShipType, MyShipTypeConstants.GetShipTypeProperties(templateBuilder.Builder.ShipType).GamePlay.CargoCapacity);
                    if (m_botBuilder.ShipTemplateID != null)
                    {
                        m_botBuilder.Inventory = builderWithAllItems.Inventory;
                        m_botBuilder.Weapons   = builderWithAllItems.Weapons;
                        m_botBuilder.Engine    = builderWithAllItems.Engine;
                        m_botBuilder.Armor     = builderWithAllItems.Armor;
                        m_botBuilder.Radar     = builderWithAllItems.Radar;
                    }
                    m_botBuilder.ShipTemplateID = null;
                }
                m_botBuilder.ShipType = templateBuilder.Builder.ShipType;
                CloseAndCallOnOk();
            }
            else if (m_bot != null) // edit SmallShip
            {
                Matrix matrix = m_bot.WorldMatrix;
                MyMwcObjectBuilder_SmallShip_Bot botBuilder = m_bot.GetObjectBuilder(true) as MyMwcObjectBuilder_SmallShip_Bot;
                System.Diagnostics.Debug.Assert(botBuilder != null);

                botBuilder.Faction      = (MyMwcObjectBuilder_FactionEnum)m_selectShipFactionCombobox.GetSelectedKey();
                botBuilder.AITemplate   = (MyAITemplateEnum)m_selectAITemplateCombobox.GetSelectedKey();
                botBuilder.Aggressivity = m_aggresivitySlider.GetValue();
                botBuilder.SeeDistance  = m_seeDistanceSlider.GetValue();
                botBuilder.ShipType     = (MyMwcObjectBuilder_SmallShip_TypesEnum)m_selectSmallShipCombobox.GetSelectedKey();

                if (m_inventoryBuilder != null)
                {
                    botBuilder.Inventory = m_inventoryBuilder.Inventory;
                    botBuilder.Weapons   = m_inventoryBuilder.Weapons;
                    botBuilder.Engine    = m_inventoryBuilder.Engine;
                    botBuilder.Armor     = m_inventoryBuilder.Armor;
                    botBuilder.Radar     = m_inventoryBuilder.Radar;
                }

                MyEditorGizmo.ClearSelection();
                m_newBotBuilderToInit     = botBuilder;
                m_newBotWorldMatrixToInit = matrix;
                m_bot.MarkForClose();
                m_bot.OnClose += OnOldBodClose;
            }
            else // create SmallShip
            {
                MyMwcObjectBuilder_SmallShip_TypesEnum shipType = (MyMwcObjectBuilder_SmallShip_TypesEnum)
                                                                  Enum.ToObject(typeof(MyMwcObjectBuilder_SmallShip_TypesEnum), m_selectSmallShipCombobox.GetSelectedKey());

                MyMwcObjectBuilder_FactionEnum shipFaction = (MyMwcObjectBuilder_FactionEnum)
                                                             Enum.ToObject(typeof(MyMwcObjectBuilder_FactionEnum), m_selectShipFactionCombobox.GetSelectedKey());

                MyMwcPositionAndOrientation      positionAndOrientation = new MyMwcPositionAndOrientation(m_newObjectPosition, Vector3.Forward, Vector3.Up);
                MyMwcObjectBuilder_SmallShip_Bot botBuilder             = MyEditor.CreateDefaultBotObjectBuilder(positionAndOrientation.Position, positionAndOrientation.Forward,
                                                                                                                 positionAndOrientation.Up, shipType, shipFaction);

                botBuilder.AITemplate   = (MyAITemplateEnum)m_selectAITemplateCombobox.GetSelectedKey();
                botBuilder.Aggressivity = m_aggresivitySlider.GetValue();
                botBuilder.SeeDistance  = m_seeDistanceSlider.GetValue();

                MyEditor.Static.CreateFromObjectBuilder(botBuilder, Matrix.CreateWorld(m_newObjectPosition, Vector3.Forward, Vector3.Up), m_screenPosition);
                CloseAndCallOnOk();
            }
        }