示例#1
0
        public void UnpackFriends()
        {
            MyMwcLog.WriteLine("MyPlayerFriends::UnpackFriends - START");
            MyMwcLog.IncreaseIndent();

            m_helperInventoryItems.Clear();

            MySession.Static.Inventory.GetInventoryItems(ref m_helperInventoryItems, MyMwcObjectBuilderTypeEnum.SmallShip_Bot, null);
            foreach (var inventoryItem in m_helperInventoryItems)
            {
                MyMwcObjectBuilder_SmallShip friendObjectBuilder = (MyMwcObjectBuilder_SmallShip)inventoryItem.GetInventoryItemObjectBuilder(true);

                // We need to removed id's because mothership container could have same entity id in different sector
                friendObjectBuilder.EntityId = null;
                friendObjectBuilder.PositionAndOrientation = new MyMwcPositionAndOrientation(
                    MySession.PlayerShip.GetPosition() + new Vector3(-100, 100, 50),
                    MySession.PlayerShip.WorldMatrix.Forward,
                    MySession.PlayerShip.WorldMatrix.Up);

                var friend = (MySmallShipBot)MyEntities.CreateFromObjectBuilderAndAdd(friendObjectBuilder.DisplayName, friendObjectBuilder,
                                                                                      friendObjectBuilder.PositionAndOrientation.GetMatrix());

                friend.Activate(true, false);
                friend.SpeedModifier = 1.0f;
                friend.Save          = false;
                Add(friend);
                friend.Follow(MySession.PlayerShip);

                MySession.Static.Inventory.RemoveInventoryItem(inventoryItem);
            }

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyPlayerFriends::UnpackFriends - END");
        }
示例#2
0
 public MySmallShipTemplate(int id, StringBuilder name, MyMwcObjectBuilder_SmallShip builder, bool isSavedOnServer)
 {
     ID            = id;
     Name          = name;
     Builder       = builder;
     SavedToServer = isSavedOnServer;
 }
 public MyMwcObjectBuilder_Player(float health, float money, float withoutOxygen,
                                  MyMwcObjectBuilder_PlayerStatistics playerStatisticsObjectBuilder, MyMwcObjectBuilder_SmallShip shipObjectBuilder, MyMwcObjectBuilder_ShipConfig shipConfigObjectBuilder)
 {
     Health        = health;
     Money         = money;
     WithoutOxygen = withoutOxygen;
     PlayerStatisticsObjectBuilder = playerStatisticsObjectBuilder;
     ShipObjectBuilder             = shipObjectBuilder;
     ShipConfigObjectBuilder       = shipConfigObjectBuilder;
 }
示例#4
0
        public void ApplyToSmallShipBuilder(MyMwcObjectBuilder_SmallShip builder)
        {
            var cloneBuilder = Builder.Clone() as MyMwcObjectBuilder_SmallShip;

            builder.Inventory = cloneBuilder.Inventory;
            builder.Weapons   = cloneBuilder.Weapons;
            builder.Armor     = cloneBuilder.Armor;
            builder.Engine    = cloneBuilder.Engine;
            builder.Radar     = cloneBuilder.Radar;
            builder.ShipType  = cloneBuilder.ShipType;
        }
        private void AddBot(MyMwcObjectBuilder_SmallShip bldr)
        {
            BotTemplate newTemplate = new BotTemplate();
            MyMwcObjectBuilder_SmallShip_Bot botBuilder = bldr as MyMwcObjectBuilder_SmallShip_Bot;

            System.Diagnostics.Debug.Assert(botBuilder != null);

            newTemplate.m_builder = new MyMwcObjectBuilder_SmallShip_Bot(
                bldr.ShipType,
                bldr.Inventory,
                bldr.Weapons,
                bldr.Engine,
                bldr.AssignmentOfAmmo,
                bldr.Armor,
                bldr.Radar,
                bldr.ShipMaxHealth,
                bldr.ShipHealthRatio,
                bldr.ArmorHealth,
                bldr.Oxygen,
                bldr.Fuel,
                bldr.ReflectorLight,
                bldr.ReflectorLongRange,
                bldr.Faction,
                botBuilder != null ? botBuilder.AITemplate : MyAITemplateEnum.DEFAULT,
                botBuilder != null ? botBuilder.Aggressivity : 0,
                botBuilder != null ? botBuilder.SeeDistance : 1000,
                botBuilder != null ? botBuilder.SleepDistance : 1000,
                MyPatrolMode.CYCLE,
                null,
                BotBehaviorType.IDLE,
                MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, 0, false, true); // faction will be assigned after spawnpoint genertation
            MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip, (int)bldr.ShipType);
            //m_comboItems.AddItem(i, MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip, bldr.ShipType);

            //  MyMwcObjectBuilderTypeEnum.SmallShip, (int)m_inventory.SmallShips[i]).Description);

            newTemplate.m_name = ((MyGuiSmallShipHelperSmallShip)MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip, (int)bldr.ShipType)).Name.ToString();//bldr.ShipType.ToString();

            // find nearest new non template index
            int index = -1;

            foreach (int key in m_bots.Keys)
            {
                if (index < key && key < TEMPLATE_INDEX_OFFSET)
                {
                    index = key;
                }
            }
            index++;

            AddBot(index, newTemplate);
        }
        private void AddBot(MyMwcObjectBuilder_SmallShip bldr, MySmallShipTemplate smallShipTemplate)
        {
            BotTemplate newTemplate = new BotTemplate();
            MyMwcObjectBuilder_SmallShip_Bot botBuilder = bldr as MyMwcObjectBuilder_SmallShip_Bot;

            newTemplate.m_builder = new MyMwcObjectBuilder_SmallShip_Bot(
                smallShipTemplate.Builder.ShipType,
                null,
                null,
                null,
                smallShipTemplate.Builder.AssignmentOfAmmo,
                null,
                null,
                smallShipTemplate.Builder.ShipMaxHealth,
                smallShipTemplate.Builder.ShipHealthRatio,
                smallShipTemplate.Builder.ArmorHealth,
                smallShipTemplate.Builder.Oxygen,
                smallShipTemplate.Builder.Fuel,
                smallShipTemplate.Builder.ReflectorLight,
                smallShipTemplate.Builder.ReflectorLongRange,
                smallShipTemplate.Builder.Faction,
                botBuilder != null ? botBuilder.AITemplate : MyAITemplateEnum.DEFAULT,
                botBuilder != null ? botBuilder.Aggressivity : 0,
                botBuilder != null ? botBuilder.SeeDistance : 1000,
                botBuilder != null ? botBuilder.SleepDistance : 1000,
                MyPatrolMode.CYCLE,
                null,
                BotBehaviorType.IDLE,
                MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, 0, false, true); // faction will be assigned after spawnpoint genertation
            newTemplate.m_builder.ShipTemplateID = smallShipTemplate.ID;

            newTemplate.m_name = smallShipTemplate.Name.ToString();

            // find nearest new non template index
            int index = -1;

            foreach (int key in m_bots.Keys)
            {
                if (index < key && key < TEMPLATE_INDEX_OFFSET)
                {
                    index = key;
                }
            }
            index++;

            AddBot(index, newTemplate);
        }
        private void OnEditBot(MyMwcObjectBuilder_SmallShip bldr)
        {
            BotTemplate newTemplate = new BotTemplate();
            MyMwcObjectBuilder_SmallShip_Bot botBuilder = bldr as MyMwcObjectBuilder_SmallShip_Bot;

            System.Diagnostics.Debug.Assert(botBuilder != null);

            newTemplate.m_builder = new MyMwcObjectBuilder_SmallShip_Bot(
                bldr.ShipType,
                bldr.Inventory,
                bldr.Weapons,
                bldr.Engine,
                bldr.AssignmentOfAmmo,
                bldr.Armor,
                bldr.Radar,
                bldr.ShipMaxHealth,
                bldr.ShipHealthRatio,
                bldr.ArmorHealth,
                bldr.Oxygen,
                bldr.Fuel,
                bldr.ReflectorLight,
                bldr.ReflectorLongRange,
                bldr.Faction,
                botBuilder != null ? botBuilder.AITemplate : MyAITemplateEnum.DEFAULT,
                botBuilder != null ? botBuilder.Aggressivity : 0,
                botBuilder != null ? botBuilder.SeeDistance : 1000,
                botBuilder != null ? botBuilder.SleepDistance : 1000,
                MyPatrolMode.CYCLE,
                null,
                BotBehaviorType.IDLE,
                MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, bldr.AIPriority, false, true); // faction will be assigned after spawnpoint genertation
            newTemplate.m_name = bldr.ShipType.ToString();
            int key = m_selectShipsListbox.GetSelectedItem().Key;

            m_selectShipsListbox.RemoveItem(key);

            var itemName = MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.SmallShip, (int)newTemplate.m_builder.ShipType).Description;

            m_selectShipsListbox.AddItem(key, itemName);

            m_bots[key] = newTemplate;
        }
示例#8
0
        public void Shutdown()
        {
            Debug.Assert(IsRunning);

            SavePlayer();

            OnShutdown = null;

            IsHost = false;
            ClearCountdownNotification();
            UnregisterCallbacks();
            Peers.Shutdown();
            NewPlayer -= MyMultiplayerGameplay_NewPlayer;
            MyEntityIdentifier.CurrentPlayerId = 0;

            m_lastAmmoAssignment = null;

            StoredShip = null;

            Init();
        }
        private void OnEditBot(MyMwcObjectBuilder_SmallShip bldr, MySmallShipTemplate smallShipTemplate)
        {
            BotTemplate newTemplate = new BotTemplate();
            MyMwcObjectBuilder_SmallShip_Bot botBuilder = bldr as MyMwcObjectBuilder_SmallShip_Bot;

            newTemplate.m_builder = new MyMwcObjectBuilder_SmallShip_Bot(
                smallShipTemplate.Builder.ShipType,
                null,
                null,
                null,
                smallShipTemplate.Builder.AssignmentOfAmmo,
                null,
                null,
                smallShipTemplate.Builder.ShipMaxHealth,
                smallShipTemplate.Builder.ShipHealthRatio,
                smallShipTemplate.Builder.ArmorHealth,
                smallShipTemplate.Builder.Oxygen,
                smallShipTemplate.Builder.Fuel,
                smallShipTemplate.Builder.ReflectorLight,
                smallShipTemplate.Builder.ReflectorLongRange,
                smallShipTemplate.Builder.Faction,
                botBuilder != null ? botBuilder.AITemplate : MyAITemplateEnum.DEFAULT,
                botBuilder != null ? botBuilder.Aggressivity : 0,
                botBuilder != null ? botBuilder.SeeDistance : 1000,
                botBuilder != null ? botBuilder.SleepDistance : 1000,
                MyPatrolMode.CYCLE,
                null,
                BotBehaviorType.IDLE,
                MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE, bldr.AIPriority, false, true); // faction will be assigned after spawnpoint genertation
            newTemplate.m_builder.ShipTemplateID = smallShipTemplate.ID;
            newTemplate.m_name = smallShipTemplate.Name.ToString();
            int key = m_selectShipsListbox.GetSelectedItem().Key;

            m_selectShipsListbox.RemoveItem(key);

            m_selectShipsListbox.AddItem(key, smallShipTemplate.Name);

            m_bots[key] = newTemplate;
        }
示例#10
0
        private static void Save(MyGuiScreenInventory sender, MyGuiScreenInventorySaveResult saveResult)
        {
            // save money
            if (m_tradeForMoney)
            {
                m_player.Money = saveResult.Money;
            }

            bool isTradingWithMotherShip = IsTradingWithMothership();

            List <MyInventoryItem> itemsToMothership = new List <MyInventoryItem>();

            // save ships
            for (int i = 0; i < saveResult.SmallShipsObjectBuilders.Count; i++)
            {
                MyMwcObjectBuilder_SmallShip shipBuilder = saveResult.SmallShipsObjectBuilders[i].Builder;
                if (i == saveResult.CurrentIndex)
                {
                    if (m_curentIndex == saveResult.CurrentIndex)
                    {
                        // we want init weapons only when weapons are not same
                        if (!WeaponBuildersAreSame(m_player.Ship.Weapons.GetWeaponsObjectBuilders(true), shipBuilder.Weapons))
                        {
                            m_player.Ship.Weapons.Init(shipBuilder.Weapons, shipBuilder.AssignmentOfAmmo);
                        }
                        m_player.Ship.Inventory.Init(shipBuilder.Inventory);
                        m_player.Ship.Armor  = shipBuilder.Armor;
                        m_player.Ship.Engine = shipBuilder.Engine;
                    }
                    else
                    {
                        var oldShip = m_player.Ship;
                        m_player.Ship.MarkForClose();

                        if (MyMultiplayerGameplay.IsRunning)
                        {
                            MyMultiplayerGameplay.Static.Respawn(shipBuilder, m_player.Ship.WorldMatrix);
                        }
                        else
                        {
                            var ship = MyEntities.CreateFromObjectBuilderAndAdd(null, shipBuilder, m_player.Ship.WorldMatrix);
                        }

                        // Update bots - bot logic runs on host
                        MyBotCoordinator.ChangeShip(oldShip, m_player.Ship);
                    }
                }
                else
                {
                    if (isTradingWithMotherShip)
                    {
                        MyInventoryItem shipInventoryItem = MyInventory.CreateInventoryItemFromObjectBuilder(shipBuilder);
                        itemsToMothership.Add(shipInventoryItem);
                        //m_shipsInventoryOwner.Inventory.AddInventoryItem(shipInventoryItem);
                    }
                }
            }

            // save other side inventory
            if (m_inventoryScreenType != MyGuiScreenInventoryType.GodEditor)
            {
                if (m_otherSideInventoryOwner != null)
                {
                    if (isTradingWithMotherShip)
                    {
                        for (int i = saveResult.OtherSideInventoryObjectBuilder.InventoryItems.Count - 1; i >= 0; i--)
                        {
                            MyMwcObjectBuilder_InventoryItem itemBuilder = saveResult.OtherSideInventoryObjectBuilder.InventoryItems[i];
                            if (itemBuilder.IsTemporaryItem)
                            {
                                saveResult.OtherSideInventoryObjectBuilder.InventoryItems.RemoveAt(i);
                                // because smallships was added when ships were saved
                                if (itemBuilder.ItemObjectBuilder.GetObjectBuilderType() != MyMwcObjectBuilderTypeEnum.SmallShip_Player)
                                {
                                    itemsToMothership.Add(MyInventory.CreateInventoryItemFromInventoryItemObjectBuilder(itemBuilder));
                                }
                            }
                        }
                    }
                    m_otherSideInventoryOwner.Inventory.Init(saveResult.OtherSideInventoryObjectBuilder);
                }
            }

            if (isTradingWithMotherShip)
            {
                m_shipsInventoryOwner.Inventory.AddInventoryItems(itemsToMothership);
            }
        }
示例#11
0
        internal override bool Read(BinaryReader binaryReader, EndPoint senderEndPoint, int gameVersion)
        {
            if (!base.Read(binaryReader, senderEndPoint, gameVersion))
            {
                return(NetworkError());
            }

            //  ID
            int?id = MyMwcMessageIn.ReadInt32Ex(binaryReader, senderEndPoint);

            if (id == null)
            {
                return(NetworkError());
            }
            ID = id.Value;
            MyMwcLog.IfNetVerbose_AddToLog("ID: " + ID);

            //  Name
            bool?hasName = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (!hasName.HasValue)
            {
                return(NetworkError());
            }
            if (hasName.Value)
            {
                string name = MyMwcMessageIn.ReadStringEx(binaryReader, senderEndPoint);
                if (name == null)
                {
                    return(NetworkError());
                }
                MyMwcLog.IfNetVerbose_AddToLog("Name: " + Name);
                Name = name;
            }
            else
            {
                MyMwcLog.IfNetVerbose_AddToLog("Name: " + "null");
                Name = null;
            }

            //  Builder
            bool?hasBuilder = MyMwcMessageIn.ReadBoolEx(binaryReader, senderEndPoint);

            if (hasBuilder == null)
            {
                return(NetworkError());
            }
            if (hasBuilder.Value)
            {
                Builder = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(binaryReader, senderEndPoint) as MyMwcObjectBuilder_SmallShip;
                if (Builder == null)
                {
                    return(NetworkError());
                }
                if (Builder.Read(binaryReader, senderEndPoint, gameVersion) == false)
                {
                    return(NetworkError());
                }
            }
            else
            {
                Builder = null;
            }

            return(true);
        }
示例#12
0
 public MyMwcObjectBuilder_SmallShipTemplate(int id, string name, MyMwcObjectBuilder_SmallShip builder)
 {
     ID      = id;
     Name    = name;
     Builder = builder;
 }