Exemple #1
0
        public void RandomizeCharacterSkin()
        {
            Random random = new Random();

            CharacterSkinsManager.UpdateCharacterSkinsList();
            string[] array  = CharacterSkinsManager.CharacterSkinsNames.Where((string n) => CharacterSkinsManager.IsBuiltIn(n) && CharacterSkinsManager.GetPlayerClass(n) == m_playerClass).ToArray();
            string[] second = SubsystemPlayers.PlayersData.Select((PlayerData pd) => pd.CharacterSkinName).ToArray();
            string[] array2 = array.Except(second).ToArray();
            if (array2.Length != 0)
            {
                CharacterSkinName = array2[random.Int(0, array2.Length - 1)];
            }
            else
            {
                CharacterSkinName = array[random.Int(0, array.Length - 1)];
            }
        }
Exemple #2
0
 public override bool Simulate(float dt)
 {
     if (m_visible)
     {
         m_toGenerate += 15f * dt;
         for (int i = 0; i < base.Particles.Length; i++)
         {
             Particle particle = base.Particles[i];
             if (particle.IsActive)
             {
                 particle.Time       += dt;
                 particle.TimeToLive -= dt;
                 if (particle.TimeToLive > 0f)
                 {
                     particle.Position.Y += particle.Speed * dt;
                     particle.Speed       = MathUtils.Max(particle.Speed - 1.5f * dt, particle.TargetSpeed);
                     particle.TextureSlot = (int)MathUtils.Min(9f * particle.Time / 0.75f, 8f);
                     particle.Size        = new Vector2(0.07f * (1f + 2f * particle.Time));
                 }
                 else
                 {
                     particle.IsActive = false;
                 }
             }
             else if (m_toGenerate >= 1f)
             {
                 particle.IsActive    = true;
                 particle.Position    = m_position + 0.02f * new Vector3(0f, m_random.Float(-1f, 1f), 0f);
                 particle.Color       = Color.White;
                 particle.TargetSpeed = m_random.Float(0.45f, 0.55f) * 0.4f;
                 particle.Speed       = m_random.Float(0.45f, 0.55f) * 2.5f;
                 particle.Time        = 0f;
                 particle.Size        = Vector2.Zero;
                 particle.TimeToLive  = m_random.Float(0.3f, 1f);
                 particle.FlipX       = (m_random.Int(0, 1) == 0);
                 particle.FlipY       = (m_random.Int(0, 1) == 0);
                 m_toGenerate        -= 1f;
             }
         }
         m_toGenerate = MathUtils.Remainder(m_toGenerate, 1f);
     }
     m_visible = false;
     return(false);
 }
Exemple #3
0
        public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
        {
            int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(neighborX, neighborY, neighborZ);

            if (cellContents != 0 && cellContents != 18)
            {
                return;
            }
            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(0));
            if (!m_random.Bool(0.25f))
            {
                return;
            }
            int   num  = 0;
            int   num2 = 0;
            float max  = m_treasureData.Sum((TreasureData t) => t.Probability);
            float num3 = m_random.Float(0f, max);

            TreasureData[] treasureData = m_treasureData;
            for (int i = 0; i < treasureData.Length; i++)
            {
                TreasureData treasureData2 = treasureData[i];
                num3 -= treasureData2.Probability;
                if (num3 <= 0f)
                {
                    num  = treasureData2.Value;
                    num2 = m_random.Int(1, treasureData2.MaxCount);
                    break;
                }
            }
            if (num != 0 && num2 > 0)
            {
                for (int j = 0; j < num2; j++)
                {
                    m_subsystemPickables.AddPickable(num, 1, new Vector3(x, y, z) + m_random.Vector3(0.1f, 0.4f) + new Vector3(0.5f), Vector3.Zero, null);
                }
                int num4 = m_random.Int(3, 6);
                for (int k = 0; k < num4; k++)
                {
                    m_subsystemPickables.AddPickable(248, 1, new Vector3(x, y, z) + m_random.Vector3(0.1f, 0.4f) + new Vector3(0.5f), Vector3.Zero, null);
                }
            }
        }
Exemple #4
0
        public void Update(float dt)
        {
            ComponentPlayer componentPlayer = (m_subsystemPlayers.ComponentPlayers.Count > 0) ? m_subsystemPlayers.ComponentPlayers[0] : null;

            if (componentPlayer == null)
            {
                return;
            }
            if (m_newYearCelebrationTimeRemaining <= 0f && Time.PeriodicEvent(5.0, 0.0) && m_subsystemSky.SkyLightIntensity == 0f && !componentPlayer.ComponentSleep.IsSleeping)
            {
                DateTime now = DateTime.Now;
                if (now.Year > SettingsManager.NewYearCelebrationLastYear && now.Month == 1 && now.Day == 1 && now.Hour == 0 && now.Minute < 59)
                {
                    SettingsManager.NewYearCelebrationLastYear = now.Year;
                    m_newYearCelebrationTimeRemaining          = 180f;
                    componentPlayer.ComponentGui.DisplayLargeMessage("Happy New Year!", "--- Enjoy the fireworks ---", 15f, 3f);
                }
            }
            if (!(m_newYearCelebrationTimeRemaining > 0f))
            {
                return;
            }
            m_newYearCelebrationTimeRemaining -= dt;
            float num = (m_newYearCelebrationTimeRemaining > 10f) ? MathUtils.Lerp(1f, 7f, 0.5f * MathUtils.Sin(0.25f * m_newYearCelebrationTimeRemaining) + 0.5f) : 20f;

            if (m_random.Float(0f, 1f) < num * dt)
            {
                Vector2 vector  = m_random.Vector2(35f, 50f);
                Vector3 vector2 = componentPlayer.ComponentBody.Position + new Vector3(vector.X, 0f, vector.Y);
                TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(new Vector3(vector2.X, 120f, vector2.Z), new Vector3(vector2.X, 40f, vector2.Z), useInteractionBoxes: false, skipAirBlocks: true, null);
                if (terrainRaycastResult.HasValue)
                {
                    int data = 0;
                    data = FireworksBlock.SetShape(data, (FireworksBlock.Shape)m_random.Int(0, 7));
                    data = FireworksBlock.SetColor(data, m_random.Int(0, 7));
                    data = FireworksBlock.SetAltitude(data, m_random.Int(0, 1));
                    data = FireworksBlock.SetFlickering(data, m_random.Float(0f, 1f) < 0.25f);
                    int     value    = Terrain.MakeBlockValue(215, 0, data);
                    Vector3 position = new Vector3(terrainRaycastResult.Value.CellFace.Point.X, terrainRaycastResult.Value.CellFace.Point.Y + 1, terrainRaycastResult.Value.CellFace.Point.Z);
                    m_subsystemProjectiles.FireProjectile(value, position, new Vector3(m_random.Float(-3f, 3f), 45f, m_random.Float(-3f, 3f)), Vector3.Zero, null);
                }
            }
        }
Exemple #5
0
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
        {
            int  num    = 0;
            int  data   = 0;
            int  data2  = Terrain.ExtractData(oldValue);
            int  size   = GetSize(data2);
            bool isWild = GetIsWild(data2);

            if (isWild)
            {
                num  = ((size > 2 && Random.Float(0f, 1f) < 0.33f) ? 1 : 0);
                data = 4;
            }
            else
            {
                switch (size)
                {
                case 5:
                    num  = 1;
                    data = 4;
                    break;

                case 6:
                    num  = Random.Int(1, 2);
                    data = 4;
                    break;

                case 7:
                    num  = Random.Int(1, 3);
                    data = 5;
                    break;
                }
            }
            showDebris = true;
            BlockDropValue item;

            for (int i = 0; i < num; i++)
            {
                item = new BlockDropValue
                {
                    Value = Terrain.MakeBlockValue(173, 0, data),
                    Count = 1
                };
                dropValues.Add(item);
            }
            if (size == 7 && !isWild && Random.Bool(0.5f))
            {
                item = new BlockDropValue
                {
                    Value = 248,
                    Count = 1
                };
                dropValues.Add(item);
            }
        }
 public override void Enter(object[] parameters)
 {
     if (ScreensManager.PreviousScreen.GetType() != typeof(WorldOptionsScreen))
     {
         m_worldSettings = new WorldSettings
         {
             Name = WorldsManager.NewWorldNames[m_random.Int(0, WorldsManager.NewWorldNames.Count - 1)],
             OriginalSerializationVersion = VersionsManager.SerializationVersion
         };
     }
 }
        public void Initialize()
        {
            m_lastViewY             = null;
            m_toCreate              = m_random.Float(0f, 0.9f);
            m_batch                 = null;
            m_lastSkylightIntensity = float.MinValue;
            switch (m_precipitationType)
            {
            case PrecipitationType.Rain:
            {
                float num4 = 8f;
                float num5 = 12f;
                m_averageSpeed = (num4 + num5) / 2f;
                m_size         = new Vector2(0.02f, 0.15f);
                m_texture      = ContentManager.Get <Texture2D>("Textures/RainParticle");
                for (int j = 0; j < m_particles.Length; j++)
                {
                    Particle obj = m_particles[j];
                    obj.IsActive  = false;
                    obj.TexCoord1 = new Vector2(0f, 1f);
                    obj.TexCoord2 = new Vector2(1f, 1f);
                    obj.TexCoord3 = new Vector2(0.5f, 0f);
                    obj.Speed     = m_random.Float(num4, num5);
                }
                break;
            }

            case PrecipitationType.Snow:
            {
                float num  = 0.25f;
                float num2 = 0.5f;
                float num3 = 3f;
                m_averageSpeed = (num2 + num3) / 2f;
                m_size         = new Vector2(0.07f, 0.07f);
                m_texture      = ContentManager.Get <Texture2D>("Textures/SnowParticle");
                for (int i = 0; i < m_particles.Length; i++)
                {
                    Particle particle = m_particles[i];
                    particle.IsActive    = false;
                    particle.TextureSlot = (byte)m_random.Int(0, 15);
                    Vector2 v = new Vector2((int)particle.TextureSlot % 4, (int)particle.TextureSlot / 4) * num;
                    particle.TexCoord1 = v + new Vector2(0f, 0f);
                    particle.TexCoord2 = v + new Vector2(num, 0f);
                    particle.TexCoord3 = v + new Vector2(num, num);
                    particle.TexCoord4 = v + new Vector2(0f, num);
                    particle.Speed     = m_random.Float(num2, num3);
                }
                break;
            }

            default:
                throw new InvalidOperationException("Unknown precipitation type.");
            }
        }
Exemple #8
0
        public static string Pad()
        {
            string text   = string.Empty;
            string text2  = "0123456789abdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            Random random = new Random(171);

            for (int i = 0; i < 229; i++)
            {
                text += text2[random.Int(text2.Length)].ToString();
            }
            return(text);
        }
Exemple #9
0
        public static void Update()
        {
            if (m_fadeSound != null)
            {
                m_fadeSound.Volume = MathUtils.Min(m_fadeSound.Volume - 0.33f * Volume * Time.FrameDuration, Volume);
                if (m_fadeSound.Volume <= 0f)
                {
                    m_fadeSound.Dispose();
                    m_fadeSound = null;
                }
            }
            if (m_sound != null && Time.FrameStartTime >= m_fadeStartTime)
            {
                m_sound.Volume = MathUtils.Min(m_sound.Volume + 0.33f * Volume * Time.FrameDuration, Volume);
            }
            if (m_currentMix == Mix.None || Volume == 0f)
            {
                StopMusic();
            }
            else if (m_currentMix == Mix.Menu && (Time.FrameStartTime >= m_nextSongTime || !IsPlaying))
            {
                float startPercentage = IsPlaying ? m_random.Float(0f, 0.75f) : 0f;
                switch (m_random.Int(0, 5))
                {
                case 0:
                    PlayMusic("Music/NativeAmericanFluteSpirit", startPercentage);
                    break;

                case 1:
                    PlayMusic("Music/AloneForever", startPercentage);
                    break;

                case 2:
                    PlayMusic("Music/NativeAmerican", startPercentage);
                    break;

                case 3:
                    PlayMusic("Music/NativeAmericanHeart", startPercentage);
                    break;

                case 4:
                    PlayMusic("Music/NativeAmericanPeaceFlute", startPercentage);
                    break;

                case 5:
                    PlayMusic("Music/NativeIndianChant", startPercentage);
                    break;
                }
                m_nextSongTime = Time.FrameStartTime + (double)m_random.Float(40f, 60f);
            }
        }
        public void PlayRandomSound(string directory, float volume, float pitch, float pan, float delay)
        {
            ReadOnlyList <ContentInfo> readOnlyList = ContentManager.List(directory);

            if (readOnlyList.Count > 0)
            {
                int index = m_random.Int(0, readOnlyList.Count - 1);
                PlaySound(readOnlyList[index].Name, volume, pitch, pan, delay);
            }
            else
            {
                Log.Warning("Sounds directory \"{0}\" not found or empty.", directory);
            }
        }
        public static TerrainBrush CreateTreeBrush(Random random, int woodIndex, int leavesIndex, int height, int branchesCount, Func <int, float> leavesProbabilityByHeight, Func <int, float> branchesLengthByHeight)
        {
            TerrainBrush terrainBrush = new TerrainBrush();

            terrainBrush.AddRay(0, -1, 0, 0, height, 0, 1, 1, 1, woodIndex);
            for (int i = 0; i < branchesCount; i++)
            {
                int     x       = 0;
                int     num     = random.Int(0, height);
                int     z       = 0;
                float   s       = branchesLengthByHeight(num);
                Vector3 vector  = Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(0f, 0.33f), random.Float(-1f, 1f))) * s;
                int     x2      = (int)MathUtils.Round(vector.X);
                int     y       = num + (int)MathUtils.Round(vector.Y);
                int     z2      = (int)MathUtils.Round(vector.Z);
                int     cutFace = 0;
                if (MathUtils.Abs(vector.X) == MathUtils.Max(MathUtils.Abs(vector.X), MathUtils.Abs(vector.Y), MathUtils.Abs(vector.Z)))
                {
                    cutFace = 1;
                }
                else if (MathUtils.Abs(vector.Y) == MathUtils.Max(MathUtils.Abs(vector.X), MathUtils.Abs(vector.Y), MathUtils.Abs(vector.Z)))
                {
                    cutFace = 4;
                }
                terrainBrush.AddRay(x, num, z, x2, y, z2, 1, 1, 1, (Func <int?, int?>)((int?v) => v.HasValue ? null : new int?(Terrain.MakeBlockValue(woodIndex, 0, WoodBlock.SetCutFace(0, cutFace)))));
            }
            for (int j = 0; j < 3; j++)
            {
                terrainBrush.CalculateBounds(out Point3 min, out Point3 max);
                for (int k = min.X - 1; k <= max.X + 1; k++)
                {
                    for (int l = min.Z - 1; l <= max.Z + 1; l++)
                    {
                        for (int m = 1; m <= max.Y + 1; m++)
                        {
                            float num2 = leavesProbabilityByHeight(m);
                            if (random.Float(0f, 1f) < num2 && !terrainBrush.GetValue(k, m, l).HasValue&& (terrainBrush.CountNonDiagonalNeighbors(k, m, l, leavesIndex) != 0 || terrainBrush.CountNonDiagonalNeighbors(k, m, l, (Func <int?, int>)((int?v) => (v.HasValue && Terrain.ExtractContents(v.Value) == woodIndex) ? 1 : 0)) != 0))
                            {
                                terrainBrush.AddCell(k, m, l, 0);
                            }
                        }
                    }
                }
                terrainBrush.Replace(0, leavesIndex);
            }
            terrainBrush.AddCell(0, height, 0, leavesIndex);
            terrainBrush.Compile();
            return(terrainBrush);
        }
Exemple #12
0
 public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
 {
     showDebris = true;
     if (toolLevel >= RequiredToolLevel)
     {
         int num = Random.Int(1, 3);
         for (int i = 0; i < num; i++)
         {
             dropValues.Add(new BlockDropValue
             {
                 Value = Terrain.MakeBlockValue(85),
                 Count = 1
             });
         }
     }
 }
Exemple #13
0
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
        {
            int data = Terrain.ExtractData(oldValue);

            if (toolLevel > 3 && (data & 98304) == 32768 && (Random.Int() & 3) == 0)
            {
                dropValues.Add(new BlockDropValue {
                    Value = oldValue, Count = 1
                });
                showDebris = true;
                return;
            }
            if (!IsColored(data) && toolLevel > 2 && (data = data >> 1 & 16383) > 0 && data < 11)
            {
                if ((Random.Int() & 7) == 0)
                {
                    dropValues.Add(new BlockDropValue {
                        Value = ItemBlock.IdTable["ScrapIron"], Count = 1
                    });
                }
                else if ((Random.Int() & 7) == data && (data == 4 || data == 6))
                {
                    dropValues.Add(new BlockDropValue
                    {
                        Value = Terrain.ReplaceData(ItemBlock.Index, data == 4 ? 6 + 14 : 4 + 14),
                        Count = 1
                    });
                }
                dropValues.Add(new BlockDropValue
                {
                    Value = Terrain.ReplaceData(ItemBlock.Index, data + 14),
                    Count = 1
                });
                for (data = (Random.Int() & 1) + (2 | data & 1); data-- != 0;)
                {
                    dropValues.Add(new BlockDropValue {
                        Value = ExperienceBlock.Index, Count = 1
                    });
                }
                showDebris = true;
            }
            else
            {
                base.GetDropValues(subsystemTerrain, oldValue, newValue, toolLevel, dropValues, out showDebris);
            }
        }
        public static TerrainBrush CreateMimosaBrush(Random random, float size)
        {
            TerrainBrush terrainBrush = new TerrainBrush();
            int          value        = m_treeTrunksByType[4];
            int          value2       = m_treeLeavesByType[4];

            terrainBrush.AddRay(0, -1, 0, 0, 0, 0, 1, 1, 1, value);
            List <Point3> list = new List <Point3>();
            float         num  = random.Float(0f, (float)Math.PI * 2f);

            for (int i = 0; i < 3; i++)
            {
                float   radians = num + (float)i * MathUtils.DegToRad(120f);
                Vector3 v       = Vector3.Transform(Vector3.Normalize(new Vector3(1f, random.Float(1f, 1.5f), 0f)), Matrix.CreateRotationY(radians));
                int     num2    = random.Int((int)(0.7f * size), (int)size);
                Point3  p       = new Point3(0, 0, 0);
                Point3  item    = new Point3(Vector3.Round(new Vector3(p) + v * num2));
                terrainBrush.AddRay(p.X, p.Y, p.Z, item.X, item.Y, item.Z, 1, 1, 1, value);
                list.Add(item);
            }
            foreach (Point3 item2 in list)
            {
                float num3 = random.Float(0.3f * size, 0.45f * size);
                int   num4 = (int)MathUtils.Ceiling(num3);
                for (int j = item2.X - num4; j <= item2.X + num4; j++)
                {
                    for (int k = item2.Y - num4; k <= item2.Y + num4; k++)
                    {
                        for (int l = item2.Z - num4; l <= item2.Z + num4; l++)
                        {
                            int   num5 = MathUtils.Abs(j - item2.X) + MathUtils.Abs(k - item2.Y) + MathUtils.Abs(l - item2.Z);
                            float num6 = ((new Vector3(j, k, l) - new Vector3(item2)) * new Vector3(1f, 1.7f, 1f)).Length();
                            if (num6 <= num3 && (num3 - num6 > 1f || num5 <= 2 || random.Bool(0.7f)) && !terrainBrush.GetValue(j, k, l).HasValue)
                            {
                                terrainBrush.AddCell(j, k, l, value2);
                            }
                        }
                    }
                }
            }
            terrainBrush.Compile();
            return(terrainBrush);
        }
 public void Update(float dt)
 {
     if (!m_lootDropped && m_componentCreature.ComponentHealth.DeathTime.HasValue && m_subsystemGameInfo.TotalElapsedGameTime >= m_componentCreature.ComponentHealth.DeathTime.Value + (double)m_componentCreature.ComponentHealth.CorpseDuration)
     {
         bool num = m_componentCreature.Entity.FindComponent <ComponentOnFire>()?.IsOnFire ?? false;
         m_lootDropped = true;
         foreach (Loot item in num ? m_lootOnFireList : m_lootList)
         {
             if (m_random.Float(0f, 1f) < item.Probability)
             {
                 int num2 = m_random.Int(item.MinCount, item.MaxCount);
                 for (int i = 0; i < num2; i++)
                 {
                     Vector3 position = (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max) / 2f;
                     m_subsystemPickables.AddPickable(item.Value, 1, position, null, null);
                 }
             }
         }
     }
 }
Exemple #16
0
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
        {
            showDebris = true;
            if (toolLevel < RequiredToolLevel)
            {
                return;
            }
            if (Random.Float(0f, 1f) < 0.33f)
            {
                base.GetDropValues(subsystemTerrain, oldValue, newValue, toolLevel, dropValues, out showDebris);
                return;
            }
            int num = Random.Int(1, 3);

            for (int i = 0; i < num; i++)
            {
                dropValues.Add(new BlockDropValue
                {
                    Value = Terrain.MakeBlockValue(79),
                    Count = 1
                });
            }
        }
Exemple #17
0
        public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
        {
            int data = Terrain.ExtractData(oldValue);

            if (GetSize(data) == 2)
            {
                BlockDropValue item = new BlockDropValue
                {
                    Value = Terrain.MakeBlockValue(173, 0, 6),
                    Count = Random.Int(1, 2)
                };
                dropValues.Add(item);
                if (!GetIsWild(data))
                {
                    int num = Random.Int(1, 2);
                    for (int i = 0; i < num; i++)
                    {
                        item = new BlockDropValue
                        {
                            Value = Terrain.MakeBlockValue(205, 0, 0),
                            Count = 1
                        };
                        dropValues.Add(item);
                    }
                    if (Random.Bool(0.5f))
                    {
                        item = new BlockDropValue
                        {
                            Value = Terrain.MakeBlockValue(248),
                            Count = 1
                        };
                        dropValues.Add(item);
                    }
                }
            }
            showDebris = true;
        }
Exemple #18
0
        public BlockDebrisParticleSystem(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot)
            : base((int)(50f * strength))
        {
            m_subsystemTerrain = terrain;
            base.Texture       = terrain.Project.FindSubsystem <SubsystemBlocksTexture>(throwOnError: true).BlocksTexture;
            int num  = Terrain.ToCell(position.X);
            int num2 = Terrain.ToCell(position.Y);
            int num3 = Terrain.ToCell(position.Z);
            int x    = 0;

            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num + 1, num2, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num - 1, num2, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 + 1, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 - 1, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 + 1));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 - 1));
            base.TextureSlotsCount = 32;
            float num4 = LightingManager.LightIntensityByLightValue[x];

            color  *= num4;
            color.A = byte.MaxValue;
            float num5 = MathUtils.Sqrt(strength);

            for (int i = 0; i < base.Particles.Length; i++)
            {
                Particle obj = base.Particles[i];
                obj.IsActive = true;
                Vector3 vector = new Vector3(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f));
                obj.Position    = position + strength * 0.45f * vector;
                obj.Color       = Color.MultiplyColorOnly(color, m_random.Float(0.7f, 1f));
                obj.Size        = num5 * scale * new Vector2(m_random.Float(0.05f, 0.06f));
                obj.TimeToLive  = num5 * m_random.Float(1f, 3f);
                obj.Velocity    = num5 * 2f * (vector + new Vector3(m_random.Float(-0.2f, 0.2f), 0.6f, m_random.Float(-0.2f, 0.2f)));
                obj.TextureSlot = textureSlot % 16 * 2 + m_random.Int(0, 1) + 32 * (textureSlot / 16 * 2 + m_random.Int(0, 1));
            }
        }
        public void ManualLightingStrike(Vector3 position, Vector3 direction)
        {
            int     num    = Terrain.ToCell(position.X + direction.X * 32f);
            int     num2   = Terrain.ToCell(position.Z + direction.Z * 32f);
            Vector3?vector = null;

            for (int i = 0; i < 300; i++)
            {
                int num3 = m_random.Int(-8, 8);
                int num4 = m_random.Int(-8, 8);
                int num5 = num + num3;
                int num6 = num2 + num4;
                int num7 = SubsystemTerrain.Terrain.CalculateTopmostCellHeight(num5, num6);
                if (!vector.HasValue || (float)num7 > vector.Value.Y)
                {
                    vector = new Vector3(num5, num7, num6);
                }
            }
            if (vector.HasValue)
            {
                SubsystemSky.MakeLightningStrike(vector.Value);
            }
        }
Exemple #20
0
        public FireworksParticleSystem(Vector3 position, Color color, FireworksBlock.Shape shape, float flickering, float particleSize)
            : base(300)
        {
            base.Texture           = ContentManager.Get <Texture2D>("Textures/FireworksParticle");
            m_color                = color;
            m_flickering           = flickering;
            base.TextureSlotsCount = 2;
            if (shape == FireworksBlock.Shape.SmallBurst || shape == FireworksBlock.Shape.LargeBurst)
            {
                int num = (shape == FireworksBlock.Shape.SmallBurst) ? 100 : 200;
                while (m_nextParticle < num)
                {
                    Particle particle = base.Particles[m_nextParticle++];
                    particle.IsActive      = true;
                    particle.Position      = position;
                    particle.Size          = new Vector2(0.2f * particleSize);
                    particle.TimeToLive    = ((shape == FireworksBlock.Shape.SmallBurst) ? m_random.Float(0.5f, 2f) : m_random.Float(1f, 3f));
                    particle.Velocity      = m_random.Vector3(0.5f, 1f);
                    particle.Velocity     *= (float)((shape == FireworksBlock.Shape.SmallBurst) ? 16 : 26) * particle.Velocity.LengthSquared();
                    particle.TextureSlot   = m_random.Int(0, 3);
                    particle.FadeRate      = m_random.Float(1f, 3f);
                    particle.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                    particle.RotationSpeed = 0f;
                }
            }
            switch (shape)
            {
            case FireworksBlock.Shape.Circle:
            {
                float num4 = m_random.Float(0f, (float)Math.PI * 2f);
                int   num5 = 150;
                for (int j = 0; j < num5; j++)
                {
                    float    x2   = (float)Math.PI * 2f * (float)j / (float)num5 + num4;
                    Vector3  v2   = new Vector3(MathUtils.Sin(x2) + 0.1f * m_random.Float(-1f, 1f), 0f, MathUtils.Cos(x2) + 0.1f * m_random.Float(-1f, 1f));
                    Particle obj2 = base.Particles[m_nextParticle++];
                    obj2.IsActive      = true;
                    obj2.Position      = position;
                    obj2.Size          = new Vector2(0.2f * particleSize);
                    obj2.TimeToLive    = m_random.Float(1f, 3f);
                    obj2.Velocity      = 20f * v2;
                    obj2.TextureSlot   = m_random.Int(0, 3);
                    obj2.FadeRate      = m_random.Float(1f, 3f);
                    obj2.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                    obj2.RotationSpeed = 0f;
                }
                break;
            }

            case FireworksBlock.Shape.Disc:
            {
                float num10 = m_random.Float(0f, (float)Math.PI * 2f);
                int   num11 = 13;
                for (int m = 0; m <= num11; m++)
                {
                    float num12 = (float)m / (float)num11;
                    int   num13 = (int)MathUtils.Round(num12 * 2f * (float)num11);
                    for (int n = 0; n < num13; n++)
                    {
                        float    x5   = (float)Math.PI * 2f * (float)n / (float)num13 + num10;
                        Vector3  v4   = new Vector3(num12 * MathUtils.Sin(x5) + 0.1f * m_random.Float(-1f, 1f), 0f, num12 * MathUtils.Cos(x5) + 0.1f * m_random.Float(-1f, 1f));
                        Particle obj4 = base.Particles[m_nextParticle++];
                        obj4.IsActive      = true;
                        obj4.Position      = position;
                        obj4.Size          = new Vector2(0.2f * particleSize);
                        obj4.TimeToLive    = m_random.Float(1f, 3f);
                        obj4.Velocity      = 22f * v4;
                        obj4.TextureSlot   = m_random.Int(0, 3);
                        obj4.FadeRate      = m_random.Float(1f, 3f);
                        obj4.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                        obj4.RotationSpeed = 0f;
                    }
                }
                break;
            }

            case FireworksBlock.Shape.Ball:
            {
                float   num14 = m_random.Float(0f, (float)Math.PI * 2f);
                int     num15 = 12;
                Vector3 v5    = default(Vector3);
                for (int num16 = 0; num16 <= num15; num16++)
                {
                    float x6 = (float)Math.PI * (float)num16 / (float)num15;
                    v5.Y = MathUtils.Cos(x6);
                    float num17 = MathUtils.Sin(x6);
                    int   num18 = (int)MathUtils.Round(num17 * 2f * (float)num15);
                    for (int num19 = 0; num19 < num18; num19++)
                    {
                        float x7 = (float)Math.PI * 2f * (float)num19 / (float)num18 + num14;
                        v5.X = num17 * MathUtils.Sin(x7);
                        v5.Z = num17 * MathUtils.Cos(x7);
                        Particle obj5 = base.Particles[m_nextParticle++];
                        obj5.IsActive      = true;
                        obj5.Position      = position;
                        obj5.Size          = new Vector2(0.2f * particleSize);
                        obj5.TimeToLive    = m_random.Float(1f, 3f);
                        obj5.Velocity      = 20f * v5;
                        obj5.TextureSlot   = m_random.Int(0, 3);
                        obj5.FadeRate      = m_random.Float(1f, 3f);
                        obj5.BaseColor     = m_color * m_random.Float(0.5f, 1f);
                        obj5.RotationSpeed = 0f;
                    }
                }
                break;
            }

            case FireworksBlock.Shape.ShortTrails:
            case FireworksBlock.Shape.LongTrails:
            {
                float   num6 = m_random.Float(0f, (float)Math.PI * 2f);
                int     num7 = 3;
                Vector3 v3   = default(Vector3);
                for (int k = 0; k <= num7; k++)
                {
                    float x3   = (float)Math.PI * (float)k / (float)num7;
                    float num8 = MathUtils.Sin(x3);
                    int   num9 = (int)MathUtils.Round(num8 * (float)((shape == FireworksBlock.Shape.ShortTrails) ? 3 : 2) * (float)num7);
                    for (int l = 0; l < num9; l++)
                    {
                        float x4 = (float)Math.PI * 2f * (float)l / (float)num9 + num6;
                        v3.X = num8 * MathUtils.Sin(x4) + 0.3f * m_random.Float(-1f, 1f);
                        v3.Y = MathUtils.Cos(x3) + 0.3f * m_random.Float(-1f, 1f);
                        v3.Z = num8 * MathUtils.Cos(x4) + 0.3f * m_random.Float(-1f, 1f);
                        Particle obj3 = base.Particles[m_nextParticle++];
                        obj3.IsActive            = true;
                        obj3.Position            = position;
                        obj3.Size                = new Vector2(0.25f);
                        obj3.TimeToLive          = m_random.Float(0.5f, 2.5f);
                        obj3.Velocity            = ((shape == FireworksBlock.Shape.ShortTrails) ? (25f * v3) : (35f * v3));
                        obj3.TextureSlot         = m_random.Int(0, 3);
                        obj3.FadeRate            = m_random.Float(1f, 3f);
                        obj3.BaseColor           = m_color * m_random.Float(0.5f, 1f);
                        obj3.GenerationFrequency = ((shape == FireworksBlock.Shape.ShortTrails) ? 1.9f : 2.1f);
                        obj3.RotationSpeed       = m_random.Float(-40f, 40f);
                    }
                }
                break;
            }

            case FireworksBlock.Shape.FlatTrails:
            {
                float num2 = m_random.Float(0f, (float)Math.PI * 2f);
                int   num3 = 13;
                for (int i = 0; i < num3; i++)
                {
                    float    x   = (float)Math.PI * 2f * (float)i / (float)num3 + num2;
                    Vector3  v   = new Vector3(MathUtils.Sin(x) + 0.1f * m_random.Float(-1f, 1f), 0f, MathUtils.Cos(x) + 0.1f * m_random.Float(-1f, 1f));
                    Particle obj = base.Particles[m_nextParticle++];
                    obj.IsActive            = true;
                    obj.Position            = position;
                    obj.Size                = new Vector2(0.25f);
                    obj.TimeToLive          = m_random.Float(0.5f, 2.5f);
                    obj.Velocity            = 25f * v;
                    obj.TextureSlot         = m_random.Int(0, 3);
                    obj.FadeRate            = m_random.Float(1f, 3f);
                    obj.BaseColor           = m_color * m_random.Float(0.5f, 1f);
                    obj.GenerationFrequency = 2.5f;
                    obj.RotationSpeed       = m_random.Float(-40f, 40f);
                }
                break;
            }
            }
        }
        public ReportCommunityContentDialog(string address, string displayName, string userId)
        {
            m_address = address;
            m_userId  = userId;
            XElement node = ContentManager.Get <XElement>("Dialogs/ReportCommunityContentDialog");

            LoadContents(this, node);
            m_nameLabel    = Children.Find <LabelWidget>("ReportCommunityContentDialog.Name");
            m_container    = Children.Find <ContainerWidget>("ReportCommunityContentDialog.Container");
            m_reportButton = Children.Find <ButtonWidget>("ReportCommunityContentDialog.Report");
            m_cancelButton = Children.Find <ButtonWidget>("ReportCommunityContentDialog.Cancel");
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Cruelty",
                Tag  = "cruelty"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Dating",
                Tag  = "dating"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Drugs / Alcohol",
                Tag  = "drugs"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Hate Speech",
                Tag  = "hate"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Plagiarism",
                Tag  = "plagiarism"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Racism",
                Tag  = "racism"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Sex / Nudity",
                Tag  = "sex"
            });
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Excessive Swearing",
                Tag  = "swearing"
            });
            Random random = new Random();

            m_reasonWidgetsList.RandomShuffle((int max) => random.Int(0, max - 1));
            m_reasonWidgetsList.Add(new CheckboxWidget
            {
                Text = "Other",
                Tag  = "other"
            });
            foreach (CheckboxWidget reasonWidgets in m_reasonWidgetsList)
            {
                m_container.Children.Add(reasonWidgets);
            }
            m_nameLabel.Text         = displayName;
            m_reportButton.IsEnabled = false;
        }
Exemple #22
0
        public override void OnChunkInitialized(TerrainChunk chunk)
        {
            if (!(Utils.SubsystemTerrain.TerrainContentsGenerator is TerrainContentsGenerator generator) || chunk.IsLoaded)
            {
                return;
            }
            int x = chunk.Coords.X - 1;
            int y = chunk.Coords.Y - 1;
            const int
                f1 = 0x63721054,
                f2 = 0x04317562,
                f3 = 0x52473601,
                f4 = 0x61234057,
                f5 = 0x07142563,
                f6 = 0x53721604,
                f7 = 0x64317052,
                f8 = 0x02473561,
                f9 = 0x51234607,
                fa = 0x67142053,
                fb = 0x03721564,
                fc = 0x54317602,
                fd = 0x62473051,
                fe = 0x01234567,
                ff = 0x57142603;
            Random random;

            for (int i = x; i < x + 2; i++)
            {
                int k, ix16 = i << 4;
                for (int j = y; j < y + 2; j++)
                {
                    random = new Random(generator.m_seed + i + (f1 ^ f4 ^ f5 ^ f7 ^ fa ^ fc ^ fd) * j);
                    int       jx16 = j << 4;
                    float     num2 = generator.CalculateMountainRangeFactor(ix16, jx16);
                    const int index = BasaltBlock.Index, index2 = BasaltBlock.Index;
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i ^ fe, j ^ ff, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(SmallBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 30), jx16 | (random.Int() & 15), index2 | (int)BrushType.Au << 15);
                    }
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + 713, j + f3, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(SmallBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 30), jx16 | (random.Int() & 15), index2 | (int)BrushType.Ag << 15);
                    }
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f2, j + 396, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(PtBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 15), jx16 | (random.Int() & 15), index2 | (int)BrushType.Pt << 15);
                    }
                    for (k = 3 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f6, j + 131, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Pb << 15);
                    }
                    for (k = (int)(0.5f + 2f * num2 * SimplexNoise.OctavedNoise(i + 432, j + f9, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(BBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 15), jx16 | (random.Int() & 15), index | (int)BrushType.Hg << 15);
                    }
                    for (k = 3 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + 711, j + fb, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(BBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 40), jx16 | (random.Int() & 15), index | (int)BrushType.Sn << 15);
                    }
                    for (k = 2 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f8, j + 272, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Ti << 15);
                    }
                    for (k = 2 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + fa, j + fc, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(BBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Cr << 15);
                    }
                    for (k = 2 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f3, j + f6, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | (int)BrushType.Ni << 15);
                    }
                    for (k = 20 + (int)(8f * num2 * SimplexNoise.OctavedNoise(i + fa ^ f5 + f1, j + fc - f9, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintMaskSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | 65536 << 14);
                    }
                    for (k = 9 + (int)(8f * num2 * SimplexNoise.OctavedNoise(i + f5 ^ f8 + f1, j + f9 - fc, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintMaskSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 50), jx16 | (random.Int() & 15), index | 32768 << 14);
                    }
                    for (k = 1 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + fc, j + f9, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(SmallBrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(2, 20), jx16 | (random.Int() & 15), index2 | (int)BrushType.U << 15);
                    }
                    for (k = 3 + (int)(2f * num2 * SimplexNoise.OctavedNoise(i + f3, j + f1, 0.33f, 1, 1f, 1f)); k-- != 0;)
                    {
                        chunk.PaintFastSelective(ABrushes[random.Int() & 15].Cells, ix16 | (random.Int() & 15), random.UniformInt(45, 70), jx16 | (random.Int() & 15), 3 | (int)BrushType.P << 15);
                    }
                    if (generator.CalculateOceanShoreDistance(ix16, y << 4) < -90f)
                    {
                        int n = TerrainChunk.CalculateCellIndex(random.Int() & 15, 35, random.Int() & 15);
                        for (k = 0; k < 45; k++)
                        {
                            if (Terrain.ExtractContents(chunk.GetCellValueFast(n + k)) == WaterBlock.Index && BlocksManager.Blocks[Terrain.ExtractContents(chunk.GetCellValueFast(n + k - 1))].IsCollidable)
                            {
                                chunk.SetCellValueFast(n + k, IceBlock.Index | 32 << 14);
                                break;
                            }
                        }
                    }
                }
                random = new Random(generator.m_seed ^ (x << 16 | y));
                if ((random.Int() & 1) != 0)
                {
                    chunk.PaintSelective(OilPocketCells[random.Int() & 15], x << 16 | (random.Int() & 15), random.UniformInt(40, 70), y << 16 | (random.Int() & 15), 3);
                }
            }
        }
Exemple #23
0
        public override void Load(ValuesDictionary valuesDictionary)
        {
            base.Load(valuesDictionary);
            Utils.Load(Project);
            //Utils.SubsystemItemsScanner.ItemsScanned += GarbageCollectItems;
            var arr = valuesDictionary.GetValue("AlloysData", "0").Split(',');

            AlloysData = new DynamicArray <Metal>(arr.Length);
            int i;

            for (i = 0; i < arr.Length; i++)
            {
                if (short.TryParse(arr[i], NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out short value))
                {
                    AlloysData.Add((Metal)value);
                }
            }
            SmallBrushes = new TerrainBrush[16];
            PtBrushes    = new TerrainBrush[16];
            BBrushes     = new TerrainBrush[16];
            ABrushes     = new TerrainBrush[16];
            //NaruralGasBrushes = new TerrainBrush[16];
            OilPocketCells = new TerrainBrush.Cell[16][];
            //MinCounts = new int[12, 16];
            var          random = new Random(17034);
            TerrainBrush brush;
            int          j, k;

            for (i = 0; i < 16; i++)
            {
                brush = new TerrainBrush();
                Vector3 v, vec;
                for (j = random.Int() & 1; j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(2, 5); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 1);                         //Ag
                        vec += v;
                    }
                }
                brush.Compile();
                SmallBrushes[i] = brush;
                brush           = new TerrainBrush();
                for (j = random.UniformInt(1, 3); j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-2f, 2f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(2, 3); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 2);                         //Pt
                        vec += v;
                    }
                }
                brush.Compile();
                PtBrushes[i] = brush;
                brush        = new TerrainBrush();
                for (j = random.UniformInt(2, 4); j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-0.25f, 0.25f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(3, 5); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 8);                         //Ti
                        vec += v;
                    }
                }
                brush.Compile();
                ABrushes[i] = brush;
                brush       = new TerrainBrush();
                for (j = random.UniformInt(3, 5); j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(2, 5); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 5);                         //Sn
                        vec += v;
                    }
                }
                brush.Compile();
                BBrushes[i] = brush;
                var cells = TerrainContentsGenerator.m_basaltPocketBrushes[i].Cells;
                OilPocketCells[i] = new TerrainBrush.Cell[j = cells.Length];
                while (j-- != 0)
                {
                    if ((cells[j].Value & random.Int()) != 0)
                    {
                        OilPocketCells[i][j]       = cells[j];
                        OilPocketCells[i][j].Value = RottenMeatBlock.Index | 1 << 4 << 14;
                    }
                }
            }
        }
 public static float GetRandomVoltage()
 {
     return((float)s_random.Int(0, 15) / 15f);
 }
Exemple #25
0
        public static void AttackBody(ComponentBody target, ComponentCreature attacker, Vector3 hitPoint, Vector3 hitDirection, float attackPower, bool isMeleeAttack)
        {
            if (attacker != null && attacker is ComponentPlayer && target.Entity.FindComponent <ComponentPlayer>() != null && !target.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true).WorldSettings.IsFriendlyFireEnabled)
            {
                attacker.Entity.FindComponent <ComponentGui>(throwOnError: true).DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: true, playNotificationSound: true);
                return;
            }
            if (attackPower > 0f)
            {
                ComponentClothing componentClothing = target.Entity.FindComponent <ComponentClothing>();
                if (componentClothing != null)
                {
                    attackPower = componentClothing.ApplyArmorProtection(attackPower);
                }
                ComponentLevel componentLevel = target.Entity.FindComponent <ComponentLevel>();
                if (componentLevel != null)
                {
                    attackPower /= componentLevel.ResilienceFactor;
                }
                ComponentHealth componentHealth = target.Entity.FindComponent <ComponentHealth>();
                if (componentHealth != null)
                {
                    float  num = attackPower / componentHealth.AttackResilience;
                    string cause;
                    if (attacker != null)
                    {
                        string str          = attacker.KillVerbs[s_random.Int(0, attacker.KillVerbs.Count - 1)];
                        string attackerName = attacker.DisplayName;
                        cause = string.Format(LanguageControl.Get(fName, 4), attackerName, LanguageControl.Get(fName, str));
                    }
                    else
                    {
                        switch (s_random.Int(0, 5))
                        {
                        case 0:
                            cause = LanguageControl.Get(fName, 5);
                            break;

                        case 1:
                            cause = LanguageControl.Get(fName, 6);
                            break;

                        case 2:
                            cause = LanguageControl.Get(fName, 7);
                            break;

                        case 3:
                            cause = LanguageControl.Get(fName, 8);
                            break;

                        case 4:
                            cause = LanguageControl.Get(fName, 9);
                            break;

                        default:
                            cause = LanguageControl.Get(fName, 10);
                            break;
                        }
                    }
                    float health = componentHealth.Health;
                    componentHealth.Injure(num, attacker, ignoreInvulnerability: false, cause);
                    if (num > 0f)
                    {
                        target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound("Audio/Impacts/Body", 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false);
                        float num2 = (health - componentHealth.Health) * componentHealth.AttackResilience;
                        if (attacker is ComponentPlayer && num2 > 0f)
                        {
                            string text2 = (0f - num2).ToString("0", CultureInfo.InvariantCulture);
                            HitValueParticleSystem particleSystem = new HitValueParticleSystem(hitPoint + 0.75f * hitDirection, 1f * hitDirection + attacker.ComponentBody.Velocity, Color.White, text2);
                            target.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem);
                        }
                    }
                }
                ComponentDamage componentDamage = target.Entity.FindComponent <ComponentDamage>();
                if (componentDamage != null)
                {
                    float num3 = attackPower / componentDamage.AttackResilience;
                    componentDamage.Damage(num3);
                    if (num3 > 0f)
                    {
                        target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound(componentDamage.DamageSoundName, 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false);
                    }
                }
            }
            float num4 = 0f;
            float x    = 0f;

            if (isMeleeAttack && attacker != null)
            {
                float num5 = (attackPower >= 2f) ? 1.25f : 1f;
                float num6 = MathUtils.Pow(attacker.ComponentBody.Mass / target.Mass, 0.5f);
                float x2   = num5 * num6;
                num4 = 5.5f * MathUtils.Saturate(x2);
                x    = 0.25f * MathUtils.Saturate(x2);
            }
            else if (attackPower > 0f)
            {
                num4 = 2f;
                x    = 0.2f;
            }
            if (num4 > 0f)
            {
                target.ApplyImpulse(num4 * Vector3.Normalize(hitDirection + s_random.Vector3(0.1f) + 0.2f * Vector3.UnitY));
                ComponentLocomotion componentLocomotion = target.Entity.FindComponent <ComponentLocomotion>();
                if (componentLocomotion != null)
                {
                    componentLocomotion.StunTime = MathUtils.Max(componentLocomotion.StunTime, x);
                }
            }
        }