Beispiel #1
0
            //auxiliary function to skil a boring step from the process of declar  ing the inventory lists
            private List <MyInventoryItem> fillListFromInventory(IMyInventory vfCargo)
            {
                List <MyInventoryItem> itemInv = new List <MyInventoryItem>();

                vfCargo.GetItems(itemInv);
                return(itemInv);
            }
Beispiel #2
0
        private void ViewCargoInventory(IMyCargoContainer cargo)
        {
            if (cargo == null)
            {
                Print("Контейнер не найден");
                return;
            }

            Print($"Контейнер: {cargo.CustomName}");
            IMyInventory inventory = cargo.GetInventory();

            if (inventory != null)
            {
                Print($"items: {inventory.GetItems().Count}");
                foreach (var item in inventory.GetItems())
                {
                    Print(
                        $"{cargo.CustomName} \n\t\tN: {item.Content.SubtypeName}, \n\t\tI: {item.Content.SubtypeId}, \n\t\tT: {item.Content.TypeId}");
                }
            }
            else
            {
                Print("Конейнер пуст");
            }
        }
        private bool Transfer(IMyInventory source, IMyInventory destination, string itemType, VRage.MyFixedPoint amount)
        {
            //Moves given amount of given type from source to destination
            int ixSource;
            List <MyInventoryItem> sourceItems = GetInventoryItems(source);

            ixSource = IndexOfFirstTradeItem(source, itemType, false);
            if (ixSource < 0)
            {
                Display(Info.MsgErrTransferNoItemsInSource, itemType, source.ToString());
                return(false);
            }

            MyInventoryItem item = sourceItems[ixSource];

            if (amount > item.Amount)
            {
                Display(Info.MsgErrTransferInsufficientItemsInSource, source.ToString(), item.Amount + "/" + amount.ToString() + " " + itemType);
                return(false);
            }

            if (!source.TransferItemTo(destination, ixSource, null, true, amount))
            {
                Display(Info.MsgErrTransferFailed, amount.ToString() + " " + itemType, source.ToString() + " -> " + destination.ToString());
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public void setupContainerDict(IMyCargoContainer container)
        {
            bool found = false;
            List <IMyCargoContainer> tempList = new List <IMyCargoContainer>();
            IMyInventory             tempInv  = container.GetInventory();
            string volumeString = "";

            if ((float)tempInv.CurrentVolume > 0.0f)
            {
                volumeString = " (" + (((float)tempInv.CurrentVolume / (float)tempInv.MaxVolume) * 100.0f).ToString("N1") + "%)";
            }
            else
            {
                volumeString = " (0%)";
            }

            foreach (string vString in CargoPrefix)
            {
                if (!(container_dict.ContainsKey(vString)))
                {
                    container.CustomName = vString + " Cargo Container 01" + volumeString;
                    tempList.Add(container);
                    container_dict.Add(vString, tempList);
                    found = true;
                    break;
                }
            }
            if (!(found))
            {
                Echo("Dict already contains the proper key.\n" + container.CustomName + " is lost");
            }
        }
        public void Main(string containerName)
        {
            IMyCargoContainer cargo = FindBlock <IMyCargoContainer>(containerName);
            IMyTextPanel      debug = FindBlock <IMyTextPanel>("debug");

            if (cargo == null || debug == null)
            {
                debug.WritePublicText("Cargo or debug not found!", false);
                return;
            }
            IMyInventory cargoInventory = cargo.GetInventory(0);

            var assemblers = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyAssembler>(assemblers);
            for (int i = 0; i < assemblers.Count; i++)
            {
                if (!assemblers[i].HasInventory)
                {
                    continue;
                }
                IMyInventory            inventory = assemblers[i].GetInventory(1);
                List <IMyInventoryItem> items     = inventory.GetItems();
                debug.WritePublicText("Items Moved:" + items.Count + "\n", true);
                // Move items to cargo
                for (int j = 0; j < items.Count; j++)
                {
                    inventory.TransferItemTo(cargoInventory, 0, null, stackIfPossible: true);
                }
            }
        }
Beispiel #6
0
        bool AddItemToInventory(string type, int amountRequired, int fetchAmount)
        {
            int amountRemaining = amountRequired;

            for (int i = 0; i < SourceInventories.Count; i++)
            {
                IMyInventory sourceInventory    = SourceInventories[i];
                Nullable <MyInventoryItem> item = InventoryUtils.FindItemInInventoryBySubType(sourceInventory, type);
                if (item.HasValue)
                {
                    int  amountToAdd = item.Value.Amount.ToIntSafe() > amountRemaining ? amountRemaining : item.Value.Amount.ToIntSafe();
                    bool result      = InventoryUtils.TransferItemToAvailableInventory(item.Value, (MyFixedPoint)amountToAdd, sourceInventory, MyInventories, fetchAmount);
                    if (result)
                    {
                        amountRemaining = amountRemaining - amountToAdd;
                    }
                }
                if (amountRemaining <= 0)
                {
                    return(true);
                }
            }
            ;

            return(false);
        }
        internal void GetAvailableComponents(ref Dictionary <string, int> result)
        {
            if (MyAPIGateway.Session.CreativeMode)
            {
                return;
            }

            IMyInventory inventory = GetConstructionInventory();

            if (inventory != null)
            {
                foreach (var item in inventory.GetItems())
                {
                    //Logging.Instance.WriteLine(string.Format("Item: {0} - {1}", item.Amount, item.Content.SubtypeName));

                    if ((int)item.Amount < 1)
                    {
                        continue;
                    }

                    if (!result.ContainsKey(item.Content.SubtypeName))
                    {
                        result.Add(item.Content.SubtypeName, (int)item.Amount);
                    }
                    else
                    {
                        result[item.Content.SubtypeName] += (int)item.Amount;
                    }
                }
            }
        }
Beispiel #8
0
            public void UpdateInventories()
            {
                /*
                 * grabs all blocks with inventories on the grid (except assemblers, reactors, etc.)
                 * adds blocks to different sorting categories (potentially multiple)
                 */

                ClearGridInfo();

                inventoryBlocks.Clear();
                parent.GridTerminalSystem.GetBlocksOfType(inventoryBlocks, b => InventoryBlockIsValid(b));

                foreach (IMyTerminalBlock block in inventoryBlocks)
                {
                    if (!idToCategoryKeySet.ContainsKey(block.EntityId)) // to avoid creating new dictionaries literally every run
                    {
                        idToCategoryKeySet[block.EntityId] = new HashSet <string>();
                    }

                    if (!AddCategoriesToBlock(block))
                    {
                        miscInventoryBlocks.Add(block);

                        IMyInventory inventory = block.GetInventory();
                        CurrentMiscVolume += inventory.CurrentVolume;
                        MaxMiscVolume     += inventory.MaxVolume;
                    }
                }
            }
Beispiel #9
0
        public int GetItemCountFromInventory(IMyInventory inventory, string itemName)
        {
            MyDefinitionId myDefinitionId = GetMyDefinitionIdByName(itemName);
            MyItemType     myItemType     = MyItemType.MakeComponent(myDefinitionId.SubtypeId.ToString());

            return((int)inventory.GetItemAmount(myItemType));
        }
Beispiel #10
0
        private void getCounts(string itemstring)
        {
            int count = 0;
            List <IMyCargoContainer> containers = new List <IMyCargoContainer>();

            GridTerminalSystem.GetBlocksOfType(containers, (IMyCargoContainer block) => block.HasInventory);
            //Echo("Found " + containers.Count.ToString() + " containers");
            for (int i = 0; i < containers.Count; i++)
            {
                IMyCargoContainer      cont  = containers[i];
                List <MyInventoryItem> items = new List <MyInventoryItem>();
                if (cont.HasInventory)
                {
                    IMyInventory cont_inv = cont.GetInventory() as IMyInventory;
                    cont_inv.GetItems(items, (MyInventoryItem item) => item.Type.ToString() == itemstring);
                    //Echo("Found " + items.Count.ToString() + " items in " + cont.Name);
                    for (int j = 0; j < items.Count; j++)
                    {
                        var item = items[j];
                        count += item.Amount.ToIntSafe();
                    }
                }
            }
            counts[itemstring] = count;
        }
Beispiel #11
0
            private bool AddCategoriesToBlock(IMyTerminalBlock block)
            {
                /*
                 * try (and add) all relevant categories to a block, mark the category as active, and increment inventory counts
                 * true if any category was added, false if not
                 */

                bool hasCategory = false;

                string[] customData = block.CustomData.Split(newLine);

                foreach (string tag in customData)
                {
                    string categoryKey;

                    if (tagToCategoryKey.TryGetValue(tag, out categoryKey))
                    {
                        Category category = Categories[categoryKey];

                        ActiveCategories[categoryKey] = category; // doesn't really matter what's used for this key

                        category.Inventories.Add(block);

                        IMyInventory inventory = block.GetInventory();
                        category.CurrentVolume += inventory.CurrentVolume;
                        category.MaxVolume     += inventory.MaxVolume;

                        idToCategoryKeySet[block.EntityId].Add(categoryKey);

                        hasCategory = true;
                    }
                }
                return(hasCategory);
            }
        //this makes sure all tools are connected to the same conveyor system
        private bool AreToolsConnected(List <IMyCubeBlock> tools)
        {
            if (tools.Count != 8)
            {
                return(false);
            }
            bool found = true;

            Wrapper.GameAction(() =>
            {
                for (int i = 1; i < tools.Count; ++i)
                {
                    IMyInventory toolInventory    = (IMyInventory)((IMyShipToolBase)tools[0]).GetInventory(0);
                    IMyInventory compareInventory = (IMyInventory)((IMyShipToolBase)tools[i]).GetInventory(0);
                    if (compareInventory == null || toolInventory == null)
                    {
                        continue;
                    }
                    if (!toolInventory.IsConnectedTo(compareInventory))
                    {
                        found = false;
                    }
                }
            });
            return(found);
        }
Beispiel #13
0
        /// <summary>
        /// Finds the next higher level tool.
        /// Returns true if the id was changed.
        /// </summary>
        private bool Upgrade(ref MyDefinitionId id, int index)
        {
            if (MyAPIGateway.Session.CreativeMode)
            {
                if (index == Ids.Length - 1)
                {
                    return(false);
                }

                EquipIndex = index + 1;
                id         = Ids[EquipIndex];
                return(true);
            }

            IMyInventory inv = p.Character.GetInventory();
            MyFixedPoint one = 1;

            for (int i = index + 1; i < Ids.Length; i++)
            {
                if (inv.ContainItems(one, Ids[i]))
                {
                    id = Ids[i];
                    return(true);
                }
            }
            return(false);
        }
Beispiel #14
0
        /// <summary>
        /// Finds the best available tool.
        /// Returns true if the id was changed.
        /// </summary>
        private bool MakeBest(ref MyDefinitionId id, int index)
        {
            if (MyAPIGateway.Session.CreativeMode)
            {
                if (index == EquipIndex)
                {
                    return(false);
                }

                id = Ids[EquipIndex];
                return(true);
            }

            IMyInventory inv = p.Character.GetInventory();
            MyFixedPoint one = 1;

            for (int i = Ids.Length - 1; i > index; i--)
            {
                if (inv.ContainItems(one, Ids[i]))
                {
                    id = Ids[i];
                    return(true);
                }
            }
            return(false);
        }
        public static double RemoveFromInventory(IMyInventory inventory, MyDefinitionId itemDefinition, double amount)
        {
            var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(itemDefinition);
            MyObjectBuilder_InventoryItem item = new MyObjectBuilder_InventoryItem
            {
                Amount = new MyFixedPoint {
                    RawValue = (long)(amount * _multi)
                },
                PhysicalContent = content
            };
            MyFixedPoint inventoryAmount = inventory.GetItemAmount(itemDefinition);

            if (inventoryAmount >= item.Amount)
            {
                inventory.RemoveItemsOfType(item.Amount, item.PhysicalContent);

                return(amount);
            }

            if (inventoryAmount <= 0)
            {
                return(0);
            }

            inventory.RemoveItemsOfType(inventoryAmount, item.PhysicalContent);

            return(inventoryAmount.RawValue == 0 ? 0 : inventoryAmount.RawValue / _multi);
        }
Beispiel #16
0
        public void UpdateItemAmount(InventoryItemEntity item, float newAmount)
        {
            if (BackingObject != null)
            {
                SandboxGameAssemblyWrapper.Instance.GameAction(new Action(delegate()
                {
                    IMyInventory myInventory = (IMyInventory)BackingObject;
                    if (newAmount == 0)
                    {
                        myInventory.RemoveItems(item.ItemId);
                    }
                    else if (newAmount > item.Amount)
                    {
                        myInventory.AddItems((MyFixedPoint)(newAmount - item.Amount), item.PhysicalContent, (int)item.ItemId);
                    }
                    else if (newAmount < item.Amount)
                    {
                        myInventory.RemoveItemsAt((int)item.ItemId, (MyFixedPoint)(item.Amount - newAmount), true);
                    }
                }));
            }

            /*
             * InventoryDelta delta = new InventoryDelta();
             * delta.item = item;
             * delta.oldAmount = item.Amount;
             * delta.newAmount = newAmount;
             *
             * m_itemDeltaQueue.Enqueue(delta);
             *
             * Action action = InternalUpdateItemAmount;
             * SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
             */
        }
Beispiel #17
0
        void EmptyInventory(IMyInventory inventory, int fetchAmount)
        {
            List <MyInventoryItem> items = new List <MyInventoryItem>();

            inventory.GetItems(items);
            items.ForEach(item => InventoryUtils.TransferItemToAvailableInventory(item, item.Amount, inventory, SourceInventories, fetchAmount));
        }
Beispiel #18
0
        /// <summary>
        /// Push all components into destinations
        /// </summary>
        public static bool PushComponents(this IMyInventory srcInventory, List <IMyInventory> destinations)
        {
            var moved = false;

            lock (destinations)
            {
                var srcItems = srcInventory.GetItems();
                for (int i1 = srcItems.Count - 1; i1 >= 0; i1--)
                {
                    var srcItem = srcItems[i1];
                    foreach (var destInventory in destinations)
                    {
                        if (destInventory.CanItemsBeAdded(srcItem.Amount, srcItem.Content.GetId()))
                        {
                            moved = srcInventory.TransferItemTo(destInventory, i1, null, true, srcItem.Amount) || moved;
                            break;
                        }
                        //If not the whole amount could be transfered i give up.
                        //I could check if parts could be transfered, but as long as ComputeAmountThatFits is not available,
                        //it would be try and error and a performance gain
                    }
                }
            }
            return(moved);
        }
        private void RemoveBlockInventory(MyCubeBlock block)
        {
            if (block is IMyGunBaseUser)
            {
                return;
            }

            if (block.HasInventory)
            {
                IMyInventory inventory = block.GetInventory(0);
                if (inventory != null)
                {
                    Inventories.Remove(inventory);
                }

                inventory = block.GetInventory(1);
                if (inventory != null)
                {
                    Inventories.Remove(inventory);
                }

                inventory = block.GetInventory(2);                 // just adding this because
                if (inventory != null)
                {
                    Inventories.Remove(inventory);
                }
            }
        }
Beispiel #20
0
 private void fillSpecialInventory(IMyInventory inventory, MyContext context)
 {
     for (int i = 0; i < DESIRED_ITEMS.Length; ++i)
     {
         fillSpecialInventoryWithItem(inventory, i, context);
     }
 }
            public bool Eject(IMyInventory inventory, MyInventoryItem item)
            {
                //Log.Info($"IfFull: {IsFull}");
                if (IsFull)
                {
                    return(false);
                }
                var dst = Ejectors[Index].GetInventory(0);

                do
                {
                    while (dst.IsFull)
                    {
                        Index++;
                        Used++;
                        //Log.Info($"Index:{Index}, Used:{Used}");
                        if (Index >= Ejectors.Count)
                        {
                            //Log.Info("resetting Index");
                            Index = 0;
                        }
                        if (Used >= Ejectors.Count)
                        {
                            //Log.Info("setting IsFull");
                            IsFull = true;
                            return(false);
                        }
                        dst = Ejectors[Index].GetInventory(0);
                    }
                } while(!inventory.TransferItemTo(dst, item));
                return(true);
            }
Beispiel #22
0
 public void RefineryCleanup(int inventory_index, List <IMyCargoContainer> cargo_list)
 {
     foreach (IMyRefinery refinery in refinery_list)
     {
         IMyInventory           refinery_inventory = refinery.GetInventory(inventory_index);
         List <MyInventoryItem> items = new List <MyInventoryItem>();
         refinery_inventory.GetItems(items);
         MyInventoryItem[] refinery_items = items.ToArray();
         for (int idx = 0; idx < refinery_items.Length; idx++)
         {
             MyInventoryItem refinery_item = refinery_items[idx];
             foreach (IMyCargoContainer cargo in cargo_list)
             {
                 IMyInventory cargo_inventory = cargo.GetInventory(0);
                 if (!cargo_inventory.IsFull)
                 {
                     refinery_inventory.TransferItemTo(cargo_inventory, idx, null, true, null);
                 }
                 if (refinery_item.Amount.ToIntSafe() < 1)
                 {
                     break;
                 }
             }
         }
     }
 }
Beispiel #23
0
            public Dictionary <string, double> Count(string end_with)
            {
                Dictionary <string, double> count = new Dictionary <string, double>();

                foreach (IMyCargoContainer cargo in cargo_list)
                {
                    IMyInventory           cargo_inventory = cargo.GetInventory(0);
                    List <MyInventoryItem> items           = new List <MyInventoryItem>();
                    cargo_inventory.GetItems(items);
                    foreach (MyInventoryItem refinery_item in items)
                    {
                        if (refinery_item.Type.TypeId.ToString().EndsWith(end_with))
                        {
                            string name   = Property.GetName(refinery_item);
                            double amount = 0;
                            Double.TryParse(refinery_item.Amount.ToString(), out amount);
                            if (count.ContainsKey(name))
                            {
                                count[name] = count[name] + amount;
                            }
                            else
                            {
                                count.Add(name, amount);
                            }
                        }
                    }
                }
                return(count);
            }
Beispiel #24
0
        /// <summary>
        /// Push all components into destinations
        /// </summary>
        public static bool PushComponents(this IMyInventory srcInventory, List <IMyInventory> destinations, ExcludeInventory exclude)
        {
            var moved = false;

            lock (destinations)
            {
                var srcItems = new List <MyInventoryItem>();
                srcInventory.GetItems(srcItems);
                for (int srcItemIndex = srcItems.Count - 1; srcItemIndex >= 0; srcItemIndex--)
                {
                    var srcItem = srcItems[srcItemIndex];
                    moved = TryTransferItemTo(srcInventory, destinations, srcItemIndex, srcItem, true, exclude) || moved;
                }

                if (!moved)
                {
                    srcItems.Clear();
                    srcInventory.GetItems(srcItems);
                    for (int srcItemIndex = srcItems.Count - 1; srcItemIndex >= 0; srcItemIndex--)
                    {
                        var srcItem = srcItems[srcItemIndex];
                        moved = TryTransferItemTo(srcInventory, destinations, srcItemIndex, srcItem, false, exclude) || moved;
                    }
                }
            }
            return(moved);
        }
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     Block     = Entity as IMyCollector;
     inventory = Block.GetInventory();
     Block.UseConveyorSystem = false;
     NeedsUpdate             = MyEntityUpdateEnum.EACH_10TH_FRAME;
 }
Beispiel #26
0
        /// <summary>
        /// As long as ComputeAmountThatFits is not available for modding we have to try
        /// </summary>
        public static VRage.MyFixedPoint MaxItemsAddable(this IMyInventory destInventory, VRage.MyFixedPoint maxNeeded, MyItemType itemType)
        {
            if (destInventory.CanItemsBeAdded(maxNeeded, itemType))
            {
                return(maxNeeded);
            }

            int maxPossible = 0;
            int currentStep = Math.Max((int)maxNeeded / 2, 1);
            int currentTry  = 0;

            while (currentStep > 0)
            {
                currentTry = maxPossible + currentStep;
                if (destInventory.CanItemsBeAdded(currentTry, itemType))
                {
                    maxPossible = currentTry;
                }
                else
                {
                    if (currentStep <= 1)
                    {
                        break;
                    }
                }
                if (currentStep > 1)
                {
                    currentStep = currentStep / 2;
                }
            }
            return(maxPossible);
        }
        void MoveToContainer(
            MyInventoryItem item,
            IMyInventory currentInv,
            int itemIndex,
            List <CargoContainer> containers)
        {
            List <CargoContainer> candidateContainers = new List <CargoContainer>();

            FindCargoSpace(item, currentInv, containers, candidateContainers);
            foreach (CargoContainer container in candidateContainers)
            {
                IMyInventory targetInv           = container.container.GetInventory();
                float        remainingItemVolume = ItemVolume(item);
                float        transferrableVolume = Math.Min(remainingItemVolume,
                                                            targetInv.MaxVolume.RawValue - targetInv.CurrentVolume.RawValue);
                if (currentInv.TransferItemTo(
                        targetInv,
                        item,
                        ItemAmount(item.Type, transferrableVolume)
                        ))
                {
                    remainingItemVolume -= transferrableVolume;
                    if (remainingItemVolume == 0f)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #28
0
        private void RemoveInventory(IMyInventory playerInventory, List <Sandbox.Game.Entities.MyEntity> cargoBlocks, MyFixedPoint amount, MyDefinitionId definitionId)
        {
            var available = playerInventory.GetItemAmount(definitionId);

            if (amount <= available)
            {
                playerInventory.RemoveItemsOfType(amount, definitionId);
                amount = 0;
            }
            else
            {
                playerInventory.RemoveItemsOfType(available, definitionId);
                amount -= available;
            }

            foreach (var cubeBlock in cargoBlocks)
            {
                if (amount > 0)
                {
                    var cubeInventory = cubeBlock.GetInventory();
                    available = cubeInventory.GetItemAmount(definitionId);
                    if (amount <= available)
                    {
                        cubeInventory.RemoveItemsOfType(amount, definitionId);
                        amount = 0;
                    }
                    else
                    {
                        cubeInventory.RemoveItemsOfType(available, definitionId);
                        amount -= available;
                    }
                }
            }
        }
Beispiel #29
0
        private List <MyInventoryItem> GetInventoryItems(IMyInventory container)
        {
            List <MyInventoryItem> items = new List <MyInventoryItem>();

            container.GetItems(items);
            return(items);
        }
 public override void UpdateOnceBeforeFrame()
 {
     resourceSink = Entity.Components.Get <MyResourceSinkComponent>();
     resourceSink.SetRequiredInputByType(electricityDefinition, 0.0001f);
     setPowerConsumption = 0.0001f;
     m_inventory         = ((Sandbox.ModAPI.Ingame.IMyTerminalBlock)Entity).GetInventory(0) as IMyInventory;
 }
        public static MyGuiScreenInventory OpenInventory(MyGuiScreenInventoryType inventoryScreenType, MyEntity otherSide = null, MySmallShipInteractionActionEnum? action = null)
        {
            MyMwcLog.WriteLine("OpenInventory()");


            // return harvester when opening inventory, harvester can update inventory, which would not propagete to inventory screen and closing inventory would override those changes
            var harvester = MySession.PlayerShip.Weapons.GetMountedHarvestingDevice();
            if (harvester != null && harvester.CurrentState != MyHarvestingDeviceEnum.InsideShip)
                harvester.Shot(null);

            StringBuilder otherSideInventoryName = null;
            MyInventory otherSideInventory = null;
            List<MySmallShipBuilderWithName> shipsObjectBuilders = null;
            bool closeOtherSideInventory = false;
            
            m_inventoryScreenType = inventoryScreenType;
            m_shipsInventoryOwner = MySession.Static;
            m_player = MySession.Static.Player;
            m_detectedEntity = otherSide;
            m_detectedAction = action;
            shipsObjectBuilders = new List<MySmallShipBuilderWithName>();
            shipsObjectBuilders.Add(new MySmallShipBuilderWithName(MySession.PlayerShip.GetObjectBuilder(true) as MyMwcObjectBuilder_SmallShip_Player));

            switch(m_inventoryScreenType)
            {            
                case MyGuiScreenInventoryType.GodEditor:
                    LoadGodEditorInventory(ref otherSideInventory, ref otherSideInventoryName, ref shipsObjectBuilders);
                    closeOtherSideInventory = true;
                    break;
                case MyGuiScreenInventoryType.InGameEditor:
                    LoadIngameEditorInventory(ref otherSideInventory, ref otherSideInventoryName);
                    break;
                case MyGuiScreenInventoryType.Game:
                    LoadGameInventory(ref otherSideInventory, ref otherSideInventoryName, ref shipsObjectBuilders);
                    break;
            }
            
            var currentShipBuilder = shipsObjectBuilders[0];            
            shipsObjectBuilders.Sort((x, y) => ((int)x.Builder.ShipType).CompareTo((int)y.Builder.ShipType));
            m_curentIndex = shipsObjectBuilders.IndexOf(currentShipBuilder);
            MyMwcObjectBuilder_Inventory otherSideInventoryBuilder = otherSideInventory != null ? otherSideInventory.GetObjectBuilder(true) : null;
            if (closeOtherSideInventory) 
            {
                Debug.Assert(otherSideInventory != null);
                otherSideInventory.Close();
            }
            m_currentInventoryScreen = new MyGuiScreenInventory(shipsObjectBuilders, m_curentIndex,
                                                                      m_player.Money, m_tradeForMoney,
                                                                      otherSideInventoryBuilder, otherSideInventoryName,
                                                                      m_inventoryScreenType);
            m_currentInventoryScreen.OnSave += Save;
            m_currentInventoryScreen.Closed += OnInventoryScreenClosed;
            MyGuiScreenGamePlay.Static.HideSelectAmmo();
            return m_currentInventoryScreen;
        }
 void IMySlimBlock.IncreaseMountLevel(float welderMountAmount, long welderOwnerPlayerId, IMyInventory outputInventory, float maxAllowedBoneMovement, bool isHelping, MyOwnershipShareModeEnum share)
 {
     IncreaseMountLevel(welderMountAmount, welderOwnerPlayerId, outputInventory as MyInventoryBase, maxAllowedBoneMovement, isHelping, share);
 }
 void IMySlimBlock.ClearConstructionStockpile(IMyInventory outputInventory)
 {
     ClearConstructionStockpile(outputInventory as MyInventoryBase);
 }
 void IMySlimBlock.MoveItemsToConstructionStockpile(IMyInventory fromInventory)
 {
     MoveItemsToConstructionStockpile(fromInventory as MyInventoryBase);
 }
 private bool TransferItemsTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex, VRage.MyFixedPoint? amount,bool useConveyor)
 {
     MyInventory dstInventory = dst as MyInventory;
     if (dstInventory != null)
     {
         if (sourceItemIndex < 0 || sourceItemIndex >= this.m_items.Count || (useConveyor == true && IsConnected(dstInventory) == false))
         {
             return false;
         }
         Transfer(this as MyInventory, dstInventory, this.GetItems()[sourceItemIndex].ItemId, targetItemIndex.HasValue ? targetItemIndex.Value : -1, amount);
         return true;
     }
     return false;
 }
 void IMySlimBlock.MoveItemsFromConstructionStockpile(IMyInventory toInventory, Sandbox.Common.ObjectBuilders.MyItemFlags flags)
 {
     MoveItemsFromConstructionStockpile(toInventory as MyInventory, flags);
 }
 private bool TransferItemsFrom(IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex, bool? stackIfPossible, VRage.MyFixedPoint? amount,bool useConveyors)
 {
     MyInventory srcInventory = sourceInventory as MyInventory;
     if (srcInventory != null && (useConveyors == false || IsConnected(srcInventory) == true))
     {
         TransferItemFrom(srcInventory, sourceItemIndex, targetItemIndex, stackIfPossible, amount);
         return true;
     }
     return false;
 }
 bool IMyInventory.IsConnectedTo(IMyInventory dst)
 {
     MyInventory dstInventory = dst as MyInventory;
     if (dstInventory != null)
     {
         return IsConnected(dstInventory);            
     }
     return false;
 }
 void IMySlimBlock.MoveItemsFromConstructionStockpile(IMyInventory toInventory, MyItemFlags flags)
 {
     MoveItemsFromConstructionStockpile(toInventory as MyInventory, flags);
 }
Beispiel #40
0
        /// <summary>
        /// Get the component amount and index from an inventory.
        /// </summary>
        /// <param name="inventory">Inventory to search.</param>
        /// <param name="defId">Component definition</param>
        /// <param name="amount">Amount of components in inventory</param>
        /// <param name="index">Component position in inventory</param>
        private void GetComponentInInventory(IMyInventory inventory, MyDefinitionId defId, out int amount, out int index)
        {
            amount = (int)inventory.GetItemAmount(defId);
            if (amount == 0)
            {
                index = -1;
                return;
            }

            var allItems = inventory.GetItems();
            for (index = 0; index < allItems.Count; index++)
                if (allItems[index].Content.GetId() == defId)
                    return;
        }
        private static void LoadIngameEditorInventory(ref MyInventory otherSideInventory, ref StringBuilder otherSideInventoryName) 
        {
            m_otherSideInventoryOwner = MyEditor.Static.FoundationFactory.PrefabContainer;

            otherSideInventory = m_otherSideInventoryOwner.Inventory;
            otherSideInventoryName = new StringBuilder();
            otherSideInventoryName.Append(MyEditor.Static.FoundationFactory.PrefabContainer.DisplayName);
            //otherSideInventoryName.Append(MyTextsWrapper.Get(MyTextsWrapperEnum.OtherSideInventory)); 
        }
 /// <summary>
 /// Gets inventory, only items which affect multiplayer
 /// </summary>
 MyMwcObjectBuilder_Inventory GetInventory(IMyInventory ship, bool gameMechanicsItemsOnly)
 {
     var builder = ship.Inventory.GetObjectBuilder(false);
     builder.InventoryItems.RemoveAll(ItemPredicateRemoveShips);
     if (gameMechanicsItemsOnly)
     {
         builder.InventoryItems.RemoveAll(ItemPredicateRemove);
     }
     return builder;
 }
        private static void LoadGameInventory(ref MyInventory otherSideInventory, ref StringBuilder otherSideInventoryName, ref List<MySmallShipBuilderWithName> shipsObjectBuilders) 
        {
            if (MySession.PlayerShip.TradeDetector != null && m_detectedEntity == null)
            {
                m_detectedEntity = MySession.PlayerShip.TradeDetector.GetNearestEntity();
            }            

            if (m_detectedEntity != null)
            {
                if (m_detectedAction == null)
                {
                    m_detectedAction = (MySmallShipInteractionActionEnum)MySession.PlayerShip.TradeDetector.GetNearestEntityCriterias();
                }                
                m_otherSideInventoryOwner = m_detectedEntity as IMyInventory;

                otherSideInventory = m_otherSideInventoryOwner.Inventory;
                string entityName;
                if (m_detectedEntity is MyPrefabHangar)
                {
                    entityName = ((m_detectedEntity) as MyPrefabHangar).GetOwner().GetCorrectDisplayName();
                }
                else
                {
                    entityName = m_detectedEntity.GetCorrectDisplayName();
                }

                switch (m_detectedAction)
                {
                    case MySmallShipInteractionActionEnum.TradeForFree:
                        if (IsTradingWithMothership())
                        {
                            List<MyInventoryItem> inventoryItems = new List<MyInventoryItem>();
                            foreach (MyInventoryItem inventoryItem in m_shipsInventoryOwner.Inventory.GetInventoryItems())
                            {
                                if (inventoryItem.ObjectBuilderType == MyMwcObjectBuilderTypeEnum.SmallShip_Player)
                                {
                                    shipsObjectBuilders.Add(new MySmallShipBuilderWithName(inventoryItem.GetInventoryItemObjectBuilder(false) as MyMwcObjectBuilder_SmallShip_Player));
                                }
                                else if (inventoryItem.ObjectBuilderType == MyMwcObjectBuilderTypeEnum.SmallShip_HackingTool)
                                {
                                    inventoryItem.CanBeMoved = false;
                                }
                                else 
                                {
                                    continue;
                                }
                                inventoryItem.IsTemporaryItem = true;
                                inventoryItems.Add(inventoryItem);
                            }

                            //m_shipsInventoryOwner.Inventory.RemoveInventoryItems(inventoryItems);
                            //m_shipsInventoryOwner.Inventory.RemoveInventoryItems(MyMwcObjectBuilderTypeEnum.SmallShip_Player, null);
                            //m_shipsInventoryOwner.Inventory.ClearInventoryItems(false);
                            m_shipsInventoryOwner.Inventory.RemoveInventoryItems(inventoryItems, false);
                            otherSideInventory.AddInventoryItems(inventoryItems);
                        }
                        break;
                    case MySmallShipInteractionActionEnum.TradeForMoney:
                        m_tradeForMoney = true;
                        if (m_detectedEntity is MySmallShipBot) 
                        {
                            otherSideInventory.PriceCoeficient = 3f;
                        }
                        break;
                    case MySmallShipInteractionActionEnum.Blocked:
                    case MySmallShipInteractionActionEnum.Build:
                    case MySmallShipInteractionActionEnum.Loot:
                    case MySmallShipInteractionActionEnum.Examine:
                    case MySmallShipInteractionActionEnum.ExamineEmpty:
                        break;
                    default:
                        throw new MyMwcExceptionApplicationShouldNotGetHere();
                }

                otherSideInventoryName = new StringBuilder();
                if (string.IsNullOrEmpty(entityName))
                {
                    otherSideInventoryName.Append(MyTextsWrapper.Get(MyTextsWrapperEnum.OtherSide));
                }
                else
                {
                    otherSideInventoryName.Append(entityName);
                    //otherSideInventoryName.Append(MyTextsWrapper.Get(MyTextsWrapperEnum.OtherSideInventory));
                }

                if (OpeningInventoryScreen != null)
                {
                    OpeningInventoryScreen(m_detectedEntity, m_detectedAction.Value);
                }
            }
        }
 private static void Clear()
 {                        
     m_otherSideInventoryOwner = null;
     m_player = null;
     m_shipsInventoryOwner = null;
     m_tradeForMoney = false;            
     m_entityDetector = null;
     m_detectedAction = null;
     m_currentInventoryScreen.OnSave -= Save;
     m_currentInventoryScreen.Closed -= OnInventoryScreenClosed;
     m_currentInventoryScreen = null;
 }
Beispiel #45
0
 public MissingStock(IMyInventory inventory, VRage.MyFixedPoint amount)
 {
     Inventory = inventory;
     Amount = amount;
 }
 void IMySlimBlock.DecreaseMountLevel(float grinderAmount, IMyInventory outputInventory, bool useDefaultDeconstructEfficiency)
 {
     DecreaseMountLevel(grinderAmount, outputInventory as MyInventoryBase, useDefaultDeconstructEfficiency);
 }
 public bool TransferItemTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex = default(int?), bool? stackIfPossible = default(bool?), MyFixedPoint? amount = default(MyFixedPoint?))
 {
     throw new NotImplementedException();
 }
 bool IMyInventory.TransferItemFrom(IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex, bool? stackIfPossible, VRage.MyFixedPoint? amount)
 {
     return TransferItemsFrom(sourceInventory, sourceItemIndex, targetItemIndex, stackIfPossible, amount,true);
 }
 public bool IsConnectedTo(IMyInventory dst)
 {
     throw new NotImplementedException();
 }
 bool VRage.Game.ModAPI.IMyInventory.TransferItemFrom(IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex = null, bool? stackIfPossible = null, VRage.MyFixedPoint? amount = null, bool checkConnection = false)
 {
    return TransferItemsFrom(sourceInventory, sourceItemIndex, targetItemIndex, stackIfPossible, amount, checkConnection);
 }
Beispiel #51
0
        public static bool InventoryAdd(IMyInventory inventory, MyFixedPoint amount, MyDefinitionId definitionId)
        {
            var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId);

            var gasContainer = content as MyObjectBuilder_GasContainerObject;
            if (gasContainer != null)
                gasContainer.GasLevel = 1f;

            MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem { Amount = amount, Content = content };

            if (inventory.CanItemsBeAdded(inventoryItem.Amount, definitionId))
            {
                inventory.AddItems(inventoryItem.Amount, (MyObjectBuilder_PhysicalObject)inventoryItem.Content, -1);
                return true;
            }

            // Inventory full. Could not add the item.
            return false;
        }
 bool IMyInventory.TransferItemTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex, bool? stackIfPossible, VRage.MyFixedPoint? amount)
 {
     return TransferItemsTo(dst, sourceItemIndex, targetItemIndex, amount,true);
 }
 bool IMySlimBlock.CanContinueBuild(IMyInventory sourceInventory)
 {
     return CanContinueBuild(sourceInventory as MyInventory);
 }
 bool Sandbox.ModAPI.IMyInventory.TransferItemTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex = null, bool? stackIfPossible = null, VRage.MyFixedPoint? amount = null, bool checkConnection=false)
 {
    return TransferItemsTo(dst, sourceItemIndex, targetItemIndex, amount, checkConnection);
 }
 void IMySlimBlock.FullyDismount(IMyInventory outputInventory)
 {
     FullyDismount(outputInventory as MyInventory);
 }