Ejemplo n.º 1
0
        public Vector3 FindBestCameraPosition(Vector3 targetPosition, float distance)
        {
            Vector3?vector = null;

            for (int i = 0; i < 36; i++)
            {
                float   x       = 1f + (float)Math.PI * 2f * (float)i / 36f;
                Vector3 v2      = Vector3.Normalize(new Vector3(MathUtils.Sin(x), 0.5f, MathUtils.Cos(x)));
                Vector3 vector2 = targetPosition + v2 * distance;
                TerrainRaycastResult?terrainRaycastResult = base.GameWidget.SubsystemGameWidgets.SubsystemTerrain.Raycast(targetPosition, vector2, useInteractionBoxes: false, skipAirBlocks: true, (int v, float d) => !BlocksManager.Blocks[Terrain.ExtractContents(v)].IsTransparent);
                Vector3 zero = Vector3.Zero;
                if (terrainRaycastResult.HasValue)
                {
                    CellFace cellFace = terrainRaycastResult.Value.CellFace;
                    zero = new Vector3((float)cellFace.X + 0.5f, (float)cellFace.Y + 0.5f, (float)cellFace.Z + 0.5f) - 1f * v2;
                }
                else
                {
                    zero = vector2;
                }
                if (!vector.HasValue || Vector3.Distance(zero, targetPosition) > Vector3.Distance(vector.Value, targetPosition))
                {
                    vector = zero;
                }
            }
            if (vector.HasValue)
            {
                return(vector.Value);
            }
            return(targetPosition);
        }
Ejemplo n.º 2
0
        public void CalculateTemperature(int x, int y, int z, float meterTemperature, float meterInsulation, out float temperature, out float temperatureFlux)
        {
            m_toVisit.Clear();
            for (int i = 0; i < m_visited.Length; i++)
            {
                m_visited[i] = 0;
            }
            float num  = 0f;
            float num2 = 0f;
            float num3 = 0f;
            float num4 = 0f;
            float num5 = 0f;
            float num6 = 0f;

            m_toVisit.Add(133152);
            for (int j = 0; j < m_toVisit.Count; j++)
            {
                int num7 = m_toVisit.Array[j];
                if ((m_visited[num7 / 32] & (1 << num7)) != 0)
                {
                    continue;
                }
                m_visited[num7 / 32] |= 1 << num7;
                int          num8        = (num7 & 0x3F) - 32;
                int          num9        = ((num7 >> 6) & 0x3F) - 32;
                int          num10       = ((num7 >> 12) & 0x3F) - 32;
                int          num11       = num8 + x;
                int          num12       = num9 + y;
                int          num13       = num10 + z;
                Terrain      terrain     = base.SubsystemTerrain.Terrain;
                TerrainChunk chunkAtCell = terrain.GetChunkAtCell(num11, num13);
                if (chunkAtCell == null || num12 < 0 || num12 >= 256)
                {
                    continue;
                }
                int   x2            = num11 & 0xF;
                int   y2            = num12;
                int   z2            = num13 & 0xF;
                int   cellValueFast = chunkAtCell.GetCellValueFast(x2, y2, z2);
                int   num14         = Terrain.ExtractContents(cellValueFast);
                Block block         = BlocksManager.Blocks[num14];
                float heat          = GetHeat(cellValueFast);
                if (heat > 0f)
                {
                    int   num15 = MathUtils.Abs(num8) + MathUtils.Abs(num9) + MathUtils.Abs(num10);
                    int   num16 = (num15 <= 0) ? 1 : (4 * num15 * num15 + 2);
                    float num17 = 1f / (float)num16;
                    num5 += num17 * 36f * heat;
                    num6 += num17;
                }
                else if (block.IsHeatBlocker(cellValueFast))
                {
                    int   num18 = MathUtils.Abs(num8) + MathUtils.Abs(num9) + MathUtils.Abs(num10);
                    int   num19 = (num18 <= 0) ? 1 : (4 * num18 * num18 + 2);
                    float num20 = 1f / (float)num19;
                    float num21 = terrain.SeasonTemperature;
                    float num22 = SubsystemWeather.GetTemperatureAdjustmentAtHeight(y2);
                    float num23 = (block is WaterBlock) ? (MathUtils.Max((float)chunkAtCell.GetTemperatureFast(x2, z2) + num21 - 6f, 0f) + num22) : ((!(block is IceBlock)) ? ((float)chunkAtCell.GetTemperatureFast(x2, z2) + num21 + num22) : (0f + num21 + num22));
                    num  += num20 * num23;
                    num2 += num20;
                }
                else if (y >= chunkAtCell.GetTopHeightFast(x2, z2))
                {
                    int   num24 = MathUtils.Abs(num8) + MathUtils.Abs(num9) + MathUtils.Abs(num10);
                    int   num25 = (num24 <= 0) ? 1 : (4 * num24 * num24 + 2);
                    float num26 = 1f / (float)num25;
                    PrecipitationShaftInfo precipitationShaftInfo = m_subsystemWeather.GetPrecipitationShaftInfo(x, z);
                    float num27 = terrain.SeasonTemperature;
                    float num28 = (y >= precipitationShaftInfo.YLimit) ? MathUtils.Lerp(0f, -2f, precipitationShaftInfo.Intensity) : 0f;
                    float num29 = MathUtils.Lerp(-6f, 0f, m_subsystemSky.SkyLightIntensity);
                    float num30 = SubsystemWeather.GetTemperatureAdjustmentAtHeight(y2);
                    num3 += num26 * ((float)chunkAtCell.GetTemperatureFast(x2, z2) + num27 + num28 + num29 + num30);
                    num4 += num26;
                }
                else if (m_toVisit.Count < 4090)
                {
                    if (num8 > -30)
                    {
                        m_toVisit.Add(num7 - 1);
                    }
                    if (num8 < 30)
                    {
                        m_toVisit.Add(num7 + 1);
                    }
                    if (num9 > -30)
                    {
                        m_toVisit.Add(num7 - 64);
                    }
                    if (num9 < 30)
                    {
                        m_toVisit.Add(num7 + 64);
                    }
                    if (num10 > -30)
                    {
                        m_toVisit.Add(num7 - 4096);
                    }
                    if (num10 < 30)
                    {
                        m_toVisit.Add(num7 + 4096);
                    }
                }
            }
            float num31 = 0f;

            for (int k = -7; k <= 7; k++)
            {
                for (int l = -7; l <= 7; l++)
                {
                    TerrainChunk chunkAtCell2 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + k, z + l);
                    if (chunkAtCell2 == null || chunkAtCell2.State < TerrainChunkState.InvalidVertices1)
                    {
                        continue;
                    }
                    for (int m = -7; m <= 7; m++)
                    {
                        int num32 = k * k + m * m + l * l;
                        if (num32 > 49 || num32 <= 0)
                        {
                            continue;
                        }
                        int x3    = (x + k) & 0xF;
                        int num33 = y + m;
                        int z3    = (z + l) & 0xF;
                        if (num33 >= 0 && num33 < 256)
                        {
                            float heat2 = GetHeat(chunkAtCell2.GetCellValueFast(x3, num33, z3));
                            if (heat2 > 0f && !base.SubsystemTerrain.Raycast(new Vector3(x, y, z) + new Vector3(0.5f, 0.75f, 0.5f), new Vector3(x + k, y + m, z + l) + new Vector3(0.5f, 0.75f, 0.5f), useInteractionBoxes: false, skipAirBlocks: true, delegate(int raycastValue, float d)
                            {
                                Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(raycastValue)];
                                return(block2.IsCollidable && !block2.IsTransparent);
                            }).HasValue)
                            {
                                num31 += heat2 * 3f / (float)(num32 + 2);
                            }
                        }
                    }
                }
            }
            float num34 = 0f;
            float num35 = 0f;

            if (num31 > 0f)
            {
                float num36 = 3f * num31;
                num34 += 35f * num36;
                num35 += num36;
            }
            if (num2 > 0f)
            {
                float num37 = 1f;
                num34 += num / num2 * num37;
                num35 += num37;
            }
            if (num4 > 0f)
            {
                float num38 = 4f * MathUtils.Pow(num4, 0.25f);
                num34 += num3 / num4 * num38;
                num35 += num38;
            }
            if (num6 > 0f)
            {
                float num39 = 1.5f * MathUtils.Pow(num6, 0.25f);
                num34 += num5 / num6 * num39;
                num35 += num39;
            }
            if (meterInsulation > 0f)
            {
                num34 += meterTemperature * meterInsulation;
                num35 += meterInsulation;
            }
            temperature     = ((num35 > 0f) ? (num34 / num35) : meterTemperature);
            temperatureFlux = num35 - meterInsulation;
        }
Ejemplo n.º 3
0
        public static float GetHeat(int value)
        {
            int num = Terrain.ExtractContents(value);

            return(BlocksManager.Blocks[num].GetHeat(value));
        }
Ejemplo n.º 4
0
        public static void CRInitialize()
        {
            CraftingRecipesManager.m_recipes = new List <CraftingRecipe>();
            var recipes    = new List <CraftingRecipe>();
            var enumerator = ContentManager.CombineXml(ContentManager.Get <XElement>("CraftingRecipes"), ModsManager.GetEntries(".cr"), "Description", "Result", "Recipes").Descendants("Recipe").GetEnumerator();

            while (enumerator.MoveNext())
            {
                XElement xelement       = enumerator.Current;
                var      craftingRecipe = new CraftingRecipe
                {
                    Ingredients = new string[36]
                };
                string attributeValue = XmlUtils.GetAttributeValue <string>(xelement, "Result");
                craftingRecipe.ResultValue = CraftingRecipesManager.DecodeResult(attributeValue);
                craftingRecipe.ResultCount = XmlUtils.GetAttributeValue <int>(xelement, "ResultCount");
                string attributeValue2 = XmlUtils.GetAttributeValue(xelement, "Remains", string.Empty);
                if (!string.IsNullOrEmpty(attributeValue2))
                {
                    craftingRecipe.RemainsValue = CraftingRecipesManager.DecodeResult(attributeValue2);
                    craftingRecipe.RemainsCount = XmlUtils.GetAttributeValue <int>(xelement, "RemainsCount");
                }
                craftingRecipe.RequiredHeatLevel = XmlUtils.GetAttributeValue <float>(xelement, "RequiredHeatLevel");
                craftingRecipe.Description       = XmlUtils.GetAttributeValue <string>(xelement, "Description");
                if (craftingRecipe.ResultCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.ResultValue)].MaxStacking)
                {
                    throw new InvalidOperationException($"In recipe for \"{attributeValue}\" ResultCount is larger than max stacking of result block.");
                }
                if (craftingRecipe.RemainsValue != 0 && craftingRecipe.RemainsCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.RemainsValue)].MaxStacking)
                {
                    throw new InvalidOperationException($"In Recipe for \"{attributeValue2}\" RemainsCount is larger than max stacking of remains block.");
                }
                var dictionary = new Dictionary <char, string>();
                foreach (XAttribute item in xelement.Attributes().Where(CraftingRecipesManager.c._.Initialize_b__3_1))
                {
                    CraftingRecipesManager.DecodeIngredient(item.Value, out string craftingId, out int?data);
                    if (BlocksManager.FindBlocksByCraftingId(craftingId).Length == 0)
                    {
                        throw new InvalidOperationException($"Block with craftingId \"{item.Value}\" not found.");
                    }
                    if (data.HasValue && (data.Value < 0 || data.Value > 262143))
                    {
                        throw new InvalidOperationException($"Data in recipe ingredient \"{item.Value}\" must be between 0 and 0x3FFFF.");
                    }
                    dictionary.Add(item.Name.LocalName[0], item.Value);
                }
                string[] array       = xelement.Value.Trim().Split('\n');
                string[] ingredients = craftingRecipe.Ingredients;
                for (int i = 0; i < array.Length; i++)
                {
                    int num2 = array[i].IndexOf('"');
                    int num3 = array[i].LastIndexOf('"');
                    if (num2 < 0 || num3 < 0 || num3 <= num2)
                    {
                        throw new InvalidOperationException("Invalid recipe line.");
                    }
                    string text = array[i].Substring(num2 + 1, num3 - num2 - 1);
                    for (int j = 0; j < text.Length; j++)
                    {
                        char c = text[j];
                        if (char.IsLower(c))
                        {
                            string text2 = dictionary[c];
                            if (ItemBlock.IdTable.TryGetValue(text2, out int value))
                            {
                                text2 = BlocksManager.Blocks[Terrain.ExtractContents(value)].CraftingId + ":" + Terrain.ExtractData(value);
                            }
                            ingredients[j + i * 6] = text2;
                        }
                    }
                }
                CraftingRecipesManager.m_recipes.Add(craftingRecipe);
                if (craftingRecipe.RequiredHeatLevel >= 300f)
                {
                    CraftingRecipesManager.DecodeIngredient(ingredients[0], out string craftingId, out int?num);
                    if (!num.HasValue)
                    {
                        continue;
                    }
                    recipes.Add(new CraftingRecipe
                    {
                        ResultValue       = Terrain.ReplaceData(BlocksManager.FindBlocksByCraftingId(craftingId)[0].BlockIndex, num.Value),
                        ResultCount       = GetCount(ingredients),
                        RemainsValue      = craftingRecipe.RemainsValue,
                        RemainsCount      = craftingRecipe.RemainsCount,
                        RequiredHeatLevel = 1f,
                        Ingredients       = (string[])ingredients.Clone(),
                        Description       = craftingRecipe.Description + Utils.Get(" (温度过低)")
                    });
                }
            }
            var blocks = BlocksManager.Blocks;

            for (int i = 0; i < blocks.Length; i++)
            {
                using (var enumerator2 = blocks[i].GetProceduralCraftingRecipes().GetEnumerator())
                    while (enumerator2.MoveNext())
                    {
                        var old = enumerator2.Current.Ingredients;
                        if (old.Length == 9)
                        {
                            var ingredients = new string[36];
                            ingredients[0]  = old[0];
                            ingredients[1]  = old[1];
                            ingredients[2]  = old[2];
                            ingredients[6]  = old[3];
                            ingredients[7]  = old[4];
                            ingredients[8]  = old[5];
                            ingredients[12] = old[6];
                            ingredients[13] = old[7];
                            ingredients[14] = old[8];
                            enumerator2.Current.Ingredients = ingredients;
                        }
                        CraftingRecipesManager.m_recipes.Add(enumerator2.Current);
                    }
            }
            CraftingRecipesManager.m_recipes.Sort(CraftingRecipesManager.c._.Initialize_b__3_0);
            CraftingRecipesManager.m_recipes.AddRange(recipes);
        }
Ejemplo n.º 5
0
        public void GetAllConnectedNeighbors(int x, int y, int z, int mountingFace, DynamicArray <ElectricConnectionPath> list)
        {
            int cellValue = SubsystemTerrain.Terrain.GetCellValue(x, y, z);
            IElectricElementBlock electricElementBlock = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)] as IElectricElementBlock;

            if (electricElementBlock == null)
            {
                return;
            }
            for (ElectricConnectorDirection electricConnectorDirection = ElectricConnectorDirection.Top; electricConnectorDirection < (ElectricConnectorDirection)5; electricConnectorDirection++)
            {
                for (int i = 0; i < 4; i++)
                {
                    ElectricConnectionPath electricConnectionPath = m_connectionPathsTable[20 * mountingFace + 4 * (int)electricConnectorDirection + i];
                    if (electricConnectionPath == null)
                    {
                        break;
                    }
                    ElectricConnectorType?connectorType = electricElementBlock.GetConnectorType(SubsystemTerrain, cellValue, mountingFace, electricConnectionPath.ConnectorFace, x, y, z);
                    if (!connectorType.HasValue)
                    {
                        break;
                    }
                    int x2         = x + electricConnectionPath.NeighborOffsetX;
                    int y2         = y + electricConnectionPath.NeighborOffsetY;
                    int z2         = z + electricConnectionPath.NeighborOffsetZ;
                    int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(x2, y2, z2);
                    IElectricElementBlock electricElementBlock2 = BlocksManager.Blocks[Terrain.ExtractContents(cellValue2)] as IElectricElementBlock;
                    if (electricElementBlock2 == null)
                    {
                        continue;
                    }
                    ElectricConnectorType?connectorType2 = electricElementBlock2.GetConnectorType(SubsystemTerrain, cellValue2, electricConnectionPath.NeighborFace, electricConnectionPath.NeighborConnectorFace, x2, y2, z2);
                    if (connectorType2.HasValue && ((connectorType.Value != 0 && connectorType2.Value != ElectricConnectorType.Output) || (connectorType.Value != ElectricConnectorType.Output && connectorType2.Value != 0)))
                    {
                        int connectionMask  = electricElementBlock.GetConnectionMask(cellValue);
                        int connectionMask2 = electricElementBlock2.GetConnectionMask(cellValue2);
                        if ((connectionMask & connectionMask2) != 0)
                        {
                            list.Add(electricConnectionPath);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public virtual bool ShouldGenerateFace(SubsystemTerrain subsystemTerrain, int face, int value, int neighborValue)
 {
     return(BlocksManager.Blocks[Terrain.ExtractContents(neighborValue)].IsFaceTransparent(subsystemTerrain, CellFace.OppositeFace(face), neighborValue));
 }
Ejemplo n.º 7
0
 public virtual IItem GetItem(ref int value)
 {
     return(Terrain.ExtractContents(value) != Index ? null : Items[Terrain.ExtractData(value)]);
 }
Ejemplo n.º 8
0
        public void Update(float dt)
        {
            PlayerInput playerInput = ComponentInput.PlayerInput;

            if (ComponentInput.IsControlledByTouch && m_aim.HasValue)
            {
                playerInput.Look = Vector2.Zero;
            }
            if (ComponentMiner.Inventory != null)
            {
                ComponentMiner.Inventory.ActiveSlotIndex += playerInput.ScrollInventory;
                if (playerInput.SelectInventorySlot.HasValue)
                {
                    ComponentMiner.Inventory.ActiveSlotIndex = MathUtils.Clamp(playerInput.SelectInventorySlot.Value, 0, 9);
                }
            }
            ComponentSteedBehavior componentSteedBehavior = null;
            ComponentBoat          componentBoat          = null;
            ComponentMount         mount = ComponentRider.Mount;

            if (mount != null)
            {
                componentSteedBehavior = mount.Entity.FindComponent <ComponentSteedBehavior>();
                componentBoat          = mount.Entity.FindComponent <ComponentBoat>();
            }
            if (componentSteedBehavior != null)
            {
                if (playerInput.Move.Z > 0.5f && !m_speedOrderBlocked)
                {
                    if (PlayerData.PlayerClass == PlayerClass.Male)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/MaleYellFast", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    else
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellFast", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    componentSteedBehavior.SpeedOrder = 1;
                    m_speedOrderBlocked = true;
                }
                else if (playerInput.Move.Z < -0.5f && !m_speedOrderBlocked)
                {
                    if (PlayerData.PlayerClass == PlayerClass.Male)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/MaleYellSlow", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    else
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellSlow", 0.75f, 0f, base.ComponentBody.Position, 2f, autoDelay: false);
                    }
                    componentSteedBehavior.SpeedOrder = -1;
                    m_speedOrderBlocked = true;
                }
                else if (MathUtils.Abs(playerInput.Move.Z) <= 0.25f)
                {
                    m_speedOrderBlocked = false;
                }
                componentSteedBehavior.TurnOrder   = playerInput.Move.X;
                componentSteedBehavior.JumpOrder   = (playerInput.Jump ? 1 : 0);
                base.ComponentLocomotion.LookOrder = new Vector2(playerInput.Look.X, 0f);
            }
            else if (componentBoat != null)
            {
                componentBoat.TurnOrder                   = playerInput.Move.X;
                componentBoat.MoveOrder                   = playerInput.Move.Z;
                base.ComponentLocomotion.LookOrder        = new Vector2(playerInput.Look.X, 0f);
                base.ComponentCreatureModel.RowLeftOrder  = (playerInput.Move.X <-0.2f || playerInput.Move.Z> 0.2f);
                base.ComponentCreatureModel.RowRightOrder = (playerInput.Move.X > 0.2f || playerInput.Move.Z > 0.2f);
            }
            else
            {
                base.ComponentLocomotion.WalkOrder = (base.ComponentBody.IsSneaking ? (0.66f * new Vector2(playerInput.SneakMove.X, playerInput.SneakMove.Z)) : new Vector2(playerInput.Move.X, playerInput.Move.Z));
                base.ComponentLocomotion.FlyOrder  = new Vector3(0f, playerInput.Move.Y, 0f);
                base.ComponentLocomotion.TurnOrder = playerInput.Look * new Vector2(1f, 0f);
                base.ComponentLocomotion.JumpOrder = MathUtils.Max(playerInput.Jump ? 1 : 0, base.ComponentLocomotion.JumpOrder);
            }
            base.ComponentLocomotion.LookOrder  += playerInput.Look * (SettingsManager.FlipVerticalAxis ? new Vector2(0f, -1f) : new Vector2(0f, 1f));
            base.ComponentLocomotion.VrLookOrder = playerInput.VrLook;
            base.ComponentLocomotion.VrMoveOrder = playerInput.VrMove;
            int   num   = Terrain.ExtractContents(ComponentMiner.ActiveBlockValue);
            Block block = BlocksManager.Blocks[num];
            bool  flag  = false;

            if (playerInput.Interact.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                if (!ComponentMiner.Use(playerInput.Interact.Value))
                {
                    TerrainRaycastResult?terrainRaycastResult = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.Interact.Value, RaycastMode.Interaction);
                    if (terrainRaycastResult.HasValue)
                    {
                        if (!ComponentMiner.Interact(terrainRaycastResult.Value))
                        {
                            if (ComponentMiner.Place(terrainRaycastResult.Value))
                            {
                                m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                                flag           = true;
                                m_isAimBlocked = true;
                            }
                        }
                        else
                        {
                            m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                            flag           = true;
                            m_isAimBlocked = true;
                        }
                    }
                }
                else
                {
                    m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                    flag           = true;
                    m_isAimBlocked = true;
                }
            }
            float num2 = (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative) ? 0.1f : 1.4f;

            if (playerInput.Aim.HasValue && block.IsAimable && m_subsystemTime.GameTime - m_lastActionTime > (double)num2)
            {
                if (!m_isAimBlocked)
                {
                    Ray3    value  = playerInput.Aim.Value;
                    Vector3 vector = GameWidget.ActiveCamera.WorldToScreen(value.Position + value.Direction, Matrix.Identity);
                    Point2  size   = Window.Size;
                    if (ComponentInput.IsControlledByVr || (vector.X >= (float)size.X * 0.02f && vector.X < (float)size.X * 0.98f && vector.Y >= (float)size.Y * 0.02f && vector.Y < (float)size.Y * 0.98f))
                    {
                        m_aim = value;
                        if (ComponentMiner.Aim(value, AimState.InProgress))
                        {
                            ComponentMiner.Aim(m_aim.Value, AimState.Cancelled);
                            m_aim          = null;
                            m_isAimBlocked = true;
                        }
                        else if (!m_aimHintIssued && Time.PeriodicEvent(1.0, 0.0))
                        {
                            Time.QueueTimeDelayedExecution(Time.RealTime + 3.0, delegate
                            {
                                if (!m_aimHintIssued && m_aim.HasValue && !base.ComponentBody.IsSneaking)
                                {
                                    m_aimHintIssued = true;
                                    ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                                }
                            });
                        }
                    }
                    else if (m_aim.HasValue)
                    {
                        ComponentMiner.Aim(m_aim.Value, AimState.Cancelled);
                        m_aim          = null;
                        m_isAimBlocked = true;
                    }
                }
            }
            else
            {
                m_isAimBlocked = false;
                if (m_aim.HasValue)
                {
                    ComponentMiner.Aim(m_aim.Value, AimState.Completed);
                    m_aim            = null;
                    m_lastActionTime = m_subsystemTime.GameTime;
                }
            }
            flag |= m_aim.HasValue;
            if (playerInput.Hit.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                BodyRaycastResult?bodyRaycastResult = ComponentMiner.Raycast <BodyRaycastResult>(playerInput.Hit.Value, RaycastMode.Interaction);
                if (bodyRaycastResult.HasValue)
                {
                    flag           = true;
                    m_isDigBlocked = true;
                    if (Vector3.Distance(bodyRaycastResult.Value.HitPoint(), base.ComponentCreatureModel.EyePosition) <= 2f)
                    {
                        ComponentMiner.Hit(bodyRaycastResult.Value.ComponentBody, bodyRaycastResult.Value.HitPoint(), playerInput.Hit.Value.Direction);
                    }
                }
            }
            if (playerInput.Dig.HasValue && !flag && !m_isDigBlocked && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                TerrainRaycastResult?terrainRaycastResult2 = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.Dig.Value, RaycastMode.Digging);
                if (terrainRaycastResult2.HasValue && ComponentMiner.Dig(terrainRaycastResult2.Value))
                {
                    m_lastActionTime = m_subsystemTime.GameTime;
                    m_subsystemTerrain.TerrainUpdater.RequestSynchronousUpdate();
                }
            }
            if (!playerInput.Dig.HasValue)
            {
                m_isDigBlocked = false;
            }
            if (playerInput.Drop && ComponentMiner.Inventory != null)
            {
                IInventory inventory = ComponentMiner.Inventory;
                int        slotValue = inventory.GetSlotValue(inventory.ActiveSlotIndex);
                int        num3      = inventory.RemoveSlotItems(count: inventory.GetSlotCount(inventory.ActiveSlotIndex), slotIndex: inventory.ActiveSlotIndex);
                if (slotValue != 0 && num3 != 0)
                {
                    Vector3 position = base.ComponentBody.Position + new Vector3(0f, base.ComponentBody.BoxSize.Y * 0.66f, 0f) + 0.25f * base.ComponentBody.Matrix.Forward;
                    Vector3 value2   = 8f * Matrix.CreateFromQuaternion(base.ComponentCreatureModel.EyeRotation).Forward;
                    m_subsystemPickables.AddPickable(slotValue, num3, position, value2, null);
                }
            }
            if (!playerInput.PickBlockType.HasValue || flag)
            {
                return;
            }
            ComponentCreativeInventory componentCreativeInventory = ComponentMiner.Inventory as ComponentCreativeInventory;

            if (componentCreativeInventory == null)
            {
                return;
            }
            TerrainRaycastResult?terrainRaycastResult3 = ComponentMiner.Raycast <TerrainRaycastResult>(playerInput.PickBlockType.Value, RaycastMode.Digging, raycastTerrain: true, raycastBodies: false, raycastMovingBlocks: false);

            if (!terrainRaycastResult3.HasValue)
            {
                return;
            }
            int value3 = terrainRaycastResult3.Value.Value;

            value3 = Terrain.ReplaceLight(value3, 0);
            int               num4           = Terrain.ExtractContents(value3);
            Block             block2         = BlocksManager.Blocks[num4];
            int               num5           = 0;
            IEnumerable <int> creativeValues = block2.GetCreativeValues();

            if (block2.GetCreativeValues().Contains(value3))
            {
                num5 = value3;
            }
            if (num5 == 0 && !block2.IsNonDuplicable)
            {
                List <BlockDropValue> list = new List <BlockDropValue>();
                block2.GetDropValues(m_subsystemTerrain, value3, 0, int.MaxValue, list, out bool _);
                if (list.Count > 0 && list[0].Count > 0)
                {
                    num5 = list[0].Value;
                }
            }
            if (num5 == 0)
            {
                num5 = creativeValues.FirstOrDefault();
            }
            if (num5 == 0)
            {
                return;
            }
            int num6 = -1;

            for (int i = 0; i < 10; i++)
            {
                if (componentCreativeInventory.GetSlotCapacity(i, num5) > 0 && componentCreativeInventory.GetSlotCount(i) > 0 && componentCreativeInventory.GetSlotValue(i) == num5)
                {
                    num6 = i;
                    break;
                }
            }
            if (num6 < 0)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (componentCreativeInventory.GetSlotCapacity(j, num5) > 0 && (componentCreativeInventory.GetSlotCount(j) == 0 || componentCreativeInventory.GetSlotValue(j) == 0))
                    {
                        num6 = j;
                        break;
                    }
                }
            }
            if (num6 < 0)
            {
                num6 = componentCreativeInventory.ActiveSlotIndex;
            }
            componentCreativeInventory.RemoveSlotItems(num6, int.MaxValue);
            componentCreativeInventory.AddSlotItems(num6, num5, 1);
            componentCreativeInventory.ActiveSlotIndex = num6;
            ComponentGui.DisplaySmallMessage(block2.GetDisplayName(m_subsystemTerrain, value3), Color.White, blinking: false, playNotificationSound: false);
            m_subsystemAudio.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f, 0f);
        }
Ejemplo n.º 9
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);
                    int num2      = slotValue;
                    int num3      = 0;
                    if (num == 212 && slotCount > 0)
                    {
                        if (!m_aimStartTimes.TryGetValue(componentMiner, out double value))
                        {
                            value = m_subsystemTime.GameTime;
                            m_aimStartTimes[componentMiner] = value;
                        }
                        float   num4 = (float)(m_subsystemTime.GameTime - value);
                        float   num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0);
                        Vector3 v    = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.2f * MathUtils.Saturate((num4 - 2.5f) / 6f)) * new Vector3
                        {
                            X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f),
                            Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f),
                            Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f)
                        };
                        aim.Direction = Vector3.Normalize(aim.Direction + v);
                        switch (state)
                        {
                        case AimState.InProgress:
                        {
                            if (num4 >= 10f)
                            {
                                componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound();
                                return(true);
                            }
                            if (num4 > 0.5f && !MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: true));
                                m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>();
                            if (componentFirstPersonModel != null)
                            {
                                componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction);
                                componentFirstPersonModel.ItemOffsetOrder   = new Vector3(-0.21f, 0.15f, 0.08f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.4f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.08f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false));
                                m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            bool    flag   = false;
                            int     value2 = 0;
                            int     num6   = 0;
                            float   s      = 0f;
                            Vector3 vector = Vector3.Zero;
                            MusketBlock.LoadState  loadState  = MusketBlock.GetLoadState(data);
                            BulletBlock.BulletType?bulletType = MusketBlock.GetBulletType(data);
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                switch (loadState)
                                {
                                case MusketBlock.LoadState.Empty:
                                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load gunpowder first", Color.White, blinking: true, playNotificationSound: false);
                                    break;

                                case MusketBlock.LoadState.Gunpowder:
                                case MusketBlock.LoadState.Wad:
                                    flag = true;
                                    componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No bullet, blind shot fired", Color.White, blinking: true, playNotificationSound: false);
                                    break;

                                case MusketBlock.LoadState.Loaded:
                                    flag = true;
                                    if (bulletType == BulletBlock.BulletType.Buckshot)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall));
                                        num6   = 8;
                                        vector = new Vector3(0.04f, 0.04f, 0.25f);
                                        s      = 80f;
                                    }
                                    else if (bulletType == BulletBlock.BulletType.BuckshotBall)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall));
                                        num6   = 1;
                                        vector = new Vector3(0.06f, 0.06f, 0f);
                                        s      = 60f;
                                    }
                                    else if (bulletType.HasValue)
                                    {
                                        value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, bulletType.Value));
                                        num6   = 1;
                                        s      = 120f;
                                    }
                                    break;
                                }
                            }
                            if (flag)
                            {
                                if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f)
                                {
                                    m_subsystemAudio.PlaySound("Audio/MusketMisfire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, autoDelay: true);
                                }
                                else
                                {
                                    Vector3 vector2 = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                    Vector3 vector3 = Vector3.Normalize(vector2 + aim.Direction * 10f - vector2);
                                    Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY));
                                    Vector3 v2      = Vector3.Normalize(Vector3.Cross(vector3, vector4));
                                    for (int i = 0; i < num6; i++)
                                    {
                                        Vector3    v3         = m_random.Float(0f - vector.X, vector.X) * vector4 + m_random.Float(0f - vector.Y, vector.Y) * v2 + m_random.Float(0f - vector.Z, vector.Z) * vector3;
                                        Projectile projectile = m_subsystemProjectiles.FireProjectile(value2, vector2, s * (vector3 + v3), Vector3.Zero, componentMiner.ComponentCreature);
                                        if (projectile != null)
                                        {
                                            projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear;
                                        }
                                    }
                                    m_subsystemAudio.PlaySound("Audio/MusketFire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 10f, autoDelay: true);
                                    m_subsystemParticles.AddParticleSystem(new GunSmokeParticleSystem(m_subsystemTerrain, vector2 + 0.3f * vector3, vector3));
                                    m_subsystemNoise.MakeNoise(vector2, 1f, 40f);
                                    componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-4f * vector3);
                                }
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetLoadState(Terrain.ExtractData(num2), MusketBlock.LoadState.Empty));
                                num3 = 1;
                            }
                            if (MusketBlock.GetHammerState(Terrain.ExtractData(num2)))
                            {
                                num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false));
                                m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                    if (num2 != slotValue)
                    {
                        inventory.RemoveSlotItems(activeSlotIndex, 1);
                        inventory.AddSlotItems(activeSlotIndex, num2, 1);
                    }
                    if (num3 > 0)
                    {
                        componentMiner.DamageActiveTool(num3);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 10
0
        public override bool Simulate(float dt)
        {
            dt = MathUtils.Clamp(dt, 0f, 0.1f);
            float num  = MathUtils.Pow(0.1f, 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.25f, 0.25f, 0.25f);
                        }
                        if (plane.Normal.Y != 0f)
                        {
                            particle.Velocity *= new Vector3(0.25f, -0.25f, 0.25f);
                        }
                        if (plane.Normal.Z != 0f)
                        {
                            particle.Velocity *= new Vector3(0.25f, 0.25f, -0.25f);
                        }
                    }
                    particle.Position    = vector;
                    particle.Velocity.Y += -9.81f * dt;
                    particle.Velocity   *= num;
                    particle.Color      *= MathUtils.Saturate(particle.TimeToLive);
                }
                else
                {
                    particle.IsActive = false;
                }
            }
            return(!flag);
        }
Ejemplo n.º 11
0
        public void HandleInput()
        {
            WidgetInput    input          = m_componentPlayer.GameWidget.Input;
            PlayerInput    playerInput    = m_componentPlayer.ComponentInput.PlayerInput;
            ComponentRider componentRider = m_componentPlayer.ComponentRider;

            if (m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled)
            {
                if (!m_keyboardHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Keyboard) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_keyboardHelpMessageShown = true;
                    DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (!m_gamepadHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Gamepads) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_gamepadHelpMessageShown = true;
                    DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                }
            }
            if (playerInput.KeyboardHelp)
            {
                if (m_keyboardHelpDialog == null)
                {
                    m_keyboardHelpDialog = new KeyboardHelpDialog();
                }
                if (m_keyboardHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_keyboardHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, m_keyboardHelpDialog);
                }
            }
            if (playerInput.GamepadHelp)
            {
                if (m_gamepadHelpDialog == null)
                {
                    m_gamepadHelpDialog = new GamepadHelpDialog();
                }
                if (m_gamepadHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_gamepadHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, m_gamepadHelpDialog);
                }
            }
            if (m_helpButtonWidget.IsClicked)
            {
                ScreensManager.SwitchScreen("Help");
            }
            if (playerInput.ToggleInventory || m_inventoryButtonWidget.IsClicked)
            {
                if (IsInventoryVisible())
                {
                    ModalPanelWidget = null;
                }
                else if (m_componentPlayer.ComponentMiner.Inventory is ComponentCreativeInventory)
                {
                    ModalPanelWidget = new CreativeInventoryWidget(m_componentPlayer.Entity);
                }
                else
                {
                    ModalPanelWidget = new FullInventoryWidget(m_componentPlayer.ComponentMiner.Inventory, m_componentPlayer.Entity.FindComponent <ComponentCraftingTable>(throwOnError: true));
                }
            }
            if (playerInput.ToggleClothing || m_clothingButtonWidget.IsClicked)
            {
                if (IsClothingVisible())
                {
                    ModalPanelWidget = null;
                }
                else
                {
                    ModalPanelWidget = new ClothingWidget(m_componentPlayer);
                }
            }
            if (m_sneakButtonWidget.IsClicked || playerInput.ToggleSneak)
            {
                bool isSneaking = m_componentPlayer.ComponentBody.IsSneaking;
                m_componentPlayer.ComponentBody.IsSneaking = !isSneaking;
                if (m_componentPlayer.ComponentBody.IsSneaking != isSneaking)
                {
                    if (m_componentPlayer.ComponentBody.IsSneaking)
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 4), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (componentRider != null && (m_mountButtonWidget.IsClicked || playerInput.ToggleMount))
            {
                bool flag = componentRider.Mount != null;
                if (flag)
                {
                    componentRider.StartDismounting();
                }
                else
                {
                    ComponentMount componentMount = componentRider.FindNearestMount();
                    if (componentMount != null)
                    {
                        componentRider.StartMounting(componentMount);
                    }
                }
                if (componentRider.Mount != null != flag)
                {
                    if (componentRider.Mount != null)
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 5), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 6), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if ((m_editItemButton.IsClicked || playerInput.EditItem) && m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue)
            {
                Point3 value     = m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.Value;
                int    cellValue = m_subsystemTerrain.Terrain.GetCellValue(value.X, value.Y, value.Z);
                int    contents  = Terrain.ExtractContents(cellValue);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditBlock(value.X, value.Y, value.Z, cellValue, m_componentPlayer); i++)
                {
                }
            }
            else if ((m_editItemButton.IsClicked || playerInput.EditItem) && IsActiveSlotEditable())
            {
                IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;
                if (inventory != null)
                {
                    int activeSlotIndex = inventory.ActiveSlotIndex;
                    int num             = Terrain.ExtractContents(inventory.GetSlotValue(activeSlotIndex));
                    if (BlocksManager.Blocks[num].IsEditable)
                    {
                        SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                        for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditInventoryItem(inventory, activeSlotIndex, m_componentPlayer); i++)
                        {
                        }
                    }
                }
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_creativeFlyButtonWidget.IsClicked || playerInput.ToggleCreativeFly) && componentRider.Mount == null)
            {
                bool isCreativeFlyEnabled = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
                m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled = !isCreativeFlyEnabled;
                if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled != isCreativeFlyEnabled)
                {
                    if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled)
                    {
                        m_componentPlayer.ComponentLocomotion.JumpOrder = 1f;
                        DisplaySmallMessage(LanguageControl.Get(fName, 7), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 8), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (!m_componentPlayer.ComponentInput.IsControlledByVr && (m_cameraButtonWidget.IsClicked || playerInput.SwitchCameraMode))
            {
                GameWidget gameWidget = m_componentPlayer.GameWidget;
                if (gameWidget.ActiveCamera.GetType() == typeof(FppCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <TppCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 9), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (gameWidget.ActiveCamera.GetType() == typeof(TppCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <OrbitCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 10), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (gameWidget.ActiveCamera.GetType() == typeof(OrbitCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <FixedCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 11), Color.White, blinking: false, playNotificationSound: false);
                }
                else
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <FppCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 12), Color.White, blinking: false, playNotificationSound: false);
                }
            }
            if (m_photoButtonWidget.IsClicked || playerInput.TakeScreenshot)
            {
                ScreenCaptureManager.CapturePhoto(delegate
                {
                    DisplaySmallMessage(LanguageControl.Get(fName, 13), Color.White, blinking: false, playNotificationSound: false);
                }, delegate
                {
                    DisplaySmallMessage(LanguageControl.Get(fName, 14), Color.White, blinking: false, playNotificationSound: false);
                });
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_lightningButtonWidget.IsClicked || playerInput.Lighting))
            {
                Matrix matrix = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
                base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true).ManualLightingStrike(m_componentPlayer.ComponentCreatureModel.EyePosition, matrix.Forward);
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_timeOfDayButtonWidget.IsClicked || playerInput.TimeOfDay))
            {
                float num2  = MathUtils.Remainder(0.25f, 1f);
                float num3  = MathUtils.Remainder(0.5f, 1f);
                float num4  = MathUtils.Remainder(0.75f, 1f);
                float num5  = MathUtils.Remainder(1f, 1f);
                float num6  = MathUtils.Remainder(num2 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num7  = MathUtils.Remainder(num3 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num8  = MathUtils.Remainder(num4 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num9  = MathUtils.Remainder(num5 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num10 = MathUtils.Min(num6, num7, num8, num9);
                if (num6 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num6;
                    DisplaySmallMessage(LanguageControl.Get(fName, 15), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num7 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num7;
                    DisplaySmallMessage(LanguageControl.Get(fName, 16), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num8 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num8;
                    DisplaySmallMessage(LanguageControl.Get(fName, 17), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num9 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num9;
                    DisplaySmallMessage(LanguageControl.Get(fName, 18), Color.White, blinking: false, playNotificationSound: false);
                }
            }
            if (ModalPanelWidget != null)
            {
                if (input.Cancel || input.Back || m_backButtonWidget.IsClicked)
                {
                    ModalPanelWidget = null;
                }
            }
            else if (input.Back || m_backButtonWidget.IsClicked)
            {
                DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new GameMenuDialog(m_componentPlayer));
            }
        }
Ejemplo n.º 12
0
        public void DestroyCell(int toolLevel, int x, int y, int z, int newValue, bool noDrop, bool noParticleSystem)
        {
            int   cellValue = Terrain.GetCellValue(x, y, z);
            int   num       = Terrain.ExtractContents(cellValue);
            Block block     = BlocksManager.Blocks[num];

            if (num != 0)
            {
                bool showDebris = true;
                if (!noDrop)
                {
                    m_dropValues.Clear();
                    block.GetDropValues(this, cellValue, newValue, toolLevel, m_dropValues, out showDebris);
                    for (int i = 0; i < m_dropValues.Count; i++)
                    {
                        BlockDropValue dropValue = m_dropValues[i];
                        if (dropValue.Count > 0)
                        {
                            SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(dropValue.Value));
                            for (int j = 0; j < blockBehaviors.Length; j++)
                            {
                                blockBehaviors[j].OnItemHarvested(x, y, z, cellValue, ref dropValue, ref newValue);
                            }
                            if (dropValue.Count > 0 && Terrain.ExtractContents(dropValue.Value) != 0)
                            {
                                Vector3 position = new Vector3(x, y, z) + new Vector3(0.5f);
                                m_subsystemPickables.AddPickable(dropValue.Value, dropValue.Count, position, null, null);
                            }
                        }
                    }
                }
                if (showDebris && !noParticleSystem && m_subsystemViews.CalculateDistanceFromNearestView(new Vector3(x, y, z)) < 16f)
                {
                    m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(this, new Vector3((float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f), cellValue, 1f));
                }
            }
            ChangeCell(x, y, z, newValue);
        }
Ejemplo n.º 13
0
        public TerrainRaycastResult?Raycast(Vector3 start, Vector3 end, bool useInteractionBoxes, bool skipAirBlocks, Func <int, float, bool> action)
        {
            float num = Vector3.Distance(start, end);

            if (num > 1000f)
            {
                Log.Warning("Terrain raycast too long, trimming.");
                end = start + 1000f * Vector3.Normalize(end - start);
            }
            Ray3  ray   = new Ray3(start, Vector3.Normalize(end - start));
            float x     = start.X;
            float y     = start.Y;
            float z     = start.Z;
            float x2    = end.X;
            float y2    = end.Y;
            float z2    = end.Z;
            int   num2  = Terrain.ToCell(x);
            int   num3  = Terrain.ToCell(y);
            int   num4  = Terrain.ToCell(z);
            int   num5  = Terrain.ToCell(x2);
            int   num6  = Terrain.ToCell(y2);
            int   num7  = Terrain.ToCell(z2);
            int   num8  = (x < x2) ? 1 : ((x > x2) ? (-1) : 0);
            int   num9  = (y < y2) ? 1 : ((y > y2) ? (-1) : 0);
            int   num10 = (z < z2) ? 1 : ((z > z2) ? (-1) : 0);
            float num11 = MathUtils.Floor(x);
            float num12 = num11 + 1f;
            float num13 = ((x > x2) ? (x - num11) : (num12 - x)) / Math.Abs(x2 - x);
            float num14 = MathUtils.Floor(y);
            float num15 = num14 + 1f;
            float num16 = ((y > y2) ? (y - num14) : (num15 - y)) / Math.Abs(y2 - y);
            float num17 = MathUtils.Floor(z);
            float num18 = num17 + 1f;
            float num19 = ((z > z2) ? (z - num17) : (num18 - z)) / Math.Abs(z2 - z);
            float num20 = 1f / Math.Abs(x2 - x);
            float num21 = 1f / Math.Abs(y2 - y);
            float num22 = 1f / Math.Abs(z2 - z);

            while (true)
            {
                BoundingBox boundingBox       = default(BoundingBox);
                int         collisionBoxIndex = 0;
                float?      num23             = null;
                int         cellValue         = Terrain.GetCellValue(num2, num3, num4);
                int         num24             = Terrain.ExtractContents(cellValue);
                if (num24 != 0 || !skipAirBlocks)
                {
                    Ray3        ray2 = new Ray3(ray.Position - new Vector3(num2, num3, num4), ray.Direction);
                    int         nearestBoxIndex;
                    BoundingBox nearestBox;
                    float?      num25 = BlocksManager.Blocks[num24].Raycast(ray2, this, cellValue, useInteractionBoxes, out nearestBoxIndex, out nearestBox);
                    if (num25.HasValue && (!num23.HasValue || num25.Value < num23.Value))
                    {
                        num23             = num25;
                        collisionBoxIndex = nearestBoxIndex;
                        boundingBox       = nearestBox;
                    }
                }
                if (num23.HasValue && num23.Value <= num && (action == null || action(cellValue, num23.Value)))
                {
                    int     face   = 0;
                    Vector3 vector = start - new Vector3(num2, num3, num4) + num23.Value * ray.Direction;
                    float   num26  = float.MaxValue;
                    float   num27  = MathUtils.Abs(vector.X - boundingBox.Min.X);
                    if (num27 < num26)
                    {
                        num26 = num27;
                        face  = 3;
                    }
                    num27 = MathUtils.Abs(vector.X - boundingBox.Max.X);
                    if (num27 < num26)
                    {
                        num26 = num27;
                        face  = 1;
                    }
                    num27 = MathUtils.Abs(vector.Y - boundingBox.Min.Y);
                    if (num27 < num26)
                    {
                        num26 = num27;
                        face  = 5;
                    }
                    num27 = MathUtils.Abs(vector.Y - boundingBox.Max.Y);
                    if (num27 < num26)
                    {
                        num26 = num27;
                        face  = 4;
                    }
                    num27 = MathUtils.Abs(vector.Z - boundingBox.Min.Z);
                    if (num27 < num26)
                    {
                        num26 = num27;
                        face  = 2;
                    }
                    num27 = MathUtils.Abs(vector.Z - boundingBox.Max.Z);
                    if (num27 < num26)
                    {
                        num26 = num27;
                        face  = 0;
                    }
                    TerrainRaycastResult value = default(TerrainRaycastResult);
                    value.Ray      = ray;
                    value.Value    = cellValue;
                    value.CellFace = new CellFace
                    {
                        X    = num2,
                        Y    = num3,
                        Z    = num4,
                        Face = face
                    };
                    value.CollisionBoxIndex = collisionBoxIndex;
                    value.Distance          = num23.Value;
                    return(value);
                }
                if (num13 <= num16 && num13 <= num19)
                {
                    if (num2 == num5)
                    {
                        break;
                    }
                    num13 += num20;
                    num2  += num8;
                }
                else if (num16 <= num13 && num16 <= num19)
                {
                    if (num3 == num6)
                    {
                        break;
                    }
                    num16 += num21;
                    num3  += num9;
                }
                else
                {
                    if (num4 == num7)
                    {
                        break;
                    }
                    num19 += num22;
                    num4  += num10;
                }
            }
            return(null);
        }
Ejemplo n.º 14
0
        public override bool Simulate(float dt)
        {
            dt = MathUtils.Clamp(dt, 0f, 0.1f);
            float num  = MathUtils.Pow(0.2f, dt);
            float num2 = MathUtils.Pow(1E-07f, 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)
                    {
                        particle.Velocity          = Vector3.Zero;
                        particle.Position          = terrainRaycastResult.Value.HitPoint(0.03f);
                        particle.HighDampingFactor = m_random.Float(0.5f, 1f);
                        if (terrainRaycastResult.Value.CellFace.Face >= 4)
                        {
                            particle.NoGravity = true;
                        }
                    }
                    else
                    {
                        particle.Position = vector;
                    }
                    if (!particle.NoGravity)
                    {
                        particle.Velocity.Y += -9.81f * dt;
                    }
                    particle.Velocity *= ((particle.HighDampingFactor > 0f) ? (num2 * particle.HighDampingFactor) : num);
                    particle.Color     = m_color * MathUtils.Saturate(1.5f * particle.TimeToLive * particle.Alpha);
                }
                else
                {
                    particle.IsActive = false;
                }
            }
            return(!flag);
        }
Ejemplo n.º 15
0
        public Dictionary <string, string> GetBlockProperties(int value)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            int   num   = Terrain.ExtractContents(value);
            Block block = BlocksManager.Blocks[num];

            if (block.DefaultEmittedLightAmount > 0)
            {
                dictionary.Add(LanguageControl.Get(fName, 1), block.DefaultEmittedLightAmount.ToString());
            }
            if (block.FuelFireDuration > 0f)
            {
                dictionary.Add(LanguageControl.Get(fName, 2), block.FuelFireDuration.ToString());
            }
            dictionary.Add(LanguageControl.Get(fName, 3), (block.MaxStacking > 1) ? string.Format(LanguageControl.Get(fName, 4), block.MaxStacking.ToString()) : LanguageControl.Get("Usual", "no"));
            dictionary.Add(LanguageControl.Get(fName, 5), (block.FireDuration > 0f) ? LanguageControl.Get("Usual", "yes") : LanguageControl.Get("Usual", "no"));
            if (block.GetNutritionalValue(value) > 0f)
            {
                dictionary.Add(LanguageControl.Get(fName, 6), block.GetNutritionalValue(value).ToString());
            }
            if (block.GetRotPeriod(value) > 0)
            {
                dictionary.Add(LanguageControl.Get(fName, 7), string.Format(LanguageControl.Get(fName, 25), $"{(2 * block.GetRotPeriod(value) * 60f / 1200f):0.0}"));
            }
            if (block.DigMethod != 0)
            {
                dictionary.Add(LanguageControl.Get(fName, 8), LanguageControl.Get("DigMethod", block.DigMethod.ToString()));
                dictionary.Add(LanguageControl.Get(fName, 9), block.DigResilience.ToString());
            }
            if (block.ExplosionResilience > 0f)
            {
                dictionary.Add(LanguageControl.Get(fName, 10), block.ExplosionResilience.ToString());
            }
            if (block.GetExplosionPressure(value) > 0f)
            {
                dictionary.Add(LanguageControl.Get(fName, 11), block.GetExplosionPressure(value).ToString());
            }
            bool flag = false;

            if (block.GetMeleePower(value) > 1f)
            {
                dictionary.Add(LanguageControl.Get(fName, 12), block.GetMeleePower(value).ToString());
                flag = true;
            }
            if (block.GetMeleePower(value) > 1f)
            {
                dictionary.Add(LanguageControl.Get(fName, 13), $"{100f * block.GetMeleeHitProbability(value):0}%");
                flag = true;
            }
            if (block.GetProjectilePower(value) > 1f)
            {
                dictionary.Add(LanguageControl.Get(fName, 14), block.GetProjectilePower(value).ToString());
                flag = true;
            }
            if (block.ShovelPower > 1f)
            {
                dictionary.Add(LanguageControl.Get(fName, 15), block.ShovelPower.ToString());
                flag = true;
            }
            if (block.HackPower > 1f)
            {
                dictionary.Add(LanguageControl.Get(fName, 16), block.HackPower.ToString());
                flag = true;
            }
            if (block.QuarryPower > 1f)
            {
                dictionary.Add(LanguageControl.Get(fName, 17), block.QuarryPower.ToString());
                flag = true;
            }
            if (flag && block.Durability > 0)
            {
                dictionary.Add(LanguageControl.Get(fName, 18), block.Durability.ToString());
            }
            if (block.DefaultExperienceCount > 0f)
            {
                dictionary.Add(LanguageControl.Get(fName, 19), block.DefaultExperienceCount.ToString());
            }
            if (block is ClothingBlock)
            {
                ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                dictionary.Add(LanguageControl.Get(fName, 20), clothingData.CanBeDyed ? LanguageControl.Get("Usual", "yes") : LanguageControl.Get("Usual", "no"));
                dictionary.Add(LanguageControl.Get(fName, 21), $"{(int)(clothingData.ArmorProtection * 100f)}%");
                dictionary.Add(LanguageControl.Get(fName, 22), clothingData.Sturdiness.ToString());
                dictionary.Add(LanguageControl.Get(fName, 23), $"{clothingData.Insulation:0.0} clo");
                dictionary.Add(LanguageControl.Get(fName, 24), $"{clothingData.MovementSpeedFactor * 100f:0}%");
            }
            return(dictionary);
        }
        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 == 200 && slotCount > 0)
                    {
                        int draw = CrossbowBlock.GetDraw(data);
                        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.01f : 0.03f) + 0.15f * MathUtils.Saturate((num2 - 2.5f) / 6f)) * 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 >= 10f)
                            {
                                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.22f, 0.15f, 0.1f);
                                componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f);
                            }
                            componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder       = 1.3f;
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder   = new Vector3(-0.08f, -0.1f, 0.07f);
                            componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.55f, 0f, 0f);
                            break;
                        }

                        case AimState.Cancelled:
                            m_aimStartTimes.Remove(componentMiner);
                            break;

                        case AimState.Completed:
                        {
                            ArrowBlock.ArrowType?arrowType = CrossbowBlock.GetArrowType(data);
                            if (draw != 15)
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Draw the crossbow first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            else if (!arrowType.HasValue)
                            {
                                componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load a bolt first", Color.White, blinking: true, playNotificationSound: false);
                            }
                            else
                            {
                                Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f;
                                Vector3 v2     = Vector3.Normalize(vector + aim.Direction * 10f - vector);
                                int     value2 = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value));
                                float   s      = 38f;
                                if (m_subsystemProjectiles.FireProjectile(value2, vector, s * v2, Vector3.Zero, componentMiner.ComponentCreature) != null)
                                {
                                    data = CrossbowBlock.SetArrowType(data, null);
                                    m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0.05f);
                                }
                            }
                            inventory.RemoveSlotItems(activeSlotIndex, 1);
                            int value3 = Terrain.MakeBlockValue(num, 0, CrossbowBlock.SetDraw(data, 0));
                            inventory.AddSlotItems(activeSlotIndex, value3, 1);
                            if (draw > 0)
                            {
                                componentMiner.DamageActiveTool(1);
                                m_subsystemAudio.PlaySound("Audio/CrossbowBoing", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0f);
                            }
                            m_aimStartTimes.Remove(componentMiner);
                            break;
                        }
                        }
                    }
                }
            }
            return(false);
        }