コード例 #1
0
        void GetAvailableMedicalRooms(long playerId, out List <MyMedicalRoom> medicalRooms)
        {
            List <MyCubeGrid> cubeGrids = MyEntities.GetEntities().OfType <MyCubeGrid>().ToList();

            medicalRooms = new List <MyMedicalRoom>();

            foreach (var grid in cubeGrids)
            {
                grid.GridSystems.UpdatePower();

                foreach (var slimBlock in grid.GetBlocks())
                {
                    MyMedicalRoom medicalRoom = slimBlock.FatBlock as MyMedicalRoom;
                    if (medicalRoom != null)
                    {
                        medicalRoom.UpdateIsWorking();

                        if (medicalRoom.IsWorking)
                        {
                            if (medicalRoom.HasPlayerAccess(playerId) || medicalRoom.SetFactionToSpawnee)
                            {
                                medicalRooms.Add(medicalRoom);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        private static void SpawnLemming()
        {
            m_spawnCount--;

            if (m_spawnCount <= 0)
            {
                m_timeToNextSpawn = -1;
                return;
            }

            Vector3D spawnPosition = m_spawnMedical.PositionComp.GetPosition() + (MyMedicalRoom.GetSafePlaceRelative() * (Matrix)m_spawnMedical.WorldMatrix).Translation;
            MatrixD  matrix        = m_spawnMedical.WorldMatrix;

            matrix.Translation = spawnPosition;

            var character = MyCharacter.CreateCharacter((Matrix)matrix, Vector3.Zero, "Lemming" + m_lemmings.Count, null, null, false, true);

            character.EnableJetpack(false, false, true, true);
            character.AIMode = true;
            MatrixD m = character.WorldMatrix;

            m             = m * Matrix.CreateRotationY(-MathHelper.PiOver2);
            m.Translation = character.PositionComp.GetPosition();
            character.PositionComp.SetWorldMatrix(m);
            character.Save = false;
            MyLemmingCharacter lemming = new MyLemmingCharacter()
            {
                Character = character,
            };

            m_lemmings.Add(lemming);
        }
コード例 #3
0
        private void OnTableItemSelected(MyGuiControlTable sender, MyGuiControlTable.EventArgs eventArgs)
        {
            if (m_respawnsTable.SelectedRow != null)
            {
                m_respawnButton.Enabled = true;

                if (m_respawnsTable.SelectedRow.UserData == null || m_respawnsTable.SelectedRow.UserData as MyMedicalRoom == null)
                {
                    MySession.SetCameraController(MyCameraControllerEnum.Spectator, null, new Vector3D(1000000)); //just somewhere out of the game area to see our beautiful skybox
                    return;
                }

                MyMedicalRoom medicalRoom             = (MyMedicalRoom)m_respawnsTable.SelectedRow.UserData;
                Vector3D      medRoomPosition         = (Vector3D)medicalRoom.PositionComp.GetPosition();
                Vector3D      preferredCameraPosition = medRoomPosition + medicalRoom.WorldMatrix.Up * 20 + medicalRoom.WorldMatrix.Right * 20 + medicalRoom.WorldMatrix.Forward * 20;
                Vector3D?     cameraPosition          = MyEntities.FindFreePlace(preferredCameraPosition, 1);
                if (!cameraPosition.HasValue)
                {
                    cameraPosition = preferredCameraPosition;
                }

                MySession.SetCameraController(MyCameraControllerEnum.Spectator, null, cameraPosition);
                MySpectatorCameraController.Static.Target = (Vector3D)medRoomPosition;
            }
            else
            {
                m_respawnButton.Enabled = false;
            }
        }
コード例 #4
0
        private void SpawnInMedicalRoom(MyPlayer player, MyMedicalRoom medical, bool joiningGame)
        {
            if (MySession.Static.Settings.EnableOxygen)
            {
                player.Identity.ChangeToOxygenSafeSuit();
            }

            if (medical.HasSpawnPosition())
            {
                Matrix matrix = medical.GetSpawnPosition();
                player.SpawnAt(matrix, medical.Parent.Physics.LinearVelocity, false);
                medical.TryTakeSpawneeOwnership(player);
            }
            else if (joiningGame)
            {
                Vector3 medicalPosition = medical.PositionComp.GetPosition();
                medicalPosition += -medical.WorldMatrix.Up + medical.WorldMatrix.Right;
                Matrix matrix = medical.WorldMatrix;
                matrix.Translation = medicalPosition;
                player.SpawnAt(matrix, medical.Parent.Physics.LinearVelocity);
            }
            else
            {
                Matrix  invWorldRot      = Matrix.Invert(medical.WorldMatrix.GetOrientation());
                Vector3 relativeVelocity = Vector3.Transform(medical.Parent.Physics.LinearVelocity, invWorldRot);
                player.SpawnAtRelative(medical, MyMedicalRoom.GetSafePlaceRelative(), relativeVelocity);
            }
        }
コード例 #5
0
        static void GetAvailableMedicalRooms(long playerId, List <MyMedicalRoomInfo> medicalRooms)
        {
            List <MyCubeGrid> cubeGrids = MyEntities.GetEntities().OfType <MyCubeGrid>().ToList();

            foreach (var grid in cubeGrids)
            {
                grid.GridSystems.UpdatePower();

                foreach (var slimBlock in grid.GetBlocks())
                {
                    MyMedicalRoom medicalRoom = slimBlock.FatBlock as MyMedicalRoom;
                    if (medicalRoom != null)
                    {
                        medicalRoom.UpdateIsWorking();

                        if (medicalRoom.IsWorking)
                        {
                            if (medicalRoom.HasPlayerAccess(playerId) || medicalRoom.SetFactionToSpawnee)
                            {
                                MyMedicalRoomInfo info = new MyMedicalRoomInfo();
                                info.MedicalRoomId   = medicalRoom.EntityId;
                                info.MedicalRoomName = medicalRoom.CustomName != null?medicalRoom.CustomName.ToString() : (medicalRoom.Name != null ? medicalRoom.Name : medicalRoom.ToString());

                                info.OxygenLevel = medicalRoom.GetOxygenLevel();
                                info.OwnerId     = medicalRoom.IDModule.Owner;

                                Vector3D medRoomPosition         = medicalRoom.PositionComp.GetPosition();
                                Vector3D preferredCameraPosition = medRoomPosition + medicalRoom.WorldMatrix.Up * 20 + medicalRoom.WorldMatrix.Right * 20 + medicalRoom.WorldMatrix.Forward * 20;
                                Vector3D?cameraPosition          = MyEntities.FindFreePlace(preferredCameraPosition, 1);

                                if (!cameraPosition.HasValue)
                                {
                                    cameraPosition = preferredCameraPosition;
                                }

                                info.PrefferedCameraPosition = cameraPosition.Value;
                                info.MedicalRoomPosition     = medRoomPosition;
                                info.MedicalRoomUp           = medicalRoom.PositionComp.WorldMatrix.Up;
                                if (medicalRoom.CubeGrid.Physics != null)
                                {
                                    info.MedicalRoomVelocity = medicalRoom.CubeGrid.Physics.LinearVelocity;
                                }

                                medicalRooms.Add(info);
                            }
                        }
                    }
                }
            }
        }
コード例 #6
0
        private MyMedicalRoom FindRespawnMedicalRoom(long medicalRoomId, MyPlayer player)
        {
            MyMedicalRoom medicalRoom = null;

            if (MyEntities.TryGetEntityById(medicalRoomId, out medicalRoom))
            {
                if (!medicalRoom.IsWorking)
                {
                    return(null);
                }

                if (player != null && !medicalRoom.HasPlayerAccess(player.Identity.IdentityId))
                {
                    return(null);
                }
            }
            return(medicalRoom);
        }
コード例 #7
0
        private MyMedicalRoom GetNearestMedRoom(Vector3 position, out List <MyMedicalRoom> medicalRooms, long?identityId = null)
        {
            List <MyCubeGrid> cubeGrids = MyEntities.GetEntities().OfType <MyCubeGrid>().ToList();

            medicalRooms = new List <MyMedicalRoom>();

            MyMedicalRoom closestMedicalRoom = null;
            float         closestDistance    = float.MaxValue;

            foreach (var grid in cubeGrids)
            {
                foreach (var slimBlock in grid.GetBlocks())
                {
                    MyMedicalRoom medicalRoom = slimBlock.FatBlock as MyMedicalRoom;
                    if (medicalRoom != null && medicalRoom.IsWorking)
                    {
                        if (!identityId.HasValue || medicalRoom.HasPlayerAccess(identityId.Value))
                        {
                            float distanceFromCenter = (float)medicalRoom.PositionComp.GetPosition().Length();

                            //Limit spawn position to be inside the world (with some safe margin)
                            if ((!MyEntities.IsWorldLimited() && distanceFromCenter > MAX_DISTANCE_TO_RESPAWN) ||
                                (MyEntities.IsWorldLimited() && distanceFromCenter > MyEntities.WorldSafeHalfExtent()))
                            {
                                continue;
                            }

                            float distance = Vector3.Distance(position, medicalRoom.PositionComp.GetPosition());

                            medicalRooms.Add(medicalRoom);

                            if (distance < closestDistance)
                            {
                                closestMedicalRoom = medicalRoom;
                                closestDistance    = distance;
                            }
                        }
                    }
                }
            }
            return(closestMedicalRoom);
        }
コード例 #8
0
        private static StringBuilder GetOwnerDisplayName(MyMedicalRoom medRoom)
        {
            long owner = medRoom.IDModule.Owner;

            if (owner == 0)
            {
                return(MyTexts.Get(MySpaceTexts.BlockOwner_Nobody));
            }

            var identity = Sync.Players.TryGetIdentity(owner);

            if (identity != null)
            {
                return(new StringBuilder(identity.DisplayName));
            }
            else
            {
                return(MyTexts.Get(MySpaceTexts.BlockOwner_Unknown));
            }
        }
コード例 #9
0
        private static void StartSurprise(object senderEvent)
        {
            BoundingSphereD sphere = new BoundingSphereD(new Vector3D(-18.75f, -2.5f, -1.25f), 2);

            m_getEntities.Clear();
            MyGamePruningStructure.GetAllEntitiesInSphere(ref sphere, m_getEntities);

            m_spawnMedical = null;
            foreach (var entity in m_getEntities)
            {
                m_spawnMedical = entity as MyMedicalRoom;
                if (m_spawnMedical != null)
                {
                    m_spawnMedical.OnClose += delegate { m_spawnMedical = null; };
                    break;
                }
            }

            m_started = true;
        }
コード例 #10
0
        protected override void UnloadData()
        {
            m_getEntities.Clear();
            m_lemmings.Clear();
            m_timeToNextSpawn  = -1;
            m_timeToNextChange = -1;
            m_spawnMedical     = null;
            m_spawnCount       = SPAWN_COUNT;
            MyLemmingCharacter.Positions.Clear();
            m_started     = false;
            m_globalEvent = null;
            m_timeToEnd   = LIFE_TIME;

            if (m_notification != null)
            {
                MyHud.Notifications.Remove(m_notification);
                m_notification = null;
            }

            base.UnloadData();
        }
コード例 #11
0
        private static void AssignMedRoomsToServer()
        {
            if (MySession.LocalHumanPlayer == null)
            {
                return;
            }

            List <MyCubeGrid> cubeGrids = MyEntities.GetEntities().OfType <MyCubeGrid>().ToList();

            foreach (var grid in cubeGrids)
            {
                foreach (var slimBlock in grid.GetBlocks())
                {
                    MyMedicalRoom medicalRoom = slimBlock.FatBlock as MyMedicalRoom;
                    if (medicalRoom != null)
                    {
                        medicalRoom.IDModule.Owner     = MySession.LocalHumanPlayer.Identity.IdentityId;
                        medicalRoom.IDModule.ShareMode = MyOwnershipShareModeEnum.Faction;
                    }
                }
            }
        }
コード例 #12
0
        public override void Use(UseActionEnum actionEnum, IMyEntity entity)
        {
            var user     = entity as MyCharacter;
            var relation = Block.GetUserRelationToOwner(user.ControllerInfo.ControllingIdentityId);

            if (!relation.IsFriendly())
            {
                if (user.ControllerInfo.IsLocallyHumanControlled())
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.AccessDenied);
                }
                return;
            }

            switch (actionEnum)
            {
            case UseActionEnum.Manipulate:
                if (Block is MyMedicalRoom)
                {
                    MyMedicalRoom medRoom = (MyMedicalRoom)Block;
                    if (!medRoom.SuitChangeAllowed)
                    {
                        MyHud.Notifications.Add(MyNotificationSingletons.AccessDenied);
                        break;
                    }

                    if (medRoom.CustomWardrobesEnabled)
                    {
                        MyGuiSandbox.AddScreen(MyGuiScreenGamePlay.ActiveGameplayScreen = new MyGuiScreenWardrobe(user, medRoom.CustomWardrobeNames));
                        break;
                    }
                }

                MyGuiSandbox.AddScreen(MyGuiScreenGamePlay.ActiveGameplayScreen = new MyGuiScreenWardrobe(user));
                break;
            }
        }
コード例 #13
0
        protected override void UnloadData()
        {
            m_getEntities.Clear();
            m_lemmings.Clear();
            m_timeToNextSpawn = -1;
            m_timeToNextChange = -1;
            m_spawnMedical = null;
            m_spawnCount = SPAWN_COUNT;
            MyLemmingCharacter.Positions.Clear();
            m_started = false;
            m_globalEvent = null;
            m_timeToEnd = LIFE_TIME;

            if (m_notification != null)
            {
                MyHud.Notifications.Remove(m_notification);
                m_notification = null;
            }

            base.UnloadData();
        }
コード例 #14
0
        public bool HandleRespawnRequest(bool joinGame, bool newIdentity, long medicalRoomId, string respawnShipId, MyPlayer.PlayerId playerId, Vector3D?spawnPosition)
        {
            MyPlayer player = Sync.Players.TryGetPlayerById(playerId);

            bool spawnAsNewPlayer = newIdentity || player == null;

            Debug.Assert(player == null || player.Identity != null, "Respawning player has no identity!");

            if (!MySessionComponentMissionTriggers.CanRespawn(playerId))
            {
                return(false);
            }

            Vector3D currentPosition = Vector3D.Zero;

            if (player != null && player.Character != null)
            {
                currentPosition = player.Character.PositionComp.GetPosition();
            }

            if (TryFindCryoChamberCharacter(player))
            {
                //Player found in chamber;
                return(true);
            }

            if (!spawnAsNewPlayer)
            {
                // Find medical room to spawn at
                MyMedicalRoom medicalRoom = null;
                if (medicalRoomId == 0 || !MyFakes.SHOW_FACTIONS_GUI)
                {
                    List <MyMedicalRoom> medRooms = new List <MyMedicalRoom>();
                    medicalRoom = GetNearestMedRoom(currentPosition, out medRooms, MySession.Static.CreativeMode ? (long?)null : player.Identity.IdentityId);
                    if (joinGame && medRooms.Count > 0)
                    {
                        medicalRoom = medRooms[MyRandom.Instance.Next(0, medRooms.Count)];
                    }
                }
                else
                {
                    medicalRoom = FindRespawnMedicalRoom(medicalRoomId, player);
                    if (medicalRoom == null)
                    {
                        return(false);
                    }
                }

                // If spawning in medical room fails, we will spawn as a new player
                if (medicalRoom != null)
                {
                    SpawnInMedicalRoom(player, medicalRoom, joinGame);
                }
                else
                {
                    spawnAsNewPlayer = true;
                }
            }

            if (spawnAsNewPlayer)
            {
                bool resetIdentity = MySession.Static.Settings.PermanentDeath.Value;
                if (player == null)
                {
                    var identity = Sync.Players.CreateNewIdentity(player.DisplayName);
                    player        = Sync.Players.CreateNewPlayer(identity, playerId, player.DisplayName);
                    resetIdentity = false;
                }

                if (MySession.Static.CreativeMode)
                {
                    Vector3D?correctedPos = MyEntities.FindFreePlace(currentPosition, 1, 200);
                    if (correctedPos.HasValue)
                    {
                        currentPosition = correctedPos.Value;
                    }
                    player.SpawnAt(Matrix.CreateTranslation(currentPosition), Vector3.Zero);
                }
                else
                {
                    SpawnAsNewPlayer(player, currentPosition, respawnShipId, resetIdentity);
                }
            }

            return(true);
        }
コード例 #15
0
 public override int CountAvailableSpawns(MyPlayer player)
 {
     return(MyMedicalRoom.AvailableMedicalRoomsCount(player.Identity.IdentityId));
 }
コード例 #16
0
 public MyUseObjectMedicalRoom(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     m_medicalRoom = (MyMedicalRoom)owner;
     m_localMatrix = dummyData.Matrix;
 }
コード例 #17
0
        private static StringBuilder GetOwnerDisplayName(MyMedicalRoom medRoom)
        {
            long owner = medRoom.IDModule.Owner;

            if (owner == 0) return MyTexts.Get(MySpaceTexts.BlockOwner_Nobody);

            var identity = Sync.Players.TryGetIdentity(owner);
            if (identity != null) return new StringBuilder(identity.DisplayName);
            else return MyTexts.Get(MySpaceTexts.BlockOwner_Unknown);
        }
コード例 #18
0
 public MyUseObjectMedicalRoom(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     m_medicalRoom = (MyMedicalRoom)owner;
     m_localMatrix = dummyData.Matrix;
 }
コード例 #19
0
        private static void StartSurprise(object senderEvent)
        {
            BoundingSphereD sphere = new BoundingSphereD(new Vector3D(-18.75f, -2.5f, -1.25f), 2);
            m_getEntities.Clear();
            MyGamePruningStructure.GetAllEntitiesInSphere(ref sphere, m_getEntities);

            m_spawnMedical = null;
            foreach (var entity in m_getEntities)
            {
                m_spawnMedical = entity as MyMedicalRoom;
                if (m_spawnMedical != null)
                {
                    m_spawnMedical.OnClose += delegate { m_spawnMedical = null; };
                    break;
                }
            }

            m_started = true;
        }
コード例 #20
0
 public SyncClass(MyMedicalRoom block)
 {
     m_block = block;
 }