Пример #1
0
        public bool CanWearClothing(int value)
        {
            ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
            IList <int>  list         = GetClothes(clothingData.Slot);

            if (list.Count == 0)
            {
                return(true);
            }
            ClothingData clothingData2 = ClothingBlock.GetClothingData(Terrain.ExtractData(list[list.Count - 1]));

            return(clothingData.Layer > clothingData2.Layer);
        }
Пример #2
0
        public static void AddClothingFactor(int clothingValue, ref float clothingFactor, ICollection <Factor> factors)
        {
            ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(clothingValue));

            if (clothingData.MovementSpeedFactor != 1f)
            {
                clothingFactor *= clothingData.MovementSpeedFactor;
                factors?.Add(new Factor
                {
                    Value       = clothingData.MovementSpeedFactor,
                    Description = clothingData.DisplayName
                });
            }
        }
Пример #3
0
        public float ApplyArmorProtection(float attackPower)
        {
            float        num  = m_random.Float(0f, 1f);
            ClothingSlot slot = (num < 0.1f) ? ClothingSlot.Feet : ((num < 0.3f) ? ClothingSlot.Legs : ((num < 0.9f) ? ClothingSlot.Torso : ClothingSlot.Head));
            float        num2 = ((ClothingBlock)BlocksManager.Blocks[203]).Durability + 1;
            List <int>   list = new List <int>(GetClothes(slot));

            for (int i = 0; i < list.Count; i++)
            {
                int          value        = list[i];
                ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                float        x            = (num2 - (float)BlocksManager.Blocks[203].GetDamage(value)) / num2 * clothingData.Sturdiness;
                float        num3         = MathUtils.Min(attackPower * MathUtils.Saturate(clothingData.ArmorProtection), x);
                if (num3 > 0f)
                {
                    attackPower -= num3;
                    if (m_subsystemGameInfo.WorldSettings.GameMode != 0)
                    {
                        float x2          = num3 / clothingData.Sturdiness * num2 + 0.001f;
                        int   damageCount = (int)(MathUtils.Floor(x2) + (float)(m_random.Bool(MathUtils.Remainder(x2, 1f)) ? 1 : 0));
                        list[i] = BlocksManager.DamageItem(value, damageCount);
                    }
                    if (!string.IsNullOrEmpty(clothingData.ImpactSoundsFolder))
                    {
                        m_subsystemAudio.PlayRandomSound(clothingData.ImpactSoundsFolder, 1f, m_random.Float(-0.3f, 0.3f), m_componentBody.Position, 4f, 0.15f);
                    }
                }
            }
            int num4 = 0;

            while (num4 < list.Count)
            {
                if (Terrain.ExtractContents(list[num4]) != 203)
                {
                    list.RemoveAt(num4);
                    m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0));
                }
                else
                {
                    num4++;
                }
            }
            SetClothes(slot, list);
            return(MathUtils.Max(attackPower, 0f));
        }
Пример #4
0
        public void ProcessSlotItems(int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
        {
            processedCount = 0;
            processedValue = 0;
            if (processCount != 1)
            {
                return;
            }
            Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)];

            if (block.GetNutritionalValue(value) > 0f)
            {
                if (block is BucketBlock)
                {
                    processedValue = Terrain.MakeBlockValue(90, 0, Terrain.ExtractData(value));
                    processedCount = 1;
                }
                if (count > 1 && processedCount > 0 && processedValue != value)
                {
                    processedValue = value;
                    processedCount = processCount;
                }
                else if (!m_componentVitalStats.Eat(value))
                {
                    processedValue = value;
                    processedCount = processCount;
                }
            }
            if (block is ClothingBlock)
            {
                ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                List <int>   list         = new List <int>(GetClothes(clothingData.Slot));
                list.Add(value);
                SetClothes(clothingData.Slot, list);
            }
        }
Пример #5
0
        public void NormalMovement(float dt)
        {
            m_componentCreature.ComponentBody.IsGravityEnabled    = true;
            m_componentCreature.ComponentBody.IsGroundDragEnabled = true;
            m_componentCreature.ComponentBody.IsWaterDragEnabled  = true;
            Vector3 velocity = m_componentCreature.ComponentBody.Velocity;
            Vector3 right    = m_componentCreature.ComponentBody.Matrix.Right;
            Vector3 vector   = Vector3.Transform(m_componentCreature.ComponentBody.Matrix.Forward, Quaternion.CreateFromAxisAngle(right, LookAngles.Y));

            if (WalkSpeed > 0f && WalkOrder.HasValue)
            {
                if (IsCreativeFlyEnabled)
                {
                    Vector3 v = new Vector3(WalkOrder.Value.X, 0f, WalkOrder.Value.Y);
                    if (FlyOrder.HasValue)
                    {
                        v += FlyOrder.Value;
                    }
                    Vector3 v2  = (!SettingsManager.HorizontalCreativeFlight || m_componentPlayer == null || m_componentPlayer.ComponentInput.IsControlledByTouch) ? Vector3.Normalize(vector + 0.1f * Vector3.UnitY) : Vector3.Normalize(vector * new Vector3(1f, 0f, 1f));
                    Vector3 v3  = CreativeFlySpeed * (right * v.X + Vector3.UnitY * v.Y + v2 * v.Z);
                    float   num = (v == Vector3.Zero) ? 5f : 3f;
                    velocity += MathUtils.Saturate(num * dt) * (v3 - velocity);
                    m_componentCreature.ComponentBody.IsGravityEnabled    = false;
                    m_componentCreature.ComponentBody.IsGroundDragEnabled = false;
                    m_flying = true;
                }
                else
                {
                    Vector2 value = WalkOrder.Value;
                    if (m_walkSpeedWhenTurning > 0f && MathUtils.Abs(TurnOrder.X) > 0.02f)
                    {
                        value.Y = MathUtils.Max(value.Y, MathUtils.Lerp(0f, m_walkSpeedWhenTurning, MathUtils.Saturate(2f * MathUtils.Abs(TurnOrder.X))));
                    }
                    float num2 = WalkSpeed;
                    if (m_componentCreature.ComponentBody.ImmersionFactor > 0.2f)
                    {
                        num2 *= 0.66f;
                    }
                    if (value.Y < 0f)
                    {
                        num2 *= 0.6f;
                    }
                    if (m_componentLevel != null)
                    {
                        num2 *= m_componentLevel.SpeedFactor;
                    }
                    if (m_componentMount != null)
                    {
                        ComponentRider rider = m_componentMount.Rider;
                        if (rider != null)
                        {
                            ComponentClothing componentClothing = rider.Entity.FindComponent <ComponentClothing>();
                            if (componentClothing != null)
                            {
                                num2 *= componentClothing.SteedMovementSpeedFactor;
                            }
                        }
                    }
                    Vector3 v4      = value.X * Vector3.Normalize(new Vector3(right.X, 0f, right.Z)) + value.Y * Vector3.Normalize(new Vector3(vector.X, 0f, vector.Z));
                    Vector3 vector2 = num2 * v4 + m_componentCreature.ComponentBody.StandingOnVelocity;
                    float   num4;
                    if (m_componentCreature.ComponentBody.StandingOnValue.HasValue)
                    {
                        float num3 = MathUtils.Max(BlocksManager.Blocks[Terrain.ExtractContents(m_componentCreature.ComponentBody.StandingOnValue.Value)].FrictionFactor, m_minFrictionFactor);
                        num4 = MathUtils.Saturate(dt * 6f * AccelerationFactor * num3);
                        if (num3 < 0.25f)
                        {
                            SlipSpeed = num2 * value.Length();
                        }
                        m_walking = true;
                    }
                    else
                    {
                        num4 = MathUtils.Saturate(dt * 6f * AccelerationFactor * InAirWalkFactor);
                        if (m_componentCreature.ComponentBody.ImmersionFactor > 0f)
                        {
                            m_swimming = true;
                        }
                        else
                        {
                            m_falling = true;
                        }
                    }
                    velocity.X += num4 * (vector2.X - velocity.X);
                    velocity.Z += num4 * (vector2.Z - velocity.Z);
                    Vector3 vector3 = value.X * right + value.Y * vector;
                    if (m_componentLevel != null)
                    {
                        vector3 *= m_componentLevel.SpeedFactor;
                    }
                    velocity.Y += 10f * AccelerationFactor * vector3.Y * m_componentCreature.ComponentBody.ImmersionFactor * dt;
                    m_componentCreature.ComponentBody.IsGroundDragEnabled = false;
                    if (m_componentPlayer != null && Time.PeriodicEvent(10.0, 0.0) && (m_shoesWarningTime == 0.0 || Time.FrameStartTime - m_shoesWarningTime > 300.0) && m_componentCreature.ComponentBody.StandingOnValue.HasValue && m_componentCreature.ComponentBody.ImmersionFactor < 0.1f)
                    {
                        bool flag   = false;
                        int  value2 = m_componentPlayer.ComponentClothing.GetClothes(ClothingSlot.Feet).LastOrDefault();
                        if (Terrain.ExtractContents(value2) == 203)
                        {
                            flag = (ClothingBlock.GetClothingData(Terrain.ExtractData(value2)).MovementSpeedFactor > 1f);
                        }
                        if (!flag && vector2.LengthSquared() / velocity.LengthSquared() > 0.99f && WalkOrder.Value.LengthSquared() > 0.99f)
                        {
                            m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(GetType().Name, 1), Color.White, blinking: true, playNotificationSound: true);
                            m_shoesWarningTime = Time.FrameStartTime;
                        }
                    }
                }
            }
            if (FlySpeed > 0f && FlyOrder.HasValue)
            {
                Vector3 value3 = FlyOrder.Value;
                Vector3 v5     = FlySpeed * value3;
                velocity += MathUtils.Saturate(2f * AccelerationFactor * dt) * (v5 - velocity);
                m_componentCreature.ComponentBody.IsGravityEnabled = false;
                m_flying = true;
            }
            if (SwimSpeed > 0f && SwimOrder.HasValue && m_componentCreature.ComponentBody.ImmersionFactor > 0.5f)
            {
                Vector3 value4 = SwimOrder.Value;
                Vector3 v6     = SwimSpeed * value4;
                float   num5   = 2f;
                if (value4.LengthSquared() >= 0.99f)
                {
                    v6   *= MathUtils.Lerp(1f, 2f, m_swimBurstRemaining);
                    num5 *= MathUtils.Lerp(1f, 4f, m_swimBurstRemaining);
                    m_swimBurstRemaining -= dt;
                }
                velocity += MathUtils.Saturate(num5 * AccelerationFactor * dt) * (v6 - velocity);
                m_componentCreature.ComponentBody.IsGravityEnabled    = (MathUtils.Abs(value4.Y) <= 0.07f);
                m_componentCreature.ComponentBody.IsWaterDragEnabled  = false;
                m_componentCreature.ComponentBody.IsGroundDragEnabled = false;
                m_swimming = true;
            }
            if (JumpOrder > 0f && (m_componentCreature.ComponentBody.StandingOnValue.HasValue || m_componentCreature.ComponentBody.ImmersionFactor > 0.5f) && !m_componentCreature.ComponentBody.IsSneaking)
            {
                float num6 = JumpSpeed;
                if (m_componentLevel != null)
                {
                    num6 *= 0.25f * (m_componentLevel.SpeedFactor - 1f) + 1f;
                }
                velocity.Y = MathUtils.Min(velocity.Y + MathUtils.Saturate(JumpOrder) * num6, num6);
                m_jumping  = true;
                m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
                m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 10f);
            }
            if (MathUtils.Abs(m_componentCreature.ComponentBody.CollisionVelocityChange.Y) > 3f)
            {
                m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
                m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 10f);
            }
            m_componentCreature.ComponentBody.Velocity = velocity;
        }
Пример #6
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);
        }
Пример #7
0
 public static string MakeClothingValue(int index, int color)
 {
     return(Terrain.MakeBlockValue(203, 0, ClothingBlock.SetClothingIndex(ClothingBlock.SetClothingColor(0, color), index)).ToString(CultureInfo.InvariantCulture));
 }
Пример #8
0
 public void UpdateRenderTargets()
 {
     if (m_skinTexture == null || m_componentPlayer.PlayerData.CharacterSkinName != m_skinTextureName)
     {
         m_skinTexture     = CharacterSkinsManager.LoadTexture(m_componentPlayer.PlayerData.CharacterSkinName);
         m_skinTextureName = m_componentPlayer.PlayerData.CharacterSkinName;
         Utilities.Dispose(ref m_innerClothedTexture);
         Utilities.Dispose(ref m_outerClothedTexture);
     }
     if (m_innerClothedTexture == null || m_innerClothedTexture.Width != m_skinTexture.Width || m_innerClothedTexture.Height != m_skinTexture.Height)
     {
         m_innerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentHumanModel.TextureOverride = m_innerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (m_outerClothedTexture == null || m_outerClothedTexture.Width != m_skinTexture.Width || m_outerClothedTexture.Height != m_skinTexture.Height)
     {
         m_outerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, 1, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentOuterClothingModel.TextureOverride = m_outerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (DrawClothedTexture && !m_clothedTexturesValid)
     {
         m_clothedTexturesValid = true;
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_innerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             int             num             = 0;
             TexturedBatch2D texturedBatch2D = m_primitivesRenderer.TexturedBatch(m_skinTexture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
             texturedBatch2D.QueueQuad(Vector2.Zero, new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             ClothingSlot[] innerSlotsOrder = m_innerSlotsOrder;
             foreach (ClothingSlot slot in innerSlotsOrder)
             {
                 foreach (int clothe in GetClothes(slot))
                 {
                     int          data         = Terrain.ExtractData(clothe);
                     ClothingData clothingData = ClothingBlock.GetClothingData(data);
                     Color        fabricColor  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (!clothingData.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
             Display.RenderTarget = m_outerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             num             = 0;
             innerSlotsOrder = m_outerSlotsOrder;
             foreach (ClothingSlot slot2 in innerSlotsOrder)
             {
                 foreach (int clothe2 in GetClothes(slot2))
                 {
                     int          data2         = Terrain.ExtractData(clothe2);
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(data2);
                     Color        fabricColor2  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data2));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData2.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (clothingData2.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_outerClothedTexture.Width, m_outerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor2);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
     }
 }
Пример #9
0
 public void Update(float dt)
 {
     if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(0.5, 0.0))
     {
         foreach (int enumValue in EnumUtils.GetEnumValues(typeof(ClothingSlot)))
         {
             bool flag = false;
             m_clothesList.Clear();
             m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue));
             int num = 0;
             while (num < m_clothesList.Count)
             {
                 int          value        = m_clothesList[num];
                 ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                 if ((float)clothingData.PlayerLevelRequired > m_componentPlayer.PlayerData.Level)
                 {
                     m_componentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), clothingData.PlayerLevelRequired, clothingData.DisplayName), Color.White, blinking: true, playNotificationSound: true);
                     m_subsystemPickables.AddPickable(value, 1, m_componentBody.Position, null, null);
                     m_clothesList.RemoveAt(num);
                     flag = true;
                 }
                 else
                 {
                     num++;
                 }
             }
             if (flag)
             {
                 SetClothes((ClothingSlot)enumValue, m_clothesList);
             }
         }
     }
     if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0) && ((m_componentLocomotion.LastWalkOrder.HasValue && m_componentLocomotion.LastWalkOrder.Value != Vector2.Zero) || (m_componentLocomotion.LastSwimOrder.HasValue && m_componentLocomotion.LastSwimOrder.Value != Vector3.Zero) || m_componentLocomotion.LastJumpOrder != 0f))
     {
         if (m_lastTotalElapsedGameTime.HasValue)
         {
             foreach (int enumValue2 in EnumUtils.GetEnumValues(typeof(ClothingSlot)))
             {
                 bool flag2 = false;
                 m_clothesList.Clear();
                 m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue2));
                 for (int i = 0; i < m_clothesList.Count; i++)
                 {
                     int          value2        = m_clothesList[i];
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(Terrain.ExtractData(value2));
                     float        num2          = (m_componentVitalStats.Wetness > 0f) ? (10f * clothingData2.Sturdiness) : (20f * clothingData2.Sturdiness);
                     double       num3          = MathUtils.Floor(m_lastTotalElapsedGameTime.Value / (double)num2);
                     if (MathUtils.Floor(m_subsystemGameInfo.TotalElapsedGameTime / (double)num2) > num3 && m_random.Float(0f, 1f) < 0.75f)
                     {
                         m_clothesList[i] = BlocksManager.DamageItem(value2, 1);
                         flag2            = true;
                     }
                 }
                 int num4 = 0;
                 while (num4 < m_clothesList.Count)
                 {
                     if (Terrain.ExtractContents(m_clothesList[num4]) != 203)
                     {
                         m_clothesList.RemoveAt(num4);
                         m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0));
                         m_componentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                     }
                     else
                     {
                         num4++;
                     }
                 }
                 if (flag2)
                 {
                     SetClothes((ClothingSlot)enumValue2, m_clothesList);
                 }
             }
         }
         m_lastTotalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
     }
     UpdateRenderTargets();
 }
Пример #10
0
 public void SetClothes(ClothingSlot slot, IEnumerable <int> clothes)
 {
     if (!m_clothes[slot].SequenceEqual(clothes))
     {
         m_clothes[slot].Clear();
         m_clothes[slot].AddRange(clothes);
         m_clothedTexturesValid = false;
         float num = 0f;
         foreach (KeyValuePair <ClothingSlot, List <int> > clothe in m_clothes)
         {
             foreach (int item in clothe.Value)
             {
                 ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(item));
                 num += clothingData.DensityModifier;
             }
         }
         float num2 = num - m_densityModifierApplied;
         m_densityModifierApplied += num2;
         m_componentBody.Density  += num2;
         SteedMovementSpeedFactor  = 1f;
         float num3 = 2f;
         float num4 = 0.2f;
         float num5 = 0.4f;
         float num6 = 2f;
         foreach (int clothe2 in GetClothes(ClothingSlot.Head))
         {
             ClothingData clothingData2 = ClothingBlock.GetClothingData(Terrain.ExtractData(clothe2));
             num3 += clothingData2.Insulation;
             SteedMovementSpeedFactor *= clothingData2.SteedMovementSpeedFactor;
         }
         foreach (int clothe3 in GetClothes(ClothingSlot.Torso))
         {
             ClothingData clothingData3 = ClothingBlock.GetClothingData(Terrain.ExtractData(clothe3));
             num4 += clothingData3.Insulation;
             SteedMovementSpeedFactor *= clothingData3.SteedMovementSpeedFactor;
         }
         foreach (int clothe4 in GetClothes(ClothingSlot.Legs))
         {
             ClothingData clothingData4 = ClothingBlock.GetClothingData(Terrain.ExtractData(clothe4));
             num5 += clothingData4.Insulation;
             SteedMovementSpeedFactor *= clothingData4.SteedMovementSpeedFactor;
         }
         foreach (int clothe5 in GetClothes(ClothingSlot.Feet))
         {
             ClothingData clothingData5 = ClothingBlock.GetClothingData(Terrain.ExtractData(clothe5));
             num6 += clothingData5.Insulation;
             SteedMovementSpeedFactor *= clothingData5.SteedMovementSpeedFactor;
         }
         Insulation = 1f / (1f / num3 + 1f / num4 + 1f / num5 + 1f / num6);
         float num7 = MathUtils.Min(num3, num4, num5, num6);
         if (num3 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Head;
         }
         else if (num4 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Torso;
         }
         else if (num5 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Legs;
         }
         else if (num6 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Feet;
         }
     }
 }
Пример #11
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);
        }