Example #1
0
        private void PickupPickerController_SubmitChoice(On.RoR2.PickupPickerController.orig_SubmitChoice orig, PickupPickerController self, int choiceIndex)
        {
            var CommandCubes = InstanceTracker.GetInstancesList <PickupPickerController>();

            CommandCubes.Remove(self);
            var displayToken = self.GetComponent <GenericDisplayNameProvider>().displayToken;
            var isModifying  = Input.GetKey(ModifierKey.Value);

            if (isModifying)
            {
                Debug.Log("we are modifying");
                if (!NetworkServer.active)
                {
                    Debug.Log("We are a client!");
                    var i = 0;
                    foreach (var cube in CommandCubes.ToList())
                    {
                        Debug.Log("Entered foreach loop with cube # " + i);
                        if (Vector3.Distance(self.gameObject.transform.position, cube.gameObject.transform.position) <= Radius.Value)
                        {
                            Debug.Log("Cube is in distance");
                            if (cube.GetComponent <GenericDisplayNameProvider>()?.displayToken == displayToken)
                            {
                                Debug.Log("The display token is valid, Writing the network options.");
                                NetworkWriter networkWriter = cube.networkUIPromptController.BeginMessageToServer();
                                networkWriter.Write(0);
                                networkWriter.Write(choiceIndex);
                                cube.networkUIPromptController.FinishMessageToServer(networkWriter);
                            }
                        } //get rid of the return or it wont work in multiplayer
                        i++;
                    }
                }
                else
                {
                    foreach (var cube in CommandCubes.ToList())
                    {
                        if (Vector3.Distance(self.gameObject.transform.position, cube.gameObject.transform.position) <= Radius.Value)
                        {
                            if (cube.GetComponent <GenericDisplayNameProvider>()?.displayToken == displayToken)
                            {
                                cube.HandlePickupSelected(choiceIndex);
                            }
                        }
                    }
                }
            }
            Debug.Log("We've exited.");
            orig(self, choiceIndex);
        }
Example #2
0
        private void PickupPickerController_SubmitChoice1(On.RoR2.PickupPickerController.orig_SubmitChoice orig, PickupPickerController self, int choiceIndex)
        {
            var CommandCubes = InstanceTracker.GetInstancesList <PickupPickerController>();

            CommandCubes.Remove(self);
            var displayToken = self.GetComponent <GenericDisplayNameProvider>().displayToken;
            var isModifying  = Input.GetKey(ModifierKey.Value);


            if (isModifying && self.networkUIPromptController.currentParticipantMaster) //2nd check to prevent recursion from the forloop
            {
                string choices = "";

                // Collect Cubes
                for (int i = 0; i < CommandCubes.Count; i++)
                {
                    var cube = CommandCubes[i];
                    if (Vector3.Distance(self.gameObject.transform.position, cube.gameObject.transform.position) <= finalRadius)
                    {
                        if (cube.GetComponent <GenericDisplayNameProvider>()?.displayToken == displayToken)
                        {
                            var network = cube.networkUIPromptController;
                            if (!network.currentParticipantMaster) //prevents recursion and theft
                            {
                                choices += $"{i},";
                            }
                        }
                    }
                }

                //Send Request
                if (!choices.IsNullOrWhiteSpace())
                {
                    new Networking.RadiusCommandToServer(choices, choiceIndex).Send(NetworkDestination.Server);
                }
            }
            orig(self, choiceIndex);
        }