public static MyFixedPoint GetMaxAmountPossible(IMyInventory inv, MyObjectBuilder_InventoryItem Item)
        {
            var def       = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.PhysicalContent.GetId());
            var MaxAmount = (int)((inv.MaxVolume - inv.CurrentVolume).RawValue / (def.Volume * 1000000));

            return(MaxAmount > Item.Amount ? Item.Amount : MaxAmount);
        }
        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);
        }
Ejemplo n.º 3
0
        private void BTN_InventoryItem_Add_Click(object sender, EventArgs e)
        {
            if (CMB_ItemType.SelectedItem == null)
            {
                return;
            }
            if (Amount <= 0.0f)
            {
                return;
            }

            try
            {
                MyObjectBuilder_InventoryItem objectBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_InventoryItem>();
                objectBuilder.Content = MyObjectBuilderSerializer.CreateNewObject(SelectedType.TypeId, SelectedType.SubtypeId.ToString());
                objectBuilder.Amount  = (MyFixedPoint)Amount;
                InventoryItemEntity newItem = new InventoryItemEntity(objectBuilder);

                InventoryContainer.NewEntry(newItem);

                Close();
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
        public override void UpdateBeforeSimulation()
        {
            if (Reactor == null)
            {
                NeedsUpdate = MyEntityUpdateEnum.NONE;
                return;
            }

            if (Reactor.IsFunctional == true)
            {
                if (Reactor.GetInventory().Empty() == true)
                {
                    var fuelId   = new MyDefinitionId(typeof(MyObjectBuilder_Ingot), "UraniumB");
                    var content  = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(fuelId);
                    var fuelItem = new MyObjectBuilder_InventoryItem {
                        Amount = 1, Content = content
                    };

                    if (Reactor.GetInventory().CanItemsBeAdded(100, fuelId) == true && MyAPIGateway.Multiplayer.IsServer == true)
                    {
                        Reactor.GetInventory().AddItems(100, fuelItem.Content);
                    }
                }
            }

            NeedsUpdate = MyEntityUpdateEnum.NONE;
        }
Ejemplo n.º 5
0
        private void ReloadIce(MyEntity gun, SerializableDefinitionId ammo)
        {
            var         cGun = gun;
            MyInventory inv  = cGun.GetInventory(0);

            VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);

            if (point.RawValue > 1000000)
            {
                return;
            }
            //inv.Clear();
            VRage.MyFixedPoint amount = new VRage.MyFixedPoint();
            amount.RawValue = 2000000;

            MyObjectBuilder_InventoryItem ii = new MyObjectBuilder_InventoryItem()
            {
                Amount  = 100,
                Content = new MyObjectBuilder_Ore()
                {
                    SubtypeName = ammo.SubtypeName
                }
            };

            inv.AddItems(amount, ii.Content);
        }
        private void BTN_InventoryItem_Add_Click(object sender, EventArgs e)
        {
            if (CMB_ItemType.SelectedItem == null)
            {
                return;
            }
            if (Amount <= 0.0f)
            {
                return;
            }

            try
            {
                MyObjectBuilder_InventoryItem objectBuilder = MyObjectBuilder_Base.CreateNewObject <MyObjectBuilder_InventoryItem>();
                objectBuilder.Content = MyObjectBuilder_Base.CreateNewObject(SelectedType.TypeId, SelectedType.SubtypeId);
                objectBuilder.Amount  = Amount;
                InventoryItemEntity newItem = new InventoryItemEntity(objectBuilder);

                Container.NewEntry(newItem);

                this.Close();
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }
        }
Ejemplo n.º 7
0
 public MyInventoryItem(MyObjectBuilder_InventoryItem item)
 {
     Debug.Assert(item.Amount > 0, "Creating inventory item with zero amount!");
     ItemId  = 0;
     Amount  = item.Amount;
     Content = item.PhysicalContent;
 }
Ejemplo n.º 8
0
        /**
         * Locates all the Oxygen generator class blocks on the given grid,
         * then adds 2000 ice if there is room to do so.
         *
         * Only call on server.
         */
        public static void FillOxygenGenerators(IMyCubeGrid targetGrid)
        {
            List <IMySlimBlock> blockList = new List <IMySlimBlock>();

            targetGrid.GetBlocks(blockList, b => b.FatBlock is Sandbox.ModAPI.IMyGasGenerator);
            foreach (var block in blockList)
            {
                IMyGasGenerator gasGenerator = ((IMyGasGenerator)block.FatBlock);
                if (gasGenerator == null)
                {
                    continue;
                }

                MyDefinitionId definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Ice");
                MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                    Amount  = AMOUNT_ICE_TO_ADD,
                    Content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId)
                };

                IMyInventory gasGeneratorInv = gasGenerator.GetInventory(0);
                if (!gasGeneratorInv.CanItemsBeAdded(AMOUNT_ICE_TO_ADD, definitionId))
                {
                    continue;
                }
                gasGeneratorInv.AddItems(AMOUNT_ICE_TO_ADD, inventoryItem.Content);
            }
        }
Ejemplo n.º 9
0
        internal virtual void ReloadWeapon()
        {
            if (!_ammoReloadPending)
            {
                return;
            }

            var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(_ammoMagazineDefinition.Id);
            MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                Amount = 1, Content = content
            };
            float freeSpace   = (float)(_weaponBlock.GetInventory().MaxVolume - _weaponBlock.GetInventory().CurrentVolume);
            var   amountToAdd = Math.Floor(freeSpace / _ammoMagazineDefinition.Volume);

            if (amountToAdd > _weaponSystem.AmmoReplenishClipAmount && _weaponSystem.AmmoReplenishClipAmount > -1)
            {
                var adjustedAmt = amountToAdd - _weaponSystem.AmmoReplenishClipAmount;
                amountToAdd = adjustedAmt;
            }

            if (amountToAdd > 0 && _weaponBlock.GetInventory().CanItemsBeAdded((MyFixedPoint)amountToAdd, _ammoMagazineDefinition.Id) == true)
            {
                _weaponBlock.GetInventory().AddItems((MyFixedPoint)amountToAdd, inventoryItem.Content);
            }

            _ammoReloadPending = false;
        }
Ejemplo n.º 10
0
 public MyPhysicalInventoryItem(MyObjectBuilder_InventoryItem item)
 {
     Debug.Assert(item.Amount > 0, "Creating inventory item with zero amount!");
     ItemId  = 0;
     Amount  = item.Amount;
     Scale   = item.Scale;
     Content = item.PhysicalContent.Clone() as MyObjectBuilder_PhysicalObject;
 }
Ejemplo n.º 11
0
 private void InsertOperatingItem_Request([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder, long senderEntityId)
 {
     if (IsLocked && senderEntityId != m_lockedByEntityId)
     {
         return;
     }
     MyMultiplayer.RaiseEvent(this, x => x.InsertOperatingItem_Event, itemBuilder);
 }
 public MyPhysicalInventoryItem(MyObjectBuilder_InventoryItem item)
 {
     Debug.Assert(item.Amount > 0, "Creating inventory item with zero amount!");
     ItemId = 0;
     Amount = item.Amount;
     Scale = item.Scale;
     Content = item.PhysicalContent;
 }
Ejemplo n.º 13
0
 private void RemoveOperatingItem_Request([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder, MyFixedPoint amount, long senderEntityId)
 {
     if (IsLocked && senderEntityId != m_lockedByEntityId)
     {
         return;
     }
     MyMultiplayer.RaiseEvent(this, x => x.RemoveOperatingItem_Event, itemBuilder, amount);
 }
Ejemplo n.º 14
0
        internal void Additem(MyObjectBuilder_InventoryItem item)
        {
            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            item.ItemId = _inventory.nextItemId++;
            _inventory.Items.Add(item);
            Items.Add(CreateItem(item, contentPath));
        }
Ejemplo n.º 15
0
        private void Reload(MyEntity gun, SerializableDefinitionId ammo, bool reactor = false)
        {
            var         cGun = gun;
            MyInventory inv  = cGun.GetInventory(0);

            VRage.MyFixedPoint amount = new VRage.MyFixedPoint();
            amount.RawValue = 2000000;
            var hasEnough = inv.ContainItems(amount, new MyObjectBuilder_Ingot()
            {
                SubtypeName = ammo.SubtypeName
            });

            VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);

            if (hasEnough)
            {
                return;
            }
            //inv.Clear();

            Logger.Debug(ammo.SubtypeName + " [ReloadGuns] Amount " + amount);
            MyObjectBuilder_InventoryItem ii;

            if (reactor)
            {
                Logger.Debug(ammo.SubtypeName + " [ReloadGuns] loading reactor " + point.RawValue);
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount  = 10,
                    Content = new MyObjectBuilder_Ingot()
                    {
                        SubtypeName = ammo.SubtypeName
                    }
                };
                Logger.Debug(ammo.SubtypeName + " [ReloadGuns] loading reactor 2 " + point.RawValue);
            }
            else
            {
                Logger.Debug(ammo.SubtypeName + " [ReloadGuns] loading guns " + point.RawValue);
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount  = 4,
                    Content = new MyObjectBuilder_AmmoMagazine()
                    {
                        SubtypeName = ammo.SubtypeName
                    }
                };
                Logger.Debug(ammo.SubtypeName + " [ReloadGuns] loading guns 2 " + point.RawValue);
            }
            //inv.
            Logger.Debug(amount + " Amount : content " + ii.Content);
            inv.AddItems(amount, ii.Content);


            point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
        }
Ejemplo n.º 16
0
        private void Reload(MyEntity gun, SerializableDefinitionId ammo, bool reactor = false)
        {
            var         cGun = gun;
            MyInventory inv  = cGun.GetInventory(0);

            VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);

            if (point.RawValue > 1000000)
            {
                return;
            }
            //inv.Clear();
            VRage.MyFixedPoint amount = new VRage.MyFixedPoint();
            amount.RawValue = 2000000;
            Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + amount, logPath);
            MyObjectBuilder_InventoryItem ii;

            if (reactor)
            {
                Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] loading reactor " + point.RawValue, "ItemManager.txt");
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount  = 10,
                    Content = new MyObjectBuilder_Ingot()
                    {
                        SubtypeName = ammo.SubtypeName
                    }
                };
                Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] loading reactor 2 " + point.RawValue, "ItemManager.txt");
            }
            else
            {
                Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] loading guns " + point.RawValue, "ItemManager.txt");
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount  = 4,
                    Content = new MyObjectBuilder_AmmoMagazine()
                    {
                        SubtypeName = ammo.SubtypeName
                    }
                };
                Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] loading guns 2 " + point.RawValue, "ItemManager.txt");
            }
            //inv.
            Util.GetInstance().Log(amount + " Amount : content " + ii.Content, "ItemManager.txt");
            inv.AddItems(amount, ii.Content);


            point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
        }
Ejemplo n.º 17
0
        public static void WeaponCoreReplenishment(IMyTerminalBlock block)
        {
            MES_SessionCore.Instance.WeaponCore.DisableRequiredPower(block);
            var ammoList = GetCompatibleAmmoTypes(block);

            //Fill Ammos -
            int totalMagazines = 0;
            int totalLoopRuns  = 0;
            int maxMagazines   = 100;           //Until Moved To Config;
            int maxLoopRuns    = 100;

            if (ammoList.Count == 0)
            {
                return;
            }

            while (totalMagazines < maxMagazines && totalLoopRuns < maxLoopRuns)
            {
                totalLoopRuns++;
                bool breakNow  = false;
                bool noLoop    = true;
                bool addedItem = false;

                foreach (var ammoId in ammoList)
                {
                    if (ammoId.SubtypeName == "Energy")
                    {
                        continue;
                    }

                    noLoop = false;
                    var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(ammoId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = 1, Content = content
                    };

                    if (block.GetInventory().CanItemsBeAdded(1, ammoId) == true)
                    {
                        block.GetInventory().AddItems(1, inventoryItem.Content);
                        totalMagazines++;
                        addedItem = true;
                    }
                }

                if (breakNow || noLoop || !addedItem)
                {
                    break;
                }
            }
        }
        protected override void InternalRefreshObjectBuilderMap()
        {
            try
            {
                if (m_rawDataObjectBuilderListResourceLock.Owned)
                {
                    return;
                }
                if (WorldManager.Instance.IsWorldSaving)
                {
                    return;
                }
                if (WorldManager.Instance.InternalGetResourceLock() == null)
                {
                    return;
                }
                if (WorldManager.Instance.InternalGetResourceLock().Owned)
                {
                    return;
                }

                m_rawDataObjectBuilderListResourceLock.AcquireExclusive();

                m_rawDataObjectBuilderList.Clear();
                foreach (Object entity in GetBackingDataList())
                {
                    if (!IsValidEntity(entity))
                    {
                        continue;
                    }

                    MyObjectBuilder_InventoryItem baseEntity = (MyObjectBuilder_InventoryItem)InventoryItemEntity.InvokeEntityMethod(entity, InventoryItemEntity.InventoryItemGetObjectBuilderMethod);
                    if (baseEntity == null)
                    {
                        continue;
                    }

                    m_rawDataObjectBuilderList.Add(entity, baseEntity);
                }

                m_rawDataObjectBuilderListResourceLock.ReleaseExclusive();
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
                m_rawDataObjectBuilderListResourceLock.ReleaseExclusive();
            }
        }
Ejemplo n.º 19
0
        public InventoryItemEntity(Object backingObject, InventoryEntity parent)
        {
            m_backingObject   = backingObject;
            m_parentContainer = parent;

            IMyInventoryItem item = (IMyInventoryItem)backingObject;
            MyObjectBuilder_InventoryItem newItem = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_InventoryItem>( );

            newItem.Amount  = item.Amount;
            newItem.Content = item.Content;
            newItem.ItemId  = item.ItemId;
            m_objectBuilder = newItem;

            m_definition   = MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Content.GetId( ));
            m_definitionId = m_definition.Id;
        }
        public InventoryItemEntity NewEntry()
        {
            MyObjectBuilder_InventoryItem defaults   = new MyObjectBuilder_InventoryItem();
            SerializableDefinitionId      itemTypeId = new SerializableDefinitionId(typeof(MyObjectBuilder_Ore), "Stone");

            defaults.PhysicalContent = (MyObjectBuilder_PhysicalObject)MyObjectBuilder_PhysicalObject.CreateNewObject(itemTypeId);
            defaults.Amount          = 1;

            InventoryItemEntity newItem = m_itemManager.NewEntry <InventoryItemEntity>(defaults);

            newItem.ItemId = NextItemId;
            NextItemId     = NextItemId + 1;

            RefreshInventory();

            return(newItem);
        }
Ejemplo n.º 21
0
        public static bool InventoryAdd(IMyInventory inventory, MyFixedPoint amount, MyDefinitionId definitionId)
        {
            var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId);

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

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

            // Inventory full. Could not add the item.
            return(false);
        }
Ejemplo n.º 22
0
        private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string contentPath)
        {
            var definition = SpaceEngineersApi.GetDefinition(item.Content.TypeId, item.Content.SubtypeName) as MyObjectBuilder_PhysicalItemDefinition;

            string name;
            string textureFile;
            double massMultiplyer;
            double volumeMultiplyer;

            if (definition == null)
            {
                name             = item.Content.SubtypeName + " " + item.Content.TypeId.ToString();
                massMultiplyer   = 1;
                volumeMultiplyer = 1;
                textureFile      = null;
            }
            else
            {
                name             = definition.DisplayName;
                massMultiplyer   = definition.Mass;
                volumeMultiplyer = definition.Volume.Value;
                textureFile      = SpaceEngineersCore.GetDataPathOrDefault(definition.Icon, Path.Combine(contentPath, definition.Icon));
            }

            var newItem = new InventoryModel(item)
            {
                Name             = name,
                Amount           = (decimal)item.Amount,
                SubtypeId        = item.Content.SubtypeName,
                TypeId           = item.Content.TypeId,
                MassMultiplyer   = massMultiplyer,
                VolumeMultiplyer = volumeMultiplyer,
                TextureFile      = textureFile,
                IsUnique         = item.Content.TypeId == SpaceEngineersTypes.PhysicalGunObject || item.Content.TypeId == SpaceEngineersTypes.OxygenContainerObject,
                IsInteger        = item.Content.TypeId == SpaceEngineersTypes.Component || item.Content.TypeId == SpaceEngineersTypes.AmmoMagazine,
                IsDecimal        = item.Content.TypeId == SpaceEngineersTypes.Ore || item.Content.TypeId == SpaceEngineersTypes.Ingot,
                Exists           = definition != null, // item no longer exists in Space Engineers definitions.
            };

            TotalVolume += newItem.Volume;
            TotalMass   += newItem.Mass;

            return(newItem);
        }
        private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false)
        {
            var cGun = gun;

            Sandbox.ModAPI.IMyInventory inv   = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0);
            VRage.MyFixedPoint          point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
            Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt");
            if (point.RawValue > 1000000)
            {
                return;
            }
            //inv.Clear();
            VRage.MyFixedPoint amount = new VRage.MyFixedPoint();
            amount.RawValue = 2000000;

            MyObjectBuilder_InventoryItem ii;

            if (reactor)
            {
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount  = 10,
                    Content = new MyObjectBuilder_Ingot()
                    {
                        SubtypeName = ammo.SubtypeName
                    }
                };
            }
            else
            {
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount  = 4,
                    Content = new MyObjectBuilder_AmmoMagazine()
                    {
                        SubtypeName = ammo.SubtypeName
                    }
                };
            }
            inv.AddItems(amount, ii.PhysicalContent);

            point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
            Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt");
        }
Ejemplo n.º 24
0
        public static bool FixUnfinishedBlock(IMyInventory inv, IMySlimBlock slimBlock, long owner)
        {
            bool success = true;

            Dictionary <string, int> missingParts = new Dictionary <string, int>();

            slimBlock.GetMissingComponents(missingParts);

            if (missingParts.Keys.Count == 0)
            {
                return(success);
            }

            foreach (var part in missingParts.Keys.ToList())
            {
                MyDefinitionId defId   = new MyDefinitionId(typeof(MyObjectBuilder_Component), part);
                var            content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(defId);
                MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                    Amount = 1, Content = content
                };

                while (missingParts[part] > 0)
                {
                    if (inv.CanItemsBeAdded(1, defId) == true)
                    {
                        inv.AddItems(1, inventoryItem.Content);
                        missingParts[part]--;
                    }
                    else
                    {
                        //Logger.AddMsg("Failed To Add Repair Component To Container", true);
                        success = false;
                        break;
                    }
                }

                slimBlock.MoveItemsToConstructionStockpile(inv);
                slimBlock.IncreaseMountLevel(10000, owner, inv);
            }

            return(success);
        }
        private static double AddToInventory(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
            };

            if (!inventory.CanItemsBeAdded(item.Amount, itemDefinition))
            {
                return(0);
            }

            inventory.AddItems(item.Amount, item.PhysicalContent);

            return(amount);
        }
        public InventoryItemEntity(MyObjectBuilder_InventoryItem definition, Object backingObject)
            : base(definition, backingObject)
        {
            if (m_physicalItemsManager == null)
            {
                m_physicalItemsManager = new PhysicalItemDefinitionsManager();
                m_physicalItemsManager.Load(PhysicalItemDefinitionsManager.GetContentDataFile("PhysicalItems.sbc"));
            }
            if (m_componentsManager == null)
            {
                m_componentsManager = new ComponentDefinitionsManager();
                m_componentsManager.Load(ComponentDefinitionsManager.GetContentDataFile("Components.sbc"));
            }
            if (m_ammoManager == null)
            {
                m_ammoManager = new AmmoMagazinesDefinitionsManager();
                m_ammoManager.Load(AmmoMagazinesDefinitionsManager.GetContentDataFile("AmmoMagazines.sbc"));
            }

            FindMatchingItem();
        }
Ejemplo n.º 27
0
        private void BTN_InventoryItem_Add_Click(object sender, EventArgs e)
        {
            if (CMB_ItemType.SelectedItem == null)
            {
                return;
            }
            if (Amount <= 0.0f)
            {
                return;
            }

            try
            {
                SandboxGameAssemblyWrapper.Instance.GameAction(() =>
                {
                    var amount  = (MyFixedPoint)Amount;
                    var content =
                        (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(SelectedType);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem
                    {
                        Amount  = amount,
                        Content = content
                    };

                    if (InventoryContainer.CanItemsBeAdded(amount, SelectedType))
                    {
                        InventoryContainer.AddItems(amount, inventoryItem.Content);
                    }
                });
                Close();
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        private void AwardPoints(ZoneBlock zone, IMyFaction faction, int enemies, bool displayHeader)
        {
            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                return;
            }

            string planetName = zone.GetClosestPlanet();

            if (!Planets.Any(description => description.Name == planetName))
            {
                PlanetDescription p = new PlanetDescription()
                {
                    Name   = planetName,
                    Scores = new List <ScoreDescription>()
                };

                Planets.Add(p);
            }

            long facId = faction.FactionId;
            PlanetDescription planet   = Planets.Find(w => w.Name == planetName);
            IMyCubeGrid       kothGrid = (zone.Entity as IMyCubeBlock).CubeGrid;

            if (!planet.Scores.Any(s => s.FactionId == facId))
            {
                planet.Scores.Add(new ScoreDescription()
                {
                    FactionId   = facId,
                    FactionName = faction.Name,
                    FactionTag  = faction.Tag,
                    Points      = 1,
                    PlanetId    = planetName,
                    GridName    = kothGrid.DisplayName
                });
            }

            int total = GetTotalScore(planet);
            ScoreDescription score = planet.Scores.Find(s => s.FactionId == facId);
            int current            = score.Points;

            int points;

            if (zone.PointsOnCap.Value == 0)
            {
                points = (int)(((float)(total - current) / (float)total) * 5f * enemies) + 1 + enemies;
            }
            else
            {
                points = zone.PointsOnCap.Value;
            }

            planet.Scores.Find(s => s.FactionId == facId).Points += points;
            zone.PointsEarnedSincePrize += points;


            if (zone.AwardPointsAsCredits.Value)
            {
                faction.RequestChangeBalance(points * zone.CreditsPerPoint.Value);
            }


            if (zone.PointsEarnedSincePrize >= zone.PointsForPrize.Value)
            {
                zone.PointsEarnedSincePrize -= zone.PointsForPrize.Value;

                IMyCargoContainer   prizebox = null;
                List <IMySlimBlock> temp     = new List <IMySlimBlock>();
                kothGrid.GetBlocks(temp, s => {
                    if (prizebox == null &&
                        s.FatBlock != null &&
                        s.FatBlock is IMyCargoContainer &&
                        s.FatBlock.BlockDefinition.SubtypeId == "Prizebox")
                    {
                        prizebox = s.FatBlock as IMyCargoContainer;
                    }

                    return(false);
                });

                if (zone.UseComponentReward.Value)
                {
                    string prizeType = (zone.AdvancedComponentSelection.Value) ? zone.PrizeComponentSubtypeId.Value : zone.SelectedComponentString.Value;
                    int    amount    = zone.PrizeAmountComponent.Value;

                    MyDefinitionId                definitionId  = new MyDefinitionId(typeof(MyObjectBuilder_Component), prizeType);
                    MyObjectBuilder_Component     content       = (MyObjectBuilder_Component)MyObjectBuilderSerializer.CreateNewObject(definitionId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = amount, Content = content
                    };

                    if (zone.SpawnIntoPrizeBox.Value)
                    {
                        if (prizebox == null)
                        {
                            Tools.Log(MyLogSeverity.Error, $"Could not find prize box on grid: {kothGrid.DisplayName} - {kothGrid.EntityId}");
                        }
                        else if (prizebox.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            prizebox.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                    else
                    {
                        if (zone.Entity.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            zone.Entity.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                }

                if (zone.UseIngotReward.Value)
                {
                    string prizeType = (zone.AdvancedIngotSelection.Value) ? zone.PrizeIngotSubtypeId.Value : zone.SelectedIngotString.Value;
                    int    amount    = zone.PrizeAmountIngot.Value;

                    MyDefinitionId                definitionId  = new MyDefinitionId(typeof(MyObjectBuilder_Ingot), prizeType);
                    MyObjectBuilder_Ingot         content       = (MyObjectBuilder_Ingot)MyObjectBuilderSerializer.CreateNewObject(definitionId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = amount, Content = content
                    };

                    if (zone.SpawnIntoPrizeBox.Value)
                    {
                        if (prizebox == null)
                        {
                            Tools.Log(MyLogSeverity.Error, $"Could not find prize box on grid: {kothGrid.DisplayName} - {kothGrid.EntityId}");
                        }
                        else if (prizebox.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            prizebox.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                    else
                    {
                        if (zone.Entity.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            zone.Entity.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                }

                if (zone.UseOreReward.Value)
                {
                    string prizeType = (zone.AdvancedOreSelection.Value) ? zone.PrizeOreSubtypeId.Value : zone.SelectedOreString.Value;
                    int    amount    = zone.PrizeAmountOre.Value;

                    MyDefinitionId                definitionId  = new MyDefinitionId(typeof(MyObjectBuilder_Ore), prizeType);
                    MyObjectBuilder_Ore           content       = (MyObjectBuilder_Ore)MyObjectBuilderSerializer.CreateNewObject(definitionId);
                    MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem {
                        Amount = amount, Content = content
                    };

                    if (zone.SpawnIntoPrizeBox.Value)
                    {
                        if (prizebox == null)
                        {
                            Tools.Log(MyLogSeverity.Error, $"Could not find prize box on grid: {kothGrid.DisplayName} - {kothGrid.EntityId}");
                        }
                        else if (prizebox.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            prizebox.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                    else
                    {
                        if (zone.Entity.GetInventory().CanItemsBeAdded(amount, definitionId))
                        {
                            zone.Entity.GetInventory().AddItems(amount, inventoryItem.Content);
                        }
                    }
                }
            }

            StringBuilder message = new StringBuilder();

            if (displayHeader && zone.IsLocationNamed.Value)
            {
                if (zone.EncampmentMode.Value)
                {
                    message.Append($"{kothGrid.DisplayName} on {planetName} Encampment Payout");
                }
                else
                {
                    message.Append($"{kothGrid.DisplayName} on {planetName} under attack");
                }
            }

            byte[] bytes = Encoding.ASCII.GetBytes(message.ToString());
            MyAPIGateway.Multiplayer.SendMessageToServer(8008, bytes);
            Network.Say(message.ToString());

            message.Clear();
            if (zone.AwardPointsAsCredits.Value)
            {
                message.Append($"{faction.Name} Scored {points} Points! ({points * zone.CreditsPerPoint.Value} credits)");
            }
            else
            {
                message.Append($"{faction.Name} Scored {points} Points!");
            }


            SaveData();

            //NEXUS: if nexus is initialized, broadcast the message to nexus (and all other sectors in that way)
            //NEXUS: KotH should work normally if nexus is not initialized
            if (nexusInit)
            {
                //NEXUS: sends the message this sector displays in the chat to all the other sectors
                byte[] nexMessage = Encoding.ASCII.GetBytes(message.ToString());
                Nexus.SendMessageToAllServers(nexMessage);

                //NEXUS: score is broadcasted to other sectors, this basically triggers the save not just on this sector but on all the others with the same score
                var serializedScore = MyAPIGateway.Utilities.SerializeToBinary <List <PlanetDescription> >(Planets);
                Nexus2.SendMessageToAllServers(serializedScore);
            }

            bytes = Encoding.ASCII.GetBytes(message.ToString());
            MyAPIGateway.Multiplayer.SendMessageToServer(8008, bytes);
            Network.Say(message.ToString());
        }
Ejemplo n.º 30
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, PhysicalContent = content };

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

            // Inventory full. Could not add the item.
            return false;
        }
Ejemplo n.º 31
0
 public InventoryItemEntity( MyObjectBuilder_InventoryItem definition, Object backingObject )
     : base(definition, backingObject)
 {
     m_definition = MyDefinitionManager.Static.GetPhysicalItemDefinition( PhysicalContent );
     m_definitionId = m_definition.Id;
 }
Ejemplo n.º 32
0
 public InventoryItemEntity(MyObjectBuilder_InventoryItem definition, Object backingObject)
     : base(definition, backingObject)
 {
     m_definition   = MyDefinitionManager.Static.GetPhysicalItemDefinition(PhysicalContent);
     m_definitionId = m_definition.Id;
 }
Ejemplo n.º 33
0
        private void RemoveOperatingItem_Event([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder, MyFixedPoint amount)
        {
            var item = new MyPhysicalInventoryItem(itemBuilder);

            RemoveOperatingItem_Implementation(item, amount);
        }