Beispiel #1
0
        public World()
        {
            Random rnd = new Random();

            #if SILVERLIGHT
            Res.SearchPath.addPath("file://K:/Projects/steel/moora/Resources");
            //            dirs.Add("http://division.kindex.lv/moora/terrain");
            #else
            Res.SearchPath.addPath("../../../Resources");
            Res.SearchPath.addPath("Resources");
            #endif
            terrain = new Terrain(rnd);
            //            map = new RandomMap(21, 18, terrain, rnd);

            List<string> file = Res.TextFile.GetTextFile("map.txt");

            map = new FileMap(terrain, file);

            int char_x;
            int char_y;

            int try_number = 0;
            do
            {
                char_x = rnd.Next(0, map.X);
                char_y = rnd.Next(0, map.Y);
                if (try_number++ > 1000)
                {
                    break;
                }
            }
            while (map.getTerrain(char_x, char_y) != TerrainType.Sand);

            character = new Character(char_x, char_y, map);
        }
        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
        {
            int data = Terrain.ExtractData(value);

            return(face != GetFace(data));
        }
 public override bool ShouldAvoid(int value)
 {
     return(GetSpikesState(Terrain.ExtractData(value)));
 }
Beispiel #4
0
        public void MatureSapling(SaplingData saplingData)
        {
            if (!(m_subsystemGameInfo.TotalElapsedGameTime >= saplingData.MatureTime))
            {
                return;
            }
            int          x            = saplingData.Point.X;
            int          y            = saplingData.Point.Y;
            int          z            = saplingData.Point.Z;
            TerrainChunk chunkAtCell  = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z - 6);
            TerrainChunk chunkAtCell2 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z + 6);
            TerrainChunk chunkAtCell3 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z - 6);
            TerrainChunk chunkAtCell4 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z + 6);

            if (chunkAtCell != null && chunkAtCell.State == TerrainChunkState.Valid && chunkAtCell2 != null && chunkAtCell2.State == TerrainChunkState.Valid && chunkAtCell3 != null && chunkAtCell3.State == TerrainChunkState.Valid && chunkAtCell4 != null && chunkAtCell4.State == TerrainChunkState.Valid)
            {
                int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(x, y - 1, z);
                if (cellContents == 2 || cellContents == 8)
                {
                    if (base.SubsystemTerrain.Terrain.GetCellLight(x, y + 1, z) >= 9)
                    {
                        bool flag = false;
                        for (int i = x - 1; i <= x + 1; i++)
                        {
                            for (int j = z - 1; j <= z + 1; j++)
                            {
                                int cellContents2 = base.SubsystemTerrain.Terrain.GetCellContents(i, y - 1, j);
                                if (BlocksManager.Blocks[cellContents2] is WaterBlock)
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        float num = 0f;
                        if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative)
                        {
                            num = 1f;
                        }
                        else
                        {
                            int num2 = base.SubsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
                            int num3 = base.SubsystemTerrain.Terrain.GetHumidity(x, z);
                            if (flag)
                            {
                                num2 = (num2 + 10) / 2;
                                num3 = MathUtils.Max(num3, 12);
                            }
                            num = 2f * PlantsManager.CalculateTreeProbability(saplingData.Type, num2, num3, y);
                        }
                        if (m_random.Bool(num))
                        {
                            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(0, 0, 0));
                            if (!GrowTree(x, y, z, saplingData.Type))
                            {
                                base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                            }
                        }
                        else
                        {
                            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                        }
                    }
                    else if (m_subsystemGameInfo.TotalElapsedGameTime > saplingData.MatureTime + 1200.0)
                    {
                        base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                    }
                }
                else
                {
                    base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                }
            }
            else
            {
                saplingData.MatureTime = m_subsystemGameInfo.TotalElapsedGameTime;
            }
        }
Beispiel #5
0
        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            int value2 = Terrain.ExtractData(value);

            BlocksManager.DrawFlatBlock(primitivesRenderer, value, size, ref matrix, null, color * SubsystemPalette.GetColor(environmentData, value2), isEmissive: false, environmentData);
        }
        public bool IsMagma(Vector3 position)
        {
            int cellContents = m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(position.X), Terrain.ToCell(position.Y), Terrain.ToCell(position.Z));

            return(BlocksManager.Blocks[cellContents] is MagmaBlock);
        }
Beispiel #7
0
        public static void DrawFlatBlock(PrimitivesRenderer3D primitivesRenderer, int value, float size,
                                         ref Matrix matrix, Texture2D texture, Color color, bool isEmissive,
                                         DrawBlockEnvironmentData environmentData)
        {
            environmentData = environmentData ?? m_defaultEnvironmentData;
            if (!isEmissive)
            {
                color = Color.MultiplyColorOnly(color, LightingManager.LightIntensityByLightValue[environmentData.Light]);
            }

            var     translation = matrix.Translation;
            Vector3 v2;
            Vector3 vector3;

            if (environmentData.BillboardDirection.HasValue)
            {
                v2      = Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, Vector3.UnitY));
                vector3 = -Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, v2));
            }
            else
            {
                v2      = matrix.Right;
                vector3 = matrix.Up;
            }

            var result1 = translation + 0.85f * size * (-v2 - vector3);
            var result2 = translation + 0.85f * size * (v2 - vector3);
            var result3 = translation + 0.85f * size * (-v2 + vector3);
            var result4 = translation + 0.85f * size * (v2 + vector3);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                var m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref result1, ref m, out result1);
                Vector3.Transform(ref result2, ref m, out result2);
                Vector3.Transform(ref result3, ref m, out result3);
                Vector3.Transform(ref result4, ref m, out result4);
            }

            var     block = Blocks[Terrain.ExtractContents(value)];
            Vector4 vector4;

            if (texture == null)
            {
                texture = environmentData.SubsystemTerrain != null
                                        ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture
                                        : BlocksTexturesManager.DefaultBlocksTexture;
                vector4 = m_slotTexCoords[block.GetFaceTextureSlot(-1, value)];
            }
            else
            {
                vector4 = new Vector4(0.0f, 0.0f, 1f, 1f);
            }

            var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null,
                                                                   RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);

            texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(vector4.X, vector4.W),
                                      new Vector2(vector4.X, vector4.Y), new Vector2(vector4.Z, vector4.Y), new Vector2(vector4.Z, vector4.W),
                                      color);
            if (environmentData.BillboardDirection.HasValue)
            {
                return;
            }
            texturedBatch3D.QueueQuad(result1, result2, result4, result3, new Vector2(vector4.X, vector4.W),
                                      new Vector2(vector4.Z, vector4.W), new Vector2(vector4.Z, vector4.Y), new Vector2(vector4.X, vector4.Y),
                                      color);
        }
Beispiel #8
0
        public void Update(float dt)
        {
            if (Coordinates.Y < 0 || Coordinates.Y > 127)
            {
                return;
            }
            if (HeatLevel > 0f)
            {
                m_fireTimeRemaining = MathUtils.Max(0f, m_fireTimeRemaining - dt);
                if (m_fireTimeRemaining == 0f)
                {
                    HeatLevel = 0f;
                }
            }
            Slot slot;

            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                float heatLevel = 0f;
                if (HeatLevel > 0f)
                {
                    heatLevel = HeatLevel;
                }
                else
                {
                    slot = m_slots[FuelSlotIndex];
                    if (slot.Count > 0)
                    {
                        var block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                        heatLevel = block is IFuel fuel?fuel.GetHeatLevel(slot.Value) : block.FuelHeatLevel;
                    }
                }
                string text = FindSmeltingRecipe(heatLevel);
                if (text != m_smeltingRecipe)
                {
                    m_smeltingRecipe = text;
                    SmeltingProgress = 0f;
                    m_music          = 0;
                }
            }
            if (m_smeltingRecipe == null)
            {
                HeatLevel           = 0f;
                m_fireTimeRemaining = 0f;
                m_music             = -1;
            }
            else if (m_smeltingRecipe != null && m_fireTimeRemaining <= 0f)
            {
                slot = m_slots[FuelSlotIndex];
                if (slot.Count > 0)
                {
                    var block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                    if (block.GetExplosionPressure(slot.Value) > 0f)
                    {
                        slot.Count = 0;
                        Utils.SubsystemExplosions.TryExplodeBlock(Coordinates.X, Coordinates.Y, Coordinates.Z, slot.Value);
                    }
                    else
                    {
                        slot.Count--;
                        if (block is IFuel fuel)
                        {
                            HeatLevel           = fuel.GetHeatLevel(slot.Value);
                            m_fireTimeRemaining = fuel.GetFuelFireDuration(slot.Value);
                        }
                        else
                        {
                            HeatLevel           = block.FuelHeatLevel;
                            m_fireTimeRemaining = block.FuelFireDuration;
                        }
                    }
                }
            }
            if (m_fireTimeRemaining <= 0f)
            {
                m_smeltingRecipe = null;
                SmeltingProgress = 0f;
                m_music          = -1;
            }
            if (m_smeltingRecipe != null)
            {
                SmeltingProgress = MathUtils.Min(SmeltingProgress + 0.02f * dt, 1f);
                if (m_music % 90 == 0)
                {
                    Utils.SubsystemAudio.PlaySound("Audio/SteamEngine", 1f, 0f, new Vector3(Coordinates), 4f, true);
                }
                m_music++;
                if (SmeltingProgress >= 1.0)
                {
                    for (int i = 0; i < m_furnaceSize; i++)
                    {
                        if (m_slots[i].Count > 0)
                        {
                            m_slots[i].Count--;
                        }
                    }
                    m_slots[ResultSlotIndex].Value = 90;
                    m_slots[ResultSlotIndex].Count++;
                    m_smeltingRecipe       = null;
                    SmeltingProgress       = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
            if (m_componentBlockEntity != null)
            {
                TerrainChunk chunk = Utils.Terrain.GetChunkAtCell(Coordinates.X, Coordinates.Z);
                if (chunk != null && chunk.State == TerrainChunkState.Valid)
                {
                    int cellValue = chunk.GetCellValueFast(Coordinates.X & 15, Coordinates.Y, Coordinates.Z & 15);
                    Utils.SubsystemTerrain.ChangeCell(Coordinates.X, Coordinates.Y, Coordinates.Z, Terrain.ReplaceData(cellValue, FurnaceNBlock.SetHeatLevel(Terrain.ExtractData(cellValue), HeatLevel > 0f ? 1 : 0)));
                }
            }
        }
Beispiel #9
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (m_componentPlayer.ComponentHealth.Health > 0f && camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) && !m_componentPlayer.ComponentInput.IsControlledByVr)
     {
         Viewport viewport  = Display.Viewport;
         Viewport viewport2 = viewport;
         viewport2.MaxDepth *= 0.1f;
         Display.Viewport    = viewport2;
         try
         {
             Matrix identity = Matrix.Identity;
             if (m_swapAnimationTime > 0f)
             {
                 float num = MathUtils.Pow(MathUtils.Sin(m_swapAnimationTime * (float)Math.PI), 3f);
                 identity *= Matrix.CreateTranslation(0f, -0.8f * num, 0.2f * num);
             }
             if (m_pokeAnimationTime > 0f)
             {
                 float num2 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                 if (m_value != 0)
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.5f * num2, 0.1f * num2, 0f * num2);
                 }
                 else
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.1f * num2, 0.2f * num2, -0.05f * num2);
                 }
             }
             if (m_componentRider.Mount != null)
             {
                 ComponentCreatureModel componentCreatureModel = m_componentRider.Mount.Entity.FindComponent <ComponentCreatureModel>();
                 if (componentCreatureModel != null)
                 {
                     float   num3     = componentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f + 0.5f;
                     Vector3 position = default(Vector3);
                     position.Y = 0.02f * MathUtils.Sin(num3);
                     position.Z = 0.02f * MathUtils.Sin(num3);
                     identity  *= Matrix.CreateRotationX(0.05f * MathUtils.Sin(num3 * 1f)) * Matrix.CreateTranslation(position);
                 }
             }
             else
             {
                 float   num4      = m_componentPlayer.ComponentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f;
                 Vector3 position2 = default(Vector3);
                 position2.X = 0.03f * MathUtils.Sin(num4 * 1f);
                 position2.Y = 0.02f * MathUtils.Sin(num4 * 2f);
                 position2.Z = 0.02f * MathUtils.Sin(num4 * 1f);
                 identity   *= Matrix.CreateRotationZ(1f * position2.X) * Matrix.CreateTranslation(position2);
             }
             Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
             int     x           = Terrain.ToCell(eyePosition.X);
             int     num5        = Terrain.ToCell(eyePosition.Y);
             int     z           = Terrain.ToCell(eyePosition.Z);
             Matrix  m           = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
             m.Translation = m_componentPlayer.ComponentCreatureModel.EyePosition;
             if (m_value != 0)
             {
                 if (num5 >= 0 && num5 <= 255)
                 {
                     TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                     if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                     {
                         m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z);
                     }
                 }
                 int     num6      = Terrain.ExtractContents(m_value);
                 Block   block     = BlocksManager.Blocks[num6];
                 Vector3 vector    = block.FirstPersonRotation * ((float)Math.PI / 180f) + m_itemRotation;
                 Vector3 position3 = block.FirstPersonOffset + m_itemOffset;
                 position3 += m_itemOffset;
                 Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * identity * Matrix.CreateTranslation(position3) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m;
                 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                 m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                 m_drawBlockEnvironmentData.Light            = m_itemLight;
                 m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                 m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5);
                 block.DrawBlock(m_primitivesRenderer, m_value, Color.White, block.FirstPersonScale, ref matrix, m_drawBlockEnvironmentData);
                 m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
             }
             else
             {
                 if (Time.FrameStartTime >= m_nextHandLightTime)
                 {
                     float?num7 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                     if (num7.HasValue)
                     {
                         m_nextHandLightTime = Time.FrameStartTime + 0.1;
                         m_handLight         = num7.Value;
                     }
                 }
                 Vector3 position4 = new Vector3(0.25f, -0.3f, -0.05f);
                 Matrix  matrix2   = Matrix.CreateScale(0.01f) * Matrix.CreateRotationX(0.8f) * Matrix.CreateRotationY(0.4f) * identity * Matrix.CreateTranslation(position4) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m * camera.ViewMatrix;
                 Display.DepthStencilState      = DepthStencilState.Default;
                 Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                 m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                 m_shader.SamplerState          = SamplerState.PointClamp;
                 m_shader.MaterialColor         = Vector4.One;
                 m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                 m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                 m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                 m_shader.LightDirection1       = Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                 m_shader.LightDirection2       = Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                 m_shader.Transforms.World[0]   = matrix2;
                 m_shader.Transforms.View       = Matrix.Identity;
                 m_shader.Transforms.Projection = camera.ProjectionMatrix;
                 foreach (ModelMesh mesh in m_handModel.Meshes)
                 {
                     foreach (ModelMeshPart meshPart in mesh.MeshParts)
                     {
                         Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                     }
                 }
             }
         }
         finally
         {
             Display.Viewport = viewport;
         }
     }
 }
Beispiel #10
0
 public override int SetDamage(int value, int damage)
 {
     return(Terrain.ReplaceData(value, (Terrain.ExtractData(value) & -65281) | (MathUtils.Clamp(damage, 0, 255) << 8)));
 }
Beispiel #11
0
 public override int GetDamage(int value)
 {
     return((Terrain.ExtractData(value) >> 8) & 0xFF);
 }
Beispiel #12
0
 public override bool IsSwapAnimationNeeded(int oldValue, int newValue)
 {
     return(Terrain.ExtractContents(oldValue) != Index
                         ? true
                         : SetHammerState(Terrain.ExtractData(newValue), true) != SetHammerState(Terrain.ExtractData(oldValue), true));
 }
Beispiel #13
0
 public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
 {
     BlocksManager.DrawMeshBlock(primitivesRenderer, GetHammerState(Terrain.ExtractData(value)) ? m_standaloneBlockMeshLoaded : m_standaloneBlockMeshUnloaded, color, 2f * size, ref matrix, environmentData);
 }
Beispiel #14
0
        public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
        {
            int data = Terrain.ExtractData(value);

            return(LanguageControl.GetBlock(fName + ":" + data, "DisplayName"));
        }
Beispiel #15
0
        public bool CheckIfBodyTouchesFire()
        {
            BoundingBox boundingBox = ComponentBody.BoundingBox;

            boundingBox.Min -= new Vector3(0.25f);
            boundingBox.Max += new Vector3(0.25f);
            int num  = Terrain.ToCell(boundingBox.Min.X);
            int num2 = Terrain.ToCell(boundingBox.Min.Y);
            int num3 = Terrain.ToCell(boundingBox.Min.Z);
            int num4 = Terrain.ToCell(boundingBox.Max.X);
            int num5 = Terrain.ToCell(boundingBox.Max.Y);
            int num6 = Terrain.ToCell(boundingBox.Max.Z);

            for (int i = num; i <= num4; i++)
            {
                for (int j = num2; j <= num5; j++)
                {
                    for (int k = num3; k <= num6; k++)
                    {
                        int cellValue = m_subsystemTerrain.Terrain.GetCellValue(i, j, k);
                        int num7      = Terrain.ExtractContents(cellValue);
                        int num8      = Terrain.ExtractData(cellValue);
                        switch (num7)
                        {
                        case 104:
                            if (num8 == 0)
                            {
                                BoundingBox box2 = new BoundingBox(new Vector3(i, j, k), new Vector3(i + 1, j + 1, k + 1));
                                if (boundingBox.Intersection(box2))
                                {
                                    return(true);
                                }
                                break;
                            }
                            if ((num8 & 1) != 0)
                            {
                                BoundingBox box3 = new BoundingBox(new Vector3(i, j, (float)k + 0.5f), new Vector3(i + 1, j + 1, k + 1));
                                if (boundingBox.Intersection(box3))
                                {
                                    return(true);
                                }
                            }
                            if ((num8 & 2) != 0)
                            {
                                BoundingBox box4 = new BoundingBox(new Vector3((float)i + 0.5f, j, k), new Vector3(i + 1, j + 1, k + 1));
                                if (boundingBox.Intersection(box4))
                                {
                                    return(true);
                                }
                            }
                            if ((num8 & 4) != 0)
                            {
                                BoundingBox box5 = new BoundingBox(new Vector3(i, j, k), new Vector3(i + 1, j + 1, (float)k + 0.5f));
                                if (boundingBox.Intersection(box5))
                                {
                                    return(true);
                                }
                            }
                            if ((num8 & 8) != 0)
                            {
                                BoundingBox box6 = new BoundingBox(new Vector3(i, j, k), new Vector3((float)i + 0.5f, j + 1, k + 1));
                                if (boundingBox.Intersection(box6))
                                {
                                    return(true);
                                }
                            }
                            break;

                        case 209:
                            if (num8 > 0)
                            {
                                BoundingBox box = new BoundingBox(new Vector3(i, j, k) + new Vector3(0.2f), new Vector3(i + 1, j + 1, k + 1) - new Vector3(0.2f));
                                if (boundingBox.Intersection(box))
                                {
                                    return(true);
                                }
                            }
                            break;
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #16
0
 public FileMap(Terrain terrain, List<string> file)
     : base(terrain)
 {
     ParseFile(file);
 }
 public void UpdateRenderTargets()
 {
     if (m_skinTexture == null || m_componentPlayer.PlayerData.CharacterSkinName != m_skinTextureName)
     {
         m_skinTexture     = CharacterSkinsManager.LoadTexture(m_componentPlayer.PlayerData.CharacterSkinName);
         m_skinTextureName = m_componentPlayer.PlayerData.CharacterSkinName;
         Utilities.Dispose(ref m_innerClothedTexture);
         Utilities.Dispose(ref m_outerClothedTexture);
     }
     if (m_innerClothedTexture == null || m_innerClothedTexture.Width != m_skinTexture.Width || m_innerClothedTexture.Height != m_skinTexture.Height)
     {
         m_innerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentHumanModel.TextureOverride = m_innerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (m_outerClothedTexture == null || m_outerClothedTexture.Width != m_skinTexture.Width || m_outerClothedTexture.Height != m_skinTexture.Height)
     {
         m_outerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentOuterClothingModel.TextureOverride = m_outerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (DrawClothedTexture && !m_clothedTexturesValid)
     {
         m_clothedTexturesValid = true;
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_innerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             int             num             = 0;
             TexturedBatch2D texturedBatch2D = m_primitivesRenderer.TexturedBatch(m_skinTexture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
             texturedBatch2D.QueueQuad(Vector2.Zero, new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             ClothingSlot[] innerSlotsOrder = m_innerSlotsOrder;
             foreach (ClothingSlot slot in innerSlotsOrder)
             {
                 foreach (int clothe in GetClothes(slot))
                 {
                     int          data         = Terrain.ExtractData(clothe);
                     ClothingData clothingData = ClothingBlock.GetClothingData(data);
                     Color        fabricColor  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (!clothingData.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
             Display.RenderTarget = m_outerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             num             = 0;
             innerSlotsOrder = m_outerSlotsOrder;
             foreach (ClothingSlot slot2 in innerSlotsOrder)
             {
                 foreach (int clothe2 in GetClothes(slot2))
                 {
                     int          data2         = Terrain.ExtractData(clothe2);
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(data2);
                     Color        fabricColor2  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data2));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData2.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (clothingData2.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_outerClothedTexture.Width, m_outerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor2);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
     }
 }
Beispiel #18
0
        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            TerrainGeometrySubset        subsetAlphaTest = geometry.SubsetAlphaTest;
            DynamicArray <TerrainVertex> vertices        = subsetAlphaTest.Vertices;
            DynamicArray <ushort>        indices         = subsetAlphaTest.Indices;
            int   count        = vertices.Count;
            int   data         = Terrain.ExtractData(value);
            int   num          = Terrain.ExtractLight(value);
            int   mountingFace = GetMountingFace(data);
            float s            = LightingManager.LightIntensityByLightValueAndFace[num + 16 * mountingFace];
            Color color        = Color.White * s;

            switch (mountingFace)
            {
            case 2:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z + 1, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z + 1, color, DefaultTextureSlot, 3, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 2));
                break;

            case 3:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 2));
                break;

            case 0:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y, z, color, DefaultTextureSlot, 1, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x + 1, y + 1, z, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                break;

            case 1:
                vertices.Count += 4;
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z, color, DefaultTextureSlot, 0, ref vertices.Array[count]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z, color, DefaultTextureSlot, 3, ref vertices.Array[count + 1]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y + 1, z + 1, color, DefaultTextureSlot, 2, ref vertices.Array[count + 2]);
                BlockGeometryGenerator.SetupLitCornerVertex(x, y, z + 1, color, DefaultTextureSlot, 1, ref vertices.Array[count + 3]);
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 1));
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)(count + 3));
                indices.Add((ushort)count);
                indices.Add((ushort)(count + 2));
                break;
            }
        }
Beispiel #19
0
        public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size,
                                         ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData)
        {
            environmentData = environmentData ?? m_defaultEnvironmentData;
            var texture = environmentData.SubsystemTerrain != null
                                ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture
                                : BlocksTexturesManager.DefaultBlocksTexture;
            var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null,
                                                                   RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
            var s = LightingManager.LightIntensityByLightValue[environmentData.Light];

            color    = Color.MultiplyColorOnly(color, s);
            topColor = Color.MultiplyColorOnly(topColor, s);
            var translation = matrix.Translation;
            var vector3_1   = matrix.Right * size.X;
            var vector3_2   = matrix.Up * size.Y;
            var vector3_3   = matrix.Forward * size.Z;
            var result1     = translation + 0.5f * (-vector3_1 - vector3_2 - vector3_3);
            var result2     = translation + 0.5f * (vector3_1 - vector3_2 - vector3_3);
            var result3     = translation + 0.5f * (-vector3_1 + vector3_2 - vector3_3);
            var result4     = translation + 0.5f * (vector3_1 + vector3_2 - vector3_3);
            var result5     = translation + 0.5f * (-vector3_1 - vector3_2 + vector3_3);
            var result6     = translation + 0.5f * (vector3_1 - vector3_2 + vector3_3);
            var result7     = translation + 0.5f * (-vector3_1 + vector3_2 + vector3_3);
            var result8     = translation + 0.5f * (vector3_1 + vector3_2 + vector3_3);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                var m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref result1, ref m, out result1);
                Vector3.Transform(ref result2, ref m, out result2);
                Vector3.Transform(ref result3, ref m, out result3);
                Vector3.Transform(ref result4, ref m, out result4);
                Vector3.Transform(ref result5, ref m, out result5);
                Vector3.Transform(ref result6, ref m, out result6);
                Vector3.Transform(ref result7, ref m, out result7);
                Vector3.Transform(ref result8, ref m, out result8);
            }

            var block         = Blocks[Terrain.ExtractContents(value)];
            var slotTexCoord1 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)];
            var color1        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward));

            texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(slotTexCoord1.X, slotTexCoord1.W),
                                      new Vector2(slotTexCoord1.X, slotTexCoord1.Y), new Vector2(slotTexCoord1.Z, slotTexCoord1.Y),
                                      new Vector2(slotTexCoord1.Z, slotTexCoord1.W), color1);
            var slotTexCoord2 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)];
            var color2        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward));

            texturedBatch3D.QueueQuad(result5, result6, result8, result7, new Vector2(slotTexCoord2.Z, slotTexCoord2.W),
                                      new Vector2(slotTexCoord2.X, slotTexCoord2.W), new Vector2(slotTexCoord2.X, slotTexCoord2.Y),
                                      new Vector2(slotTexCoord2.Z, slotTexCoord2.Y), color2);
            var slotTexCoord3 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)];
            var color3        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up));

            texturedBatch3D.QueueQuad(result1, result2, result6, result5, new Vector2(slotTexCoord3.X, slotTexCoord3.Y),
                                      new Vector2(slotTexCoord3.Z, slotTexCoord3.Y), new Vector2(slotTexCoord3.Z, slotTexCoord3.W),
                                      new Vector2(slotTexCoord3.X, slotTexCoord3.W), color3);
            var slotTexCoord4 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)];
            var color4        = Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up));

            texturedBatch3D.QueueQuad(result3, result7, result8, result4, new Vector2(slotTexCoord4.X, slotTexCoord4.W),
                                      new Vector2(slotTexCoord4.X, slotTexCoord4.Y), new Vector2(slotTexCoord4.Z, slotTexCoord4.Y),
                                      new Vector2(slotTexCoord4.Z, slotTexCoord4.W), color4);
            var slotTexCoord5 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)];
            var color5        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right));

            texturedBatch3D.QueueQuad(result1, result5, result7, result3, new Vector2(slotTexCoord5.Z, slotTexCoord5.W),
                                      new Vector2(slotTexCoord5.X, slotTexCoord5.W), new Vector2(slotTexCoord5.X, slotTexCoord5.Y),
                                      new Vector2(slotTexCoord5.Z, slotTexCoord5.Y), color5);
            var slotTexCoord6 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)];
            var color6        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right));

            texturedBatch3D.QueueQuad(result2, result4, result8, result6, new Vector2(slotTexCoord6.X, slotTexCoord6.W),
                                      new Vector2(slotTexCoord6.X, slotTexCoord6.Y), new Vector2(slotTexCoord6.Z, slotTexCoord6.Y),
                                      new Vector2(slotTexCoord6.Z, slotTexCoord6.W), color6);
        }
        public override bool Simulate(float dt)
        {
            dt = MathUtils.Clamp(dt, 0f, 0.1f);
            float num  = MathUtils.Pow(0.04f, dt);
            bool  flag = false;

            for (int i = 0; i < base.Particles.Length; i++)
            {
                Particle particle = base.Particles[i];
                if (!particle.IsActive)
                {
                    continue;
                }
                flag = true;
                particle.TimeToLive -= dt;
                if (particle.TimeToLive > 0f)
                {
                    Vector3 position = particle.Position;
                    Vector3 vector   = position + particle.Velocity * dt;
                    TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                    if (terrainRaycastResult.HasValue)
                    {
                        Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
                        vector = position;
                        if (plane.Normal.X != 0f)
                        {
                            particle.Velocity *= new Vector3(-0.1f, 0.1f, 0.1f);
                        }
                        if (plane.Normal.Y != 0f)
                        {
                            particle.Velocity *= new Vector3(0.1f, -0.1f, 0.1f);
                        }
                        if (plane.Normal.Z != 0f)
                        {
                            particle.Velocity *= new Vector3(0.1f, 0.1f, -0.1f);
                        }
                    }
                    particle.Position    = vector;
                    particle.Velocity.Y += -10f * dt;
                    particle.Velocity   *= num;
                    particle.Color      *= MathUtils.Saturate(particle.TimeToLive);
                    particle.TextureSlot = (int)(8.99f * MathUtils.Saturate(2f - particle.TimeToLive));
                }
                else
                {
                    particle.IsActive = false;
                }
            }
            return(!flag);
        }
        public void Update(float dt)
        {
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;

            foreach (Projectile projectile in m_projectiles)
            {
                if (projectile.ToRemove)
                {
                    m_projectilesToRemove.Add(projectile);
                }
                else
                {
                    Block block = BlocksManager.Blocks[Terrain.ExtractContents(projectile.Value)];
                    if (totalElapsedGameTime - projectile.CreationTime > 40.0)
                    {
                        projectile.ToRemove = true;
                    }
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Z));
                    if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4)
                    {
                        projectile.NoChunk = true;
                        if (projectile.TrailParticleSystem != null)
                        {
                            projectile.TrailParticleSystem.IsStopped = true;
                        }
                    }
                    else
                    {
                        projectile.NoChunk = false;
                        Vector3              position             = projectile.Position;
                        Vector3              vector               = position + projectile.Velocity * dt;
                        Vector3              v                    = block.ProjectileTipOffset * Vector3.Normalize(projectile.Velocity);
                        BodyRaycastResult?   bodyRaycastResult    = m_subsystemBodies.Raycast(position + v, vector + v, 0.2f, (ComponentBody body, float distance) => true);
                        TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position + v, vector + v, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                        bool flag = block.DisintegratesOnHit;
                        if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue)
                        {
                            CellFace?                cellFace       = terrainRaycastResult.HasValue ? new CellFace?(terrainRaycastResult.Value.CellFace) : null;
                            ComponentBody            componentBody  = bodyRaycastResult.HasValue ? bodyRaycastResult.Value.ComponentBody : null;
                            SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(projectile.Value));
                            for (int i = 0; i < blockBehaviors.Length; i++)
                            {
                                flag |= blockBehaviors[i].OnHitAsProjectile(cellFace, componentBody, projectile);
                            }
                            projectile.ToRemove |= flag;
                        }
                        Vector3?vector2 = null;
                        if (bodyRaycastResult.HasValue && (!terrainRaycastResult.HasValue || bodyRaycastResult.Value.Distance < terrainRaycastResult.Value.Distance))
                        {
                            if (projectile.Velocity.Length() > 10f)
                            {
                                ComponentMiner.AttackBody(bodyRaycastResult.Value.ComponentBody, projectile.Owner, bodyRaycastResult.Value.HitPoint(), Vector3.Normalize(projectile.Velocity), block.GetProjectilePower(projectile.Value), isMeleeAttack: false);
                                if (projectile.Owner != null && projectile.Owner.PlayerStats != null)
                                {
                                    projectile.Owner.PlayerStats.RangedHits++;
                                }
                            }
                            if (projectile.IsIncendiary)
                            {
                                bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentOnFire>()?.SetOnFire(projectile?.Owner, m_random.Float(6f, 8f));
                            }
                            vector = position;
                            projectile.Velocity        *= -0.05f;
                            projectile.Velocity        += m_random.Vector3(0.33f * projectile.Velocity.Length());
                            projectile.AngularVelocity *= -0.05f;
                        }
                        else if (terrainRaycastResult.HasValue)
                        {
                            CellFace cellFace2 = terrainRaycastResult.Value.CellFace;
                            int      cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                            int      num       = Terrain.ExtractContents(cellValue);
                            Block    block2    = BlocksManager.Blocks[num];
                            float    num2      = projectile.Velocity.Length();
                            SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                            for (int j = 0; j < blockBehaviors2.Length; j++)
                            {
                                blockBehaviors2[j].OnHitByProjectile(cellFace2, projectile);
                            }
                            if (num2 > 10f && m_random.Float(0f, 1f) > block2.ProjectileResilience)
                            {
                                m_subsystemTerrain.DestroyCell(0, cellFace2.X, cellFace2.Y, cellFace2.Z, 0, noDrop: true, noParticleSystem: false);
                                m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f);
                            }
                            if (projectile.IsIncendiary)
                            {
                                m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, 1f);
                                Vector3 vector3 = projectile.Position - 0.75f * Vector3.Normalize(projectile.Velocity);
                                for (int k = 0; k < 8; k++)
                                {
                                    Vector3 v2 = (k == 0) ? Vector3.Normalize(projectile.Velocity) : m_random.Vector3(1.5f);
                                    TerrainRaycastResult?terrainRaycastResult2 = m_subsystemTerrain.Raycast(vector3, vector3 + v2, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => true);
                                    if (terrainRaycastResult2.HasValue)
                                    {
                                        m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult2.Value.CellFace.X, terrainRaycastResult2.Value.CellFace.Y, terrainRaycastResult2.Value.CellFace.Z, 1f);
                                    }
                                }
                            }
                            if (num2 > 5f)
                            {
                                m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f);
                            }
                            if (block.IsStickable && num2 > 10f && m_random.Bool(block2.ProjectileStickProbability))
                            {
                                Vector3 v3 = Vector3.Normalize(projectile.Velocity);
                                float   s  = MathUtils.Lerp(0.1f, 0.2f, MathUtils.Saturate((num2 - 15f) / 20f));
                                vector2 = position + terrainRaycastResult.Value.Distance * Vector3.Normalize(projectile.Velocity) + v3 * s;
                            }
                            else
                            {
                                Plane plane = cellFace2.CalculatePlane();
                                vector = position;
                                if (plane.Normal.X != 0f)
                                {
                                    projectile.Velocity *= new Vector3(-0.3f, 0.3f, 0.3f);
                                }
                                if (plane.Normal.Y != 0f)
                                {
                                    projectile.Velocity *= new Vector3(0.3f, -0.3f, 0.3f);
                                }
                                if (plane.Normal.Z != 0f)
                                {
                                    projectile.Velocity *= new Vector3(0.3f, 0.3f, -0.3f);
                                }
                                float num3 = projectile.Velocity.Length();
                                projectile.Velocity         = num3 * Vector3.Normalize(projectile.Velocity + m_random.Vector3(num3 / 6f, num3 / 3f));
                                projectile.AngularVelocity *= -0.3f;
                            }
                            MakeProjectileNoise(projectile);
                        }
                        if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue)
                        {
                            if (flag)
                            {
                                m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, projectile.Position, projectile.Value, 1f));
                            }
                            else if (!projectile.ToRemove && (vector2.HasValue || projectile.Velocity.Length() < 1f))
                            {
                                if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.TurnIntoPickable)
                                {
                                    int num4 = BlocksManager.DamageItem(projectile.Value, 1);
                                    if (num4 != 0)
                                    {
                                        if (vector2.HasValue)
                                        {
                                            CalculateVelocityAlignMatrix(block, vector2.Value, projectile.Velocity, out Matrix matrix);
                                            m_subsystemPickables.AddPickable(num4, 1, projectile.Position, Vector3.Zero, matrix);
                                        }
                                        else
                                        {
                                            m_subsystemPickables.AddPickable(num4, 1, position, Vector3.Zero, null);
                                        }
                                    }
                                    projectile.ToRemove = true;
                                }
                                else if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.Disappear)
                                {
                                    projectile.ToRemove = true;
                                }
                            }
                        }
                        float num5 = projectile.IsInWater ? MathUtils.Pow(0.001f, dt) : MathUtils.Pow(block.ProjectileDamping, dt);
                        projectile.Velocity.Y      += -10f * dt;
                        projectile.Velocity        *= num5;
                        projectile.AngularVelocity *= num5;
                        projectile.Position         = vector;
                        projectile.Rotation        += projectile.AngularVelocity * dt;
                        if (projectile.TrailParticleSystem != null)
                        {
                            if (!m_subsystemParticles.ContainsParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem))
                            {
                                m_subsystemParticles.AddParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem);
                            }
                            Vector3 v4 = (projectile.TrailOffset != Vector3.Zero) ? Vector3.TransformNormal(projectile.TrailOffset, Matrix.CreateFromAxisAngle(Vector3.Normalize(projectile.Rotation), projectile.Rotation.Length())) : Vector3.Zero;
                            projectile.TrailParticleSystem.Position = projectile.Position + v4;
                            if (projectile.IsInWater)
                            {
                                projectile.TrailParticleSystem.IsStopped = true;
                            }
                        }
                        bool flag2 = IsWater(projectile.Position);
                        if (projectile.IsInWater != flag2)
                        {
                            if (flag2)
                            {
                                float num6 = new Vector2(projectile.Velocity.X + projectile.Velocity.Z).Length();
                                if (num6 > 6f && num6 > 4f * MathUtils.Abs(projectile.Velocity.Y))
                                {
                                    projectile.Velocity   *= 0.5f;
                                    projectile.Velocity.Y *= -1f;
                                    flag2 = false;
                                }
                                else
                                {
                                    projectile.Velocity *= 0.2f;
                                }
                                float?surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z));
                                if (surfaceHeight.HasValue)
                                {
                                    m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, new Vector3(projectile.Position.X, surfaceHeight.Value, projectile.Position.Z), large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 6f, autoDelay: true);
                                    MakeProjectileNoise(projectile);
                                }
                            }
                            projectile.IsInWater = flag2;
                        }
                        if (IsMagma(projectile.Position))
                        {
                            m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, projectile.Position, large: false));
                            m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true);
                            projectile.ToRemove = true;
                            m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value);
                        }
                        if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(projectile.GetHashCode() % 100) / 100.0) && (m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f), Terrain.ToCell(projectile.Position.Z)) || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f) - 1, Terrain.ToCell(projectile.Position.Z))))
                        {
                            m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true);
                            projectile.ToRemove = true;
                            m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value);
                        }
                    }
                }
            }
            foreach (Projectile item in m_projectilesToRemove)
            {
                if (item.TrailParticleSystem != null)
                {
                    item.TrailParticleSystem.IsStopped = true;
                }
                m_projectiles.Remove(item);
                if (this.ProjectileRemoved != null)
                {
                    this.ProjectileRemoved(item);
                }
            }
            m_projectilesToRemove.Clear();
        }
Beispiel #22
0
 public RandomMap(int x, int y, Terrain terrain, Random rnd)
     : base(terrain)
 {
     GenerateRandomMap(x, y, rnd);
 }
        public Projectile FireProjectile(int value, Vector3 position, Vector3 velocity, Vector3 angularVelocity, ComponentCreature owner)
        {
            int     num    = Terrain.ExtractContents(value);
            Block   block  = BlocksManager.Blocks[num];
            Vector3 v      = Vector3.Normalize(velocity);
            Vector3 vector = position;

            if (owner != null)
            {
                Ray3        ray         = new Ray3(position + v * 5f, -v);
                BoundingBox boundingBox = owner.ComponentBody.BoundingBox;
                boundingBox.Min -= new Vector3(0.4f);
                boundingBox.Max += new Vector3(0.4f);
                float?num2 = ray.Intersection(boundingBox);
                if (num2.HasValue)
                {
                    if (num2.Value == 0f)
                    {
                        return(null);
                    }
                    vector = position + v * (5f - num2.Value + 0.1f);
                }
            }
            Vector3 end = vector + v * block.ProjectileTipOffset;

            if (!m_subsystemTerrain.Raycast(position, end, useInteractionBoxes: false, skipAirBlocks: true, (int testValue, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(testValue)].IsCollidable).HasValue)
            {
                Projectile projectile = AddProjectile(value, vector, velocity, angularVelocity, owner);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                for (int i = 0; i < blockBehaviors.Length; i++)
                {
                    blockBehaviors[i].OnFiredAsProjectile(projectile);
                }
                return(projectile);
            }
            return(null);
        }
Beispiel #24
0
        public void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner)
        {
            FurnitureDesign          design           = null;
            FurnitureDesign          furnitureDesign  = null;
            Dictionary <Point3, int> valuesDictionary = new Dictionary <Point3, int>();
            Point3 point      = start.Point;
            Point3 point2     = start.Point;
            int    startValue = base.SubsystemTerrain.Terrain.GetCellValue(start.Point.X, start.Point.Y, start.Point.Z);
            int    num        = Terrain.ExtractContents(startValue);

            if (BlocksManager.Blocks[num] is FurnitureBlock)
            {
                int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(startValue));
                furnitureDesign = GetDesign(designIndex);
                if (furnitureDesign == null)
                {
                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false);
                    return;
                }
                design = furnitureDesign.Clone();
                design.LinkedDesign    = null;
                design.InteractionMode = FurnitureInteractionMode.None;
                valuesDictionary.Add(start.Point, startValue);
            }
            else
            {
                Stack <Point3> val = new Stack <Point3>();
                val.Push(start.Point);
                while (val.Count > 0)
                {
                    Point3 key = val.Pop();
                    if (valuesDictionary.ContainsKey(key))
                    {
                        continue;
                    }
                    int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z);
                    if (IsValueDisallowed(cellValue))
                    {
                        componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false);
                        return;
                    }
                    if (IsValueAllowed(cellValue))
                    {
                        if (key.X < point.X)
                        {
                            point.X = key.X;
                        }
                        if (key.Y < point.Y)
                        {
                            point.Y = key.Y;
                        }
                        if (key.Z < point.Z)
                        {
                            point.Z = key.Z;
                        }
                        if (key.X > point2.X)
                        {
                            point2.X = key.X;
                        }
                        if (key.Y > point2.Y)
                        {
                            point2.Y = key.Y;
                        }
                        if (key.Z > point2.Z)
                        {
                            point2.Z = key.Z;
                        }
                        if (MathUtils.Abs(point.X - point2.X) >= 16 || MathUtils.Abs(point.Y - point2.Y) >= 16 || MathUtils.Abs(point.Z - point2.Z) >= 16)
                        {
                            componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Furniture design is too large", Color.White, blinking: true, playNotificationSound: false);
                            return;
                        }
                        valuesDictionary[key] = cellValue;
                        val.Push(new Point3(key.X - 1, key.Y, key.Z));
                        val.Push(new Point3(key.X + 1, key.Y, key.Z));
                        val.Push(new Point3(key.X, key.Y - 1, key.Z));
                        val.Push(new Point3(key.X, key.Y + 1, key.Z));
                        val.Push(new Point3(key.X, key.Y, key.Z - 1));
                        val.Push(new Point3(key.X, key.Y, key.Z + 1));
                    }
                }
                if (valuesDictionary.Count == 0)
                {
                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No suitable blocks found", Color.White, blinking: true, playNotificationSound: false);
                    return;
                }
                design = new FurnitureDesign(base.SubsystemTerrain);
                Point3 point3 = point2 - point;
                int    num2   = MathUtils.Max(MathUtils.Max(point3.X, point3.Y, point3.Z) + 1, 2);
                int[]  array  = new int[num2 * num2 * num2];
                foreach (KeyValuePair <Point3, int> item in valuesDictionary)
                {
                    Point3 point4 = item.Key - point;
                    array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value;
                }
                design.SetValues(num2, array);
                int steps = (start.Face > 3) ? CellFace.Vector3ToFace(direction, 3) : CellFace.OppositeFace(start.Face);
                design.Rotate(1, steps);
                Point3 location = design.Box.Location;
                Point3 point5   = new Point3(design.Resolution) - (design.Box.Location + design.Box.Size);
                Point3 delta    = new Point3((point5.X - location.X) / 2, -location.Y, (point5.Z - location.Z) / 2);
                design.Shift(delta);
            }
            BuildFurnitureDialog dialog = new BuildFurnitureDialog(design, furnitureDesign, delegate(bool result)
            {
                if (result)
                {
                    design = TryAddDesign(design);
                    if (design == null)
                    {
                        componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Too many different furniture designs", Color.White, blinking: true, playNotificationSound: false);
                    }
                    else
                    {
                        if (m_subsystemGameInfo.WorldSettings.GameMode != 0)
                        {
                            foreach (KeyValuePair <Point3, int> item2 in valuesDictionary)
                            {
                                base.SubsystemTerrain.DestroyCell(0, item2.Key.X, item2.Key.Y, item2.Key.Z, 0, noDrop: true, noParticleSystem: true);
                            }
                        }
                        int value        = Terrain.MakeBlockValue(227, 0, FurnitureBlock.SetDesignIndex(0, design.Index, design.ShadowStrengthFactor, design.IsLightEmitter));
                        int num3         = MathUtils.Clamp(design.Resolution, 4, 8);
                        Matrix matrix    = componentMiner.ComponentCreature.ComponentBody.Matrix;
                        Vector3 position = matrix.Translation + 1f * matrix.Forward + 1f * Vector3.UnitY;
                        m_subsystemPickables.AddPickable(value, num3, position, null, null);
                        componentMiner.DamageActiveTool(1);
                        componentMiner.Poke(forceRestart: false);
                        for (int i = 0; i < 3; i++)
                        {
                            Time.QueueTimeDelayedExecution(Time.FrameStartTime + (double)((float)i * 0.25f), delegate
                            {
                                m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f);
                            });
                        }
                        if (componentMiner.ComponentCreature.PlayerStats != null)
                        {
                            componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3;
                        }
                    }
                }
            });

            if (componentMiner.ComponentPlayer != null)
            {
                DialogsManager.ShowDialog(componentMiner.ComponentPlayer.GuiWidget, dialog);
            }
        }
Beispiel #25
0
        public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state)
        {
            IInventory inventory = componentMiner.Inventory;

            if (inventory != null)
            {
                int activeSlotIndex = inventory.ActiveSlotIndex;
                if (activeSlotIndex >= 0)
                {
                    int slotValue = inventory.GetSlotValue(activeSlotIndex);
                    int slotCount = inventory.GetSlotCount(activeSlotIndex);
                    int num       = Terrain.ExtractContents(slotValue);
                    int data      = Terrain.ExtractData(slotValue);
                    if (num == 191 && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num2 = (float)(m_subsystemTime.GameTime - value);
                        float   num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.02f : 0.04f) + 0.25f * MathUtils.Saturate((num2 - 2.1f) / 5f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num2 >= 9f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.1f, 0.15f, 0f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(0f, -0.7f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.2f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(0f, 0f, 0f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(0f, -0.2f, 0f);
                            if (m_subsystemTime.PeriodicGameTimeEvent(0.10000000149011612, 0.0))
                            {
                                int draw2 = MathUtils.Min(BowBlock.GetDraw(data) + 1, 15);
                                inventory.RemoveSlotItems(activeSlotIndex, 1);
                                inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, draw2)), 1);
                            }
                            break;
                        }

                        case AimState.Cancelled:
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)), 1);
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            int draw = BowBlock.GetDraw(data);
                            ArrowBlock.ArrowType?arrowType = BowBlock.GetArrowType(data);
                            if (arrowType.HasValue)
                            {
                                Vector3 vector  = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                Vector3 vector2 = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                                float   num4    = MathUtils.Lerp(0f, 28f, MathUtils.Pow((float)draw / 15f, 0.75f));
                                if (componentMiner.ComponentPlayer != null)
                                {
                                    num4 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f;
                                }
                                Vector3 vector3 = Vector3.Zero;
                                if (arrowType == ArrowBlock.ArrowType.WoodenArrow)
                                {
                                    vector3 = new Vector3(0.025f, 0.025f, 0.025f);
                                }
                                if (arrowType == ArrowBlock.ArrowType.StoneArrow)
                                {
                                    vector3 = new Vector3(0.01f, 0.01f, 0.01f);
                                }
                                int     value2  = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
                                Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector2, Vector3.UnitY));
                                Vector3 v2      = Vector3.Normalize(Vector3.Cross(vector2, vector4));
                                Vector3 v3      = m_random.Float(0f - vector3.X, vector3.X) * vector4 + m_random.Float(0f - vector3.Y, vector3.Y) * v2 + m_random.Float(0f - vector3.Z, vector3.Z) * vector2;
                                if (m_subsystemProjectiles.FireProjectile(value2, vector, (vector2 + v3) * num4, Vector3.Zero, componentMiner.ComponentCreature) != null)
                                {
                                    data = BowBlock.SetArrowType(data, null);
                                    m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), vector, 3f, autoDelay: true);
                                }
                            }
                            else
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load an arrow first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            int value3 = Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0));
                            inventory.AddSlotItems(activeSlotIndex, value3, 1);
                            int damageCount = 0;
                            if (draw >= 15)
                            {
                                damageCount = 2;
                            }
                            else if (draw >= 4)
                            {
                                damageCount = 1;
                            }
                            componentMiner.DamageActiveTool(damageCount);
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #26
0
        public static bool IsValueAllowed(int value)
        {
            switch (Terrain.ExtractContents(value))
            {
            case 21:
                return(true);

            case 3:
                return(true);

            case 67:
                return(true);

            case 7:
                return(true);

            case 72:
                return(true);

            case 5:
                return(true);

            case 26:
                return(true);

            case 4:
                return(true);

            case 68:
                return(true);

            case 73:
                return(true);

            case 150:
                return(true);

            case 71:
                return(true);

            case 126:
                return(true);

            case 47:
                return(true);

            case 46:
                return(true);

            case 15:
                return(true);

            case 208:
                return(true);

            case 31:
                return(true);

            case 17:
                return(true);

            case 18:
                return(true);

            case 92:
                return(true);

            default:
                return(false);
            }
        }
        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value)
        {
            int mountingFace = GetMountingFace(Terrain.ExtractData(value));

            return(face != CellFace.OppositeFace(mountingFace));
        }
Beispiel #28
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // La inn en spritefont i content-prosjektet for å
            // tegne tekst. Denne vises her.
            spritefont = Content.Load<SpriteFont>("Arial");

            // Opprett egendefinerte spillobjekter
            car = new Car(Content, "buggy");
            track = new Track(device, Content);
            obstacle = new Obstacle(device, Content);
            terrain = new Terrain(device, Content);
            skybox = new Skybox(device, Content, "miramar");
        }
 public override int GetFace(int value)
 {
     return(GetMountingFace(Terrain.ExtractData(value)));
 }
Beispiel #30
0
 public int?GetPaintColor(int value)
 {
     return(GetColor(Terrain.ExtractData(value)));
 }
Beispiel #31
0
        public void Update(float dt)
        {
            if (componentPlayer == null)
            {
                return;
            }
            if (msginfobtn.IsClicked || componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.Tab))  //消息点击
            {
                if (messageInfo.IsVisible)
                {
                    messageInfo.alwaysShow = false;
                    messageInfo.IsVisible  = messageInfo.alwaysShow;
                }
                else
                {
                    messageInfo.alwaysShow = true;
                    messageInfo.IsVisible  = messageInfo.alwaysShow;
                }
            }
            if (componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.B))
            {
                if (jeiBehavior.xjJEIWidget == null)
                {
                    jeiBehavior.player      = componentPlayer;
                    jeiBehavior.xjJEIWidget = new XjJEIWidget(jeiBehavior);
                }
                if (componentPlayer.ComponentGui.ModalPanelWidget == null)
                {
                    componentPlayer.ComponentGui.ModalPanelWidget = jeiBehavior.xjJEIWidget;
                }
                else
                {
                    componentPlayer.ComponentGui.ModalPanelWidget = null;
                }
            }
            if (componentPlayer.ComponentHealth.DeathTime.HasValue)
            {
                foreach (SubsystemXjJeiBehavior.MarkFLag mark in SubsystemXjJeiBehavior.markFLags)
                {
                    if (mark.point == componentPlayer.ComponentBody.Position)
                    {
                        markaddflag = true; break;
                    }
                }
                if (!markaddflag)
                {
                    SubsystemXjJeiBehavior.MarkFLag markFLag = new SubsystemXjJeiBehavior.MarkFLag();
                    markFLag.point = componentPlayer.ComponentBody.Position;
                    markFLag.name  = "死亡地点";
                    markFLag.color = Color.Red;
                    SubsystemXjJeiBehavior.markFLags.Add(markFLag);
                    markaddflag = true;
                }
            }
            if (touch.IsPressed)
            {
                componentPlayer.ComponentLocomotion.JumpOrder = 1f;
                jump.Texture = TextureAtlasManager.GetSubtexture("JEITextures/JEI_Jump_P").Texture;
            }
            else
            {
                jump.Texture = TextureAtlasManager.GetSubtexture("JEITextures/JEI_Jump").Texture;
            }
            if (messageInfo.IsVisible)
            {
                if (messageInfo.inputpos > 0)
                {
                    if (componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.UpArrow))
                    {
                        if (messageInfo.inputpos - 1 < 0)
                        {
                            messageInfo.inputpos = messageInfo.inputcache.Count - 1;
                        }
                        else
                        {
                            messageInfo.inputpos -= 1;
                        }
                        messageInfo.inputtext.Text = messageInfo.inputcache[messageInfo.inputpos];
                    }
                    else if (componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.DownArrow))
                    {
                        if (messageInfo.inputpos + 1 > messageInfo.inputcache.Count - 1)
                        {
                            messageInfo.inputpos = 0;
                        }
                        else
                        {
                            messageInfo.inputpos += 1;
                        }
                        messageInfo.inputtext.Text = messageInfo.inputcache[messageInfo.inputpos];
                    }
                }
            }
            block = BlocksManager.Blocks[Terrain.ExtractContents(componentPlayer.ComponentMiner.ActiveBlockValue)];
            if (block.Durability > 0)
            {
                disname = block.GetDisplayName(null, componentPlayer.ComponentMiner.ActiveBlockValue);
                if (XjJeiManager.is_NewSC && ModsManager.customer_Strings.ContainsKey(disname))
                {
                    disname = ModsManager.customer_Strings[disname];
                }
                int durty  = 0;
                int damage = block.GetDamage(componentPlayer.ComponentMiner.ActiveBlockValue);
                durty = (block.Durability - damage);
                moreInfo.setInfo(disname, durty, block.GetMeleePower(componentPlayer.ComponentMiner.ActiveBlockValue));
                moreInfo.bitmapWidget.Texture = moreInfo.texture;
            }
            else
            {
                moreInfo.naijiu.Text          = "";
                moreInfo.bitmapWidget.Texture = null;
                moreInfo.labelWidget.Text     = "";
            }
            moreInfo.setPosi(componentPlayer.ComponentBody.Position);
            moreInfo.setShow(SubsystemXjJeiBehavior.posi, SubsystemXjJeiBehavior.dura);
            if (!SubsystemXjJeiBehavior.run)
            {
                return;
            }
            if (componentPlayer.ComponentGui.ModalPanelWidget != null)
            {
                infoDialog.IsVisible = false; return;
            }
            //检测是否有方块
            Ray3 ray = new Ray3(componentPlayer.GameWidget.ActiveCamera.ViewPosition, componentPlayer.GameWidget.ActiveCamera.ViewDirection);

            terrainray = componentPlayer.ComponentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction, true, true, false);
            foreach (KeyValuePair <ComponentCreature, bool> creature in creatureSpawn.m_creatures)
            {
                if (creature.Key == null)
                {
                    hasCreature = false; continue;
                }
                Vector3 creaturePosition = creature.Key.ComponentCreatureModel.EyePosition;
                Vector3 start            = ray.Position;
                Vector3 direction        = Vector3.Normalize(ray.Direction);
                Vector3 end = ray.Position + direction * 15f;
                //检测是否有生物
                if (creature.Key.ComponentBody.Position == componentPlayer.ComponentBody.Position)
                {
                    hasCreature = false; continue;
                }
                Raymm = ray.Intersection(creature.Key.ComponentBody.BoundingBox);
                if (Raymm.HasValue)
                {
                    if (Raymm.Value <= 10f)
                    {
                        infoDialog.setCreatureinfo(creature.Key);
                        hasCreature = true;
                        break;
                    }
                }
                else
                {
                    hasCreature = false;
                }
            }
            if (terrainray.HasValue && !hasCreature)
            {
                point = terrainray.Value.CellFace.Point;
                float disb = terrainray.Value.Distance;
                if (Raymm.HasValue && Raymm.Value <= disb)
                {
                    infoDialog.IsVisible = true;
                }
                else
                {
                    cellValue = terrainray.Value.Value;
                    if (Terrain.ExtractContents(componentPlayer.ComponentMiner.ActiveBlockValue) != 0)
                    {
                        //装备的工具等级
                        block     = BlocksManager.Blocks[Terrain.ExtractContents(componentPlayer.ComponentMiner.ActiveBlockValue)];
                        toollevel = block.ToolLevel;
                        //hack为劈砍
                        //shovel为铲子
                        //quarry为镐子
                        //none为手
                    }
                    else
                    {
                        toollevel = 0;
                    }
                    block   = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)];
                    disname = block.GetDisplayName(null, cellValue);
                    if (XjJeiManager.is_NewSC && ModsManager.customer_Strings.ContainsKey(disname))
                    {
                        disname = ModsManager.customer_Strings[disname];
                    }
                    ;
                    if (subsystemPlantBlock.HandledBlocks.Contains(Terrain.ExtractContents(cellValue)))
                    {
                        grow = Terrain.ExtractData(cellValue) & 7;
                        if (Terrain.ExtractContents(cellValue) == 174)
                        {
                            grow = (int)((((float)grow) / 7f) * 100);                                           //黑麦
                        }
                        else
                        {
                            grow = (int)(((7f - (float)grow) / 7f) * 100); //南瓜
                        }
                        infoDialog.setPlantInfo(disname, cellValue, grow);
                    }
                    else
                    {//不是作物
                        grow = 0;
                        dig  = block.RequiredToolLevel;
                        infoDialog.setBlockInfo($"{disname}", cellValue, dig, block.DigMethod, toollevel);
                    }
                    infoDialog.IsVisible = true;
                }
            }
            else
            {
                if (!hasCreature)
                {
                    infoDialog.IsVisible = false;
                }
                else
                {
                    infoDialog.IsVisible = true;
                }
            }
            infoDialog.setBottomWidget(moreInfo);
            infoDialog.setUpmode(SubsystemXjJeiBehavior.upmode);
        }
Beispiel #32
0
        public int Paint(SubsystemTerrain subsystemTerrain, int value, int?color)
        {
            int data = Terrain.ExtractData(value);

            return(Terrain.ReplaceData(value, SetColor(data, color)));
        }
Beispiel #33
0
        public static bool IsPowered(Terrain terrain, int x, int y, int z)
        {
            var chunk = terrain.GetChunkAtCell(x, z);

            if (y < 0 || y > 127 || chunk == null)
            {
                return(false);
            }
            int cellValue = terrain.GetCellValueFast(x + 1, y, z);

            if (FurnaceNBlock.GetHeatLevel(cellValue) != 0)
            {
                cellValue = Terrain.ExtractContents(cellValue);
                if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index)
                {
                    return(true);
                }
            }
            cellValue = terrain.GetCellValueFast(x - 1, y, z);
            if (FurnaceNBlock.GetHeatLevel(cellValue) != 0)
            {
                cellValue = Terrain.ExtractContents(cellValue);
                if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index)
                {
                    return(true);
                }
            }
            if (y < 127)
            {
                cellValue = chunk.GetCellValueFast(x & 15, y + 1, z & 15);
                if (FurnaceNBlock.GetHeatLevel(cellValue) != 0)
                {
                    cellValue = Terrain.ExtractContents(cellValue);
                    if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index)
                    {
                        return(true);
                    }
                }
            }
            if (y > 0)
            {
                cellValue = chunk.GetCellValueFast(x & 15, y - 1, z & 15);
                if (FurnaceNBlock.GetHeatLevel(cellValue) != 0)
                {
                    cellValue = Terrain.ExtractContents(cellValue);
                    if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index)
                    {
                        return(true);
                    }
                }
            }
            cellValue = terrain.GetCellValueFast(x, y, z + 1);
            if (FurnaceNBlock.GetHeatLevel(cellValue) != 0)
            {
                cellValue = Terrain.ExtractContents(cellValue);
                if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index)
                {
                    return(true);
                }
            }
            cellValue = terrain.GetCellValueFast(x, y, z - 1);
            if (FurnaceNBlock.GetHeatLevel(cellValue) != 0)
            {
                cellValue = Terrain.ExtractContents(cellValue);
                if (cellValue == EngineBlock.Index || cellValue == EngineHBlock.Index)
                {
                    return(true);
                }
            }
            return(false);
        }
 public void Update(float dt)
 {
     if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(0.5, 0.0))
     {
         foreach (int enumValue in EnumUtils.GetEnumValues(typeof(ClothingSlot)))
         {
             bool flag = false;
             m_clothesList.Clear();
             m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue));
             int num = 0;
             while (num < m_clothesList.Count)
             {
                 int          value        = m_clothesList[num];
                 ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                 if ((float)clothingData.PlayerLevelRequired > m_componentPlayer.PlayerData.Level)
                 {
                     m_componentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), clothingData.PlayerLevelRequired, clothingData.DisplayName), Color.White, blinking: true, playNotificationSound: true);
                     m_subsystemPickables.AddPickable(value, 1, m_componentBody.Position, null, null);
                     m_clothesList.RemoveAt(num);
                     flag = true;
                 }
                 else
                 {
                     num++;
                 }
             }
             if (flag)
             {
                 SetClothes((ClothingSlot)enumValue, m_clothesList);
             }
         }
     }
     if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0) && ((m_componentLocomotion.LastWalkOrder.HasValue && m_componentLocomotion.LastWalkOrder.Value != Vector2.Zero) || (m_componentLocomotion.LastSwimOrder.HasValue && m_componentLocomotion.LastSwimOrder.Value != Vector3.Zero) || m_componentLocomotion.LastJumpOrder != 0f))
     {
         if (m_lastTotalElapsedGameTime.HasValue)
         {
             foreach (int enumValue2 in EnumUtils.GetEnumValues(typeof(ClothingSlot)))
             {
                 bool flag2 = false;
                 m_clothesList.Clear();
                 m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue2));
                 for (int i = 0; i < m_clothesList.Count; i++)
                 {
                     int          value2        = m_clothesList[i];
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(Terrain.ExtractData(value2));
                     float        num2          = (m_componentVitalStats.Wetness > 0f) ? (10f * clothingData2.Sturdiness) : (20f * clothingData2.Sturdiness);
                     double       num3          = MathUtils.Floor(m_lastTotalElapsedGameTime.Value / (double)num2);
                     if (MathUtils.Floor(m_subsystemGameInfo.TotalElapsedGameTime / (double)num2) > num3 && m_random.Float(0f, 1f) < 0.75f)
                     {
                         m_clothesList[i] = BlocksManager.DamageItem(value2, 1);
                         flag2            = true;
                     }
                 }
                 int num4 = 0;
                 while (num4 < m_clothesList.Count)
                 {
                     if (Terrain.ExtractContents(m_clothesList[num4]) != 203)
                     {
                         m_clothesList.RemoveAt(num4);
                         m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0));
                         m_componentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                     }
                     else
                     {
                         num4++;
                     }
                 }
                 if (flag2)
                 {
                     SetClothes((ClothingSlot)enumValue2, m_clothesList);
                 }
             }
         }
         m_lastTotalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
     }
     UpdateRenderTargets();
 }