Exemple #1
0
 private void OnInventoryAggregateRemoved(MyEntityComponentBase component)
 {
     this.m_inputInventory  = null;
     this.m_outputInventory = null;
     this.m_inventoryAggregate.BeforeRemovedFromContainer -= new Action <MyEntityComponentBase>(this.OnInventoryAggregateRemoved);
     this.m_inventoryAggregate.OnAfterComponentAdd        -= new Action <MyInventoryAggregate, MyInventoryBase>(this.OnInventoryAddedToAggregate);
     this.m_inventoryAggregate.OnBeforeComponentRemove    -= new Action <MyInventoryAggregate, MyInventoryBase>(this.OnBeforeInventoryRemovedFromAggregate);
     this.m_inventoryAggregate = null;
 }
 private void OnInventoryAggregateRemoved(MyEntityComponentBase component)
 {
     m_inputInventory  = null;
     m_outputInventory = null;
     m_inventoryAggregate.BeforeRemovedFromContainer -= OnInventoryAggregateRemoved;
     m_inventoryAggregate.OnAfterComponentAdd        -= OnInventoryAddedToAggregate;
     m_inventoryAggregate.OnBeforeComponentRemove    -= OnBeforeInventoryRemovedFromAggregate;
     m_inventoryAggregate = null;
 }
Exemple #3
0
 protected virtual void OnInventoryAddedToAggregate(MyInventoryAggregate aggregate, MyInventoryBase inventory)
 {
     if (this.m_inputInventory == null)
     {
         this.m_inputInventory = inventory as MyInventory;
     }
     else if (this.m_outputInventory == null)
     {
         this.m_outputInventory = inventory as MyInventory;
     }
 }
Exemple #4
0
 protected virtual void OnBeforeInventoryRemovedFromAggregate(MyInventoryAggregate aggregate, MyInventoryBase inventory)
 {
     if (ReferenceEquals(inventory, this.m_inputInventory))
     {
         this.m_inputInventory = null;
     }
     else if (ReferenceEquals(inventory, this.m_outputInventory))
     {
         this.m_outputInventory = null;
     }
 }
Exemple #5
0
 public void FixInputOutputInventories(MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
 {
     if (this.m_inventoryAggregate.InventoryCount != 2)
     {
         MyInventoryAggregate component = MyInventoryAggregate.FixInputOutputInventories(this.m_inventoryAggregate, inputInventoryConstraint, outputInventoryConstraint);
         base.Components.Remove <MyInventoryBase>();
         this.m_outputInventory = null;
         this.m_inputInventory  = null;
         base.Components.Add <MyInventoryBase>(component);
     }
 }
Exemple #6
0
 protected override void OnInventoryAddedToAggregate(MyInventoryAggregate aggregate, MyInventoryBase inventory)
 {
     base.OnInventoryAddedToAggregate(aggregate, inventory);
     if (ReferenceEquals(inventory, base.InputInventory))
     {
         base.InputInventory.ContentsChanged += new Action <MyInventoryBase>(this.inventory_OnContentsChanged);
     }
     else if (ReferenceEquals(inventory, base.OutputInventory))
     {
         base.OutputInventory.ContentsChanged += new Action <MyInventoryBase>(this.inventory_OnContentsChanged);
     }
 }
Exemple #7
0
 public override void OnCharacterDead()
 {
     if (!base.Character.IsDead)
     {
         return;
     }
     else if (!base.Character.Definition.EnableSpawnInventoryAsContainer)
     {
         return;
     }
     else if (base.Character.Definition.InventorySpawnContainerId == null)
     {
         return;
     }
     else if (base.Character.Components.Has <MyInventoryBase>())
     {
         MyInventoryBase base2 = base.Character.Components.Get <MyInventoryBase>();
         if (base2 is MyInventoryAggregate)
         {
             MyInventoryAggregate   aggregate = base2 as MyInventoryAggregate;
             List <MyComponentBase> output    = new List <MyComponentBase>();
             aggregate.GetComponentsFlattened(output);
             foreach (MyComponentBase base3 in output)
             {
                 MyContainerDefinition definition;
                 MyInventory           component = base3 as MyInventory;
                 if ((component == null) || (component.GetItemsCount() <= 0))
                 {
                     aggregate.RemoveComponent(base3);
                     continue;
                 }
                 if (MyDefinitionManager.Static.TryGetContainerDefinition(base.Character.Definition.InventorySpawnContainerId.Value, out definition))
                 {
                     aggregate.RemoveComponent(component);
                     if (Sync.IsServer)
                     {
                         MyInventory inventory = new MyInventory();
                         inventory.Init(component.GetObjectBuilder());
                         this.SpawnInventoryContainer(base.Character.Definition.InventorySpawnContainerId.Value, inventory, true, 0L);
                     }
                 }
             }
         }
         else if ((base2 is MyInventory) && base.Character.Definition.SpawnInventoryOnBodyRemoval)
         {
             this.m_spawnInventory = base2 as MyInventory;
             this.SpawnBackpack(base.Character);
         }
     }
     this.CloseComponent();
 }
        public void FixInputOutputInventories(MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            if (m_inventoryAggregate.InventoryCount == 2)
            {
                return;
            }

            var fixedAggregate = MyInventoryAggregate.FixInputOutputInventories(m_inventoryAggregate, inputInventoryConstraint, outputInventoryConstraint);

            Components.Remove <MyInventoryBase>();
            m_outputInventory = null;
            m_inputInventory  = null;
            Components.Add <MyInventoryBase>(fixedAggregate);
        }
 protected virtual void OnBeforeInventoryRemovedFromAggregate(MyInventoryAggregate aggregate, MyInventoryBase inventory)
 {
     if (inventory == m_inputInventory)
     {
         m_inputInventory = null;
     }
     else if (inventory == m_outputInventory)
     {
         m_outputInventory = null;
     }
     else
     {
         Debug.Fail("Removing inventory from aggregate, but isn't neither input nor output! This shouldn't happend.");
     }
 }
 protected virtual void OnInventoryAddedToAggregate(MyInventoryAggregate aggregate, MyInventoryBase inventory)
 {
     if (m_inputInventory == null)
     {
         m_inputInventory = inventory as MyInventory;
     }
     else if (m_outputInventory == null)
     {
         m_outputInventory = inventory as MyInventory;
     }
     else
     {
         Debug.Fail("Adding inventory to aggregate, but input and output inventory is already set!");
     }
 }
Exemple #11
0
        private void OnComponentAdded(Type type, MyEntityComponentBase component)
        {
            MyInventoryAggregate aggregate = component as MyInventoryAggregate;

            if (aggregate != null)
            {
                this.m_inventoryAggregate = aggregate;
                this.m_inventoryAggregate.BeforeRemovedFromContainer += new Action <MyEntityComponentBase>(this.OnInventoryAggregateRemoved);
                this.m_inventoryAggregate.OnAfterComponentAdd        += new Action <MyInventoryAggregate, MyInventoryBase>(this.OnInventoryAddedToAggregate);
                this.m_inventoryAggregate.OnBeforeComponentRemove    += new Action <MyInventoryAggregate, MyInventoryBase>(this.OnBeforeInventoryRemovedFromAggregate);
                foreach (MyInventory inventory in this.m_inventoryAggregate.ChildList.Reader)
                {
                    this.OnInventoryAddedToAggregate(aggregate, inventory);
                }
            }
        }
        private void OnComponentAdded(Type type, VRage.Game.Components.MyEntityComponentBase component)
        {
            var aggregate = component as MyInventoryAggregate;

            if (aggregate != null)
            {
                m_inventoryAggregate = aggregate;
                m_inventoryAggregate.BeforeRemovedFromContainer += OnInventoryAggregateRemoved;
                m_inventoryAggregate.OnAfterComponentAdd        += OnInventoryAddedToAggregate;
                m_inventoryAggregate.OnBeforeComponentRemove    += OnBeforeInventoryRemovedFromAggregate;

                foreach (var inventory in m_inventoryAggregate.ChildList.Reader)
                {
                    MyInventory inv = inventory as MyInventory;
                    OnInventoryAddedToAggregate(aggregate, inv);
                }
            }
        }
Exemple #13
0
        protected void FixSingleInventory()
        {
            MyInventoryBase inventoryBase;

            if (!Components.TryGet <MyInventoryBase>(out inventoryBase))
            {
                return;
            }
            MyInventoryAggregate aggregate     = inventoryBase as MyInventoryAggregate;
            MyInventory          bestInventory = null;

            if (aggregate != null)
            {
                foreach (var inventory in aggregate.ChildList.Reader)
                {
                    var myInventory = inventory as MyInventory;
                    if (myInventory == null)
                    {
                        continue;
                    }
                    if (bestInventory == null)
                    {
                        bestInventory = myInventory;
                    }
                    else if (bestInventory.GetItemsCount() < myInventory.GetItemsCount())
                    {
                        bestInventory = myInventory;
                    }
                }
            }
            if (bestInventory != null)
            {
                Components.Remove <MyInventoryBase>();
                Components.Add <MyInventoryBase>(bestInventory);
            }
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(ProductionBlockDefinition.ResourceSinkGroup, ProductionBlockDefinition.OperationalPowerConsumption, ComputeRequiredPower);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var ob = (MyObjectBuilder_ProductionBlock)objectBuilder;

            if (InventoryAggregate == null)
            {
                InventoryAggregate = new MyInventoryAggregate();
            }

            if (InputInventory == null)
            {
                InputInventory = new MyInventory(
                    ProductionBlockDefinition.InventoryMaxVolume,
                    ProductionBlockDefinition.InventorySize,
                    MyInventoryFlags.CanReceive);
                if (ob.InputInventory != null)
                {
                    InputInventory.Init(ob.InputInventory);
                }
            }

            Debug.Assert(InputInventory.Owner == this, "Ownership was not set!");

            if (OutputInventory == null)
            {
                OutputInventory = new MyInventory(
                    ProductionBlockDefinition.InventoryMaxVolume,
                    ProductionBlockDefinition.InventorySize,
                    MyInventoryFlags.CanSend);
                if (ob.OutputInventory != null)
                {
                    OutputInventory.Init(ob.OutputInventory);
                }
            }

            Debug.Assert(OutputInventory.Owner == this, "Ownership was not set!");

            m_nextItemId = ob.NextItemId;
            bool nextIdWasZero = m_nextItemId == 0;

            base.IsWorkingChanged += CubeBlock_IsWorkingChanged;


            ResourceSink.Update();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            if (ob.Queue != null)
            {
                m_queue.Clear();
                if (m_queue.Capacity < ob.Queue.Length)
                {
                    m_queue.Capacity = ob.Queue.Length;
                }
                for (int i = 0; i < ob.Queue.Length; ++i)
                {
                    var item = ob.Queue[i];
                    Debug.Assert(item.ItemId != null || nextIdWasZero, "Item index was null while next id for production block was given non-zero. This is inconsistency.");

                    var deserializedItem = DeserializeQueueItem(item);
                    Debug.Assert(deserializedItem.Blueprint != null, "Could not add item into production block's queue: Blueprint was not found.");
                    if (deserializedItem.Blueprint != null)
                    {
                        m_queue.Add(deserializedItem);
                        MySandboxGame.Log.WriteLine(string.Format("Could not add item into production block's queue: Blueprint {0} was not found.", item.Id));
                    }
                }

                UpdatePower();
            }

            m_useConveyorSystem.Value = ob.UseConveyorSystem;

            m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }