public MovingBlocksRaycastResult?Raycast(Vector3 start, Vector3 end, bool extendToFillCells) { Ray3 ray = new Ray3(start, Vector3.Normalize(end - start)); BoundingBox boundingBox = new BoundingBox(Vector3.Min(start, end), Vector3.Max(start, end)); m_result.Clear(); FindMovingBlocks(boundingBox, extendToFillCells, m_result); float num = float.MaxValue; MovingBlockSet movingBlockSet = null; foreach (MovingBlockSet item in m_result) { BoundingBox box = item.BoundingBox(extendToFillCells); float? num2 = ray.Intersection(box); if (num2.HasValue && num2.Value < num) { num = num2.Value; movingBlockSet = item; } } if (movingBlockSet != null) { MovingBlocksRaycastResult value = default(MovingBlocksRaycastResult); value.Ray = ray; value.Distance = num; value.MovingBlockSet = movingBlockSet; return(value); } return(null); }
public BodyRaycastResult?Raycast(Vector3 start, Vector3 end, float inflateAmount, Func <ComponentBody, float, bool> action) { float num = Vector3.Distance(start, end); Ray3 ray = new Ray3(start, (num > 0f) ? ((end - start) / num) : Vector3.UnitX); Vector2 corner = new Vector2(start.X, start.Z); Vector2 corner2 = new Vector2(end.X, end.Z); BodyRaycastResult bodyRaycastResult = default(BodyRaycastResult); bodyRaycastResult.Ray = ray; bodyRaycastResult.Distance = float.MaxValue; BodyRaycastResult value = bodyRaycastResult; m_componentBodies.Clear(); FindBodiesInArea(corner, corner2, m_componentBodies); for (int i = 0; i < m_componentBodies.Count; i++) { ComponentBody componentBody = m_componentBodies.Array[i]; float? num2; if (inflateAmount > 0f) { BoundingBox boundingBox = componentBody.BoundingBox; boundingBox.Min -= new Vector3(inflateAmount); boundingBox.Max += new Vector3(inflateAmount); num2 = ray.Intersection(boundingBox); } else { num2 = ray.Intersection(componentBody.BoundingBox); } if (num2.HasValue && num2.Value <= num && num2.Value < value.Distance && action(componentBody, num2.Value)) { value.Distance = num2.Value; value.ComponentBody = componentBody; } } if (value.ComponentBody == null) { return(null); } return(value); }
public float?Raycast(Ray3 ray, SubsystemTerrain subsystemTerrain, int value, bool useInteractionBoxes, out int nearestBoxIndex, out BoundingBox nearestBox) { float?result = null; nearestBoxIndex = 0; nearestBox = default(BoundingBox); BoundingBox[] array = useInteractionBoxes ? GetCustomInteractionBoxes(subsystemTerrain, value) : GetCustomCollisionBoxes(subsystemTerrain, value); for (int i = 0; i < array.Length; i++) { float?num = ray.Intersection(array[i]); if (num.HasValue && (!result.HasValue || num.Value < result.Value)) { nearestBoxIndex = i; result = num; } } nearestBox = array[nearestBoxIndex]; return(result); }
public Projectile FireProjectile(int value, Vector3 position, Vector3 velocity, Vector3 angularVelocity, ComponentCreature owner) { int num = Terrain.ExtractContents(value); Block block = BlocksManager.Blocks[num]; Vector3 v = Vector3.Normalize(velocity); Vector3 vector = position; if (owner != null) { Ray3 ray = new Ray3(position + v * 5f, -v); BoundingBox boundingBox = owner.ComponentBody.BoundingBox; boundingBox.Min -= new Vector3(0.4f); boundingBox.Max += new Vector3(0.4f); float?num2 = ray.Intersection(boundingBox); if (num2.HasValue) { if (num2.Value == 0f) { return(null); } vector = position + v * (5f - num2.Value + 0.1f); } } Vector3 end = vector + v * block.ProjectileTipOffset; if (!m_subsystemTerrain.Raycast(position, end, useInteractionBoxes: false, skipAirBlocks: true, (int testValue, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(testValue)].IsCollidable).HasValue) { Projectile projectile = AddProjectile(value, vector, velocity, angularVelocity, owner); SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num); for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnFiredAsProjectile(projectile); } return(projectile); } return(null); }
public void UpdateInputFromVrControllers() { VrCursorPosition = null; if (VrQuadMatrix.HasValue) { Matrix value = VrQuadMatrix.Value; Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right); Plane plane = new Plane(value.Translation, value.Translation + value.Right, value.Translation + value.Up); Ray3 ray = new Ray3(controllerMatrix.Translation, controllerMatrix.Forward); float? num = ray.Intersection(plane); if (num.HasValue) { Vector3 v = ray.Position + num.Value * ray.Direction - value.Translation; float x = Vector3.Dot(v, Vector3.Normalize(value.Right)) / value.Right.Length() * Widget.ActualSize.X; float y = (1f - Vector3.Dot(v, Vector3.Normalize(value.Up)) / value.Up.Length()) * Widget.ActualSize.Y; VrCursorPosition = Vector2.Transform(new Vector2(x, y), Widget.GlobalTransform); } } if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadLeft)) { Left = true; } if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadRight)) { Right = true; } if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadUp)) { Up = true; } if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadDown)) { Down = true; } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadLeft)) { Left = true; } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadRight)) { Right = true; } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadUp)) { Up = true; } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadDown)) { Down = true; } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.Grip)) { Back = true; Cancel = true; } if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.Touchpad) || IsVrButtonDownOnce(VrController.Left, VrControllerButton.Trigger) || IsVrButtonDownOnce(VrController.Right, VrControllerButton.Touchpad) || IsVrButtonDownOnce(VrController.Right, VrControllerButton.Trigger)) { Any = true; } if (IsVrCursorVisible && VrCursorPosition.HasValue) { if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadUp)) { Scroll = new Vector3(VrCursorPosition.Value, 1f); } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadDown)) { Scroll = new Vector3(VrCursorPosition.Value, -1f); } if (IsVrButtonDown(VrController.Right, VrControllerButton.Trigger)) { Press = VrCursorPosition.Value; } if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.Trigger)) { Ok = true; Tap = VrCursorPosition.Value; m_vrDownPoint = VrCursorPosition.Value; m_vrDragTime = Time.FrameStartTime; } if (!IsVrButtonDown(VrController.Right, VrControllerButton.Trigger) && m_vrDownPoint.HasValue) { if (GetVrTriggerPosition(VrController.Left) > 0.5f) { SpecialClick = new Segment2(m_vrDownPoint.Value, VrCursorPosition.Value); } else { Click = new Segment2(m_vrDownPoint.Value, VrCursorPosition.Value); } } } if (!IsVrButtonDown(VrController.Right, VrControllerButton.Trigger)) { m_vrDragInProgress = false; m_vrDownPoint = null; } if (m_vrDragInProgress && VrCursorPosition.HasValue) { Drag = VrCursorPosition; } else if (IsVrButtonDown(VrController.Right, VrControllerButton.Trigger) && m_vrDownPoint.HasValue) { if (Vector2.Distance(m_vrDownPoint.Value, VrCursorPosition.Value) > SettingsManager.MinimumDragDistance * Widget.GlobalScale) { m_vrDragInProgress = true; Drag = m_vrDownPoint.Value; DragMode = DragMode.AllItems; } else if (Time.FrameStartTime - m_vrDragTime > (double)SettingsManager.MinimumHoldDuration) { Hold = m_vrDownPoint.Value; HoldTime = (float)(Time.FrameStartTime - m_vrDragTime); } } }
public void Update(float dt) { if (componentPlayer == null) { return; } if (msginfobtn.IsClicked || componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.Tab)) //消息点击 { if (messageInfo.IsVisible) { messageInfo.alwaysShow = false; messageInfo.IsVisible = messageInfo.alwaysShow; } else { messageInfo.alwaysShow = true; messageInfo.IsVisible = messageInfo.alwaysShow; } } if (componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.B)) { if (jeiBehavior.xjJEIWidget == null) { jeiBehavior.player = componentPlayer; jeiBehavior.xjJEIWidget = new XjJEIWidget(jeiBehavior); } if (componentPlayer.ComponentGui.ModalPanelWidget == null) { componentPlayer.ComponentGui.ModalPanelWidget = jeiBehavior.xjJEIWidget; } else { componentPlayer.ComponentGui.ModalPanelWidget = null; } } if (componentPlayer.ComponentHealth.DeathTime.HasValue) { foreach (SubsystemXjJeiBehavior.MarkFLag mark in SubsystemXjJeiBehavior.markFLags) { if (mark.point == componentPlayer.ComponentBody.Position) { markaddflag = true; break; } } if (!markaddflag) { SubsystemXjJeiBehavior.MarkFLag markFLag = new SubsystemXjJeiBehavior.MarkFLag(); markFLag.point = componentPlayer.ComponentBody.Position; markFLag.name = "死亡地点"; markFLag.color = Color.Red; SubsystemXjJeiBehavior.markFLags.Add(markFLag); markaddflag = true; } } if (touch.IsPressed) { componentPlayer.ComponentLocomotion.JumpOrder = 1f; jump.Texture = TextureAtlasManager.GetSubtexture("JEITextures/JEI_Jump_P").Texture; } else { jump.Texture = TextureAtlasManager.GetSubtexture("JEITextures/JEI_Jump").Texture; } if (messageInfo.IsVisible) { if (messageInfo.inputpos > 0) { if (componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.UpArrow)) { if (messageInfo.inputpos - 1 < 0) { messageInfo.inputpos = messageInfo.inputcache.Count - 1; } else { messageInfo.inputpos -= 1; } messageInfo.inputtext.Text = messageInfo.inputcache[messageInfo.inputpos]; } else if (componentPlayer.ViewWidget.Input.IsKeyDownOnce(Key.DownArrow)) { if (messageInfo.inputpos + 1 > messageInfo.inputcache.Count - 1) { messageInfo.inputpos = 0; } else { messageInfo.inputpos += 1; } messageInfo.inputtext.Text = messageInfo.inputcache[messageInfo.inputpos]; } } } block = BlocksManager.Blocks[Terrain.ExtractContents(componentPlayer.ComponentMiner.ActiveBlockValue)]; if (block.Durability > 0) { disname = block.GetDisplayName(null, componentPlayer.ComponentMiner.ActiveBlockValue); if (XjJeiManager.is_NewSC && ModsManager.customer_Strings.ContainsKey(disname)) { disname = ModsManager.customer_Strings[disname]; } int durty = 0; int damage = block.GetDamage(componentPlayer.ComponentMiner.ActiveBlockValue); durty = (block.Durability - damage); moreInfo.setInfo(disname, durty, block.GetMeleePower(componentPlayer.ComponentMiner.ActiveBlockValue)); moreInfo.bitmapWidget.Texture = moreInfo.texture; } else { moreInfo.naijiu.Text = ""; moreInfo.bitmapWidget.Texture = null; moreInfo.labelWidget.Text = ""; } moreInfo.setPosi(componentPlayer.ComponentBody.Position); moreInfo.setShow(SubsystemXjJeiBehavior.posi, SubsystemXjJeiBehavior.dura); if (!SubsystemXjJeiBehavior.run) { return; } if (componentPlayer.ComponentGui.ModalPanelWidget != null) { infoDialog.IsVisible = false; return; } //检测是否有方块 Ray3 ray = new Ray3(componentPlayer.GameWidget.ActiveCamera.ViewPosition, componentPlayer.GameWidget.ActiveCamera.ViewDirection); terrainray = componentPlayer.ComponentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction, true, true, false); foreach (KeyValuePair <ComponentCreature, bool> creature in creatureSpawn.m_creatures) { if (creature.Key == null) { hasCreature = false; continue; } Vector3 creaturePosition = creature.Key.ComponentCreatureModel.EyePosition; Vector3 start = ray.Position; Vector3 direction = Vector3.Normalize(ray.Direction); Vector3 end = ray.Position + direction * 15f; //检测是否有生物 if (creature.Key.ComponentBody.Position == componentPlayer.ComponentBody.Position) { hasCreature = false; continue; } Raymm = ray.Intersection(creature.Key.ComponentBody.BoundingBox); if (Raymm.HasValue) { if (Raymm.Value <= 10f) { infoDialog.setCreatureinfo(creature.Key); hasCreature = true; break; } } else { hasCreature = false; } } if (terrainray.HasValue && !hasCreature) { point = terrainray.Value.CellFace.Point; float disb = terrainray.Value.Distance; if (Raymm.HasValue && Raymm.Value <= disb) { infoDialog.IsVisible = true; } else { cellValue = terrainray.Value.Value; if (Terrain.ExtractContents(componentPlayer.ComponentMiner.ActiveBlockValue) != 0) { //装备的工具等级 block = BlocksManager.Blocks[Terrain.ExtractContents(componentPlayer.ComponentMiner.ActiveBlockValue)]; toollevel = block.ToolLevel; //hack为劈砍 //shovel为铲子 //quarry为镐子 //none为手 } else { toollevel = 0; } block = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)]; disname = block.GetDisplayName(null, cellValue); if (XjJeiManager.is_NewSC && ModsManager.customer_Strings.ContainsKey(disname)) { disname = ModsManager.customer_Strings[disname]; } ; if (subsystemPlantBlock.HandledBlocks.Contains(Terrain.ExtractContents(cellValue))) { grow = Terrain.ExtractData(cellValue) & 7; if (Terrain.ExtractContents(cellValue) == 174) { grow = (int)((((float)grow) / 7f) * 100); //黑麦 } else { grow = (int)(((7f - (float)grow) / 7f) * 100); //南瓜 } infoDialog.setPlantInfo(disname, cellValue, grow); } else {//不是作物 grow = 0; dig = block.RequiredToolLevel; infoDialog.setBlockInfo($"{disname}", cellValue, dig, block.DigMethod, toollevel); } infoDialog.IsVisible = true; } } else { if (!hasCreature) { infoDialog.IsVisible = false; } else { infoDialog.IsVisible = true; } } infoDialog.setBottomWidget(moreInfo); infoDialog.setUpmode(SubsystemXjJeiBehavior.upmode); }