Ejemplo n.º 1
0
    public void AddParticle(Vector2 root_pos, byte elementIdx, float base_mass, float temperature, byte disease_idx, int base_disease_count, bool skip_sound = false, bool skip_decor = false, bool debug_track = false, bool disable_randomness = false)
    {
        int num = Grid.PosToCell(root_pos);

        if (!Grid.IsValidCell(num))
        {
            KCrashReporter.Assert(false, "Trying to add falling water outside of the scene");
        }
        else
        {
            if (temperature <= 0f || base_mass <= 0f)
            {
                Debug.LogError($"Unexpected water mass/temperature values added to the falling water manager T({temperature}) M({base_mass})");
            }
            float time = GetTime();
            if (!skip_sound)
            {
                if (!topSounds.TryGetValue(num, out SoundInfo value))
                {
                    value        = default(SoundInfo);
                    value.handle = LoopingSoundManager.StartSound(liquid_top_loop, root_pos, true, true);
                }
                value.startTime = time;
                LoopingSoundManager.Get().UpdateSecondParameter(value.handle, HASH_LIQUIDVOLUME, SoundUtil.GetLiquidVolume(base_mass));
                topSounds[num] = value;
            }
            while (base_mass > 0f)
            {
                float num2 = UnityEngine.Random.value * 2f * particleMassVariation - particleMassVariation;
                float num3 = Mathf.Max(0f, Mathf.Min(base_mass, particleMassToSplit + num2));
                float num4 = num3 / base_mass;
                base_mass -= num3;
                int     disease_count = (int)(num4 * (float)base_disease_count);
                int     frame         = UnityEngine.Random.Range(0, numFrames);
                Vector2 b             = (!disable_randomness) ? new Vector2(jitterStep * Mathf.Sin(offset), jitterStep * Mathf.Sin(offset + 17f)) : Vector2.zero;
                Vector2 b2            = (!disable_randomness) ? new Vector2(UnityEngine.Random.Range(0f - multipleOffsetRange.x, multipleOffsetRange.x), UnityEngine.Random.Range(0f - multipleOffsetRange.y, multipleOffsetRange.y)) : Vector2.zero;
                Element element       = ElementLoader.elements[elementIdx];
                Vector2 vector        = root_pos;
                bool    flag          = !skip_decor && SpawnLiquidTopDecor(time, Grid.CellLeft(num), false, element);
                bool    flag2         = !skip_decor && SpawnLiquidTopDecor(time, Grid.CellRight(num), true, element);
                Vector2 b3            = Vector2.ClampMagnitude(initialOffset + b + b2, 1f);
                if (flag || flag2)
                {
                    if (flag && flag2)
                    {
                        vector   += b3;
                        vector.x += 0.5f;
                    }
                    else if (flag)
                    {
                        vector += b3;
                    }
                    else
                    {
                        vector.x += 1f - b3.x;
                        vector.y += b3.y;
                    }
                }
                else
                {
                    vector   += b3;
                    vector.x += 0.5f;
                }
                int           num5     = Grid.PosToCell(vector);
                Element       element2 = Grid.Element[num5];
                Element.State state    = element2.state & Element.State.Solid;
                if (state == Element.State.Solid || (Grid.Properties[num5] & 2) != 0)
                {
                    vector.y = Mathf.Floor(vector.y + 1f);
                }
                physics.Add(new ParticlePhysics(vector, Vector2.zero, frame, elementIdx));
                particleProperties.Add(new ParticleProperties(elementIdx, num3, temperature, disease_idx, disease_count, debug_track));
            }
        }
    }