Esempio n. 1
0
 private void NetworkUser_Start(On.RoR2.NetworkUser.orig_Start orig, NetworkUser networkUser)
 {
     orig(networkUser);
     if (ThisIsServer() && IsCurrentlyInGame())
     {
         ChatHelper.GreetNewPlayer(networkUser);
     }
 }
Esempio n. 2
0
        private void SendJoinAsBlockedMessage()
        {
            string reasons = string.Join(", ", _blockingReasons.Select(r => r.Value));

            ChatHelper.AddChatMessage($"Sorry, join as is temporarily disabled for the following reason(s): {reasons}");
        }
Esempio n. 3
0
        private void JoinAs(NetworkUser user, string characterName, string username)
        {
            if (!DropInConfig.JoinAsEnabled)
            {
                Logger.LogWarning("Join_As disabled. Returning...");
                return;
            }

            if (DropInConfig.HostOnlySpawnAs)
            {
                if (NetworkUser.readOnlyInstancesList[0].netId != user.netId)
                {
                    Logger.LogWarning("HostOnlySpawnAs is enabled and the person using join_as isn't host. Returning!");
                    return;
                }
            }

            if (JoinAsBlocked)
            {
                SendJoinAsBlockedMessage();
                return;
            }

            //Finding the NetworkUser from the person who is using the command.
            NetworkUser player;

            // No user name provided, default to self
            if (string.IsNullOrWhiteSpace(username))
            {
                player = user;
            }
            else
            {
                player = GetNetUserFromString(username);
                if (player == null)
                {
                    ChatHelper.AddChatMessage($"Could not find player with identifier: {username}");
                    return;
                }
            }

            //Finding the body the player wants to spawn as.
            GameObject bodyPrefab = BodyHelper.FindBodyPrefab(characterName);

            // The character the player is trying to spawn as doesn't exist.
            if (!bodyPrefab)
            {
                ChatHelper.AddChatMessage($"{characterName} not found. Availible survivors are: {string.Join(", ", BodyHelper.GetSurvivorDisplayNames())} (or use Random)");
                Logger.LogWarning("Sent message to player informing them that what they requested to join as does not exist. Also bodyPrefab does not exist, returning!");
                return;
            }

            if (player.master == null) // If the player is joining for the first time
            {
                Logger.LogInfo($"Spawning {player.userName} as newly joined player");

                // Make sure the person can actually join. This allows SetupUserCharacterMaster (which is called in OnUserAdded) to work.
                Run.instance.SetFieldValue("allowNewParticipants", true);

                //Now that we've made sure the person can join, let's give them a CharacterMaster.
                Run.instance.OnUserAdded(player);

                ChangeOrSetCharacter(player, bodyPrefab, true);

                // Turn this back off again so a new player isn't immediatly dropped in without getting to pick their character
                Run.instance.SetFieldValue("allowNewParticipants", false);
            }
            else // The player has already joined
            {
                Logger.LogInfo($"{player.userName} has already joined, checking other join conditions");

                if (!DropInConfig.AllowReJoinAs)
                {
                    Logger.LogInfo($"{player.userName} could not use join_as after selecting ");
                    ChatHelper.AddChatMessage($"Sorry {player.userName}! The host has made it so you can't use join_as after selecting character.");
                }
                else if (player.master.lostBodyToDeath)
                {
                    Logger.LogInfo($"{player.userName} is dead and can't change character");
                    ChatHelper.AddChatMessage($"Sorry {player.userName}! You can't use join_as while dead.");
                }
                else
                {
                    Logger.LogInfo($"Changing existing character for {player.userName}");
                    ChangeOrSetCharacter(player, bodyPrefab, false);
                }
            }
        }
Esempio n. 4
0
        private void ChangeOrSetCharacter(NetworkUser player, GameObject bodyPrefab, bool firstTimeJoining)
        {
            CharacterMaster master  = player.master;
            CharacterBody   oldBody = master.GetBody();

            master.bodyPrefab = bodyPrefab;
            CharacterBody body;

            if (firstTimeJoining)
            {
                Transform spawnTransform = Stage.instance.GetPlayerSpawnTransform();
                body = master.SpawnBody(spawnTransform.position + _spawnOffset, spawnTransform.rotation);
                if (bodyPrefab.name == "HereticBody")
                {
                    master.inventory.GiveItem(RoR2Content.Items.LunarPrimaryReplacement, 1);
                    master.inventory.GiveItem(RoR2Content.Items.LunarSecondaryReplacement, 1);
                    master.inventory.GiveItem(RoR2Content.Items.LunarSpecialReplacement, 1);
                    master.inventory.GiveItem(RoR2Content.Items.LunarUtilityReplacement, 1);
                }
                Run.instance.HandlePlayerFirstEntryAnimation(body, spawnTransform.position + _spawnOffset, spawnTransform.rotation);
            }
            else
            {
                if (BodyCatalog.GetBodyName(oldBody.bodyIndex) == "CaptainBody")
                {
                    master.inventory.RemoveItem(RoR2Content.Items.CaptainDefenseMatrix, 1);
                }

                if (bodyPrefab.name == "CaptainBody")
                {
                    master.inventory.GiveItem(RoR2Content.Items.CaptainDefenseMatrix, 1);
                }

                if (BodyCatalog.GetBodyName(oldBody.bodyIndex) == "HereticBody")
                {
                    master.inventory.RemoveItem(RoR2Content.Items.LunarPrimaryReplacement, 1);
                    master.inventory.RemoveItem(RoR2Content.Items.LunarSecondaryReplacement, 1);
                    master.inventory.RemoveItem(RoR2Content.Items.LunarSpecialReplacement, 1);
                    master.inventory.RemoveItem(RoR2Content.Items.LunarUtilityReplacement, 1);
                }

                if (bodyPrefab.name != "HereticBody")
                {
                    body = master.Respawn(master.GetBody().transform.position, master.GetBody().transform.rotation);
                }
                else
                {
                    if (bodyPrefab.name == "HereticBody")
                    {
                        master.inventory.GiveItem(RoR2Content.Items.LunarPrimaryReplacement, 1);
                        master.inventory.GiveItem(RoR2Content.Items.LunarSecondaryReplacement, 1);
                        master.inventory.GiveItem(RoR2Content.Items.LunarSpecialReplacement, 1);
                        master.inventory.GiveItem(RoR2Content.Items.LunarUtilityReplacement, 1);
                    }

                    body = master.GetBody();
                }
            }

            ChatHelper.AddChatMessage($"{player.userName} is spawning as {body.GetDisplayName()}!");
        }