public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { _ = componentMiner.Inventory; if (Terrain.ExtractContents(componentMiner.ActiveBlockValue) == 178) { TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging); if (terrainRaycastResult.HasValue) { Vector3 position = terrainRaycastResult.Value.HitPoint(); DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>(); m_subsystemBodies.FindBodiesInArea(new Vector2(position.X, position.Z) - new Vector2(8f), new Vector2(position.X, position.Z) + new Vector2(8f), dynamicArray); if (dynamicArray.Count((ComponentBody b) => b.Entity.ValuesDictionary.DatabaseObject.Name == "Boat") < 6) { Entity entity = DatabaseManager.CreateEntity(base.Project, "Boat", throwIfNotFound: true); entity.FindComponent <ComponentFrame>(throwOnError: true).Position = position; entity.FindComponent <ComponentFrame>(throwOnError: true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.Float(0f, (float)Math.PI * 2f)); entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f; base.Project.AddEntity(entity); componentMiner.RemoveActiveTool(1); m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, autoDelay: true); } else { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: false); } return(true); } } return(false); }
public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) { if (worldItem.ToRemove) { return; } ComponentBlockEntity blockEntity = m_subsystemBlockEntities.GetBlockEntity(cellFace.X, cellFace.Y, cellFace.Z); if (blockEntity != null) { ComponentChest inventory = blockEntity.Entity.FindComponent <ComponentChest>(throwOnError: true); Pickable pickable = worldItem as Pickable; int num = pickable?.Count ?? 1; int num2 = ComponentInventoryBase.AcquireItems(inventory, worldItem.Value, num); if (num2 < num) { m_subsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, autoDelay: true); } if (num2 <= 0) { worldItem.ToRemove = true; } else if (pickable != null) { pickable.Count = num2; } } }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { BodyRaycastResult?bodyRaycastResult = componentMiner.Raycast <BodyRaycastResult>(ray, RaycastMode.Interaction); if (bodyRaycastResult.HasValue) { ComponentHealth componentHealth = bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentHealth>(); if (componentHealth == null || componentHealth.Health > 0f) { string entityTemplateName = bodyRaycastResult.Value.ComponentBody.Entity.ValuesDictionary.DatabaseObject.Name + "_Saddled"; Entity entity = DatabaseManager.CreateEntity(base.Project, entityTemplateName, throwIfNotFound: false); if (entity != null) { ComponentBody componentBody = entity.FindComponent <ComponentBody>(throwOnError: true); componentBody.Position = bodyRaycastResult.Value.ComponentBody.Position; componentBody.Rotation = bodyRaycastResult.Value.ComponentBody.Rotation; componentBody.Velocity = bodyRaycastResult.Value.ComponentBody.Velocity; entity.FindComponent <ComponentSpawn>(throwOnError: true).SpawnDuration = 0f; base.Project.RemoveEntity(bodyRaycastResult.Value.ComponentBody.Entity, disposeEntity: true); base.Project.AddEntity(entity); m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); } } return(true); } return(false); }
public static void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) { if (worldItem.ToRemove) { return; } var blockEntity = GetBlockEntity(cellFace.Point); if (blockEntity == null) { return; } var inventory = blockEntity.Entity.FindComponent <ComponentInventoryBase>(true); var pickable = worldItem as Pickable; int count = (pickable == null) ? 1 : pickable.Count; int value = worldItem.Value; int max = ComponentInventoryBase.AcquireItems(inventory, value, count); if (max < count) { SubsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, true); } if (max <= 0) { worldItem.ToRemove = true; } else if (pickable != null) { pickable.Count = max; } }
public void Update(float dt) { if (m_closestSoundToPlay.HasValue) { m_subsystemAudio.PlaySound("Audio/Spikes", 0.7f, m_random.Float(-0.1f, 0.1f), m_closestSoundToPlay.Value, 4f, autoDelay: true); m_closestSoundToPlay = null; } }
public void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound) { m_messageWidget.DisplayMessage(text, color, blinking); if (playNotificationSound) { m_subsystemAudio.PlaySound("Audio/UI/Message", 1f, 0f, 0f, 0f); } }
public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) { switch (state) { case AimState.InProgress: { componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 3.2f; Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(componentMiner.ActiveBlockValue)]; ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>(); if (componentFirstPersonModel != null) { componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction); componentFirstPersonModel.ItemOffsetOrder = new Vector3(0f, 0.35f, 0.17f); if (block2 is SpearBlock) { componentFirstPersonModel.ItemRotationOrder = new Vector3(-1.5f, 0f, 0f); } } if (block2 is SpearBlock) { componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(0f, -0.25f, 0f); componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(3.14159f, 0f, 0f); } break; } case AimState.Completed: { Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.4f; Vector3 v = Vector3.Normalize(vector + aim.Direction * 10f - vector); if (componentMiner.Inventory == null) { break; } int activeSlotIndex = componentMiner.Inventory.ActiveSlotIndex; int slotValue = componentMiner.Inventory.GetSlotValue(activeSlotIndex); int slotCount = componentMiner.Inventory.GetSlotCount(activeSlotIndex); int num = Terrain.ExtractContents(slotValue); Block block = BlocksManager.Blocks[num]; if (slotCount > 0) { float num2 = block.ProjectileSpeed; if (componentMiner.ComponentPlayer != null) { num2 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f; } if (m_subsystemProjectiles.FireProjectile(slotValue, vector, v * num2, m_random.Vector3(5f, 10f), componentMiner.ComponentCreature) != null) { componentMiner.Inventory.RemoveSlotItems(activeSlotIndex, 1); m_subsystemAudio.PlaySound("Audio/Throw", m_random.Float(0.2f, 0.3f), m_random.Float(-0.2f, 0.2f), aim.Position, 2f, autoDelay: true); componentMiner.Poke(forceRestart: false); } } break; } } return(false); }
public void Update(float dt) { if (m_componentDamage.Hitpoints < 0.33f) { m_componentBody.Density = 1.15f; if (m_componentDamage.Hitpoints - m_componentDamage.HitpointsChange >= 0.33f && m_componentBody.ImmersionFactor > 0f) { m_subsystemAudio.PlaySound("Audio/Sinking", 1f, 0f, m_componentBody.Position, 4f, autoDelay: true); } } else if (m_componentDamage.Hitpoints < 0.66f) { m_componentBody.Density = 0.7f; if (m_componentDamage.Hitpoints - m_componentDamage.HitpointsChange >= 0.66f && m_componentBody.ImmersionFactor > 0f) { m_subsystemAudio.PlaySound("Audio/Sinking", 1f, 0f, m_componentBody.Position, 4f, autoDelay: true); } } bool num = m_componentBody.ImmersionFactor > 0.95f; bool num2 = !num && m_componentBody.ImmersionFactor > 0.01f && !m_componentBody.StandingOnValue.HasValue && m_componentBody.StandingOnBody == null; m_turnSpeed += 2.5f * m_subsystemTime.GameTimeDelta * (1f * TurnOrder - m_turnSpeed); Quaternion rotation = m_componentBody.Rotation; float num3 = MathUtils.Atan2(2f * rotation.Y * rotation.W - 2f * rotation.X * rotation.Z, 1f - 2f * rotation.Y * rotation.Y - 2f * rotation.Z * rotation.Z); if (num2) { num3 -= m_turnSpeed * dt; } m_componentBody.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, num3); if (num2 && MoveOrder != 0f) { m_componentBody.Velocity += dt * 3f * MoveOrder * m_componentBody.Matrix.Forward; } if (num) { m_componentDamage.Damage(0.005f * dt); if (m_componentMount.Rider != null) { m_componentMount.Rider.StartDismounting(); } } MoveOrder = 0f; TurnOrder = 0f; }
public void ShapeshiftTo(string entityTemplateName) { if (string.IsNullOrEmpty(m_spawnEntityTemplateName)) { m_spawnEntityTemplateName = entityTemplateName; m_componentSpawn.DespawnDuration = 3f; m_componentSpawn.Despawn(); m_subsystemAudio.PlaySound("Audio/Shapeshift", 1f, 0f, m_componentBody.Position, 3f, autoDelay: true); } }
public void DispenseItem(Point3 point, int face, int value, DispenserBlock.Mode mode) { Vector3 vector = CellFace.FaceToVector3(face); Vector3 position = new Vector3((float)point.X + 0.5f, (float)point.Y + 0.5f, (float)point.Z + 0.5f) + 0.6f * vector; if (mode == DispenserBlock.Mode.Dispense) { float s = 1.8f; m_subsystemPickables.AddPickable(value, 1, position, s * (vector + m_random.Vector3(0.2f)), null); m_subsystemAudio.PlaySound("Audio/DispenserDispense", 1f, 0f, new Vector3(position.X, position.Y, position.Z), 3f, autoDelay: true); return; } float s2 = m_random.Float(39f, 41f); if (m_subsystemProjectiles.FireProjectile(value, position, s2 * (vector + m_random.Vector3(0.025f) + new Vector3(0f, 0.05f, 0f)), Vector3.Zero, null) != null) { m_subsystemAudio.PlaySound("Audio/DispenserShoot", 1f, 0f, new Vector3(position.X, position.Y, position.Z), 4f, autoDelay: true); } else { DispenseItem(point, face, value, DispenserBlock.Mode.Dispense); } }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { object obj = componentMiner.Raycast(ray, RaycastMode.Digging); if (obj is TerrainRaycastResult) { CellFace cellFace = ((TerrainRaycastResult)obj).CellFace; if (m_subsystemExplosivesBlockBehavior.IgniteFuse(cellFace.X, cellFace.Y, cellFace.Z)) { m_subsystemAudio.PlaySound("Audio/Match", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); return(true); } if (m_subsystemFireBlockBehavior.SetCellOnFire(cellFace.X, cellFace.Y, cellFace.Z, 1f)) { m_subsystemAudio.PlaySound("Audio/Match", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); return(true); } } else if (obj is BodyRaycastResult) { ComponentOnFire componentOnFire = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentOnFire>(); if (componentOnFire != null) { if (m_subsystemGameInfo.WorldSettings.GameMode < GameMode.Challenging || m_random.Float(0f, 1f) < 0.33f) { componentOnFire.SetOnFire(componentMiner.ComponentCreature, m_random.Float(6f, 8f)); } m_subsystemAudio.PlaySound("Audio/Match", 1f, m_random.Float(-0.1f, 0.1f), ray.Position, 1f, autoDelay: true); componentMiner.RemoveActiveTool(1); return(true); } } return(false); }
public void SwitchToNextState(int x, int y, int z, bool playSound) { HashSet <Point3> hashSet = new HashSet <Point3>(); List <Point3> list = new List <Point3>(); list.Add(new Point3(x, y, z)); int num = 0; while (num < list.Count && num < 4096) { Point3 item = list[num++]; if (!hashSet.Add(item)) { continue; } int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(item.X, item.Y, item.Z); if (Terrain.ExtractContents(cellValue) != 227) { continue; } int data = Terrain.ExtractData(cellValue); int designIndex = FurnitureBlock.GetDesignIndex(data); FurnitureDesign design = GetDesign(designIndex); if (design != null && design.LinkedDesign != null && design.LinkedDesign.Index >= 0 && (list.Count == 1 || design.InteractionMode == FurnitureInteractionMode.ConnectedMultistate)) { int data2 = FurnitureBlock.SetDesignIndex(data, design.LinkedDesign.Index, design.LinkedDesign.ShadowStrengthFactor, design.LinkedDesign.IsLightEmitter); int value = Terrain.ReplaceData(cellValue, data2); base.SubsystemTerrain.ChangeCell(item.X, item.Y, item.Z, value); if (design.InteractionMode == FurnitureInteractionMode.ConnectedMultistate) { list.Add(new Point3(item.X - 1, item.Y, item.Z)); list.Add(new Point3(item.X + 1, item.Y, item.Z)); list.Add(new Point3(item.X, item.Y - 1, item.Z)); list.Add(new Point3(item.X, item.Y + 1, item.Z)); list.Add(new Point3(item.X, item.Y, item.Z - 1)); list.Add(new Point3(item.X, item.Y, item.Z + 1)); } } } if (playSound) { m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, new Vector3(x, y, z), 2f, autoDelay: true); } }
public void AddExperience(int count, bool playSound) { if (playSound) { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 0.2f, m_random.Float(-0.1f, 0.4f), 0f, 0f); } for (int i = 0; i < count; i++) { float num = 0.012f / MathUtils.Pow(1.08f, MathUtils.Floor(m_componentPlayer.PlayerData.Level - 1f)); if (MathUtils.Floor(m_componentPlayer.PlayerData.Level + num) > MathUtils.Floor(m_componentPlayer.PlayerData.Level)) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.0, delegate { m_componentPlayer.ComponentGui.DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: false); }); Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.0, delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, -0.2f, 0f, 0f); }); Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.15000000596046448, delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, -0.03333333f, 0f, 0f); }); Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.30000001192092896, delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, 142f / (339f * (float)Math.PI), 0f, 0f); }); Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.45000001788139343, delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, 23f / 60f, 0f, 0f); }); Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.75, delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, -0.03333333f, 0f, 0f); }); Time.QueueTimeDelayedExecution(Time.FrameStartTime + 0.5 + 0.90000003576278687, delegate { m_subsystemAudio.PlaySound("Audio/ExperienceCollected", 1f, 23f / 60f, 0f, 0f); }); } m_componentPlayer.PlayerData.Level += num; } }
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); }
public bool Place(TerrainRaycastResult raycastResult, int value) { if (Place2 != null) { return(Place2(raycastResult, value)); } int num = Terrain.ExtractContents(value); if (BlocksManager.Blocks[num].IsPlaceable) { Block block = BlocksManager.Blocks[num]; BlockPlacementData placementData = block.GetPlacementValue(m_subsystemTerrain, this, value, raycastResult); if (placementData.Value != 0) { Point3 point = CellFace.FaceToPoint3(placementData.CellFace.Face); int num2 = placementData.CellFace.X + point.X; int num3 = placementData.CellFace.Y + point.Y; int num4 = placementData.CellFace.Z + point.Z; if (num3 > 0 && num3 < 255 && (IsBlockPlacingAllowed(ComponentCreature.ComponentBody) || m_subsystemGameInfo.WorldSettings.GameMode <= GameMode.Harmless)) { bool flag = false; if (block.IsCollidable) { BoundingBox boundingBox = ComponentCreature.ComponentBody.BoundingBox; boundingBox.Min += new Vector3(0.2f); boundingBox.Max -= new Vector3(0.2f); BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, placementData.Value); for (int i = 0; i < customCollisionBoxes.Length; i++) { BoundingBox box = customCollisionBoxes[i]; box.Min += new Vector3(num2, num3, num4); box.Max += new Vector3(num2, num3, num4); if (boundingBox.Intersection(box)) { flag = true; break; } } } if (!flag) { SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(placementData.Value)); for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnItemPlaced(num2, num3, num4, ref placementData, value); } m_subsystemTerrain.DestroyCell(0, num2, num3, num4, placementData.Value, noDrop: false, noParticleSystem: false); m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, new Vector3(placementData.CellFace.X, placementData.CellFace.Y, placementData.CellFace.Z), 5f, autoDelay: false); Poke(forceRestart: false); if (ComponentCreature.PlayerStats != null) { ComponentCreature.PlayerStats.BlocksPlaced++; } return(true); } } } } return(false); }
public void PostprocessExplosions(bool playExplosionSound) { Point3 point = Point3.Zero; float num = float.MaxValue; float num2 = 0f; foreach (KeyValuePair <Point3, float> item in m_pressureByPoint.ToDictionary()) { num2 += item.Value; float num3 = m_subsystemAudio.CalculateListenerDistance(new Vector3(item.Key)); if (num3 < num) { num = num3; point = item.Key; } float num4 = 0.001f * MathUtils.Pow(num2, 0.5f); float num5 = MathUtils.Saturate(item.Value / 15f - num4) * m_random.Float(0.2f, 1f); if (num5 > 0.1f) { m_explosionParticleSystem.SetExplosionCell(item.Key, num5); } } foreach (KeyValuePair <Point3, SurroundingPressurePoint> item2 in m_surroundingPressureByPoint.ToDictionary()) { int cellValue = m_subsystemTerrain.Terrain.GetCellValue(item2.Key.X, item2.Key.Y, item2.Key.Z); int num6 = Terrain.ExtractContents(cellValue); SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num6); if (blockBehaviors.Length != 0) { for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnExplosion(cellValue, item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value.Pressure); } } float probability = item2.Value.IsIncendiary ? 0.5f : 0.2f; Block block = BlocksManager.Blocks[num6]; if (block.FireDuration > 0f && item2.Value.Pressure / block.ExplosionResilience > 0.2f && m_random.Bool(probability)) { m_subsystemFireBlockBehavior.SetCellOnFire(item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value.IsIncendiary ? 1f : 0.3f); } } foreach (ComponentBody body in m_subsystemBodies.Bodies) { CalculateImpulseAndDamage(body, null, out Vector3 impulse, out float damage); impulse *= m_random.Float(0.5f, 1.5f); damage *= m_random.Float(0.5f, 1.5f); body.ApplyImpulse(impulse); body.Entity.FindComponent <ComponentHealth>()?.Injure(damage, null, ignoreInvulnerability: false, "Blasted by explosion"); body.Entity.FindComponent <ComponentDamage>()?.Damage(damage); ComponentOnFire componentOnFire = body.Entity.FindComponent <ComponentOnFire>(); if (componentOnFire != null && m_random.Float(0f, 1f) < MathUtils.Min(damage - 0.1f, 0.5f)) { componentOnFire.SetOnFire(null, m_random.Float(6f, 8f)); } } foreach (Pickable pickable in m_subsystemPickables.Pickables) { Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)]; CalculateImpulseAndDamage(pickable.Position + new Vector3(0f, 0.5f, 0f), 20f, null, out Vector3 impulse2, out float damage2); if (damage2 / block2.ExplosionResilience > 0.1f) { TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value); pickable.ToRemove = true; } else { Vector3 vector = (impulse2 + new Vector3(0f, 0.1f * impulse2.Length(), 0f)) * m_random.Float(0.75f, 1f); if (vector.Length() > 10f) { Projectile projectile = m_subsystemProjectiles.AddProjectile(pickable.Value, pickable.Position, pickable.Velocity + vector, m_random.Vector3(0f, 20f), null); if (m_random.Float(0f, 1f) < 0.33f) { m_subsystemProjectiles.AddTrail(projectile, Vector3.Zero, new SmokeTrailParticleSystem(15, m_random.Float(0.75f, 1.5f), m_random.Float(1f, 6f), Color.White)); } pickable.ToRemove = true; } else { pickable.Velocity += vector; } } } foreach (Projectile projectile2 in m_subsystemProjectiles.Projectiles) { if (!m_generatedProjectiles.ContainsKey(projectile2)) { CalculateImpulseAndDamage(projectile2.Position + new Vector3(0f, 0.5f, 0f), 20f, null, out Vector3 impulse3, out float _); projectile2.Velocity += (impulse3 + new Vector3(0f, 0.1f * impulse3.Length(), 0f)) * m_random.Float(0.75f, 1f); } } Vector3 position = new Vector3(point.X, point.Y, point.Z); float delay = m_subsystemAudio.CalculateDelay(num); if (num2 > 1000000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionEnormous", 1f, m_random.Float(-0.1f, 0.1f), position, 40f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 100f); } else if (num2 > 100000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionHuge", 1f, m_random.Float(-0.2f, 0.2f), position, 30f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 70f); } else if (num2 > 20000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionLarge", 1f, m_random.Float(-0.2f, 0.2f), position, 26f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 50f); } else if (num2 > 4000f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionMedium", 1f, m_random.Float(-0.2f, 0.2f), position, 24f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 40f); } else if (num2 > 100f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionSmall", 1f, m_random.Float(-0.2f, 0.2f), position, 22f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 35f); } else if (num2 > 0f) { if (playExplosionSound) { m_subsystemAudio.PlaySound("Audio/ExplosionTiny", 1f, m_random.Float(-0.2f, 0.2f), position, 20f, delay); } m_subsystemNoise.MakeNoise(position, 1f, 30f); } }
public void Update(float dt) { if (!base.IsAddedToProject) { return; } if (IsOnFire) { m_fireDuration = MathUtils.Max(m_fireDuration - dt, 0f); if (m_onFireParticleSystem == null) { m_onFireParticleSystem = new OnFireParticleSystem(); m_subsystemParticles.AddParticleSystem(m_onFireParticleSystem); } BoundingBox boundingBox = ComponentBody.BoundingBox; m_onFireParticleSystem.Position = 0.5f * (boundingBox.Min + boundingBox.Max); m_onFireParticleSystem.Radius = 0.5f * MathUtils.Min(boundingBox.Max.X - boundingBox.Min.X, boundingBox.Max.Z - boundingBox.Min.Z); if (ComponentBody.ImmersionFactor > 0.5f && ComponentBody.ImmersionFluidBlock is WaterBlock) { Extinguish(); m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, m_onFireParticleSystem.Position, 4f, autoDelay: true); } if (Time.PeriodicEvent(0.5, 0.0)) { float distance = m_subsystemAudio.CalculateListenerDistance(ComponentBody.Position); m_soundVolume = m_subsystemAudio.CalculateVolume(distance, 2f, 5f); } m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_soundVolume); } else { if (m_onFireParticleSystem != null) { m_onFireParticleSystem.IsStopped = true; m_onFireParticleSystem = null; } m_soundVolume = 0f; } if (!(m_subsystemTime.GameTime > m_nextCheckTime)) { return; } m_nextCheckTime = m_subsystemTime.GameTime + (double)m_random.Float(0.9f, 1.1f); TouchesFire = CheckIfBodyTouchesFire(); if (TouchesFire) { m_fireTouchCount++; if (m_fireTouchCount >= 5) { SetOnFire(null, m_random.Float(12f, 15f)); } } else { m_fireTouchCount = 0; } if (ComponentBody.ImmersionFactor > 0.2f && ComponentBody.ImmersionFluidBlock is MagmaBlock) { SetOnFire(null, m_random.Float(12f, 15f)); } }
public bool MovePiston(Point3 position, int length) { Terrain terrain = m_subsystemTerrain.Terrain; int data = Terrain.ExtractData(terrain.GetCellValue(position.X, position.Y, position.Z)); int face = PistonBlock.GetFace(data); PistonMode mode = PistonBlock.GetMode(data); int maxExtension = PistonBlock.GetMaxExtension(data); int pullCount = PistonBlock.GetPullCount(data); int speed = PistonBlock.GetSpeed(data); Point3 point = CellFace.FaceToPoint3(face); length = MathUtils.Clamp(length, 0, maxExtension + 1); int num = 0; m_movingBlocks.Clear(); Point3 offset = point; MovingBlock item; while (m_movingBlocks.Count < 8) { int cellValue = terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z); int num2 = Terrain.ExtractContents(cellValue); int face2 = PistonHeadBlock.GetFace(Terrain.ExtractData(cellValue)); if (num2 != 238 || face2 != face) { break; } DynamicArray <MovingBlock> movingBlocks = m_movingBlocks; item = new MovingBlock { Offset = offset, Value = cellValue }; movingBlocks.Add(item); offset += point; num++; } if (length > num) { DynamicArray <MovingBlock> movingBlocks2 = m_movingBlocks; item = new MovingBlock { Offset = Point3.Zero, Value = Terrain.MakeBlockValue(238, 0, PistonHeadBlock.SetFace(PistonHeadBlock.SetMode(PistonHeadBlock.SetIsShaft(0, num > 0), mode), face)) }; movingBlocks2.Add(item); int num3 = 0; while (num3 < 8) { int cellValue2 = terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z); if (!IsBlockMovable(cellValue2, face, position.Y + offset.Y, out bool isEnd)) { break; } DynamicArray <MovingBlock> movingBlocks3 = m_movingBlocks; item = new MovingBlock { Offset = offset, Value = cellValue2 }; movingBlocks3.Add(item); num3++; offset += point; if (isEnd) { break; } } if (!IsBlockBlocking(terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z))) { GetSpeedAndSmoothness(speed, out float speed2, out Vector2 smoothness); Point3 p = position + (length - num) * point; if (m_subsystemMovingBlocks.AddMovingBlockSet(new Vector3(position) + 0.01f * new Vector3(point), new Vector3(p), speed2, 0f, 0f, smoothness, m_movingBlocks, "Piston", position, testCollision: true) != null) { m_allowPistonHeadRemove = true; try { foreach (MovingBlock movingBlock in m_movingBlocks) { if (movingBlock.Offset != Point3.Zero) { m_subsystemTerrain.ChangeCell(position.X + movingBlock.Offset.X, position.Y + movingBlock.Offset.Y, position.Z + movingBlock.Offset.Z, 0); } } } finally { m_allowPistonHeadRemove = false; } m_subsystemTerrain.ChangeCell(position.X, position.Y, position.Z, Terrain.MakeBlockValue(237, 0, PistonBlock.SetIsExtended(data, isExtended: true))); m_subsystemAudio.PlaySound("Audio/Piston", 1f, 0f, new Vector3(position), 2f, autoDelay: true); } } return(false); } if (length < num) { if (mode != 0) { int num4 = 0; for (int i = 0; i < pullCount + 1; i++) { int cellValue3 = terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z); if (!IsBlockMovable(cellValue3, face, position.Y + offset.Y, out bool isEnd2)) { break; } DynamicArray <MovingBlock> movingBlocks4 = m_movingBlocks; item = new MovingBlock { Offset = offset, Value = cellValue3 }; movingBlocks4.Add(item); offset += point; num4++; if (isEnd2) { break; } } if (mode == PistonMode.StrictPulling && num4 < pullCount + 1) { return(false); } } GetSpeedAndSmoothness(speed, out float speed3, out Vector2 smoothness2); float s = (length == 0) ? 0.01f : 0f; Vector3 targetPosition = new Vector3(position) + (length - num) * new Vector3(point) + s * new Vector3(point); if (m_subsystemMovingBlocks.AddMovingBlockSet(new Vector3(position), targetPosition, speed3, 0f, 0f, smoothness2, m_movingBlocks, "Piston", position, testCollision: true) != null) { m_allowPistonHeadRemove = true; try { foreach (MovingBlock movingBlock2 in m_movingBlocks) { m_subsystemTerrain.ChangeCell(position.X + movingBlock2.Offset.X, position.Y + movingBlock2.Offset.Y, position.Z + movingBlock2.Offset.Z, 0); } } finally { m_allowPistonHeadRemove = false; } m_subsystemAudio.PlaySound("Audio/Piston", 1f, 0f, new Vector3(position), 2f, autoDelay: true); } return(false); } return(true); }
public void Update(float dt) { double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime; float num = MathUtils.Pow(0.5f, dt); float num2 = MathUtils.Pow(0.001f, dt); m_tmpPlayers.Clear(); foreach (ComponentPlayer componentPlayer in m_subsystemPlayers.ComponentPlayers) { if (componentPlayer.ComponentHealth.Health > 0f) { m_tmpPlayers.Add(componentPlayer); } } foreach (Pickable pickable in m_pickables) { if (pickable.ToRemove) { m_pickablesToRemove.Add(pickable); } else { Block block = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)]; int num3 = m_pickables.Count - m_pickablesToRemove.Count; float num4 = MathUtils.Lerp(300f, 90f, MathUtils.Saturate((float)num3 / 60f)); double num5 = totalElapsedGameTime - pickable.CreationTime; if (num5 > (double)num4) { pickable.ToRemove = true; } else { TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Z)); if (chunkAtCell != null && chunkAtCell.State > TerrainChunkState.InvalidContents4) { Vector3 position = pickable.Position; Vector3 vector = position + pickable.Velocity * dt; if (!pickable.FlyToPosition.HasValue && num5 > 0.5) { foreach (ComponentPlayer tmpPlayer in m_tmpPlayers) { ComponentBody componentBody = tmpPlayer.ComponentBody; Vector3 v = componentBody.Position + new Vector3(0f, 0.75f, 0f); float num6 = (v - pickable.Position).LengthSquared(); if (num6 < 3.0625f) { bool flag = Terrain.ExtractContents(pickable.Value) == 248; IInventory inventory = tmpPlayer.ComponentMiner.Inventory; if (flag || ComponentInventoryBase.FindAcquireSlotForItem(inventory, pickable.Value) >= 0) { if (num6 < 1f) { if (flag) { tmpPlayer.ComponentLevel.AddExperience(pickable.Count, playSound: true); pickable.ToRemove = true; } else { pickable.Count = ComponentInventoryBase.AcquireItems(inventory, pickable.Value, pickable.Count); if (pickable.Count == 0) { pickable.ToRemove = true; m_subsystemAudio.PlaySound("Audio/PickableCollected", 0.7f, -0.4f, pickable.Position, 2f, autoDelay: false); } } } else if (!pickable.StuckMatrix.HasValue) { pickable.FlyToPosition = v + 0.1f * MathUtils.Sqrt(num6) * componentBody.Velocity; } } } } } if (pickable.FlyToPosition.HasValue) { Vector3 v2 = pickable.FlyToPosition.Value - pickable.Position; float num7 = v2.LengthSquared(); if (num7 >= 0.25f) { pickable.Velocity = 6f * v2 / MathUtils.Sqrt(num7); } else { pickable.FlyToPosition = null; } } else { FluidBlock surfaceBlock; float? surfaceHeight; Vector2? vector2 = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z), out surfaceBlock, out surfaceHeight); if (!pickable.StuckMatrix.HasValue) { TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable); if (terrainRaycastResult.HasValue) { int contents = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValue(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z)); SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents); for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnHitByProjectile(terrainRaycastResult.Value.CellFace, pickable); } if (m_subsystemTerrain.Raycast(position, position, useInteractionBoxes: false, skipAirBlocks: true, (int value2, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value2)].IsCollidable).HasValue) { int num8 = Terrain.ToCell(position.X); int num9 = Terrain.ToCell(position.Y); int num10 = Terrain.ToCell(position.Z); int num11 = 0; int num12 = 0; int num13 = 0; int?num14 = null; for (int j = -3; j <= 3; j++) { for (int k = -3; k <= 3; k++) { for (int l = -3; l <= 3; l++) { if (!BlocksManager.Blocks[m_subsystemTerrain.Terrain.GetCellContents(j + num8, k + num9, l + num10)].IsCollidable) { int num15 = j * j + k * k + l * l; if (!num14.HasValue || num15 < num14.Value) { num11 = j + num8; num12 = k + num9; num13 = l + num10; num14 = num15; } } } } } if (num14.HasValue) { pickable.FlyToPosition = new Vector3(num11, num12, num13) + new Vector3(0.5f); } else { pickable.ToRemove = true; } } else { Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane(); bool flag2 = vector2.HasValue && vector2.Value != Vector2.Zero; if (plane.Normal.X != 0f) { float num16 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.Y) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f; pickable.Velocity *= new Vector3(0f - num16, num16, num16); } if (plane.Normal.Y != 0f) { float num17 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f; pickable.Velocity *= new Vector3(num17, 0f - num17, num17); if (flag2) { pickable.Velocity.Y += 0.1f * plane.Normal.Y; } } if (plane.Normal.Z != 0f) { float num18 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Y)) > 10f) ? 0.95f : 0.25f; pickable.Velocity *= new Vector3(num18, num18, 0f - num18); } vector = position; } } } else { Vector3 vector3 = pickable.StuckMatrix.Value.Translation + pickable.StuckMatrix.Value.Up * block.ProjectileTipOffset; if (!m_subsystemTerrain.Raycast(vector3, vector3, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable).HasValue) { pickable.Position = pickable.StuckMatrix.Value.Translation; pickable.Velocity = Vector3.Zero; pickable.StuckMatrix = null; } } if (surfaceBlock is WaterBlock && !pickable.SplashGenerated) { m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false)); m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 6f, autoDelay: true); pickable.SplashGenerated = true; } else if (surfaceBlock is MagmaBlock && !pickable.SplashGenerated) { m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false)); m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true); pickable.ToRemove = true; pickable.SplashGenerated = true; m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value); } else if (surfaceBlock == null) { pickable.SplashGenerated = false; } if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(pickable.GetHashCode() % 100) / 100.0) && (m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z)) == 104 || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z)))) { m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true); pickable.ToRemove = true; m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value); } if (!pickable.StuckMatrix.HasValue) { if (vector2.HasValue && surfaceHeight.HasValue) { float num19 = surfaceHeight.Value - pickable.Position.Y; float num20 = MathUtils.Saturate(3f * num19); pickable.Velocity.X += 4f * dt * (vector2.Value.X - pickable.Velocity.X); pickable.Velocity.Y -= 10f * dt; pickable.Velocity.Y += 10f * (1f / block.Density * num20) * dt; pickable.Velocity.Z += 4f * dt * (vector2.Value.Y - pickable.Velocity.Z); pickable.Velocity.Y *= num2; } else { pickable.Velocity.Y -= 10f * dt; pickable.Velocity *= num; } } } pickable.Position = vector; } } } } foreach (Pickable item in m_pickablesToRemove) { m_pickables.Remove(item); if (this.PickableRemoved != null) { this.PickableRemoved(item); } } m_pickablesToRemove.Clear(); }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { IInventory inventory = componentMiner.Inventory; int activeBlockValue = componentMiner.ActiveBlockValue; int num = Terrain.ExtractContents(activeBlockValue); if (num == 90) { object obj = componentMiner.Raycast(ray, RaycastMode.Gathering); if (obj is TerrainRaycastResult) { CellFace cellFace = ((TerrainRaycastResult)obj).CellFace; int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z); int num2 = Terrain.ExtractContents(cellValue); int data = Terrain.ExtractData(cellValue); Block block = BlocksManager.Blocks[num2]; if (block is WaterBlock && FluidBlock.GetLevel(data) == 0) { int value = Terrain.ReplaceContents(activeBlockValue, 91); inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex)); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { inventory.AddSlotItems(inventory.ActiveSlotIndex, value, 1); } base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false); return(true); } if (block is MagmaBlock && FluidBlock.GetLevel(data) == 0) { int value2 = Terrain.ReplaceContents(activeBlockValue, 93); inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex)); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { inventory.AddSlotItems(inventory.ActiveSlotIndex, value2, 1); } base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false); return(true); } } else if (obj is BodyRaycastResult) { ComponentUdder componentUdder = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentUdder>(); if (componentUdder != null && componentUdder.Milk(componentMiner)) { int value3 = Terrain.ReplaceContents(activeBlockValue, 110); inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex)); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { inventory.AddSlotItems(inventory.ActiveSlotIndex, value3, 1); } m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, autoDelay: true); } return(true); } } if (num == 91) { TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction); if (terrainRaycastResult.HasValue && componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(18))) { inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { int value4 = Terrain.ReplaceContents(activeBlockValue, 90); inventory.AddSlotItems(inventory.ActiveSlotIndex, value4, 1); } return(true); } } if (num == 93) { TerrainRaycastResult?terrainRaycastResult2 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction); if (terrainRaycastResult2.HasValue) { if (componentMiner.Place(terrainRaycastResult2.Value, Terrain.MakeBlockValue(92))) { inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1); if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) { int value5 = Terrain.ReplaceContents(activeBlockValue, 90); inventory.AddSlotItems(inventory.ActiveSlotIndex, value5, 1); } } return(true); } } switch (num) { case 110: case 245: return(true); case 251: case 252: return(true); case 128: case 129: { TerrainRaycastResult?terrainRaycastResult3 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging); if (terrainRaycastResult3.HasValue) { CellFace cellFace2 = terrainRaycastResult3.Value.CellFace; int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z); int num3 = Terrain.ExtractContents(cellValue2); Block block2 = BlocksManager.Blocks[num3]; if (block2 is IPaintableBlock) { Vector3 normal = CellFace.FaceToVector3(terrainRaycastResult3.Value.CellFace.Face); Vector3 position = terrainRaycastResult3.Value.HitPoint(); int? num4 = (num == 128) ? null : new int?(PaintBucketBlock.GetColor(Terrain.ExtractData(activeBlockValue))); Color color = num4.HasValue ? SubsystemPalette.GetColor(base.SubsystemTerrain, num4) : new Color(128, 128, 128, 128); int value6 = ((IPaintableBlock)block2).Paint(base.SubsystemTerrain, cellValue2, num4); base.SubsystemTerrain.ChangeCell(cellFace2.X, cellFace2.Y, cellFace2.Z, value6); componentMiner.DamageActiveTool(1); m_subsystemAudio.PlayRandomSound("Audio/Paint", 0.4f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentBody.Position, 2f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new PaintParticleSystem(base.SubsystemTerrain, position, normal, color)); } return(true); } break; } } return(false); }
public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) { IInventory inventory = componentMiner.Inventory; if (inventory != null) { int activeSlotIndex = inventory.ActiveSlotIndex; if (activeSlotIndex >= 0) { int slotValue = inventory.GetSlotValue(activeSlotIndex); int slotCount = inventory.GetSlotCount(activeSlotIndex); int num = Terrain.ExtractContents(slotValue); int data = Terrain.ExtractData(slotValue); if (num == 191 && slotCount > 0) { if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) { value = m_subsystemTime.GameTime; m_aimStartTimes[componentMiner] = value; } float num2 = (float)(m_subsystemTime.GameTime - value); float num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0); Vector3 v = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.02f : 0.04f) + 0.25f * MathUtils.Saturate((num2 - 2.1f) / 5f)) * new Vector3 { X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f), Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f), Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f) }; aim.Direction = Vector3.Normalize(aim.Direction + v); switch (state) { case AimState.InProgress: { if (num2 >= 9f) { componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound(); return(true); } ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>(); if (componentFirstPersonModel != null) { componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction); componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.1f, 0.15f, 0f); componentFirstPersonModel.ItemRotationOrder = new Vector3(0f, -0.7f, 0f); } componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.2f; componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(0f, 0f, 0f); componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(0f, -0.2f, 0f); if (m_subsystemTime.PeriodicGameTimeEvent(0.10000000149011612, 0.0)) { int draw2 = MathUtils.Min(BowBlock.GetDraw(data) + 1, 15); inventory.RemoveSlotItems(activeSlotIndex, 1); inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, draw2)), 1); } break; } case AimState.Cancelled: inventory.RemoveSlotItems(activeSlotIndex, 1); inventory.AddSlotItems(activeSlotIndex, Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)), 1); m_aimStartTimes.Remove(componentMiner); break; case AimState.Completed: { int draw = BowBlock.GetDraw(data); ArrowBlock.ArrowType?arrowType = BowBlock.GetArrowType(data); if (arrowType.HasValue) { Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f; Vector3 vector2 = Vector3.Normalize(vector + aim.Direction * 10f - vector); float num4 = MathUtils.Lerp(0f, 28f, MathUtils.Pow((float)draw / 15f, 0.75f)); if (componentMiner.ComponentPlayer != null) { num4 *= 0.5f * (componentMiner.ComponentPlayer.ComponentLevel.StrengthFactor - 1f) + 1f; } Vector3 vector3 = Vector3.Zero; if (arrowType == ArrowBlock.ArrowType.WoodenArrow) { vector3 = new Vector3(0.025f, 0.025f, 0.025f); } if (arrowType == ArrowBlock.ArrowType.StoneArrow) { vector3 = new Vector3(0.01f, 0.01f, 0.01f); } int value2 = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value)); Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector2, Vector3.UnitY)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector2, vector4)); Vector3 v3 = m_random.Float(0f - vector3.X, vector3.X) * vector4 + m_random.Float(0f - vector3.Y, vector3.Y) * v2 + m_random.Float(0f - vector3.Z, vector3.Z) * vector2; if (m_subsystemProjectiles.FireProjectile(value2, vector, (vector2 + v3) * num4, Vector3.Zero, componentMiner.ComponentCreature) != null) { data = BowBlock.SetArrowType(data, null); m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), vector, 3f, autoDelay: true); } } else { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load an arrow first", Color.White, blinking: true, playNotificationSound: false); } inventory.RemoveSlotItems(activeSlotIndex, 1); int value3 = Terrain.MakeBlockValue(num, 0, BowBlock.SetDraw(data, 0)); inventory.AddSlotItems(activeSlotIndex, value3, 1); int damageCount = 0; if (draw >= 15) { damageCount = 2; } else if (draw >= 4) { damageCount = 1; } componentMiner.DamageActiveTool(damageCount); m_aimStartTimes.Remove(componentMiner); break; } } } } } return(false); }
public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) { IInventory inventory = componentMiner.Inventory; if (inventory != null) { int activeSlotIndex = inventory.ActiveSlotIndex; if (activeSlotIndex >= 0) { int slotValue = inventory.GetSlotValue(activeSlotIndex); int slotCount = inventory.GetSlotCount(activeSlotIndex); int num = Terrain.ExtractContents(slotValue); int data = Terrain.ExtractData(slotValue); int num2 = slotValue; int num3 = 0; if (num == 212 && slotCount > 0) { if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) { value = m_subsystemTime.GameTime; m_aimStartTimes[componentMiner] = value; } float num4 = (float)(m_subsystemTime.GameTime - value); float num5 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0); Vector3 v = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.2f * MathUtils.Saturate((num4 - 2.5f) / 6f)) * new Vector3 { X = SimplexNoise.OctavedNoise(num5, 2f, 3, 2f, 0.5f), Y = SimplexNoise.OctavedNoise(num5 + 100f, 2f, 3, 2f, 0.5f), Z = SimplexNoise.OctavedNoise(num5 + 200f, 2f, 3, 2f, 0.5f) }; aim.Direction = Vector3.Normalize(aim.Direction + v); switch (state) { case AimState.InProgress: { if (num4 >= 10f) { componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound(); return(true); } if (num4 > 0.5f && !MusketBlock.GetHammerState(Terrain.ExtractData(num2))) { num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: true)); m_subsystemAudio.PlaySound("Audio/HammerCock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f); } ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>(); if (componentFirstPersonModel != null) { componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction); componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.21f, 0.15f, 0.08f); componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f); } componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.4f; componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(-0.08f, -0.08f, 0.07f); componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.7f, 0f, 0f); break; } case AimState.Cancelled: if (MusketBlock.GetHammerState(Terrain.ExtractData(num2))) { num2 = Terrain.MakeBlockValue(num, 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false)); m_subsystemAudio.PlaySound("Audio/HammerUncock", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f); } m_aimStartTimes.Remove(componentMiner); break; case AimState.Completed: { bool flag = false; int value2 = 0; int num6 = 0; float s = 0f; Vector3 vector = Vector3.Zero; MusketBlock.LoadState loadState = MusketBlock.GetLoadState(data); BulletBlock.BulletType?bulletType = MusketBlock.GetBulletType(data); if (MusketBlock.GetHammerState(Terrain.ExtractData(num2))) { switch (loadState) { case MusketBlock.LoadState.Empty: componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load gunpowder first", Color.White, blinking: true, playNotificationSound: false); break; case MusketBlock.LoadState.Gunpowder: case MusketBlock.LoadState.Wad: flag = true; componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No bullet, blind shot fired", Color.White, blinking: true, playNotificationSound: false); break; case MusketBlock.LoadState.Loaded: flag = true; if (bulletType == BulletBlock.BulletType.Buckshot) { value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall)); num6 = 8; vector = new Vector3(0.04f, 0.04f, 0.25f); s = 80f; } else if (bulletType == BulletBlock.BulletType.BuckshotBall) { value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, BulletBlock.BulletType.BuckshotBall)); num6 = 1; vector = new Vector3(0.06f, 0.06f, 0f); s = 60f; } else if (bulletType.HasValue) { value2 = Terrain.MakeBlockValue(214, 0, BulletBlock.SetBulletType(0, bulletType.Value)); num6 = 1; s = 120f; } break; } } if (flag) { if (componentMiner.ComponentCreature.ComponentBody.ImmersionFactor > 0.4f) { m_subsystemAudio.PlaySound("Audio/MusketMisfire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, autoDelay: true); } else { Vector3 vector2 = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f; Vector3 vector3 = Vector3.Normalize(vector2 + aim.Direction * 10f - vector2); Vector3 vector4 = Vector3.Normalize(Vector3.Cross(vector3, Vector3.UnitY)); Vector3 v2 = Vector3.Normalize(Vector3.Cross(vector3, vector4)); for (int i = 0; i < num6; i++) { Vector3 v3 = m_random.Float(0f - vector.X, vector.X) * vector4 + m_random.Float(0f - vector.Y, vector.Y) * v2 + m_random.Float(0f - vector.Z, vector.Z) * vector3; Projectile projectile = m_subsystemProjectiles.FireProjectile(value2, vector2, s * (vector3 + v3), Vector3.Zero, componentMiner.ComponentCreature); if (projectile != null) { projectile.ProjectileStoppedAction = ProjectileStoppedAction.Disappear; } } m_subsystemAudio.PlaySound("Audio/MusketFire", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 10f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new GunSmokeParticleSystem(m_subsystemTerrain, vector2 + 0.3f * vector3, vector3)); m_subsystemNoise.MakeNoise(vector2, 1f, 40f); componentMiner.ComponentCreature.ComponentBody.ApplyImpulse(-4f * vector3); } num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetLoadState(Terrain.ExtractData(num2), MusketBlock.LoadState.Empty)); num3 = 1; } if (MusketBlock.GetHammerState(Terrain.ExtractData(num2))) { num2 = Terrain.MakeBlockValue(Terrain.ExtractContents(num2), 0, MusketBlock.SetHammerState(Terrain.ExtractData(num2), state: false)); m_subsystemAudio.PlaySound("Audio/HammerRelease", 1f, m_random.Float(-0.1f, 0.1f), 0f, 0f); } m_aimStartTimes.Remove(componentMiner); break; } } } if (num2 != slotValue) { inventory.RemoveSlotItems(activeSlotIndex, 1); inventory.AddSlotItems(activeSlotIndex, num2, 1); } if (num3 > 0) { componentMiner.DamageActiveTool(num3); } } } return(false); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true); m_subsystemAudio = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); EggBlock eggBlock = (EggBlock)BlocksManager.Blocks[118]; m_layFrequency = valuesDictionary.GetValue <float>("LayFrequency"); m_eggType = eggBlock.GetEggTypeByCreatureTemplateName(base.Entity.ValuesDictionary.DatabaseObject.Name); m_stateMachine.AddState("Inactive", null, delegate { if (IsActive) { m_stateMachine.TransitionTo("Move"); } }, null); m_stateMachine.AddState("Stuck", delegate { m_stateMachine.TransitionTo("Move"); }, null, null); m_stateMachine.AddState("Move", delegate { Vector3 position2 = m_componentCreature.ComponentBody.Position; float num = 5f; Vector3 value3 = position2 + new Vector3(num * m_random.Float(-1f, 1f), 0f, num * m_random.Float(-1f, 1f)); value3.Y = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value3.X), Terrain.ToCell(value3.Z)) + 1; m_componentPathfinding.SetDestination(value3, m_random.Float(0.4f, 0.6f), 0.5f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); }, delegate { if (!m_componentPathfinding.Destination.HasValue) { m_stateMachine.TransitionTo("Lay"); } else if (m_componentPathfinding.IsStuck) { if (m_random.Float(0f, 1f) < 0.5f) { m_stateMachine.TransitionTo("Stuck"); } else { m_importanceLevel = 0f; } } }, null); m_stateMachine.AddState("Lay", delegate { m_layTime = 0f; }, delegate { if (m_eggType != null) { m_layTime += m_dt; if (m_componentCreature.ComponentBody.StandingOnValue.HasValue) { m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(0f, 0.25f * (float)MathUtils.Sin(20.0 * m_subsystemTime.GameTime) + m_layTime / 3f) - m_componentCreature.ComponentLocomotion.LookAngles; if (m_layTime >= 3f) { m_importanceLevel = 0f; int value = Terrain.MakeBlockValue(118, 0, EggBlock.SetIsLaid(EggBlock.SetEggType(0, m_eggType.EggTypeIndex), isLaid: true)); Matrix matrix = m_componentCreature.ComponentBody.Matrix; Vector3 position = 0.5f * (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max); Vector3 value2 = 3f * Vector3.Normalize(-matrix.Forward + 0.1f * matrix.Up + 0.2f * m_random.Float(-1f, 1f) * matrix.Right); m_subsystemPickables.AddPickable(value, 1, position, value2, null); m_subsystemAudio.PlaySound("Audio/EggLaid", 1f, m_random.Float(-0.1f, 0.1f), position, 2f, autoDelay: true); } } else if (m_layTime >= 3f) { m_importanceLevel = 0f; } } else { m_importanceLevel = 0f; } }, null); }
public void Update(float dt) { CollisionVelocityChange = Vector3.Zero; Velocity += m_totalImpulse; m_totalImpulse = Vector3.Zero; if (m_parentBody != null || m_velocity.LengthSquared() > 9.99999944E-11f || m_directMove != Vector3.Zero) { m_stoppedTime = 0f; } else { m_stoppedTime += dt; if (m_stoppedTime > 0.5f && !Time.PeriodicEvent(0.25, 0.0)) { return; } } Vector3 position = base.Position; TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(position.X), Terrain.ToCell(position.Z)); if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4) { Velocity = Vector3.Zero; return; } m_bodiesCollisionBoxes.Clear(); FindBodiesCollisionBoxes(position, m_bodiesCollisionBoxes); m_movingBlocksCollisionBoxes.Clear(); FindMovingBlocksCollisionBoxes(position, m_movingBlocksCollisionBoxes); if (!MoveToFreeSpace()) { ComponentHealth componentHealth = base.Entity.FindComponent <ComponentHealth>(); if (componentHealth != null) { componentHealth.Injure(1f, null, ignoreInvulnerability: true, "Crushed"); } else { base.Project.RemoveEntity(base.Entity, disposeEntity: true); } return; } if (IsGravityEnabled) { m_velocity.Y -= 10f * dt; if (ImmersionFactor > 0f) { float num = ImmersionFactor * (1f + 0.03f * MathUtils.Sin((float)MathUtils.Remainder(2.0 * m_subsystemTime.GameTime, 6.2831854820251465))); m_velocity.Y += 10f * (1f / Density * num) * dt; } } float num2 = MathUtils.Saturate(AirDrag.X * dt); float num3 = MathUtils.Saturate(AirDrag.Y * dt); m_velocity.X *= 1f - num2; m_velocity.Y *= 1f - num3; m_velocity.Z *= 1f - num2; if (IsWaterDragEnabled && ImmersionFactor > 0f && ImmersionFluidBlock != null) { Vector2?vector = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(position.X), Terrain.ToCell(position.Y), Terrain.ToCell(position.Z)); Vector3 vector2 = vector.HasValue ? new Vector3(vector.Value.X, 0f, vector.Value.Y) : Vector3.Zero; float num4 = 1f; if (ImmersionFluidBlock.FrictionFactor != 1f) { num4 = ((SimplexNoise.Noise((float)MathUtils.Remainder(6.0 * Time.FrameStartTime + (double)(GetHashCode() % 1000), 1000.0)) > 0.5f) ? ImmersionFluidBlock.FrictionFactor : 1f); } float f = MathUtils.Saturate(WaterDrag.X * num4 * ImmersionFactor * dt); float f2 = MathUtils.Saturate(WaterDrag.Y * num4 * dt); m_velocity.X = MathUtils.Lerp(m_velocity.X, vector2.X, f); m_velocity.Y = MathUtils.Lerp(m_velocity.Y, vector2.Y, f2); m_velocity.Z = MathUtils.Lerp(m_velocity.Z, vector2.Z, f); if (m_parentBody == null && vector.HasValue && !StandingOnValue.HasValue) { if (WaterTurnSpeed > 0f) { float s = MathUtils.Saturate(MathUtils.Lerp(1f, 0f, m_velocity.Length())); Vector2 vector3 = Vector2.Normalize(vector.Value) * s; base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, WaterTurnSpeed * (-1f * vector3.X + 0.71f * vector3.Y) * dt); } if (WaterSwayAngle > 0f) { base.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitX, WaterSwayAngle * (float)MathUtils.Sin((double)(200f / Mass) * m_subsystemTime.GameTime)); } } } if (m_parentBody != null) { Vector3 v = Vector3.Transform(ParentBodyPositionOffset, m_parentBody.Rotation) + m_parentBody.Position - position; m_velocity = ((dt > 0f) ? (v / dt) : Vector3.Zero); base.Rotation = ParentBodyRotationOffset * m_parentBody.Rotation; } StandingOnValue = null; StandingOnBody = null; StandingOnVelocity = Vector3.Zero; Vector3 velocity = m_velocity; float num5 = m_velocity.Length(); if (num5 > 0f) { float x = 0.45f * MathUtils.Min(BoxSize.X, BoxSize.Y, BoxSize.Z) / num5; float num6 = dt; while (num6 > 0f) { float num7 = MathUtils.Min(num6, x); MoveWithCollision(num7, m_velocity * num7 + m_directMove); m_directMove = Vector3.Zero; num6 -= num7; } } CollisionVelocityChange = m_velocity - velocity; if (IsGroundDragEnabled && StandingOnValue.HasValue) { m_velocity = Vector3.Lerp(m_velocity, StandingOnVelocity, 6f * dt); } if (!StandingOnValue.HasValue) { IsSneaking = false; } UpdateImmersionData(); if (ImmersionFluidBlock is WaterBlock && ImmersionDepth > 0.3f && !m_fluidEffectsPlayed) { m_fluidEffectsPlayed = true; m_subsystemAudio.PlayRandomSound("Audio/WaterFallIn", m_random.Float(0.75f, 1f), m_random.Float(-0.3f, 0f), position, 4f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f)); } else if (ImmersionFluidBlock is MagmaBlock && ImmersionDepth > 0f && !m_fluidEffectsPlayed) { m_fluidEffectsPlayed = true; m_subsystemAudio.PlaySound("Audio/SizzleLong", 1f, 0f, position, 4f, autoDelay: true); m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, position, (BoundingBox.Max - BoundingBox.Min).Length() > 0.8f)); } else if (ImmersionFluidBlock == null) { m_fluidEffectsPlayed = false; } }
public override bool OnAim(Ray3 aim, ComponentMiner componentMiner, AimState state) { IInventory inventory = componentMiner.Inventory; if (inventory != null) { int activeSlotIndex = inventory.ActiveSlotIndex; if (activeSlotIndex >= 0) { int slotValue = inventory.GetSlotValue(activeSlotIndex); int slotCount = inventory.GetSlotCount(activeSlotIndex); int num = Terrain.ExtractContents(slotValue); int data = Terrain.ExtractData(slotValue); if (num == 200 && slotCount > 0) { int draw = CrossbowBlock.GetDraw(data); if (!m_aimStartTimes.TryGetValue(componentMiner, out double value)) { value = m_subsystemTime.GameTime; m_aimStartTimes[componentMiner] = value; } float num2 = (float)(m_subsystemTime.GameTime - value); float num3 = (float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0); Vector3 v = ((componentMiner.ComponentCreature.ComponentBody.IsSneaking ? 0.01f : 0.03f) + 0.15f * MathUtils.Saturate((num2 - 2.5f) / 6f)) * new Vector3 { X = SimplexNoise.OctavedNoise(num3, 2f, 3, 2f, 0.5f), Y = SimplexNoise.OctavedNoise(num3 + 100f, 2f, 3, 2f, 0.5f), Z = SimplexNoise.OctavedNoise(num3 + 200f, 2f, 3, 2f, 0.5f) }; aim.Direction = Vector3.Normalize(aim.Direction + v); switch (state) { case AimState.InProgress: { if (num2 >= 10f) { componentMiner.ComponentCreature.ComponentCreatureSounds.PlayMoanSound(); return(true); } ComponentFirstPersonModel componentFirstPersonModel = componentMiner.Entity.FindComponent <ComponentFirstPersonModel>(); if (componentFirstPersonModel != null) { componentMiner.ComponentPlayer?.ComponentAimingSights.ShowAimingSights(aim.Position, aim.Direction); componentFirstPersonModel.ItemOffsetOrder = new Vector3(-0.22f, 0.15f, 0.1f); componentFirstPersonModel.ItemRotationOrder = new Vector3(-0.7f, 0f, 0f); } componentMiner.ComponentCreature.ComponentCreatureModel.AimHandAngleOrder = 1.3f; componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemOffsetOrder = new Vector3(-0.08f, -0.1f, 0.07f); componentMiner.ComponentCreature.ComponentCreatureModel.InHandItemRotationOrder = new Vector3(-1.55f, 0f, 0f); break; } case AimState.Cancelled: m_aimStartTimes.Remove(componentMiner); break; case AimState.Completed: { ArrowBlock.ArrowType?arrowType = CrossbowBlock.GetArrowType(data); if (draw != 15) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Draw the crossbow first", Color.White, blinking: true, playNotificationSound: false); } else if (!arrowType.HasValue) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Load a bolt first", Color.White, blinking: true, playNotificationSound: false); } else { Vector3 vector = componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition + componentMiner.ComponentCreature.ComponentBody.Matrix.Right * 0.3f - componentMiner.ComponentCreature.ComponentBody.Matrix.Up * 0.2f; Vector3 v2 = Vector3.Normalize(vector + aim.Direction * 10f - vector); int value2 = Terrain.MakeBlockValue(192, 0, ArrowBlock.SetArrowType(0, arrowType.Value)); float s = 38f; if (m_subsystemProjectiles.FireProjectile(value2, vector, s * v2, Vector3.Zero, componentMiner.ComponentCreature) != null) { data = CrossbowBlock.SetArrowType(data, null); m_subsystemAudio.PlaySound("Audio/Bow", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0.05f); } } inventory.RemoveSlotItems(activeSlotIndex, 1); int value3 = Terrain.MakeBlockValue(num, 0, CrossbowBlock.SetDraw(data, 0)); inventory.AddSlotItems(activeSlotIndex, value3, 1); if (draw > 0) { componentMiner.DamageActiveTool(1); m_subsystemAudio.PlaySound("Audio/CrossbowBoing", 1f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentCreatureModel.EyePosition, 3f, 0f); } m_aimStartTimes.Remove(componentMiner); break; } } } } } return(false); }