Exemple #1
0
        protected void ConduitUpdate(float dt)
        {
            int        cell         = Grid.PosToCell(base.transform.GetPosition());
            List <Tag> acceptedTags = treeFilterable.AcceptedTags;

            SolidConduitFlow conduitFlow = this.GetConduitFlow();

            SolidConduitFlow.ConduitContents contents = conduitFlow.GetContents(cell);
            Pickupable pickupable = conduitFlow.GetPickupable(contents.pickupableHandle);

            activated = false;

            if ((bool)pickupable)
            {
                foreach (var acceptedTag in acceptedTags)
                {
                    if (pickupable.HasTag(acceptedTag))
                    {
                        activated = true;
                        break;
                    }
                }
            }

            if (wasOn != activated)
            {
                OnSwitchToggled();
            }
        }
Exemple #2
0
 protected virtual void UpdateVisualState(bool force = false)
 {
     if (this.wasOn != this.activated || force)
     {
         this.wasOn = this.activated;
         if (this.activated)
         {
             animController.Play(ON_ANIMS, KAnim.PlayMode.Loop);
             int cell = Grid.PosToCell(base.transform.GetPosition());
             SolidConduitFlow conduitFlow = GetConduitFlow();
             SolidConduitFlow.ConduitContents contents = conduitFlow.GetContents(cell);
             Pickupable pickupable = conduitFlow.GetPickupable(contents.pickupableHandle);
             Color32    c          = Color.white;
             if (pickupable.PrimaryElement.DiseaseIdx != 255)
             {
                 Disease disease = Db.Get().Diseases[(int)pickupable.PrimaryElement.DiseaseIdx];
                 c = disease.overlayColour;
             }
             animController.SetSymbolTint(TINT_SYMBOL, c);
         }
         else
         {
             animController.Play(OFF_ANIMS, KAnim.PlayMode.Once);
         }
     }
 }
Exemple #3
0
    private void ConduitUpdate(float dt)
    {
        bool             flag        = false;
        SolidConduitFlow conduitFlow = GetConduitFlow();

        if (IsConnected)
        {
            SolidConduitFlow.ConduitContents contents = conduitFlow.GetContents(utilityCell);
            if (contents.pickupableHandle.IsValid() && (alwaysConsume || operational.IsOperational))
            {
                float num  = (!(capacityTag != GameTags.Any)) ? storage.MassStored() : storage.GetMassAvailable(capacityTag);
                float num2 = Mathf.Min(storage.capacityKg, capacityKG);
                float num3 = Mathf.Max(0f, num2 - num);
                if (num3 > 0f)
                {
                    Pickupable pickupable = conduitFlow.GetPickupable(contents.pickupableHandle);
                    if (pickupable.PrimaryElement.Mass <= num3 || pickupable.PrimaryElement.Mass > num2)
                    {
                        Pickupable pickupable2 = conduitFlow.RemovePickupable(utilityCell);
                        if ((bool)pickupable2)
                        {
                            storage.Store(pickupable2.gameObject, true, false, true, false);
                            flag = true;
                        }
                    }
                }
            }
        }
        storage.storageNetworkID = GetConnectedNetworkID();
        consuming = flag;
    }
Exemple #4
0
 private void ConduitUpdate(float dt)
 {
     dispensing = false;
     if (!(bool)operational || operational.IsOperational)
     {
         SolidConduitFlow flowManager = SolidConduit.GetFlowManager();
         if (flowManager.HasConduit(inputCell) && flowManager.HasConduit(outputCell) && flowManager.IsConduitFull(inputCell) && flowManager.IsConduitEmpty(outputCell))
         {
             Pickupable pickupable = flowManager.RemovePickupable(inputCell);
             if ((bool)pickupable)
             {
                 flowManager.AddPickupable(outputCell, pickupable);
                 dispensing = true;
             }
         }
     }
 }
Exemple #5
0
        private void ConduitUpdate(float dt)
        {
            if (this.operational.IsOperational)
            {
                SolidConduitFlow flowManager = SolidConduit.GetFlowManager();
                if (!flowManager.HasConduit(this.inputCell) || !flowManager.HasConduit(this.outputCell) ||
                    !flowManager.IsConduitFull(this.inputCell) || !flowManager.IsConduitEmpty(this.outputCell))
                {
                    return;
                }

                Pickupable pickupable = flowManager.RemovePickupable(this.inputCell);
                if (!(bool)((UnityEngine.Object)pickupable))
                {
                    return;
                }

                flowManager.AddPickupable(this.outputCell, pickupable);

                this.operational.SetActive(false);
            }
        }
        private void ConduitUpdate(float dt)
        {
            bool flag = false;

            if (this.operational.IsOperational)
            {
                SolidConduitFlow flowManager = SolidConduit.GetFlowManager();
                if (!flowManager.HasConduit(this.inputCell) || !flowManager.HasConduit(this.outputCell) ||
                    !flowManager.HasConduit(this.filteredCell) || (!flowManager.IsConduitFull(this.inputCell) ||
                                                                   !flowManager.IsConduitEmpty(this.outputCell) ||
                                                                   !flowManager.IsConduitEmpty(this.filteredCell)))
                {
                    return;
                }

                var acceptedTags = treeFilterable.AcceptedTags;

                Pickupable pickupable = flowManager.RemovePickupable(this.inputCell);
                if (!(bool)((UnityEngine.Object)pickupable))
                {
                    return;
                }

                foreach (var acceptedTag in acceptedTags)
                {
                    if (pickupable.HasTag(acceptedTag))
                    {
                        flowManager.AddPickupable(this.filteredCell, pickupable);
                        return;
                    }
                }

                flowManager.AddPickupable(this.outputCell, pickupable);
                this.operational.SetActive(flag, false);
            }
        }
Exemple #7
0
        private void ConduitUpdate(float dt)
        {
            bool flag = false;

            if ((this.operational.GetFlag(LogicOperationalController.LogicOperationalFlag) && this.IsConnected) || this.alwaysDispense)
            {
                SolidConduitFlow conduitFlow = this.GetConduitFlow();
                if (conduitFlow.HasConduit(this.utilityCell) && conduitFlow.IsConduitEmpty(this.utilityCell))
                {
                    Pickupable suitableItem = this.FindSuitableItem();
                    if ((bool)((UnityEngine.Object)suitableItem))
                    {
                        if ((double)suitableItem.PrimaryElement.Mass > MaxMass)
                        {
                            suitableItem = suitableItem.Take(MaxMass);
                        }
                        conduitFlow.AddPickupable(this.utilityCell, suitableItem);
                        flag = true;
                    }
                }
            }
            this.storage.storageNetworkID = this.GetConnectedNetworkID();
            this.dispensing = flag;
        }
Exemple #8
0
        private void ConduitUpdate(float dt)
        {
            SolidConduitFlow flowManager = SolidConduit.GetFlowManager();

            if (!flowManager.HasConduit(this._inputCell) || !flowManager.HasConduit(this._outputCell) || !flowManager.IsConduitFull(this._inputCell) || (!flowManager.IsConduitEmpty(this._outputCell)))
            {
                return;
            }


            Pickupable pickupable = flowManager.RemovePickupable(_inputCell);

            flowManager.AddPickupable(this._outputCell, pickupable);
            if (!(bool)((UnityEngine.Object)pickupable))
            {
                return;
            }
            if (flowManager.HasConduit(this._filteredCell) && flowManager.IsConduitEmpty(this._filteredCell))
            {
                Pickupable pickupable2 = EntityPrefabs.Instantiate(pickupable);
                flowManager.AddPickupable(this._filteredCell, pickupable2);
            }
            this.operational.SetActive(false, false);
        }
Exemple #9
0
        protected override void ConduitTick(float delta)
        {
            if (!AlwaysConsume && !operational.IsOperational)
            {
                return;
            }
            IConduitFlow conduitFlow = GetConduitManager();

            if (ConduitType != ConduitType.Solid)
            {
                ConduitFlow mngr = conduitFlow as ConduitFlow;
                ConduitFlow.ConduitContents contents = mngr.GetContents(portCell);
                if (contents.mass <= 0)
                {
                    return;
                }
                Element element         = ElementLoader.FindElementByHash(contents.element);
                bool    matchesTag      = StoreTag == GameTags.Any || element.HasTag(StoreTag);
                float   rateAmount      = ConsumptionRate * delta;
                float   maxTake         = 0f;
                float   storageContains = storage.MassStored();
                float   storageLeft     = storage.capacityKg - storageContains;
                float   portContains    = StoreTag == GameTags.Any ? storageContains : storage.GetMassAvailable(StoreTag);
                float   portLeft        = MaximumStore - portContains;
                maxTake = Mathf.Min(storageLeft, portLeft);
                maxTake = Mathf.Min(rateAmount, maxTake);
                float removed = 0f;
                if (maxTake > 0f)
                {
                    ConduitFlow.ConduitContents removedContents = mngr.RemoveElement(portCell, maxTake);
                    removed             = removedContents.mass;
                    LastConsumedElement = removedContents.element;
                    float ratio = removed / contents.mass;
                    if (!matchesTag)
                    {
                        BuildingHP.DamageSourceInfo damage = new BuildingHP.DamageSourceInfo
                        {
                            damage    = 1,
                            source    = BUILDINGS.DAMAGESOURCES.BAD_INPUT_ELEMENT,
                            popString = UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.WRONG_ELEMENT
                        };
                        Trigger((int)GameHashes.DoBuildingDamage, damage);
                        if (WrongElement == WrongElementResult.Dump)
                        {
                            int buildingCell = Grid.PosToCell(_parent.transform.GetPosition());
                            SimMessages.AddRemoveSubstance(buildingCell, contents.element, CellEventLogger.Instance.ConduitConsumerWrongElement, removed, contents.temperature, contents.diseaseIdx, contents.diseaseIdx);
                            return;
                        }
                    }
                    if (ConduitType == ConduitType.Gas)
                    {
                        if (!element.IsGas)
                        {
                            Debug.LogWarning($"[MultIO] Gas input port attempted to consume non gass: {element.id.ToString()}");
                        }
                        else
                        {
                            storage.AddGasChunk(element.id, removed, contents.temperature, contents.diseaseIdx, contents.diseaseCount, KeepZeroMassObject, false);
                        }
                    }
                    else if (ConduitType == ConduitType.Liquid)
                    {
                        if (!element.IsLiquid)
                        {
                            Debug.LogWarning($"[MultIO] Liquid input port attempted to consume non liquid: {element.id.ToString()}");
                        }
                        else
                        {
                            storage.AddLiquid(element.id, removed, contents.temperature, contents.diseaseIdx, contents.diseaseCount, KeepZeroMassObject, false);
                        }
                    }
                }
            }
            else
            {
                SolidConduitFlow mngr = conduitFlow as SolidConduitFlow;
                SolidConduitFlow.ConduitContents contents = mngr.GetContents(portCell);
                if (contents.pickupableHandle.IsValid() && (AlwaysConsume || operational.IsOperational))
                {
                    float stored           = StoreTag == GameTags.Any ? storage.MassStored() : storage.GetMassAvailable(StoreTag);
                    float maxStorage       = Mathf.Min(storage.capacityKg, MaximumStore);
                    float availableStorage = Mathf.Max(0f, maxStorage - stored);
                    if (availableStorage > 0f)
                    {
                        Pickupable tmp        = mngr.GetPickupable(contents.pickupableHandle);
                        bool       matchesTag = StoreTag == GameTags.Any || tmp.HasTag(StoreTag);
                        if (matchesTag)
                        {
                            if (tmp.PrimaryElement.Mass <= stored || tmp.PrimaryElement.Mass > maxStorage)
                            {
                                Pickupable take = mngr.RemovePickupable(portCell);
                                if (take != null)
                                {
                                    storage.Store(take.gameObject, true);
                                }
                            }
                        }
                        else
                        {
                            Pickupable take = mngr.RemovePickupable(portCell);
                            take.transform.SetPosition(Grid.CellToPos(portCell));
                            //TODO: Add a PopFX. Likely will not do damage.
                        }
                    }
                }
            }
        }
Exemple #10
0
        protected override void ConduitTick(float delta)
        {
            UpdateConduitBlockedStatus();
            bool dispensed = false;

            if (!operational.IsOperational && !AlwaysDispense)
            {
                return;
            }
            foreach (GameObject item in storage.items)
            {
                if (item.GetComponent <PrimaryElement>()?.Element.id == SimHashes.Water)
                {
                    item.AddOrGet <Pickupable>();
                }
            }
            PrimaryElement element = FindSuitableElement();

            if (element != null)
            {
                element.KeepZeroMassObject = true;
                IConduitFlow iConduitManager = GetConduitManager();
                if (iConduitManager == null)
                {
                    Debug.LogError($"[MultiIO] OutputPort.ConduitTick(): iConduitManager is null");
                }
                //Solid Conduits do not use the same kind of flow manager, so the code must be separated
                if (ConduitType == ConduitType.Solid)
                {
                    SolidConduitFlow solidManager = iConduitManager as SolidConduitFlow;
                    if (solidManager == null)
                    {
                        Debug.LogError($"[MultiIO] OutputPort.ConduitTick(): solidManager is null");
                    }
                    //Solid conveyor only needs to take elements with a Pikcupable component. The only difference between Water and Bottled Water is a Pikcupable component.
                    Pickupable pickup = element.gameObject.GetComponent <Pickupable>();
                    if (pickup == null)
                    {
                        return;
                    }
                    if (pickup.PrimaryElement.Mass > SolidOutputMax)
                    {
                        pickup = pickup.Take(SolidOutputMax);
                    }
                    solidManager.AddPickupable(portCell, pickup);
                    dispensed = true;
                }
                else if (ConduitType == ConduitType.Liquid || ConduitType == ConduitType.Gas)
                {
                    ConduitFlow conduitManager = iConduitManager as ConduitFlow;
                    if (conduitManager == null)
                    {
                        Debug.LogError($"[MutiIO] OutputPort.ConduitTick(): conduitManager is null");
                        return;
                    }
                    float amountMoved = conduitManager.AddElement(portCell, element.ElementID, element.Mass, element.Temperature, element.DiseaseIdx, element.DiseaseCount);
                    if (amountMoved > 0f)
                    {
                        float movedRatio   = amountMoved / element.Mass;
                        int   movedDisease = (int)(movedRatio * (float)element.DiseaseCount);
                        element.ModifyDiseaseCount(-movedDisease, "ConduitDispenser.ConduitUpdate");
                        element.Mass -= amountMoved;
                        _parent.Trigger((int)GameHashes.OnStorageChange, element.gameObject);
                        dispensed = true;
                    }
                }
            }
            isDispensing = dispensed;
        }