Exemplo n.º 1
0
 public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
 {
     showDebris = true;
     dropValues.Add(new BlockDropValue {
         Value = Terrain.ReplaceLight(oldValue, 0), Count = 1
     });
 }
Exemplo n.º 2
0
 public void OnItemHarvested(int x, int y, int z, int blockValue, ref BlockDropValue dropValue, ref int newBlockValue)
 {
     if (RemainCount <= 0)
     {
         dropValue.Value = Terrain.ReplaceData(Terrain.ReplaceLight(blockValue, 0), Terrain.ExtractData(blockValue) | 16384);
     }
 }
Exemplo n.º 3
0
 public override void GetDropValues(SubsystemTerrain subsystemTerrain, int oldValue, int newValue, int toolLevel, List <BlockDropValue> dropValues, out bool showDebris)
 {
     showDebris = DestructionDebrisScale > 0f;
     dropValues.Add(new BlockDropValue
     {
         Value = Terrain.ReplaceLight(Terrain.ReplaceData(oldValue, SetDirection(SetHeatLevel(Terrain.ExtractData(oldValue), 0), 0)), 0),
         Count = 1
     });
 }
Exemplo n.º 4
0
        public void ChangeCell(int x, int y, int z, int value, bool updateModificationCounter = true)
        {
            if (!Terrain.IsCellValid(x, y, z))
            {
                return;
            }
            int cellValueFast = Terrain.GetCellValueFast(x, y, z);

            value         = Terrain.ReplaceLight(value, 0);
            cellValueFast = Terrain.ReplaceLight(cellValueFast, 0);
            if (value == cellValueFast)
            {
                return;
            }
            Terrain.SetCellValueFast(x, y, z, value);
            TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z);

            if (chunkAtCell != null)
            {
                if (updateModificationCounter)
                {
                    chunkAtCell.ModificationCounter++;
                }
                TerrainUpdater.DowngradeChunkNeighborhoodState(chunkAtCell.Coords, 1, TerrainChunkState.InvalidLight, forceGeometryRegeneration: false);
            }
            m_modifiedCells[new Point3(x, y, z)] = true;
            int num  = Terrain.ExtractContents(cellValueFast);
            int num2 = Terrain.ExtractContents(value);

            if (num2 != num)
            {
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                for (int i = 0; i < blockBehaviors.Length; i++)
                {
                    blockBehaviors[i].OnBlockRemoved(cellValueFast, value, x, y, z);
                }
                SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num2);
                for (int j = 0; j < blockBehaviors2.Length; j++)
                {
                    blockBehaviors2[j].OnBlockAdded(value, cellValueFast, x, y, z);
                }
            }
            else
            {
                SubsystemBlockBehavior[] blockBehaviors3 = m_subsystemBlockBehaviors.GetBlockBehaviors(num2);
                for (int k = 0; k < blockBehaviors3.Length; k++)
                {
                    blockBehaviors3[k].OnBlockModified(value, cellValueFast, x, y, z);
                }
            }
        }
Exemplo n.º 5
0
 public void Update(float dt)
 {
     if (m_subsystemTime.PeriodicGameTimeEvent(30.0, 0.0))
     {
         foreach (KeyValuePair <Point3, Replacement> item in m_toReplace)
         {
             Point3 key = item.Key;
             if (Terrain.ReplaceLight(base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z), 0) == Terrain.ReplaceLight(item.Value.RequiredValue, 0))
             {
                 base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, item.Value.Value);
             }
         }
         m_toReplace.Clear();
     }
 }
Exemplo n.º 6
0
        public override void Simulate(ref int voltage)
        {
            int level;

            if (voltage < 20)
            {
                level = 0;
            }
            else
            {
                level    = voltage < 20 ? 0 : (voltage - 20) / 40;
                voltage -= level * 40 + 20;
            }
            if (level == Level)
            {
                return;
            }
            var p = Point;

            //SubsystemTerrain.ChangeCell(p.X, p.Y, p.Z, , true);
            var chunk = Utils.Terrain.GetChunkAtCell(p.X, p.Z);

            if (chunk != null)
            {
                if (chunk.State < TerrainChunkState.InvalidLight)
                {
                    Level = -1;
                }
                else
                {
                    p.X &= 15; p.Z &= 15;
                    int i;
                    for (i = 1; i <= level && chunk.GetCellContentsFast(p.X, p.Y + i, p.Z) == 0; i++)
                    {
                        chunk.SetCellValueFast(p.X, p.Y + i, p.Z, RottenMeatBlock.Index | 2 << 4 << 14);
                    }
                    for (; i < 8 && p.Y < 127; i++)
                    {
                        if (Terrain.ReplaceLight(chunk.GetCellValueFast(p.X, ++p.Y, p.Z), 0) == (RottenMeatBlock.Index | 2 << 4 << 14))
                        {
                            chunk.SetCellValueFast(p.X, p.Y, p.Z, 0);
                        }
                    }
                    Level = level;
                }
            }
        }
Exemplo n.º 7
0
        public override bool OnUse(Vector3 start, Vector3 direction, ComponentMiner componentMiner)
        {
            int               activeBlockValue = componentMiner.ActiveBlockValue;
            var               result           = componentMiner.PickTerrainForDigging(start, direction);
            Entity            entity;
            Vector3           position;
            BodyRaycastResult?body;

            if (activeBlockValue == ItemBlock.IdTable["Wrench"])
            {
                body = componentMiner.PickBody(start, direction);
                Matrix matrix = componentMiner.ComponentCreature.ComponentBody.Matrix;
                position = matrix.Translation + 1f * matrix.Forward + Vector3.UnitY;
                if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
                {
                    entity = body.Value.ComponentBody.Entity;
                    if (entity.FindComponent <ComponentTrain>() != null || entity.FindComponent <ComponentBoatI>() != null)
                    {
                        for (var i = entity.FindComponents <IInventory>().GetEnumerator(); i.MoveNext();)
                        {
                            i.Current.DropAllItems(position);
                        }
                        Utils.SubsystemPickables.AddPickable(ItemBlock.IdTable[entity.ValuesDictionary.DatabaseObject.Name.Length == 8 ? "Minecart" : entity.ValuesDictionary.DatabaseObject.Name], 1, position, null, null);
                        Project.RemoveEntity(entity, true);
                        return(true);
                    }
                }
            }
            else if ((activeBlockValue == ItemBlock.IdTable["Train"] || activeBlockValue == ItemBlock.IdTable["Minecart"]) && result.HasValue && Terrain.ExtractContents(result.Value.Value) == RailBlock.Index)
            {
                position = new Vector3(result.Value.CellFace.Point) + new Vector3(0.5f);
                entity   = DatabaseManager.CreateEntity(Project, activeBlockValue == ItemBlock.IdTable["Minecart"] ? "Carriage" : "Train", true);

                var rotation = componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation.ToForwardVector();
                entity.FindComponent <ComponentTrain>(true).SetDirection(RailBlock.IsDirectionX(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))
                                        ? rotation.Z < 0 ? 0 : 2
                                        : rotation.X < 0 ? 1 : 3);
                entity.FindComponent <ComponentBody>(true).Position       = position;
                entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0f;
                Project.AddEntity(entity);
                var componentTrain = entity.FindComponent <ComponentTrain>(true);
                if (activeBlockValue == ItemBlock.IdTable["Minecart"])
                {
                    componentTrain.Update(0);
                    var train = componentTrain.FindNearestTrain();
                    if (train != null)
                    {
                        componentTrain.ParentBody = train;
                    }
                }
                componentMiner.RemoveActiveTool(1);
                Utils.SubsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
                return(true);
            }

            /*else if (activeBlockValue == ItemBlock.IdTable["Minecart"])
             * {
             *      entity = DatabaseManager.CreateEntity(Project, "Carriage", true);
             *      body = componentMiner.PickBody(start, direction);
             *      if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
             *      {
             *              body = componentMiner.PickBody(start, direction);
             *              var componentTrain = entity.FindComponent<ComponentTrain>(true);
             *              var train = body.Value.ComponentBody.Entity.FindComponent<ComponentTrain>();
             *              if (train != null)
             *                      componentTrain.ParentBody = train;
             *      }
             *      else if (result.HasValue)
             *              position = result.Value.RaycastStart + Vector3.Normalize(result.Value.RaycastEnd - result.Value.RaycastStart) * result.Value.Distance; ;
             *      var rotation = componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation.ToForwardVector();
             *      entity.FindComponent<ComponentTrain>(true).SetDirection(RailBlock.IsDirectionX(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))
             *              ? rotation.Z < 0 ? 0 : 2
             *              : rotation.X < 0 ? 1 : 3);
             *      goto put;
             * }*/
            else if (activeBlockValue == ItemBlock.IdTable["基因查看器"])
            {
                body = componentMiner.PickBody(start, direction);
                if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
                {
                    var cv = body.Value.ComponentBody.Entity.FindComponent <ComponentVariant>();
                    if (cv != null)
                    {
                        DialogsManager.ShowDialog(componentMiner.ComponentPlayer?.View.GameWidget, new MessageDialog("Result", cv.Genome.ToString(), "OK", null, null));
                    }
                    return(true);
                }
            }
            else if (result.HasValue)
            {
                position = result.Value.RaycastStart + Vector3.Normalize(result.Value.RaycastEnd - result.Value.RaycastStart) * result.Value.Distance;
                if (activeBlockValue == ItemBlock.IdTable["SteamBoat"])
                {
                    entity = DatabaseManager.CreateEntity(Project, "SteamBoat", true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    goto put;
                }

                /*else if (activeBlockValue == ItemBlock.IdTable["Minecart"])
                 * {
                 *      entity = DatabaseManager.CreateEntity(Project, "Carriage", true);
                 *      entity.FindComponent<ComponentFrame>(true).Position = position;
                 *      entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
                 *      var componentTrain = entity.FindComponent<ComponentTrain>(true);
                 *      var componentMount = componentTrain.FindNearestTrain();
                 *      if (componentMount != null)
                 *              componentTrain.ParentBody = componentMount.m_componentBody;
                 *      goto put;
                 * }*/
                else if (activeBlockValue == ItemBlock.IdTable["Airship"])
                {
                    entity = DatabaseManager.CreateEntity(Project, "Airship", true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    goto put;
                }
                else if (BlocksManager.Blocks[Terrain.ExtractContents(activeBlockValue)] is ItemBlock itemblock && itemblock.GetItem(ref activeBlockValue) is Mine mine)
                {
                    entity = DatabaseManager.CreateEntity(Project, "Mine", new ValuesDictionary
                    {
                        { "Mine", new ValuesDictionary {
                              { "Type", mine.MineType }
                          } }
                    }, true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    var componentMine = entity.FindComponent <ComponentMine>(true);
                    componentMine.ExplosionPressure = mine.ExplosionPressure;
                    componentMine.Delay             = mine.Delay;
                    goto put;
                }
            }
            IInventory           inventory = componentMiner.Inventory;
            TerrainRaycastResult?result2;

            if (Terrain.ExtractContents(activeBlockValue) == 90)
            {
                result2 = componentMiner.PickTerrainForGathering(start, direction);
                if (result2.HasValue)
                {
                    CellFace cellFace  = result2.Value.CellFace;
                    int      cellValue = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z), 0);
                    if (cellValue != (RottenMeatBlock.Index | 1 << 4 << 14))
                    {
                        return(false);
                    }
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, RottenMeatBlock.Index | 2 << 4 << 14, 1);
                    }
                    Utils.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, false, false);
                    return(true);
                }
            }
            if (activeBlockValue == (RottenMeatBlock.Index | 2 << 4 << 14))
            {
                result2 = componentMiner.PickTerrainForInteraction(start, direction);
                if (result2.HasValue && componentMiner.Place(result2.Value, RottenMeatBlock.Index | 1 << 4 << 14))
                {
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, Terrain.ReplaceContents(activeBlockValue, 90), 1);
                    }
                    return(true);
                }
            }
            return(false);

put:
            entity.FindComponent <ComponentBody>(true).Position       = position;
            entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0f;
            Project.AddEntity(entity);
            componentMiner.RemoveActiveTool(1);
            Utils.SubsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
            return(true);
        }
Exemplo n.º 8
0
        protected void Driller(Point3 point, int face)
        {
            Vector3 vector    = CellFace.FaceToVector3(face);
            int     x         = point.X;
            int     y         = point.Y;
            int     z         = point.Z;
            int     slotValue = GetSlotValue(8);

            if (!(ComponentEngine.IsPowered(Utils.Terrain, x, y, z) || Utils.SubsystemGameInfo.WorldSettings.GameMode == 0) || BlocksManager.Blocks[Terrain.ExtractContents(slotValue)].Durability <= 0)
            {
                return;
            }
            int[] array = new[]
            {
                0,
                0,
                1,
                1,
                1,
                0,
                -1,
                -1,
                -1
            }, array2 = new[]
            {
                0,
                -1,
                -1,
                0,
                1,
                1,
                1,
                0,
                -1
            };
            int     num2 = 0;
            Vector3 v    = Vector3.Zero;

            for (int l = 1; l < 19; l++)
            {
                for (int m = 0; m < 9; m++)
                {
                    x = point.X - (int)vector.X * l;
                    y = point.Y - (int)vector.Y * l;
                    z = point.Z - (int)vector.Z * l;
                    if (vector.X != 0f)
                    {
                        y = point.Y + array[m];
                        z = point.Z + array2[m];
                        v = new Vector3(0f, array[m] / (float)l, array2[m] / (float)l);
                    }
                    if (vector.Y != 0f)
                    {
                        x = point.X + array[m];
                        z = point.Z + array2[m];
                        v = new Vector3(array[m] / (float)l, 0f, array2[m] / (float)l);
                    }
                    if (vector.Z != 0f)
                    {
                        x = point.X + array[m];
                        y = point.Y + array2[m];
                        v = new Vector3(array[m] / (float)l, array2[m] / (float)l, 0f);
                    }
                    int   cellValue = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(x, y, z), 0);
                    Block block     = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)];
                    if (num2 == 0 && block.BlockIndex == 92)
                    {
                        num2 = 9;
                    }
                    if (block.IsPlaceable && !block.IsDiggingTransparent && !block.DefaultIsInteractive)
                    {
                        Utils.SubsystemTerrain.ChangeCell(x, y, z, 0, true);
                        Utils.SubsystemProjectiles.FireProjectile(cellValue, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.25f * vector, 60f * (vector - v), Vector3.Zero, null);
                        RemoveSlotItems(8, 1);
                        AddSlotItems(8, BlocksManager.DamageItem(slotValue, 1 + num2), 1);
                        return;
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void Update(float dt)
        {
            Point3 coordinates = m_componentBlockEntity.Coordinates;

            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                result[0] = m_matchedIngredients[7];
                result[1] = m_matchedIngredients[8];
                result[2] = m_matchedIngredients[9];
                bool flag = FindSmeltingRecipe(5f);
                if (result[0] != m_matchedIngredients[7] || result[1] != m_matchedIngredients[8] || result[2] != m_matchedIngredients[9])
                {
                    SmeltingProgress = 0f;
                    m_time           = 0;
                }
                m_smeltingRecipe2 = flag;
                if (flag != m_smeltingRecipe)
                {
                    m_smeltingRecipe = flag;
                    SmeltingProgress = 0f;
                    m_time           = 0;
                }
            }
            if (m_smeltingRecipe2 && Utils.SubsystemTime.PeriodicGameTimeEvent(0.2, 0.0))
            {
                int num = 1;
                int num2 = 0;
                var point = CellFace.FaceToPoint3(FourDirectionalBlock.GetDirection(Utils.Terrain.GetCellValue(coordinates.X, coordinates.Y, coordinates.Z)));
                int num3 = coordinates.X - point.X;
                int num4 = coordinates.Y - point.Y;
                int num5 = coordinates.Z - point.Z, v;
                for (int i = -1; i < 2; i++)
                {
                    for (int j = -1; j < 3; j++)
                    {
                        for (int k = -1; k < 2; k++)
                        {
                            int cellValue     = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(num3 + i, num4 + j, num5 + k), 0);
                            int cellContents2 = Terrain.ExtractContents(cellValue);
                            if (j == 1 && cellValue != (MetalBlock.Index | 96 << 14))
                            {
                                num = 0;
                                break;
                            }
                            if (i * i + k * k == 1 && j == 0 && cellContents2 == 0 && ((v = Utils.Terrain.GetCellValue(num3 + 2 * i, num4 + j, num5 + 2 * k)) != (BlastBlowerBlock.Index | FurnaceNBlock.SetHeatLevel(Terrain.ExtractData(v), 1) << 14)) && (num3 + i != coordinates.X || num5 + k != coordinates.Z))
                            {
                                num = 0;
                                break;
                            }
                            if (i * i + k * k == 1 && j == 0 && cellContents2 == 0)
                            {
                                num2++;
                            }
                            if (i * i + k * k == 1 && j == 0 && cellContents2 != 0 && cellValue != (MetalBlock.Index | 96 << 14) && (num3 + i != coordinates.X || num5 + k != coordinates.Z))
                            {
                                num = 0;
                                break;
                            }
                            if (i * i + k * k == 2 && j == 0 && cellValue != (MetalBlock.Index | 96 << 14))
                            {
                                num = 0;
                                break;
                            }
                            if (j < 0 && cellValue != (MetalBlock.Index | 64 << 14))
                            {
                                num = 0;
                                break;
                            }
                        }
                    }
                }
                if (num == 0 || num2 == 0)
                {
                    m_smeltingRecipe = false;
                }
                if (num == 1 && num2 >= 2 && !m_smeltingRecipe)
                {
                    m_smeltingRecipe = m_smeltingRecipe2;
                }
            }

            if (!m_smeltingRecipe)
            {
                HeatLevel           = 0f;
                m_fireTimeRemaining = 0f;
                SmeltingProgress    = 0f;
            }
            if (m_smeltingRecipe && m_fireTimeRemaining <= 0f)
            {
                HeatLevel = 5f;
            }
            if (m_smeltingRecipe)
            {
                SmeltingProgress = MathUtils.Min(SmeltingProgress + 0.1f * dt, 1f);
                if (SmeltingProgress >= 1f)
                {
                    int[] array = new int[]
                    {
                        IronIngotBlock.Index,
                        ItemBlock.IdTable["ScrapIron"],
                        ItemBlock.IdTable["AluminumOrePowder"],
                        ItemBlock.IdTable["ChromiumOrePowder"],
                        ItemBlock.IdTable["CokeCoalPowder"]
                    };
                    for (int l = 0; l < 5; l++)
                    {
                        if (m_matchedIngredients[l] > 0)
                        {
                            int b = array[l];
                            for (int m = 0; m < m_furnaceSize; m++)
                            {
                                if (m_slots[m].Count > 0 && GetSlotValue(m) == b)
                                {
                                    if (m_slots[m].Count >= m_matchedIngredients[l])
                                    {
                                        m_slots[m].Count       -= m_matchedIngredients[l];
                                        m_matchedIngredients[l] = 0;
                                    }
                                    else
                                    {
                                        m_matchedIngredients[l] -= m_slots[m].Count;
                                        m_slots[m].Count         = 0;
                                    }
                                    if (m_matchedIngredients[l] == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (m_matchedIngredients[5] >= 1)
                    {
                        m_slots[ResultSlotIndex].Value  = ItemBlock.IdTable["SteelIngot"];
                        m_slots[ResultSlotIndex].Count += m_matchedIngredients[5];
                    }
                    if (m_matchedIngredients[6] >= 1)
                    {
                        m_slots[ResultSlotIndex].Value  = IronIngotBlock.Index;
                        m_slots[ResultSlotIndex].Count += m_matchedIngredients[6];
                    }
                    if (m_matchedIngredients[7] >= 1)
                    {
                        m_slots[ResultSlotIndex].Value  = ItemBlock.IdTable["FeAlCrAlloyIngot"];
                        m_slots[ResultSlotIndex].Count += m_matchedIngredients[7];
                    }
                    m_smeltingRecipe       = false;
                    SmeltingProgress       = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
        }
Exemplo n.º 10
0
        protected new void Driller(Point3 point, int face)
        {
            Vector3 vector = Vector3.UnitY;
            int     x      = point.X;
            int     y      = point.Y;
            int     z      = point.Z;
            int     num    = ComponentEngine.IsPowered(Utils.Terrain, x, y, z) ? 1 : 0;

            if (num != 0)
            {
                int num2 = 0;
                int l;
                for (l = 4; 3 < l && l < 8; l++)
                {
                    num2 += GetSlotCount(l);
                }
                int num3 = 0;
                int num4 = 0;
                for (int m = 0; m < 4; m++)
                {
                    if (GetSlotCount(l) == 0)
                    {
                        num3 = 0;
                        num4 = 1;
                        break;
                    }
                    num4 += BlocksManager.Blocks[Terrain.ExtractContents(GetSlotValue(m))].MaxStacking;
                    num3 += GetSlotCount(m);
                }
                int slotValue = base.GetSlotValue(8);
                if (num2 != 0 && num4 > num3 && slotValue != 0 && BlocksManager.Blocks[Terrain.ExtractContents(slotValue)].Durability > 0)
                {
                    int[] array = new int[25]
                    {
                        0,
                        0,
                        1,
                        1,
                        1,
                        0,
                        -1,
                        -1,
                        -1,
                        -1,
                        0,
                        1,
                        2,
                        2,
                        2,
                        2,
                        2,
                        1,
                        0,
                        -1,
                        -2,
                        -2,
                        -2,
                        -2,
                        -2
                    };
                    int[] array2 = new int[25]
                    {
                        0,
                        -1,
                        -1,
                        0,
                        1,
                        1,
                        1,
                        0,
                        -1,
                        -2,
                        -2,
                        -2,
                        -2,
                        -1,
                        0,
                        1,
                        2,
                        2,
                        2,
                        2,
                        2,
                        1,
                        0,
                        -1,
                        -2
                    };
                    for (int n = 1; n < 8; n++)
                    {
                        for (int num5 = 0; num5 < 25; num5++)
                        {
                            x = point.X - (int)vector.X * n;
                            y = point.Y - (int)vector.Y * n;
                            z = point.Z - (int)vector.Z * n;
                            x = point.X + array[num5];
                            z = point.Z + array2[num5];
                            //new Vector3((float)array[num5] / (float)n, 0f, (float)array2[num5] / (float)n);
                            int cellValue = Utils.Terrain.GetCellValue(x, y, z);
                            var block     = Terrain.ExtractContents(cellValue);
                            if (block == 92 || block == 18 || block == RottenMeatBlock.Index)
                            {
                                int num6;
                                for (num6 = 4; 3 < num6 && num6 < 8 && GetSlotCount(num6) == 0; num6++)
                                {
                                }
                                int num7 = 0;
                                while (true)
                                {
                                    if (num7 >= 4)
                                    {
                                        return;
                                    }
                                    if (GetSlotCount(num7) < BlocksManager.Blocks[Terrain.ExtractContents(GetSlotValue(num7))].MaxStacking || GetSlotCount(num7) == 0)
                                    {
                                        if (block == 92 && (Terrain.ExtractContents(GetSlotValue(num7)) == 93 || GetSlotCount(num7) == 0))
                                        {
                                            if (FluidBlock.GetLevel(Terrain.ExtractData(cellValue)) == 0)
                                            {
                                                RemoveSlotItems(num6, 1);
                                                AddSlotItems(num7, 93, 1);
                                                RemoveSlotItems(8, 1);
                                                AddSlotItems(8, BlocksManager.DamageItem(slotValue, 1), 1);
                                            }
                                            Utils.SubsystemTerrain.ChangeCell(x, y, z, 0);
                                            return;
                                        }
                                        if (block == 18 && (Terrain.ExtractContents(GetSlotValue(num7)) == 91 || GetSlotCount(num7) == 0))
                                        {
                                            if (FluidBlock.GetLevel(Terrain.ExtractData(cellValue)) == 0)
                                            {
                                                RemoveSlotItems(num6, 1);
                                                AddSlotItems(num7, 91, 1);
                                            }
                                            Utils.SubsystemTerrain.ChangeCell(x, y, z, 0);
                                            return;
                                        }
                                        if (Terrain.ReplaceLight(cellValue, 0) == (RottenMeatBlock.Index | 1 << 4 << 14) && (Terrain.ReplaceLight(GetSlotValue(num7), 0) == (RottenMeatBlock.Index | 2 << 4 << 14) || GetSlotCount(num7) == 0))
                                        {
                                            RemoveSlotItems(num6, 1);
                                            AddSlotItems(num7, RottenMeatBlock.Index | 2 << 4 << 14, 1);
                                            Utils.SubsystemTerrain.ChangeCell(x, y, z, 0);
                                            return;
                                        }
                                    }
                                    num7++;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public new void Update(float dt)
        {
            PlayerInput playerInput = ComponentInput.PlayerInput;

            if (ComponentInput.IsControlledByTouch && m_aimDirection.HasValue)
            {
                playerInput.Look = Vector2.Zero;
            }
            if (ComponentMiner.Inventory != null)
            {
                ComponentMiner.Inventory.ActiveSlotIndex = MathUtils.Clamp(ComponentMiner.Inventory.ActiveSlotIndex + playerInput.ScrollInventory, 0, 5);
                if (playerInput.SelectInventorySlot.HasValue)
                {
                    ComponentMiner.Inventory.ActiveSlotIndex = MathUtils.Clamp(playerInput.SelectInventorySlot.Value, 0, 5);
                }
            }
            if (m_subsystemTime.PeriodicGameTimeEvent(0.5, 0))
            {
                ReadOnlyList <int> readOnlyList = ComponentClothing.GetClothes(ClothingSlot.Head);
                if ((readOnlyList.Count > 0 && ClothingBlock.GetClothingData(readOnlyList[readOnlyList.Count - 1]).DisplayName == Utils.Get("DZˮͷ¿ø")) || (ComponentBody.ImmersionFluidBlock != null && ComponentBody.ImmersionFluidBlock.BlockIndex == RottenMeatBlock.Index))
                {
                    //if (ComponentBody.ImmersionDepth > 0.8f)
                    //ComponentScreenOverlays.BlackoutFactor = 1f;
                    ComponentHealth.Air = 1f;
                }
            }
            ComponentMount mount = ComponentRider.Mount;

            if (mount != null)
            {
                var componentSteedBehavior = mount.Entity.FindComponent <ComponentSteedBehavior>();
                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, ComponentBody.Position, 2f, false);
                        }
                        else
                        {
                            m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellFast", 0.75f, 0f, ComponentBody.Position, 2f, 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, ComponentBody.Position, 2f, false);
                        }
                        else
                        {
                            m_subsystemAudio.PlayRandomSound("Audio/Creatures/FemaleYellSlow", 0.75f, 0f, ComponentBody.Position, 2f, 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;
                    ComponentLocomotion.LookOrder    = new Vector2(playerInput.Look.X, 0f);
                }
                else
                {
                    var componentBoat = mount.Entity.FindComponent <ComponentBoat>();
                    if (componentBoat != null || mount.Entity.FindComponent <ComponentBoatI>() != null)
                    {
                        if (componentBoat != null)
                        {
                            componentBoat.TurnOrder       = playerInput.Move.X;
                            componentBoat.MoveOrder       = playerInput.Move.Z;
                            ComponentLocomotion.LookOrder = new Vector2(playerInput.Look.X, 0f);
                        }
                        else
                        {
                            ComponentLocomotion.LookOrder = playerInput.Look;
                        }
                        ComponentCreatureModel.RowLeftOrder  = playerInput.Move.X <-0.2f || playerInput.Move.Z> 0.2f;
                        ComponentCreatureModel.RowRightOrder = playerInput.Move.X > 0.2f || playerInput.Move.Z > 0.2f;
                    }
                    var c = mount.Entity.FindComponent <ComponentLocomotion>();
                    if (c != null)
                    {
                        c.WalkOrder = playerInput.Move.XZ;
                        c.FlyOrder  = new Vector3(0f, playerInput.Move.Y, 0f);
                        c.TurnOrder = playerInput.Look * new Vector2(1f, 0f);
                        c.JumpOrder = playerInput.Jump ? 1 : 0;
                        c.LookOrder = playerInput.Look;
                        if (playerInput.ToggleCreativeFly)
                        {
                            c.IsCreativeFlyEnabled = !c.IsCreativeFlyEnabled;
                        }
                    }
                }
            }
            else
            {
                ComponentLocomotion.WalkOrder = (ComponentLocomotion.WalkOrder ?? Vector2.Zero) + (ComponentBody.IsSneaking ? (0.66f * new Vector2(playerInput.SneakMove.X, playerInput.SneakMove.Z)) : new Vector2(playerInput.Move.X, playerInput.Move.Z));
                ComponentLocomotion.FlyOrder  = new Vector3(0f, playerInput.Move.Y, 0f);
                ComponentLocomotion.TurnOrder = playerInput.Look * new Vector2(1f, 0f);
                ComponentLocomotion.JumpOrder = MathUtils.Max(playerInput.Jump ? 1 : 0, ComponentLocomotion.JumpOrder);
            }
            ComponentLocomotion.LookOrder += playerInput.Look * (SettingsManager.FlipVerticalAxis ? new Vector2(0f, -1f) : new Vector2(0f, 1f));
            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)
            {
                Vector3 viewPosition = View.ActiveCamera.ViewPosition;
                var     direction    = Vector3.Normalize(View.ActiveCamera.ScreenToWorld(new Vector3(playerInput.Interact.Value, 1f), Matrix.Identity) - viewPosition);
                if (!ComponentMiner.Use(viewPosition, direction))
                {
                    var body   = ComponentMiner.PickBody(viewPosition, direction);
                    var result = ComponentMiner.PickTerrainForInteraction(viewPosition, direction);
                    if (result.HasValue && (!body.HasValue || result.Value.Distance < body.Value.Distance))
                    {
                        if (!ComponentMiner.Interact(result.Value))
                        {
                            if (ComponentMiner.Place(result.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 || block.BlockIndex == Musket2Block.Index) ? 0.1f : 1.4f;
            Vector3 viewPosition2 = View.ActiveCamera.ViewPosition;

            if (playerInput.Aim.HasValue && block.IsAimable && m_subsystemTime.GameTime - m_lastActionTime > num2)
            {
                if (!m_isAimBlocked)
                {
                    Vector2 value = playerInput.Aim.Value;
                    Vector3 v     = View.ActiveCamera.ScreenToWorld(new Vector3(value, 1f), Matrix.Identity);
                    Point2  size  = Window.Size;
                    if (playerInput.Aim.Value.X >= size.X * 0.1f && playerInput.Aim.Value.X < size.X * 0.9f && playerInput.Aim.Value.Y >= size.Y * 0.1f && playerInput.Aim.Value.Y < size.Y * 0.9f)
                    {
                        m_aimDirection = Vector3.Normalize(v - viewPosition2);
                        if (ComponentMiner.Aim(viewPosition2, m_aimDirection.Value, AimState.InProgress))
                        {
                            ComponentMiner.Aim(viewPosition2, m_aimDirection.Value, AimState.Cancelled);
                            m_aimDirection = null;
                            m_isAimBlocked = true;
                        }
                    }
                    else if (m_aimDirection.HasValue)
                    {
                        ComponentMiner.Aim(viewPosition2, m_aimDirection.Value, AimState.Cancelled);
                        m_aimDirection = null;
                        m_isAimBlocked = true;
                    }
                }
            }
            else
            {
                m_isAimBlocked = false;
                if (m_aimDirection.HasValue)
                {
                    ComponentMiner.Aim(viewPosition2, m_aimDirection.Value, AimState.Completed);
                    m_aimDirection   = null;
                    m_lastActionTime = m_subsystemTime.GameTime;
                }
            }
            flag |= m_aimDirection.HasValue;
            if (playerInput.Hit.HasValue && !flag && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                Vector3 viewPosition3          = View.ActiveCamera.ViewPosition;
                var     vector                 = Vector3.Normalize(View.ActiveCamera.ScreenToWorld(new Vector3(playerInput.Hit.Value, 1f), Matrix.Identity) - viewPosition3);
                TerrainRaycastResult?nullable3 = ComponentMiner.PickTerrainForInteraction(viewPosition3, vector);
                BodyRaycastResult?   nullable4 = ComponentMiner.PickBody(viewPosition3, vector);
                if (nullable4.HasValue && (!nullable3.HasValue || nullable3.Value.Distance > nullable4.Value.Distance))
                {
                    if (ComponentMiner.ActiveBlockValue == 0)
                    {
                        Widget widget = ComponentNGui.OpenEntity(ComponentMiner.Inventory, nullable4.Value.ComponentBody.Entity);
                        if (widget != null)
                        {
                            ComponentGui.ModalPanelWidget = widget;
                            AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                            return;
                        }
                    }
                    flag           = true;
                    m_isDigBlocked = true;
                    if (Vector3.Distance(viewPosition3 + vector * nullable4.Value.Distance, ComponentCreatureModel.EyePosition) <= 2f)
                    {
                        ComponentMiner.Hit(nullable4.Value.ComponentBody, vector);
                    }
                }
            }
            if (playerInput.Dig.HasValue && !flag && !m_isDigBlocked && m_subsystemTime.GameTime - m_lastActionTime > 0.33000001311302185)
            {
                Vector3 viewPosition4          = View.ActiveCamera.ViewPosition;
                Vector3 v2                     = View.ActiveCamera.ScreenToWorld(new Vector3(playerInput.Dig.Value, 1f), Matrix.Identity);
                TerrainRaycastResult?nullable5 = ComponentMiner.PickTerrainForDigging(viewPosition4, v2 - viewPosition4);
                if (nullable5.HasValue && ComponentMiner.Dig(nullable5.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 v3       = ComponentBody.Position + new Vector3(0f, ComponentBody.BoxSize.Y * 0.66f, 0f);
                    Matrix  matrix   = ComponentBody.Matrix;
                    Vector3 position = v3 + 0.25f * matrix.Forward;
                    matrix = Matrix.CreateFromQuaternion(ComponentCreatureModel.EyeRotation);
                    Vector3 value2 = 8f * matrix.Forward;
                    m_subsystemPickables.AddPickable(slotValue, num3, position, value2, null);
                }
            }
            if (playerInput.PickBlockType.HasValue && !flag)
            {
                if (ComponentMiner.Inventory is ComponentCreativeInventory componentCreativeInventory)
                {
                    Vector3 viewPosition5          = View.ActiveCamera.ViewPosition;
                    Vector3 v4                     = View.ActiveCamera.ScreenToWorld(new Vector3(playerInput.PickBlockType.Value, 1f), Matrix.Identity);
                    TerrainRaycastResult?nullable6 = ComponentMiner.PickTerrainForDigging(viewPosition5, v4 - viewPosition5);
                    if (nullable6.HasValue)
                    {
                        int value3 = nullable6.Value.Value;
                        value3 = Terrain.ReplaceLight(value3, 0);
                        int   num4           = Terrain.ExtractContents(value3);
                        Block block2         = BlocksManager.Blocks[num4];
                        int   num5           = 0;
                        var   creativeValues = block2.GetCreativeValues();
                        if (block2.GetCreativeValues().Contains(value3))
                        {
                            num5 = value3;
                        }
                        if (num5 == 0 && !block2.IsNonDuplicable)
                        {
                            var  list = new List <BlockDropValue>();
                            bool _;
                            block2.GetDropValues(m_subsystemTerrain, value3, 0, 2147483647, list, out _);
                            if (list.Count > 0 && list[0].Count > 0)
                            {
                                num5 = list[0].Value;
                            }
                        }
                        if (num5 == 0)
                        {
                            num5 = creativeValues.FirstOrDefault();
                        }
                        if (num5 != 0)
                        {
                            int num6 = -1;
                            for (int i = 0; i < 6; i++)
                            {
                                if (componentCreativeInventory.GetSlotCount(i) > 0 && componentCreativeInventory.GetSlotValue(i) == num5)
                                {
                                    num6 = i;
                                    break;
                                }
                            }
                            if (num6 < 0)
                            {
                                for (int j = 0; j < 6; j++)
                                {
                                    if (componentCreativeInventory.GetSlotCount(j) == 0 || componentCreativeInventory.GetSlotValue(j) == 0)
                                    {
                                        num6 = j;
                                        break;
                                    }
                                }
                            }
                            if (num6 < 0)
                            {
                                num6 = componentCreativeInventory.ActiveSlotIndex;
                            }
                            componentCreativeInventory.RemoveSlotItems(num6, 2147483647);
                            componentCreativeInventory.AddSlotItems(num6, num5, 1);
                            componentCreativeInventory.ActiveSlotIndex = num6;
                            ComponentGui.DisplaySmallMessage(block2.GetDisplayName(m_subsystemTerrain, value3), false, false);
                            m_subsystemAudio.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f, 0f);
                        }
                    }
                }
            }
            HighlightRaycastResult = ComponentMiner.PickTerrainForDigging(View.ActiveCamera.ViewPosition, View.ActiveCamera.ViewDirection);
        }
Exemplo n.º 12
0
        public void GenerateGeometry(MovingBlockSet movingBlockSet)
        {
            Point3 point = default(Point3);

            point.X = ((movingBlockSet.CurrentVelocity.X > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.X)) : (point.X = (int)MathUtils.Ceiling(movingBlockSet.Position.X)));
            point.Y = ((movingBlockSet.CurrentVelocity.Y > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.Y)) : (point.Y = (int)MathUtils.Ceiling(movingBlockSet.Position.Y)));
            point.Z = ((movingBlockSet.CurrentVelocity.Z > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.Z)) : (point.Z = (int)MathUtils.Ceiling(movingBlockSet.Position.Z)));
            if (!(point != movingBlockSet.GeometryGenerationPosition))
            {
                return;
            }
            Point3 p      = new Point3(movingBlockSet.Box.Left, movingBlockSet.Box.Top, movingBlockSet.Box.Near);
            Point3 point2 = new Point3(movingBlockSet.Box.Width, movingBlockSet.Box.Height, movingBlockSet.Box.Depth);

            point2.Y = MathUtils.Min(point2.Y, 254);
            if (m_blockGeometryGenerator == null)
            {
                int x = 2;
                x = (int)MathUtils.NextPowerOf2((uint)x);
                m_blockGeometryGenerator = new BlockGeometryGenerator(new Terrain(), m_subsystemTerrain, null, base.Project.FindSubsystem <SubsystemFurnitureBlockBehavior>(throwOnError: true), null, base.Project.FindSubsystem <SubsystemPalette>(throwOnError: true));
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < x; j++)
                    {
                        m_blockGeometryGenerator.Terrain.AllocateChunk(i, j);
                    }
                }
            }
            Terrain terrain = m_subsystemTerrain.Terrain;

            for (int k = 0; k < point2.X + 2; k++)
            {
                for (int l = 0; l < point2.Z + 2; l++)
                {
                    int x2         = k + p.X + point.X - 1;
                    int z          = l + p.Z + point.Z - 1;
                    int shaftValue = terrain.GetShaftValue(x2, z);
                    m_blockGeometryGenerator.Terrain.SetTemperature(k, l, Terrain.ExtractTemperature(shaftValue));
                    m_blockGeometryGenerator.Terrain.SetHumidity(k, l, Terrain.ExtractHumidity(shaftValue));
                    for (int m = 0; m < point2.Y + 2; m++)
                    {
                        int y     = m + p.Y + point.Y - 1;
                        int light = Terrain.ExtractLight(terrain.GetCellValue(x2, y, z));
                        m_blockGeometryGenerator.Terrain.SetCellValueFast(k, m, l, Terrain.MakeBlockValue(0, light, 0));
                    }
                }
            }
            m_blockGeometryGenerator.Terrain.SeasonTemperature = terrain.SeasonTemperature;
            m_blockGeometryGenerator.Terrain.SeasonHumidity    = terrain.SeasonHumidity;
            foreach (MovingBlock block in movingBlockSet.Blocks)
            {
                int x3    = block.Offset.X - p.X + 1;
                int y2    = block.Offset.Y - p.Y + 1;
                int z2    = block.Offset.Z - p.Z + 1;
                int value = Terrain.ReplaceLight(light: m_blockGeometryGenerator.Terrain.GetCellLightFast(x3, y2, z2), value: block.Value);
                m_blockGeometryGenerator.Terrain.SetCellValueFast(x3, y2, z2, value);
            }
            m_blockGeometryGenerator.ResetCache();
            movingBlockSet.Vertices.Clear();
            movingBlockSet.Indices.Clear();
            for (int n = 1; n < point2.X + 1; n++)
            {
                for (int num = 1; num < point2.Y + 1; num++)
                {
                    for (int num2 = 1; num2 < point2.Z + 1; num2++)
                    {
                        int cellValueFast = m_blockGeometryGenerator.Terrain.GetCellValueFast(n, num, num2);
                        int num3          = Terrain.ExtractContents(cellValueFast);
                        if (num3 != 0)
                        {
                            BlocksManager.Blocks[num3].GenerateTerrainVertices(m_blockGeometryGenerator, movingBlockSet.Geometry, cellValueFast, n, num, num2);
                        }
                    }
                }
            }
            movingBlockSet.GeometryOffset             = new Vector3(p) - new Vector3(1f);
            movingBlockSet.GeometryGenerationPosition = point;
        }
Exemplo n.º 13
0
 public override void MeasureOverride(Vector2 parentAvailableSize)
 {
     if (m_inventory != null)
     {
         bool flag = m_inventory is ComponentCreativeInventory || m_inventory is ComponentFurnitureInventory;
         int  num  = m_inventory.GetSlotCount(m_slotIndex);
         if (!flag && m_dragMode.HasValue)
         {
             num = ((m_dragMode.Value != 0) ? MathUtils.Max(num - 1, 0) : 0);
         }
         m_rectangleWidget.IsVisible = true;
         if (num > 0)
         {
             int   slotValue = m_inventory.GetSlotValue(m_slotIndex);
             int   num2      = Terrain.ExtractContents(slotValue);
             Block block     = BlocksManager.Blocks[num2];
             bool  flag2     = block.GetRotPeriod(slotValue) > 0 && block.GetDamage(slotValue) > 0;
             m_blockIconWidget.Value     = Terrain.ReplaceLight(slotValue, 15);
             m_blockIconWidget.IsVisible = !HideBlockIcon;
             if (num != m_lastCount)
             {
                 m_countWidget.Text = num.ToString();
                 m_lastCount        = num;
             }
             m_countWidget.IsVisible              = (num > 1 && !flag);
             m_editOverlayWidget.IsVisible        = (!HideEditOverlay && block.IsEditable);
             m_interactiveOverlayWidget.IsVisible = (!HideInteractiveOverlay && ((m_subsystemTerrain != null) ? block.IsInteractive(m_subsystemTerrain, slotValue) : block.DefaultIsInteractive));
             m_foodOverlayWidget.IsVisible        = (!HideFoodOverlay && block.GetRotPeriod(slotValue) > 0);
             m_foodOverlayWidget.FillColor        = (flag2 ? new Color(128, 64, 0) : new Color(160, 160, 160));
             if (!flag && !HideHealthBar && block.Durability >= 0)
             {
                 int damage = block.GetDamage(slotValue);
                 m_healthBarWidget.IsVisible = true;
                 m_healthBarWidget.Value     = (float)(block.Durability - damage) / (float)block.Durability;
             }
             else
             {
                 m_healthBarWidget.IsVisible = false;
             }
         }
         else
         {
             m_blockIconWidget.IsVisible          = false;
             m_countWidget.IsVisible              = false;
             m_healthBarWidget.IsVisible          = false;
             m_editOverlayWidget.IsVisible        = false;
             m_interactiveOverlayWidget.IsVisible = false;
             m_foodOverlayWidget.IsVisible        = false;
         }
         m_highlightWidget.IsVisible    = !HideHighlightRectangle;
         m_highlightWidget.OutlineColor = Color.Transparent;
         m_highlightWidget.FillColor    = Color.Transparent;
         m_splitLabelWidget.IsVisible   = false;
         if (m_slotIndex == m_inventory.ActiveSlotIndex)
         {
             m_highlightWidget.OutlineColor = new Color(0, 0, 0);
             m_highlightWidget.FillColor    = new Color(0, 0, 0, 80);
         }
         if (IsSplitMode())
         {
             m_highlightWidget.OutlineColor = new Color(255, 64, 0);
             m_splitLabelWidget.IsVisible   = true;
         }
     }
     else
     {
         m_rectangleWidget.IsVisible          = false;
         m_highlightWidget.IsVisible          = false;
         m_blockIconWidget.IsVisible          = false;
         m_countWidget.IsVisible              = false;
         m_healthBarWidget.IsVisible          = false;
         m_editOverlayWidget.IsVisible        = false;
         m_interactiveOverlayWidget.IsVisible = false;
         m_foodOverlayWidget.IsVisible        = false;
         m_splitLabelWidget.IsVisible         = false;
     }
     base.IsDrawRequired = (m_inventoryDragData != null);
     base.MeasureOverride(parentAvailableSize);
 }
Exemplo n.º 14
0
        public override void Update()
        {
            if (m_inventory == null || DragHostWidget == null)
            {
                return;
            }
            WidgetInput     input      = base.Input;
            ComponentPlayer viewPlayer = GetViewPlayer();
            int             slotValue  = m_inventory.GetSlotValue(m_slotIndex);
            int             num        = Terrain.ExtractContents(slotValue);
            Block           block      = BlocksManager.Blocks[num];

            if (m_componentPlayer != null)
            {
                m_blockIconWidget.DrawBlockEnvironmentData.InWorldMatrix = m_componentPlayer.ComponentBody.Matrix;
            }
            if (m_focus && !input.Press.HasValue)
            {
                m_focus = false;
            }
            else if (input.Tap.HasValue && HitTestGlobal(input.Tap.Value) == this)
            {
                m_focus = true;
            }
            if (input.SpecialClick.HasValue && HitTestGlobal(input.SpecialClick.Value.Start) == this && HitTestGlobal(input.SpecialClick.Value.End) == this)
            {
                IInventory inventory = null;
                foreach (InventorySlotWidget item in ((ContainerWidget)base.RootWidget).AllChildren.OfType <InventorySlotWidget>())
                {
                    if (item.m_inventory != null && item.m_inventory != m_inventory && item.Input == base.Input && item.IsEnabledGlobal && item.IsVisibleGlobal)
                    {
                        inventory = item.m_inventory;
                        break;
                    }
                }
                if (inventory != null)
                {
                    int num2 = ComponentInventoryBase.FindAcquireSlotForItem(inventory, slotValue);
                    if (num2 >= 0)
                    {
                        HandleMoveItem(m_inventory, m_slotIndex, inventory, num2, m_inventory.GetSlotCount(m_slotIndex));
                    }
                }
            }
            if (input.Click.HasValue && HitTestGlobal(input.Click.Value.Start) == this && HitTestGlobal(input.Click.Value.End) == this)
            {
                bool flag = false;
                if (viewPlayer != null)
                {
                    if (viewPlayer.ComponentInput.SplitSourceInventory == m_inventory && viewPlayer.ComponentInput.SplitSourceSlotIndex == m_slotIndex)
                    {
                        viewPlayer.ComponentInput.SetSplitSourceInventoryAndSlot(null, -1);
                        flag = true;
                    }
                    else if (viewPlayer.ComponentInput.SplitSourceInventory != null)
                    {
                        flag = HandleMoveItem(viewPlayer.ComponentInput.SplitSourceInventory, viewPlayer.ComponentInput.SplitSourceSlotIndex, m_inventory, m_slotIndex, 1);
                        AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                    }
                }
                if (!flag && m_inventory.ActiveSlotIndex != m_slotIndex && m_slotIndex < 10)
                {
                    m_inventory.ActiveSlotIndex = m_slotIndex;
                    if (m_inventory.ActiveSlotIndex == m_slotIndex)
                    {
                        AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                    }
                }
            }
            if (!m_focus || ProcessingOnly || viewPlayer == null)
            {
                return;
            }
            Vector2?hold = input.Hold;

            if (hold.HasValue && HitTestGlobal(hold.Value) == this && !DragHostWidget.IsDragInProgress && m_inventory.GetSlotCount(m_slotIndex) > 0 && (viewPlayer.ComponentInput.SplitSourceInventory != m_inventory || viewPlayer.ComponentInput.SplitSourceSlotIndex != m_slotIndex))
            {
                input.Clear();
                viewPlayer.ComponentInput.SetSplitSourceInventoryAndSlot(m_inventory, m_slotIndex);
                AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
            }
            Vector2?drag = input.Drag;

            if (!drag.HasValue || HitTestGlobal(drag.Value) != this || DragHostWidget.IsDragInProgress)
            {
                return;
            }
            int slotCount = m_inventory.GetSlotCount(m_slotIndex);

            if (slotCount > 0)
            {
                DragMode dragMode = input.DragMode;
                if (viewPlayer.ComponentInput.SplitSourceInventory == m_inventory && viewPlayer.ComponentInput.SplitSourceSlotIndex == m_slotIndex)
                {
                    dragMode = DragMode.SingleItem;
                }
                int num3 = (dragMode != 0) ? 1 : slotCount;
                SubsystemTerrain subsystemTerrain = m_inventory.Project.FindSubsystem <SubsystemTerrain>();
                ContainerWidget  containerWidget  = (ContainerWidget)Widget.LoadWidget(null, ContentManager.Get <XElement>("Widgets/InventoryDragWidget"), null);
                containerWidget.Children.Find <BlockIconWidget>("InventoryDragWidget.Icon").Value = Terrain.ReplaceLight(slotValue, 15);
                containerWidget.Children.Find <BlockIconWidget>("InventoryDragWidget.Icon").DrawBlockEnvironmentData.SubsystemTerrain = subsystemTerrain;
                containerWidget.Children.Find <LabelWidget>("InventoryDragWidget.Name").Text       = block.GetDisplayName(subsystemTerrain, slotValue);
                containerWidget.Children.Find <LabelWidget>("InventoryDragWidget.Count").Text      = num3.ToString();
                containerWidget.Children.Find <LabelWidget>("InventoryDragWidget.Count").IsVisible = (!(m_inventory is ComponentCreativeInventory) && !(m_inventory is ComponentFurnitureInventory));
                DragHostWidget.BeginDrag(containerWidget, new InventoryDragData
                {
                    Inventory = m_inventory,
                    SlotIndex = m_slotIndex,
                    DragMode  = dragMode
                }, delegate
                {
                    m_dragMode = null;
                });
                m_dragMode = dragMode;
            }
        }
Exemplo n.º 15
0
 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
 {
     return(new BlockPlacementData {
         Value = Terrain.ReplaceLight(value, 0), CellFace = raycastResult.CellFace
     });
 }
Exemplo n.º 16
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);
        }