Ejemplo n.º 1
0
        private void CheckAmmoInventory(MyInventoryBase inventory, MyPhysicalInventoryItem item, MyFixedPoint amount)
        {
            var ammoMag = item.Content as MyObjectBuilder_AmmoMagazine;

            if (ammoMag != null)
            {
                var myInventory = inventory as MyInventory;
                if (myInventory == null)
                {
                    return;
                }
                var magId = ammoMag.GetObjectId();
                if (AmmoInventories.ContainsKey(magId))
                {
                    lock (AmmoInventories[magId])
                    {
                        var hasIntentory = AmmoInventories[magId].ContainsKey(myInventory);

                        if (!hasIntentory && amount > 0)
                        {
                            AmmoInventories[magId][myInventory] = amount;
                            Session.FutureEvents.Schedule(CheckReload, magId, 1);
                        }
                        else if (hasIntentory && AmmoInventories[magId][myInventory] + amount > 0)
                        {
                            AmmoInventories[magId][myInventory] += amount;
                            Session.FutureEvents.Schedule(CheckReload, magId, 1);
                        }
                        else if (hasIntentory)
                        {
                            MyFixedPoint pointRemoved;
                            AmmoInventories[magId].TryRemove(myInventory, out pointRemoved);
                        }
                    }
                }
            }
            Session.AmmoMoveTriggered++;
        }
Ejemplo n.º 2
0
 internal void FatBlockAdded(MyCubeBlock myCubeBlock)
 {
     try
     {
         var battery = myCubeBlock as MyBatteryBlock;
         if (battery != null)
         {
             if (Batteries.Add(battery))
             {
                 SourceCount++;
             }
             UpdatePowerSources = true;
         }
         else if (myCubeBlock is IMyCargoContainer || myCubeBlock is IMyAssembler || myCubeBlock is IMyShipConnector || myCubeBlock is MyCockpit)
         {
             MyInventory inventory;
             if (myCubeBlock.TryGetInventory(out inventory) && Inventories.Add(inventory))
             {
                 inventory.InventoryContentChanged += CheckAmmoInventory;
                 foreach (var item in inventory.GetItems())
                 {
                     var ammoMag = item.Content as MyObjectBuilder_AmmoMagazine;
                     if (ammoMag != null && AmmoInventories.ContainsKey(ammoMag.GetObjectId()))
                     {
                         CheckAmmoInventory(inventory, item, item.Amount);
                     }
                 }
             }
         }
         else if (myCubeBlock is IMyUserControllableGun || myCubeBlock is MyConveyorSorter)
         {
             ScanBlockGroups = true;
         }
     }
     catch (Exception ex) { Log.Line($"Exception in Controller FatBlockAdded: {ex}"); }
 }