Exemplo n.º 1
0
        public void TakeFloatingObject(MyFloatingObject obj)
        {
            MyFixedPoint amount = obj.Item.Amount;

            if (MyPerGameSettings.ConstrainInventory())
            {
                amount = MyFixedPoint.Min(ComputeAmountThatFits(obj.Item.Content.GetObjectId()), amount);
            }
            if (amount > 0)
            {
                if (Sync.IsServer)
                {
                    if (obj.MarkedForClose)
                    {
                        return;
                    }
                    MyFloatingObjects.RemoveFloatingObject(obj, amount);
                    AddItemsInternal(amount, obj.Item.Content);
                    SyncObject.SendAddItemsAnnounce(this, amount, obj.Item.Content);
                }
                else
                {
                    SyncObject.TakeFloatingObjectRequest(this, obj);
                }
            }
        }
Exemplo n.º 2
0
        public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1)
        {
            Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject, "This type of inventory can't add other types than PhysicalObjects!");
            MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject;

            if (physicalObjectBuilder == null)
            {
                return(false);
            }
            if (amount == 0)
            {
                return(false);
            }
            if (!CanItemsBeAdded(amount, physicalObjectBuilder.GetObjectId()))
            {
                return(false);
            }

            if (Sync.IsServer)
            {
                if (MyPerGameSettings.ConstrainInventory())
                {
                    AffectAddBySurvival(ref amount, physicalObjectBuilder);
                }
                if (amount == 0)
                {
                    return(false);
                }
                AddItemsInternal(amount, physicalObjectBuilder, index);
                SyncObject.SendAddItemsAnnounce(this, amount, physicalObjectBuilder, index);
            }
            else
            {
                SyncObject.SendAddItemsRequest(this, index, amount, physicalObjectBuilder);
            }
            return(true);
        }