private void ShieldIntersect(MyEntity ent) { var grid = ent as MyCubeGrid; if (grid == null) { return; } var bOriBBoxD = new MyOrientedBoundingBoxD(grid.PositionComp.LocalAABB, grid.PositionComp.WorldMatrixRef); if (EntInside(grid, ref bOriBBoxD)) { return; } var sObb = ShieldComp.DefenseShields.SOriBBoxD; if (!sObb.Intersects(ref SOriBBoxD)) { return; } ShieldGridComponent shieldComponent; grid.Components.TryGet(out shieldComponent); if (shieldComponent?.DefenseShields == null) { return; } var ds = shieldComponent.DefenseShields; if (!ds.NotFailed) { EntIntersectInfo entInfo; WebEnts.TryRemove(ent, out entInfo); Session.Instance.EntIntersectInfoPool.Return(entInfo); } var dsVerts = ds.ShieldComp.PhysicsOutside; var dsMatrixInv = ds.DetectMatrixOutsideInv; _insidePoints.Clear(); CustomCollision.ShieldX2PointsInside(dsVerts, dsMatrixInv, ShieldComp.PhysicsOutside, DetectMatrixOutsideInv, _insidePoints); var collisionAvg = Vector3D.Zero; var numOfPointsInside = _insidePoints.Count; for (int i = 0; i < numOfPointsInside; i++) { collisionAvg += _insidePoints[i]; } if (numOfPointsInside > 0) { collisionAvg /= numOfPointsInside; } if (collisionAvg == Vector3D.Zero) { GridIntersect(ent); return; } var iFortified = DsSet.Settings.FortifyShield && DsState.State.Enhancer; var bFortified = ds.DsSet.Settings.FortifyShield && ds.DsState.State.Enhancer; var iWinForceFight = iFortified && !bFortified; var iLoseForceFight = !iFortified && bFortified; if (!iLoseForceFight && (MyGrid.EntityId > grid.EntityId || iWinForceFight)) { ComputeCollisionPhysics(grid, MyGrid, collisionAvg); } else if (!_isServer) { return; } var damage = ((ds._shieldMaxChargeRate * ConvToHp) * DsState.State.ModulateKinetic) * 0.01666666666f; var shieldEvent = Session.Instance.ShieldEventPool.Get(); shieldEvent.Init(this, damage, collisionAvg, grid.EntityId); Session.Instance.ThreadEvents.Enqueue(shieldEvent); }
private void ShieldIntersect(MyEntity ent) { var grid = ent as MyCubeGrid; if (grid == null) { return; } if (GridInside(grid, MyOrientedBoundingBoxD.CreateFromBoundingBox(grid.PositionComp.WorldAABB))) { return; } ShieldGridComponent shieldComponent; grid.Components.TryGet(out shieldComponent); if (shieldComponent?.DefenseShields == null) { return; } var ds = shieldComponent.DefenseShields; if (!ds.WasOnline) { EntIntersectInfo entInfo; WebEnts.TryRemove(ent, out entInfo); } var dsVerts = ds.ShieldComp.PhysicsOutside; var dsMatrixInv = ds.DetectMatrixOutsideInv; var myGrid = Shield.CubeGrid; var insidePoints = new List <Vector3D>(); if (_isServer) { CustomCollision.ShieldX2PointsInside(dsVerts, dsMatrixInv, ShieldComp.PhysicsOutside, DetectMatrixOutsideInv, insidePoints); } else { CustomCollision.ClientShieldX2PointsInside(dsVerts, dsMatrixInv, ShieldComp.PhysicsOutsideLow, DetectMatrixOutsideInv, insidePoints); } var bPhysics = ((IMyCubeGrid)grid).Physics; var sPhysics = myGrid.Physics; var bMass = grid.GetCurrentMass(); var sMass = ((MyCubeGrid)myGrid).GetCurrentMass(); if (bMass <= 0) { bMass = int.MaxValue; } if (sMass <= 0) { sMass = int.MaxValue; } var bVel = bPhysics.LinearVelocity; var bVelLen = bVel.Length(); var momentum = (bMass * bVel) + (sMass * sPhysics.LinearVelocity); var resultVelocity = momentum / (bMass + sMass); var collisionAvg = Vector3D.Zero; var numOfPointsInside = insidePoints.Count; for (int i = 0; i < numOfPointsInside; i++) { collisionAvg += insidePoints[i]; } collisionAvg /= numOfPointsInside; if (numOfPointsInside > 0 && !bPhysics.IsStatic) { var ejectorAccel = numOfPointsInside > 10 ? numOfPointsInside : 10; var impulseData = new MyImpulseData { MyGrid = grid, Direction = (resultVelocity - bVel) * bMass, Position = bPhysics.CenterOfMassWorld }; var forceData = new MyAddForceData { MyGrid = grid, Force = (bPhysics.CenterOfMassWorld - collisionAvg) * bMass * ejectorAccel, MaxSpeed = MathHelper.Clamp(bVelLen, 1f, 50f) }; ImpulseData.Enqueue(impulseData); ForceData.Enqueue(forceData); } if (!_isServer || numOfPointsInside <= 0) { return; } var shieldMaxChargeRate = ds._shieldMaxChargeRate; var damage = ((shieldMaxChargeRate * ConvToHp) * DsState.State.ModulateKinetic) * 0.01666666666f; if (_mpActive) { if (_isServer) { AddShieldHit(ds.Shield.EntityId, damage, Session.Instance.MPEnergy, null, false, collisionAvg); } } else { EnergyHit = true; WorldImpactPosition = collisionAvg; ds.EnergyHit = true; ds.WorldImpactPosition = collisionAvg; Absorb += damage; ImpactSize = damage; WebDamage = true; } }
private void ShieldIntersect(MyEntity ent) { var grid = ent as MyCubeGrid; if (grid == null) { return; } if (EntInside(grid, MyOrientedBoundingBoxD.CreateFromBoundingBox(grid.PositionComp.WorldAABB))) { return; } ShieldGridComponent shieldComponent; grid.Components.TryGet(out shieldComponent); if (shieldComponent?.DefenseShields == null) { return; } var ds = shieldComponent.DefenseShields; if (!ds.NotFailed) { EntIntersectInfo entInfo; WebEnts.TryRemove(ent, out entInfo); Session.Instance.EntIntersectInfoPool.Return(entInfo); } var dsVerts = ds.ShieldComp.PhysicsOutside; var dsMatrixInv = ds.DetectMatrixOutsideInv; var insidePoints = new List <Vector3D>(); CustomCollision.ShieldX2PointsInside(dsVerts, dsMatrixInv, ShieldComp.PhysicsOutside, DetectMatrixOutsideInv, insidePoints); var collisionAvg = Vector3D.Zero; var numOfPointsInside = insidePoints.Count; for (int i = 0; i < numOfPointsInside; i++) { collisionAvg += insidePoints[i]; } if (numOfPointsInside > 0) { collisionAvg /= numOfPointsInside; } if (collisionAvg == Vector3D.Zero) { return; } if (MyGrid.EntityId > grid.EntityId) { ComputeCollisionPhysics(grid, MyGrid, collisionAvg); } else if (!_isServer) { return; } var damage = ((ds._shieldMaxChargeRate * ConvToHp) * DsState.State.ModulateKinetic) * 0.01666666666f; var shieldEvent = Session.Instance.ShieldEventPool.Get(); shieldEvent.Init(this, damage, collisionAvg, grid.EntityId); Session.Instance.ThreadEvents.Enqueue(shieldEvent); }