public BagInventoryWrapper( MyInventoryBagEntity entity )
 {
     Entity = entity;
 }
Exemplo n.º 2
0
        public static List <MyEntityListInfoItem> GetEntityList(MyEntityTypeEnum selectedType)
        {
            MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();
            List <MyEntityListInfoItem>    list          = new List <MyEntityListInfoItem>(entities.Count);
            ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();

            switch (selectedType)
            {
            case MyEntityTypeEnum.Grids:
            case MyEntityTypeEnum.SmallGrids:
            case MyEntityTypeEnum.LargeGrids:
                foreach (MyCubeGrid grid in entities)
                {
                    if (grid == null)
                    {
                        continue;
                    }
                    if (((selectedType != MyEntityTypeEnum.LargeGrids) || (grid.GridSizeEnum != MyCubeSize.Small)) && ((((selectedType != MyEntityTypeEnum.SmallGrids) || (grid.GridSizeEnum != MyCubeSize.Large)) && (!grid.Closed && (grid.Physics != null))) && ReferenceEquals(MyGridPhysicalHierarchy.Static.GetRoot(grid), grid)))
                    {
                        CreateListInfoForGrid(grid, out m_gridItem);
                        AccountChildren(grid);
                        list.Add(m_gridItem);
                    }
                }
                return(list);

            case MyEntityTypeEnum.Characters:
                break;

            case MyEntityTypeEnum.FloatingObjects:
                foreach (MyEntity entity in entities)
                {
                    MyFloatingObject obj2 = entity as MyFloatingObject;
                    if (obj2 != null)
                    {
                        if (obj2.Closed)
                        {
                            continue;
                        }
                        if (obj2.Physics == null)
                        {
                            continue;
                        }
                        list.Add(new MyEntityListInfoItem(obj2.DisplayName, obj2.EntityId, 0, 0, obj2.Physics.Mass, obj2.PositionComp.GetPosition(), obj2.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(obj2, onlinePlayers), "", 0L, 0f, 0f));
                    }
                    MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity;
                    if (((entity2 != null) && !entity2.Closed) && (entity2.Physics != null))
                    {
                        MyIdentity identity2   = MySession.Static.Players.TryGetIdentity(entity2.OwnerIdentityId);
                        string     ownerName   = "";
                        float      ownerLogin  = 0f;
                        float      ownerLogout = 0f;
                        if (identity2 != null)
                        {
                            ownerName   = identity2.DisplayName;
                            ownerLogin  = (int)(DateTime.Now - identity2.LastLoginTime).TotalSeconds;
                            ownerLogout = (int)(DateTime.Now - identity2.LastLogoutTime).TotalSeconds;
                        }
                        list.Add(new MyEntityListInfoItem(entity2.DisplayName, entity2.EntityId, 0, 0, entity2.Physics.Mass, entity2.PositionComp.GetPosition(), entity2.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(entity2, onlinePlayers), ownerName, entity2.OwnerIdentityId, ownerLogin, ownerLogout));
                    }
                }
                return(list);

            case MyEntityTypeEnum.Planets:
                foreach (MyPlanet planet in entities)
                {
                    if (planet == null)
                    {
                        continue;
                    }
                    if (!planet.Closed)
                    {
                        list.Add(new MyEntityListInfoItem(planet.StorageName, planet.EntityId, 0, 0, 0f, planet.PositionComp.GetPosition(), 0f, MySession.GetPlayerDistance(planet, onlinePlayers), "", 0L, 0f, 0f));
                    }
                }
                return(list);

            case MyEntityTypeEnum.Asteroids:
                foreach (MyVoxelBase base2 in entities)
                {
                    if (base2 == null)
                    {
                        continue;
                    }
                    if (!(base2 is MyPlanet) && !base2.Closed)
                    {
                        list.Add(new MyEntityListInfoItem(base2.StorageName, base2.EntityId, 0, 0, 0f, base2.PositionComp.GetPosition(), 0f, MySession.GetPlayerDistance(base2, onlinePlayers), "", 0L, 0f, 0f));
                    }
                }
                return(list);

            default:
                throw new ArgumentOutOfRangeException();
            }
            foreach (MyIdentity identity in MySession.Static.Players.GetAllIdentities())
            {
                MyPlayer.PlayerId id;
                string            displayName = identity.DisplayName;
                if (Sync.Players.TryGetPlayerId(identity.IdentityId, out id))
                {
                    MyPlayer player = null;
                    if (!Sync.Players.TryGetPlayerById(id, out player))
                    {
                        object[] objArray1 = new object[] { displayName, " (", MyTexts.Get(MyCommonTexts.OfflineStatus), ")" };
                        displayName = string.Concat(objArray1);
                    }
                }
                if (identity.Character != null)
                {
                    list.Add(new MyEntityListInfoItem(displayName, identity.Character.EntityId, 0, 0, identity.Character.CurrentMass, identity.Character.PositionComp.GetPosition(), identity.Character.Physics.LinearVelocity.Length(), 0f, identity.DisplayName, identity.IdentityId, (float)((int)(DateTime.Now - identity.LastLoginTime).TotalSeconds), (float)((int)(DateTime.Now - identity.LastLogoutTime).TotalSeconds)));
                }
                else
                {
                    foreach (long num in identity.SavedCharacters)
                    {
                        MyCharacter character;
                        if (MyEntities.TryGetEntityById <MyCharacter>(num, out character, false))
                        {
                            list.Add(new MyEntityListInfoItem(displayName, num, 0, 0, character.CurrentMass, character.PositionComp.GetPosition(), character.Physics.LinearVelocity.Length(), 0f, identity.DisplayName, identity.IdentityId, (float)((int)(DateTime.Now - identity.LastLoginTime).TotalSeconds), (float)((int)(DateTime.Now - identity.LastLogoutTime).TotalSeconds)));
                        }
                    }
                }
            }
            return(list);
        }
Exemplo n.º 3
0
        public static MyDetectedEntityInfo Create(MyEntity entity, long sensorOwner, Vector3D?hitPosition = new Vector3D?())
        {
            MyDetectedEntityType             type;
            MyRelationsBetweenPlayerAndBlock neutral;
            string displayName;

            if (entity == null)
            {
                return(new MyDetectedEntityInfo());
            }
            MatrixD      zero     = MatrixD.Zero;
            Vector3      velocity = (Vector3)Vector3D.Zero;
            int          totalGamePlayTimeInMilliseconds = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            BoundingBoxD worldAABB = entity.PositionComp.WorldAABB;

            if (entity.Physics != null)
            {
                zero     = entity.Physics.GetWorldMatrix().GetOrientation();
                velocity = entity.Physics.LinearVelocity;
            }
            MyCubeGrid topMostParent = entity.GetTopMostParent(null) as MyCubeGrid;

            if (topMostParent != null)
            {
                type    = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyDetectedEntityType.LargeGrid : MyDetectedEntityType.SmallGrid;
                neutral = (topMostParent.BigOwners.Count != 0) ? MyIDModule.GetRelation(sensorOwner, topMostParent.BigOwners[0], MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare) : MyRelationsBetweenPlayerAndBlock.NoOwnership;
                if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                    displayName = topMostParent.DisplayName;
                }
                else
                {
                    displayName = (topMostParent.GridSizeEnum != MyCubeSize.Small) ? MyTexts.GetString(MySpaceTexts.DetectedEntity_LargeGrid) : MyTexts.GetString(MySpaceTexts.DetectedEntity_SmallGrid);
                }
                zero = topMostParent.WorldMatrix.GetOrientation();
                return(new MyDetectedEntityInfo(topMostParent.EntityId, displayName, type, hitPosition, zero, topMostParent.Physics.LinearVelocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyCharacter character = entity as MyCharacter;

            if (character != null)
            {
                type    = !character.IsPlayer ? MyDetectedEntityType.CharacterOther : MyDetectedEntityType.CharacterHuman;
                neutral = MyIDModule.GetRelation(sensorOwner, character.GetPlayerIdentityId(), MyOwnershipShareModeEnum.Faction, MyRelationsBetweenPlayerAndBlock.Enemies, MyRelationsBetweenFactions.Enemies, MyRelationsBetweenPlayerAndBlock.FactionShare);
                if ((neutral == MyRelationsBetweenPlayerAndBlock.Owner) || (neutral == MyRelationsBetweenPlayerAndBlock.FactionShare))
                {
                    displayName = character.DisplayNameText;
                }
                else
                {
                    displayName = !character.IsPlayer ? MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterOther) : MyTexts.GetString(MySpaceTexts.DetectedEntity_CharacterHuman);
                }
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, type, hitPosition, zero, velocity, neutral, character.Model.BoundingBox.Transform(character.WorldMatrix), (long)totalGamePlayTimeInMilliseconds));
            }
            neutral = MyRelationsBetweenPlayerAndBlock.Neutral;
            MyFloatingObject obj2 = entity as MyFloatingObject;

            if (obj2 != null)
            {
                displayName = obj2.Item.Content.SubtypeName;
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity;

            if (entity2 != null)
            {
                displayName = entity2.DisplayName;
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.FloatingObject, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            MyPlanet planet = entity as MyPlanet;

            if (planet != null)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(planet.PositionComp.GetPosition(), (double)planet.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds));
            }
            MyVoxelPhysics physics = entity as MyVoxelPhysics;

            if (physics != null)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Planet);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Planet, hitPosition, zero, velocity, neutral, BoundingBoxD.CreateFromSphere(new BoundingSphereD(physics.Parent.PositionComp.GetPosition(), (double)physics.Parent.MaximumRadius)), (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyVoxelMap)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Asteroid);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Asteroid, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyMeteor)
            {
                displayName = MyTexts.GetString(MySpaceTexts.DetectedEntity_Meteor);
                return(new MyDetectedEntityInfo(entity.EntityId, displayName, MyDetectedEntityType.Meteor, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            if (entity is MyMissile)
            {
                return(new MyDetectedEntityInfo(entity.EntityId, entity.DisplayName, MyDetectedEntityType.Missile, hitPosition, zero, velocity, neutral, worldAABB, (long)totalGamePlayTimeInMilliseconds));
            }
            Vector3D?nullable    = null;
            MatrixD  orientation = new MatrixD();
            Vector3  vector2     = new Vector3();

            return(new MyDetectedEntityInfo(0L, string.Empty, MyDetectedEntityType.Unknown, nullable, orientation, vector2, MyRelationsBetweenPlayerAndBlock.NoOwnership, new BoundingBoxD(), (long)MySandboxGame.TotalGamePlayTimeInMilliseconds));
        }