public IEnumerable <IEntityRootComponent> GetEntityComponents(DataInventory dataInventory)
        {
            var entities   = _databaseReadOnly.GetDataEntitiesInventory(dataInventory);
            var components = entities.Select(dataEntity => TryGetEntityComponent(dataEntity, out var result) ? result : null).Where(component => component != null);

            return(components);
        }
        public bool TryGetInventoryComponent(DataInventory dataInventory, out InventoryComponent componentResult)
        {
            var slotRootComponent = _bindSlots.Components.FirstOrDefault(component => component.Data.DataInventory == dataInventory);

            componentResult = slotRootComponent?.InventoryComponent;
            return(componentResult != null);
        }
Example #3
0
 public CheckTargetInventoryIsOverflow(DataInventory inventory, string idEntity, int amountWantPut, int totalLeftToPut)
 {
     Inventory       = inventory;
     IdEntity        = idEntity;
     AmountWantPut   = amountWantPut;
     _totalLeftToPut = totalLeftToPut;
 }
 public CauseTargetInventoryIsOverflow(DataInventory inventory, string idEntity, int amountWantPut, int amountCanPut)
 {
     Inventory     = inventory;
     IdEntity      = idEntity;
     AmountWantPut = amountWantPut;
     AmountCanPut  = amountCanPut;
 }
Example #5
0
        private void ASetInventory_Load(object sender, EventArgs e)
        {
            _dataTypes.Add('A', new List <string> {
                "Номер", "RFID бр-т"
            });
            _dataTypes.Add('B', new List <string> {
                "Бейсболка", "Бут.Воды"
            });
            _dataTypes.Add('C', new List <string> {
                "Футболка", "Сув.букл"
            });

            mainThread = new Thread(() =>
            {
                while (true)
                {
                    DateTime eTime;
                    DateTime.TryParse(s_GlobalMarathonDate, out eTime);
                    var resultTime = eTime.Subtract(DateTime.Now);
                    if (lbEndTime.InvokeRequired && !lbEndTime.IsDisposed)
                    {
                        if (resultTime > TimeSpan.Zero)
                        {
                            lbEndTime.BeginInvoke((MethodInvoker)(() => lbEndTime.Text = getTime(resultTime)));
                        }

                        lbEndTime.BeginInvoke((MethodInvoker)(() => lbEndTime.Location = new Point((this.Size.Width - lbEndTime.Size.Width) / 2, 16)));
                    }
                    Thread.Sleep(1000);
                }
            })
            {
                IsBackground = true,
                Priority     = ThreadPriority.Lowest
            };
            mainThread.Start();

            var m_DataTable = new DataTable();

            DataInventory.Rows.Add(_dataTypes['A'][0]); //0
            DataInventory.Rows.Add(_dataTypes['A'][1]); //1
            DataInventory.Rows.Add(_dataTypes['B'][0]); //2
            DataInventory.Rows.Add(_dataTypes['B'][1]); //3
            DataInventory.Rows.Add(_dataTypes['C'][0]); //4
            DataInventory.Rows.Add(_dataTypes['C'][1]); //5

            DataInventory.ClearSelection();
            DataInventory.CurrentCell = null;

            DataInventory[0, 1].ReadOnly                 =
                DataInventory[0, 2].ReadOnly             =
                    DataInventory[0, 3].ReadOnly         =
                        DataInventory[0, 4].ReadOnly     =
                            DataInventory[0, 5].ReadOnly = true;


            DataInventory.ClearSelection();
            DataInventory.CurrentCell = null;
        }
        public void BindInventory(InventoryComponent inventoryComponent, DataInventory dataInventoryInDatabase)
        {
            var inventoryStructure = _databaseReadOnly.GetInventoryStructure(dataInventoryInDatabase);

            inventoryComponent.SetInventoryStructure(inventoryStructure);
            UnBindSlotsComponentsToData(inventoryComponent);
            BindSlotsComponentsToData(inventoryComponent);
        }
Example #7
0
 public DataSlot GetSlotOrNull(DataInventory inventory,
                               Vector2Int position)
 {
     return(_slots.FirstOrDefault(sl =>
                                  sl.DataInventory == inventory &&
                                  sl.Column == position.x &&
                                  sl.Row == position.y));
 }
Example #8
0
        private bool NoMoveInHotBarIfHaveSameId(DataInventory inventoryFrom, DataInventory inventoryTo, DataEntity dataEntity)
        {
            if (inventoryTo == inventoryFrom)
            {
                return(true);
            }
            var ids = DatabaseReadOnly.GetDataEntitiesInventory(inventoryTo).Select(data => data.Id).Distinct();

            return(!(inventoryTo == _inventoryObject.DataInventory && ids.Contains(dataEntity.Id)));
        }
Example #9
0
        private void SetDataInventory(DataInventory dataInventory)
        {
            _dataInventory = dataInventory;
            var slotRootComponents = GetSlots();

            foreach (var slotRootComponent in slotRootComponents)
            {
                slotRootComponent.SetInventory(this, dataInventory);
            }
        }
        public InventoryComponent GetInventoryComponent(DataInventory dataInventory)
        {
            var tryGetInventoryComponent = TryGetInventoryComponent(dataInventory, out var componentResult);

            if (!tryGetInventoryComponent)
            {
                throw new Exception();
            }
            return(componentResult);
        }
        private bool ValidateStatsRequired(DataInventory inventoryTo, DataEntity dataEntity)
        {
            if (inventoryTo != _dummy.DataInventory)
            {
                return(true);
            }
            var dataEntityEquipment = dataEntity as DataEntityEquipment;
            var result = dataEntityEquipment?.RequiredMinStats.CompareTo(_heroComponent.Stats) < 0;

            return(result);
        }
Example #12
0
        public bool IsOutBorderInventory(DataInventory inventory, DataEntity dataEntity, Vector2Int coordinateSlotLeftTop)
        {
            if (inventory.TypeInventory != DataInventory.TypeInventoryEnum.GridSupportMultislotEntity)
            {
                return(false);
            }
            var targetSlots    = GetSlots(inventory, dataEntity.GetArea(coordinateSlotLeftTop));
            int countSlotsArea = dataEntity.Dimensions.x * dataEntity.Dimensions.y;

            return(countSlotsArea > targetSlots.Count());
        }
Example #13
0
        private MoveBetweenInventoriesInputData GetInputDataCommandMoveCoins(DataInventory fromInventory, DataInventory toInventory, int sumCoins)
        {
            MoveBetweenInventoriesInputData result = null;

            if (sumCoins != 0)
            {
                result = new MoveBetweenInventoriesInputData(fromInventory, toInventory,
                                                             InputData.IdCoins, sumCoins);
            }
            return(result);
        }
Example #14
0
        public RemoveInputData([NotNull] DataEntity dataEntity, int amountRemove)
        {
            if (amountRemove <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amountRemove));
            }

            DataEntity   = dataEntity;
            Inventory    = DataEntity.DataInventory;
            AmountRemove = amountRemove;
        }
Example #15
0
        private void BindEntityToSlots(DataInventory inventory, DataEntity entity, DataSlot slotLeftTop)
        {
            var slots = GetSlotsForEntityInInventory(inventory, slotLeftTop.Vector2Int, entity);

            UnbindEntityFromSlots(entity);

            foreach (var slot in slots)
            {
                _dictionaryBindSlotToEntity.Add(slot, entity);
            }
            ((IDataInventorySetter)entity).SetDataInventory(slotLeftTop.DataInventory);
        }
        private void BuffDebaf(DataEntity dataEntity, DataInventory fromInventory, DataInventory toInventory)
        {
            if (fromInventory == _dummy.DataInventory)
            {
                _heroComponent.Stats -= ((DataEntityEquipment)dataEntity).BuffStatsIfEquipment;
            }

            if (toInventory == _dummy.DataInventory)
            {
                _heroComponent.Stats += ((DataEntityEquipment)dataEntity).BuffStatsIfEquipment;
            }
        }
        private bool ValidateBodyPart(DataInventory inventory, DataEntity dataEntity, DataSlot dataSlot)
        {
            if (inventory != _dummy.DataInventory)
            {
                return(true);
            }
            var dataEntityEquipment = dataEntity as DataEntityEquipment;
            var dataSlotDummy       = dataSlot as DataSlotDummy;
            var result = dataEntityEquipment?.BodyPart == dataSlotDummy?.BodyPart;

            return(result);
        }
Example #18
0
        public virtual void UpdateEntitiesInventory(DataInventory dataInventory)
        {
            var entities = _readOnlyDatabase.Entities.Where(entity => entity.DataInventory == dataInventory);

            foreach (var dataEntity in entities)
            {
                var isEntityExist = _bindComponentToDataDbRead.TryGetEntityComponent(dataEntity, out _);
                if (!isEntityExist)
                {
                    Create(dataEntity, _readOnlyDatabase.GetSlotOrNull(dataEntity));
                }
                UpdatePositionEntity(dataEntity);
            }
        }
        /// <summary>
        /// Here it is implemented with the help of the function, but in a real project it is better to implement the CommandComposite
        /// </summary>
        /// <param name="fromInventory"></param>
        /// <param name="toInventory"></param>
        private void MoveAllEntities(DataInventory fromInventory, DataInventory toInventory)
        {
            var command = Commands.Create <MoveBetweenInventoriesCommand>();

            var idAmountDictionary = DatabaseReadOnly.GetDataEntitiesInventory(fromInventory)
                                     .ToDictionary(entity => entity, entity => entity.Amount)
                                     .GroupBy(pair => pair.Key.Id)
                                     .ToDictionary(pairs => pairs.Key, pairs => pairs.Sum(pair => pair.Value));

            foreach (var pair in idAmountDictionary)
            {
                command.EnterData(new MoveBetweenInventoriesInputData(fromInventory, toInventory, pair.Key,
                                                                      pair.Value))
                .ExecuteTry();
            }
        }
Example #20
0
        public GameObject CreateInventory(PresetInventory preset)
        {
            var canvasInventory = CreateCanvasInventory(preset.NameInventory);
            var rootInventory   = CreateRootInventory(preset, canvasInventory);

            // Data
            var dataInventory      = new DataInventory(preset.NameInventory, preset.TypeInventory);
            var inventoryComponent = rootInventory.GetComponent <InventoryComponent>();

            inventoryComponent.Init(dataInventory);

            // Slots
            CreateSlots(preset, rootInventory);

            return(canvasInventory);
        }
Example #21
0
        private void LoadIfNecessary(DataInventory dataInventory)
        {
            if (_dataEntitiesForLoad == null || !_dataEntitiesForLoad.Any())
            {
                return;
            }

            var command = CommandsFactory.Create <CreateEntitiesCommand>()
                          .EnterData(new CreateEntitiesInputData(dataInventory, _dataEntitiesForLoad));
            var executeTry = command.ExecuteTry();

            if (!executeTry)
            {
                Debug.Log(command.GetCausesFailure());
                throw new Exception();
            }
        }
Example #22
0
        public IEnumerable <DataSlot> GetSlotsForEntityInInventory(DataInventory inventory, Vector2Int position,
                                                                   DataEntity dataEntity)
        {
            var result = new List <DataSlot>();
            var isOutBorderInventory = IsOutBorderInventory(inventory, dataEntity, position);

            Contract.Assert(!isOutBorderInventory, "IsOutBorderInventory!");
            if (inventory.TypeInventory == DataInventory.TypeInventoryEnum.GridSupportMultislotEntity)
            {
                result = GetSlots(inventory, dataEntity.GetArea(position)).ToList();
            }
            else
            {
                result.Add(GetSlotOrNull(inventory, position));
            }
            return(result);
        }
Example #23
0
        public DataInventory GetInventory(string cashbagCode)
        {
            var           bm            = businessmanRepository.FindAll(p => p.CashbagCode == cashbagCode).FirstOrDefault();
            DataInventory datainventory = new DataInventory();

            if (bm != null)
            {
                var query = orderRepository.FindAll(p =>
                                                    p.BusinessmanCode == bm.Code &&
                                                    p.OrderStatus == EnumOrderStatus.IssueAndCompleted &&
                                                    p.SkyWays.Where(s => s.StartDateTime > DateTime.Now).Count() > 0
                                                    );

                int ordercount = query.Count();
                datainventory.TotalMoney = query.Select(p => p.OrderMoney).Sum();
                datainventory.Info       = "该商户已出票未起飞的订单共计:" + ordercount + ",订单总金额:" + datainventory.TotalMoney;
            }
            return(datainventory);
        }
Example #24
0
        public CauseNoRequiredAmountInSourceInventory([NotNull] DataInventory inventoryFrom, string idEntity, int amountWantTake, int amountCanTake)
        {
            if (string.IsNullOrEmpty(idEntity))
            {
                throw new System.ArgumentException("message", nameof(idEntity));
            }

            if (amountWantTake <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amountWantTake));
            }
            if (amountCanTake < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amountCanTake));
            }

            IdEntity       = idEntity;
            InventoryFrom  = inventoryFrom;
            AmountWantTake = amountWantTake;
            AmountCanTake  = amountCanTake;
        }
Example #25
0
        private Transform CreateTransform(DataInventory dataInventory, DataEntity dataEntity)
        {
            var inventoryComponent = _bindComponentToDataDbRead.GetInventoryComponent(dataInventory);
            var prefab             = _factoryDataEntityPrefab.GetPrefab(dataEntity.GetType());
            var entityTransform    = prefab.InstantiateOnRootCanvas().transform;

            entityTransform.SetParent(inventoryComponent.CanvasInventory.transform);

            var sprite = dataEntity.Sprite;

            if (sprite == null)
            {
                throw new NullReferenceException($"{this}: Sprite cannot be null!");
            }
            var image = entityTransform.gameObject.GetComponentInChildren <Image>();

            image.sprite        = sprite;
            image.raycastTarget = false;

            return(entityTransform);
        }
Example #26
0
        public MoveBetweenInventoriesInputData([NotNull] DataInventory fromInventory,
                                               [NotNull] DataInventory inventory, string idEntity, int amount)
        {
            if (amount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(amount));
            }
            FromInventory = fromInventory ?? throw new ArgumentNullException(nameof(fromInventory));
            ToInventory   = inventory ?? throw new ArgumentNullException(nameof(inventory));
            IdEntity      = idEntity;
            Amount        = amount;

            if (string.IsNullOrEmpty(idEntity))
            {
                throw new ArgumentException("message", nameof(idEntity));
            }

            if (FromInventory == ToInventory)
            {
                throw new Exception("FromInventory == ToInventory!");
            }
        }
Example #27
0
 internal BindState(InventoryBinding inventoryDataBind, DataInventory dataInventory) : base(inventoryDataBind)
 {
     DataInventory = dataInventory;
 }
 public CheckNotFreeSlotsInventoryForCreateEntities(DataInventory inventory, IEnumerable <DataEntity> entities, IEnumerable <ICommand> commandsChainForExecute)
 {
     Inventory = inventory;
     Entities  = entities;
     _commandsChainForExecute = commandsChainForExecute;
 }
Example #29
0
 private List <DataSlot> GetSlotsInventory(DataInventory dataInventory) =>
 _slots.Where(slot => slot.DataInventory == dataInventory).ToList();
Example #30
0
 public bool IsAreaEntityForInventory(IEntityRootComponent entitySource, DataInventory inventoryTo)
 {
     return(entitySource.Data.IsAreaEntity &&
            inventoryTo.TypeInventory == DataInventory.TypeInventoryEnum.GridSupportMultislotEntity);
 }