Esempio n. 1
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);
         }
     }
 }
Esempio n. 2
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();
            }
        }
Esempio n. 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;
    }
        protected override void ConduitUpdate(float dt)
        {
            this.currentValue = 0f;

            int cell = Grid.PosToCell(this);

            SolidConduitFlow.ConduitContents contents = Game.Instance.solidConduitFlow.GetContents(cell);
            if (contents.pickupableHandle.IsValid())
            {
                Pickupable pickupable = Game.Instance.solidConduitFlow.GetPickupable(contents.pickupableHandle);
                this.currentValue = pickupable.TotalAmount * 1000f;
            }

            // spawn code should never toggle as it crashes on load
            if (dt < 0)
            {
                return;
            }

            if (this.activateAboveThreshold)
            {
                // Empty is always false
                if (this.currentValue <= 0f)
                {
                    if (base.IsSwitchedOn)
                    {
                        this.Toggle();
                    }
                    return;
                }

                // Full is always true
                if (this.currentValue >= this.max)
                {
                    if (!base.IsSwitchedOn)
                    {
                        this.Toggle();
                    }
                    return;
                }

                if ((this.currentValue > this.threshold && !base.IsSwitchedOn) || (this.currentValue <= this.threshold && base.IsSwitchedOn))
                {
                    this.Toggle();
                }
            }
            else if ((this.currentValue > this.threshold && base.IsSwitchedOn) || (this.currentValue <= this.threshold && !base.IsSwitchedOn))
            {
                this.Toggle();
            }
        }
        protected override void ConduitUpdate(float dt)
        {
            int cell = Grid.PosToCell(this);

            SolidConduitFlow.ConduitContents contents = Game.Instance.solidConduitFlow.GetContents(cell);
            if (contents.pickupableHandle.IsValid())
            {
                Pickupable     pickupable     = Game.Instance.solidConduitFlow.GetPickupable(contents.pickupableHandle);
                PrimaryElement primaryElement = pickupable.GetComponent <PrimaryElement>();

                if (primaryElement != null)
                {
                    this.currentValue = primaryElement.DiseaseCount;
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }

            // spawn code should never toggle as it crashes on load
            if (dt < 0)
            {
                return;
            }


            if (this.activateAboveThreshold)
            {
                if ((this.currentValue > this.threshold && !base.IsSwitchedOn) || (this.currentValue <= this.threshold && base.IsSwitchedOn))
                {
                    this.Toggle();
                }
            }
            else if ((this.currentValue > this.threshold && base.IsSwitchedOn) || (this.currentValue <= this.threshold && !base.IsSwitchedOn))
            {
                this.Toggle();
            }
        }
Esempio n. 6
0
        protected override void ConduitUpdate(float dt)
        {
            SimHashes currentElement = SimHashes.Vacuum;

            int cell = Grid.PosToCell(this);

            SolidConduitFlow.ConduitContents contents = Game.Instance.solidConduitFlow.GetContents(cell);
            if (contents.pickupableHandle.IsValid())
            {
                Pickupable     pickupable     = Game.Instance.solidConduitFlow.GetPickupable(contents.pickupableHandle);
                PrimaryElement primaryElement = pickupable.GetComponent <PrimaryElement>();

                if (primaryElement != null)
                {
                    currentElement = primaryElement.ElementID;
                }
            }

            // spawn code should never toggle as it crashes on load
            if (dt < 0)
            {
                return;
            }

            if (base.IsSwitchedOn)
            {
                if (currentElement != this.desiredElement)
                {
                    this.Toggle();
                }
            }
            else if (currentElement == this.desiredElement)
            {
                this.Toggle();
            }
        }
Esempio n. 7
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.
                        }
                    }
                }
            }
        }