public override int MoveInto(BuildingInventory receiver, int count)
        {
            BuildingInventory sender = this;
            int startCount           = count;

            bool transmittedARessource = true;

            while (count > 0 && transmittedARessource)
            {
                transmittedARessource = false;
                foreach (RessourceType ressourceType in sender.Outgoing)
                {
                    if (count <= 0)
                    {
                        break;
                    }
                    if (receiver.Incoming.Contains(ressourceType))
                    {
                        int senderAmount = sender.GetRessourceAmount(ressourceType);

                        int received = receiver.AddRessource(ressourceType, Mathf.Min(senderAmount, 1));
                        count -= received;
                        if (received > 0)
                        {
                            transmittedARessource = true;
                        }
                        sender.RemoveRessource(ressourceType, received);
                    }
                }
            }
            return(startCount - count);
        }
Exemple #2
0
        public virtual int MoveInto(BuildingInventory receiver, int count)
        {
            Inventory sender     = this;
            int       startCount = count;

            bool transmittedARessource = true;

            while (count > 0 && transmittedARessource)
            {
                transmittedARessource = false;
                List <RessourceType> iterList = new List <RessourceType>(sender.Storage.Keys);
                foreach (RessourceType ressourceType in iterList)
                {
                    if (count <= 0)
                    {
                        break;
                    }
                    if (receiver.Incoming.Contains(ressourceType))
                    {
                        int senderAmount = sender.GetRessourceAmount(ressourceType);
                        int received     = receiver.AddRessource(ressourceType, Mathf.Min(senderAmount, 1));
                        count -= received;
                        if (received > 0)
                        {
                            transmittedARessource = true;
                        }
                        sender.RemoveRessource(ressourceType, received);
                    }
                }
            }
            return(startCount - count);
        }