Ejemplo n.º 1
0
        private static void InventoryBaseTransferItem_Implementation(MyInventoryTransferEventContent eventParams)
        {
            if (!MyEntities.EntityExists(eventParams.DestinationOwnerId) || !MyEntities.EntityExists(eventParams.SourceOwnerId))
            {
                return;
            }

            MyEntity                sourceOwner = MyEntities.GetEntityById(eventParams.SourceOwnerId);
            MyInventoryBase         source      = sourceOwner.GetInventory(eventParams.SourceInventoryId);
            MyEntity                destOwner   = MyEntities.GetEntityById(eventParams.DestinationOwnerId);
            MyInventoryBase         dst         = destOwner.GetInventory(eventParams.DestinationInventoryId);
            var                     items       = source.GetItems();
            MyPhysicalInventoryItem?foundItem   = null;

            foreach (var item in items)
            {
                if (item.ItemId == eventParams.ItemId)
                {
                    foundItem = item;
                }
            }

            if (foundItem.HasValue)
            {
                dst.TransferItemsFrom(source, foundItem, eventParams.Amount);
            }
        }
Ejemplo n.º 2
0
        private static void FixTransferAmount(MyInventory src, MyInventory dst, MyPhysicalInventoryItem?srcItem, bool spawn, ref MyFixedPoint remove, ref MyFixedPoint add)
        {
            Debug.Assert(Sync.IsServer);
            if (srcItem.Value.Amount < remove)
            {
                remove = srcItem.Value.Amount;
                add    = remove;
            }

            if (!MySession.Static.CreativeMode && !src.Equals(dst))
            {
                MyFixedPoint space = dst.ComputeAmountThatFits(srcItem.Value.Content.GetId());
                if (space < remove)
                {
                    if (spawn)
                    {
                        MyEntity e = (dst.Owner as MyEntity);
                        Matrix   m = e.WorldMatrix;
                        MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(remove - space, srcItem.Value.Content), e.PositionComp.GetPosition() + m.Forward + m.Up, m.Forward, m.Up, e.Physics);
                    }
                    else
                    {
                        remove = space;
                    }
                    add = space;
                }
            }
        }
Ejemplo n.º 3
0
        public void ConsumeAmmo()
        {
            if (Sync.IsServer)
            {
                CurrentAmmo -= AMMO_PER_SHOOT;
                if (CurrentAmmo < 0 && HasEnoughAmmunition())
                {
                    CurrentAmmo = WeaponProperties.AmmoMagazineDefinition.Capacity - 1;

                    if (!MySession.Static.CreativeMode)
                    {
                        m_user.AmmoInventory.RemoveItemsOfType(1, CurrentAmmoMagazineId);
                    }
                }

                RefreshAmmunitionAmount();
            }

            var weaponInventory = m_user.AmmoInventory;

            if (weaponInventory != null)
            {
                MyPhysicalInventoryItem?inventoryItem = null;
                if (InventoryItemId.HasValue)
                {
                    inventoryItem = weaponInventory.GetItemByID(InventoryItemId.Value);
                }
                else
                {
                    inventoryItem = weaponInventory.FindUsableItem(m_user.PhysicalItemId);
                    if (inventoryItem.HasValue)
                    {
                        InventoryItemId = inventoryItem.Value.ItemId;
                    }
                }

                if (inventoryItem.HasValue)
                {
                    var pgo = inventoryItem.Value.Content as MyObjectBuilder_PhysicalGunObject;
                    if (pgo != null)
                    {
                        var gunBaseObjectBuilder = pgo.GunEntity as IMyObjectBuilder_GunObject <MyObjectBuilder_GunBase>;
                        Debug.Assert(gunBaseObjectBuilder != null, "ObjectBuilder of an entity implementing IMyGunObject probably does not implement IMyObjectBuilder_GunObject!");

                        if (gunBaseObjectBuilder != null)
                        {
                            if (gunBaseObjectBuilder.DeviceBase == null)
                            {
                                gunBaseObjectBuilder.InitializeDeviceBase(GetObjectBuilder());
                            }
                            else
                            {
                                gunBaseObjectBuilder.GetDevice().RemainingAmmo = CurrentAmmo;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public static MyInventoryItem?MakeAPIItem(this MyPhysicalInventoryItem?item)
 {
     if (item != null)
     {
         return(new MyInventoryItem?(item.Value.MakeAPIItem()));
     }
     return(null);
 }
Ejemplo n.º 5
0
        IMyInventoryItem IMyInventory.FindItem(SerializableDefinitionId contentId)
        {
            MyPhysicalInventoryItem?item = FindItem(contentId);

            if (item != null)
            {
                return(item.Value);
            }
            return(null);
        }
Ejemplo n.º 6
0
        IMyInventoryItem IMyInventory.GetItemByID(uint id)
        {
            MyPhysicalInventoryItem?item = GetItemByID(id);

            if (item != null)
            {
                return(item.Value);
            }
            return(null);
        }
Ejemplo n.º 7
0
        Sandbox.ModAPI.Interfaces.IMyInventoryItem Sandbox.ModAPI.Interfaces.IMyInventory.FindItem(SerializableDefinitionId contentId)
        {
            MyPhysicalInventoryItem?item = FindItem(contentId);

            if (item != null)
            {
                return(item.Value);
            }
            return(null);
        }
Ejemplo n.º 8
0
        Sandbox.ModAPI.Interfaces.IMyInventoryItem Sandbox.ModAPI.Interfaces.IMyInventory.GetItemByID(uint id)
        {
            MyPhysicalInventoryItem?item = GetItemByID(id);

            if (item != null)
            {
                return(item.Value);
            }
            return(null);
        }
        private void RefreshSelectedInventoryItem()
        {
            if (m_focusedGridControl != null)
            {
                m_selectedInventory = (MyInventory)m_focusedGridControl.UserData;
                var selectedItem = m_focusedGridControl.SelectedItem;
                m_selectedInventoryItem = (selectedItem != null) ? (MyPhysicalInventoryItem?)selectedItem.UserData
                                                                 : null;
            }
            else
            {
                m_selectedInventory = null;
                m_selectedInventoryItem = null;
            }

            if (m_throwOutButton != null)
            {
                m_throwOutButton.Enabled = m_selectedInventoryItem.HasValue &&
                                           (m_focusedOwnerControl != null && m_focusedOwnerControl.InventoryOwner == m_userAsOwner);
            }
        }