Beispiel #1
0
        internal void FatBlockAdded(MyCubeBlock cube)
        {
            try
            {
                var battery      = cube as MyBatteryBlock;
                var weaponType   = (cube is MyConveyorSorter || cube is IMyUserControllableGun);
                var isWeaponBase = weaponType && cube.BlockDefinition != null && (Session.ReplaceVanilla && Session.VanillaIds.ContainsKey(cube.BlockDefinition.Id) || Session.WeaponPlatforms.ContainsKey(cube.BlockDefinition.Id));

                if (!isWeaponBase && (cube is MyConveyor || cube is IMyConveyorTube || cube is MyConveyorSorter || cube is MyCargoContainer || cube is MyCockpit || cube is IMyAssembler || cube is IMyShipConnector) && cube.CubeGrid.IsSameConstructAs(MyGrid))
                {
                    MyInventory inventory;
                    if (cube.HasInventory && cube.TryGetInventory(out inventory) && InventoryMonitor.TryAdd(cube, inventory))
                    {
                        inventory.InventoryContentChanged += CheckAmmoInventory;
                        Construct.RootAi.Construct.NewInventoryDetected = true;

                        int monitors;
                        if (!Session.InventoryMonitors.TryGetValue(inventory, out monitors))
                        {
                            Session.InventoryMonitors[inventory]  = 0;
                            Session.InventoryItems[inventory]     = Session.PhysicalItemListPool.Get();
                            Session.AmmoThreadItemList[inventory] = Session.BetterItemsListPool.Get();
                        }
                        else
                        {
                            Session.InventoryMonitors[inventory] = monitors + 1;
                        }
                    }
                }
                else if (battery != null)
                {
                    if (Batteries.Add(battery))
                    {
                        SourceCount++;
                    }
                    UpdatePowerSources = true;
                }
                else if (isWeaponBase)
                {
                    MyOrientedBoundingBoxD b;
                    BoundingSphereD        s;
                    MyOrientedBoundingBoxD blockBox;
                    SUtils.GetBlockOrientedBoundingBox(cube, out blockBox);
                    if (Session.IsWeaponAreaRestricted(cube.BlockDefinition.Id.SubtypeId, blockBox, cube.CubeGrid, cube.EntityId, null, out b, out s))
                    {
                        if (Session.IsServer)
                        {
                            cube.CubeGrid.RemoveBlock(cube.SlimBlock);
                        }
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in Controller FatBlockAdded: {ex} - {cube?.BlockDefinition == null} - RootAiNull: {Construct.RootAi == null}"); }
        }