コード例 #1
0
        private static double TAPI_GetDistanceToShield(IMyTerminalBlock block, Vector3D pos)
        {
            var logic = block?.GameLogic?.GetAs <DefenseShields>()?.ShieldComp?.DefenseShields;

            if (logic == null)
            {
                return(-1);
            }

            return(CustomCollision.EllipsoidDistanceToPos(logic.DetectMatrixOutsideInv, logic.DetectMatrixOutside, pos));
        }
コード例 #2
0
        private void PlayerIntersect(MyEntity ent)
        {
            var character = ent as IMyCharacter;

            if (character == null || character.MarkedForClose || character.IsDead)
            {
                return;
            }

            var npcname = character.ToString();

            if (npcname.Equals(SpaceWolf))
            {
                if (_isServer)
                {
                    var charEvent = Session.Instance.PlayerEffectPool.Get();
                    charEvent.Init(character, this);
                    Session.Instance.ThreadEvents.Enqueue(charEvent);
                }
                return;
            }
            var player = MyAPIGateway.Multiplayer.Players.GetPlayerControllingEntity(ent);

            if (player == null || player.PromoteLevel == MyPromoteLevel.Owner || player.PromoteLevel == MyPromoteLevel.Admin)
            {
                return;
            }
            var bOriBBoxD = new MyOrientedBoundingBoxD(ent.PositionComp.LocalAABB, ent.PositionComp.WorldMatrixRef);

            Vector3D closestPos;
            var      sMatrix = DetectMatrixOutside;
            var      dist    = CustomCollision.EllipsoidDistanceToPos(ref DetectMatrixOutsideInv, ref sMatrix, ref bOriBBoxD.Center, out closestPos);

            if (dist <= ent.PositionComp.LocalVolume.Radius)
            {
                var collisionData = new MyCollisionPhysicsData
                {
                    Entity1      = ent,
                    Force1       = -Vector3.Normalize(ShieldEnt.PositionComp.WorldAABB.Center - closestPos),
                    CollisionAvg = closestPos
                };
                if (_isServer)
                {
                    var charEvent = Session.Instance.PlayerCollisionPool.Get();
                    charEvent.Init(collisionData, this);
                    Session.Instance.ThreadEvents.Enqueue(charEvent);
                }
            }
        }
コード例 #3
0
        private static IMyTerminalBlock TAPI_GetClosestShield(Vector3D pos)
        {
            MyCubeBlock cloestSBlock = null;
            var         closestDist  = double.MaxValue;

            lock (Session.Instance.ActiveShields)
            {
                foreach (var s in Session.Instance.ActiveShields)
                {
                    if (Vector3D.DistanceSquared(s.DetectionCenter, pos) > Session.Instance.SyncDistSqr)
                    {
                        continue;
                    }

                    var sDist = CustomCollision.EllipsoidDistanceToPos(s.DetectMatrixOutsideInv, s.DetectMatrixOutside, pos);
                    if (sDist > 0 && sDist < closestDist)
                    {
                        cloestSBlock = s.MyCube;
                        closestDist  = sDist;
                    }
                }
            }
            return(cloestSBlock as IMyTerminalBlock);
        }