// Use this for initialization
    void Start()
    {
        combatController = GetComponent <ICombatController> ();
        if (combatController == null)
        {
            combatController = new NullCombatController();
        }

        virtualController = GetComponent <IVirtualController> ();
        if (virtualController == null)
        {
            virtualController = new NullVirtualController();
        }
        virtualController.SetMovementSpeedProperties(
            projectileSpeed,
            projectileMaxSpeedBoost,
            0f,
            0f
            );

        lifeTimer = new Timer(lifeTimeSec);
        lifeTimer.startTimer();

        indestructableTimer = new Timer(indesctructableTimeSec);
        indestructableTimer.startTimer();
    }
Пример #2
0
    void Start()
    {
        Camera camera = Camera.main;

        if (camera == null)
        {
            GameObject cameraGameObject = Instantiate(new GameObject());
            camera = cameraGameObject.AddComponent <Camera> ();
        }

        cameraController = camera.GetComponent <ICameraController> ();
        if (cameraController == null)
        {
            cameraController = camera.gameObject.AddComponent <DynamicCameraController> ();
        }

        specialBox = GameObject.FindGameObjectWithTag("Special Box");
        if (specialBox == null)
        {
            specialBox = new GameObject();
        }

        GameObject player = GameObject.FindGameObjectWithTag("Player");

        playerInputController = player.GetComponent <IInputController> ();
        if (player == null || playerInputController == null)
        {
            playerInputController = new NullInputController();
        }
        playerInputController.SetCameraController(cameraController);
        playerInputController.SetCameraMode(
            CameraMode.THIRD_PERSON,
            Vector3.zero
            );

        playerVirtualController = player.GetComponent <IVirtualController> ();
        if (player == null || playerVirtualController == null)
        {
            playerVirtualController = new NullVirtualController();
        }

        playerHealthController = player.GetComponent <IHealthController> ();
        if (playerHealthController == null)
        {
            playerHealthController = new NullHealthController();
        }

        CameraModeTrigger [] cameraModeTriggers = ( CameraModeTrigger [] )GameObject.FindObjectsOfType <CameraModeTrigger> ();
        foreach (CameraModeTrigger cameraModeTrigger in cameraModeTriggers)
        {
            cameraModeTrigger.SetCameraModeListener(this);
        }
    }
Пример #3
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            //See the console
            if (args.Count == 0)
            {
                BotProgram.MsgHandler.QueueMessage($"The current console is {InputGlobals.CurrentConsoleVal}. To set the console, add one as an argument: {GetValidConsoleStr()}");
                return;
            }

            string consoleStr = args[0];

            if (Enum.TryParse <InputGlobals.InputConsoles>(consoleStr, true, out InputGlobals.InputConsoles console) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Please enter a valid console: {GetValidConsoleStr()}");
                return;
            }

            if (console == InputGlobals.CurrentConsoleVal)
            {
                BotProgram.MsgHandler.QueueMessage($"The current console is already {InputGlobals.CurrentConsoleVal}!");
                return;
            }

            //First stop all inputs completely while changing consoles - we don't want data from other inputs remaining
            InputHandler.CancelRunningInputs();

            //Wait until no inputs are running
            while (InputHandler.CurrentRunningInputs > 0)
            {
            }

            //Set console and buttons
            InputGlobals.SetConsole(console, args);

            for (int i = 0; i < InputGlobals.ControllerMngr.ControllerCount; i++)
            {
                IVirtualController controller = InputGlobals.ControllerMngr.GetController(i);
                if (controller.IsAcquired == true)
                {
                    controller.Reset();
                }
            }

            //Resume inputs
            InputHandler.ResumeRunningInputs();

            BotProgram.MsgHandler.QueueMessage($"Set console to {InputGlobals.CurrentConsoleVal} and reset all running inputs!");
        }
Пример #4
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            //Console.WriteLine("Executed");
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count > 1)
            {
                BotProgram.MsgHandler.QueueMessage("Usage: \"controller number\"");
                return;
            }

            int controllerIndex = 0;

            //Default to the user's controller port
            User user = BotProgram.GetUser(e.Command.ChatMessage.DisplayName, false);

            if (user != null)
            {
                controllerIndex = user.Team;
            }

            //Parse the controller port if we have another argument
            if (args.Count == 1)
            {
                //Console.WriteLine("Found arg");
                string arg = args[0];

                //Couldn't parse
                if (int.TryParse(arg, out int value) == false)
                {
                    BotProgram.MsgHandler.QueueMessage("Usage: \"controller number\"");
                    return;
                }

                //Subtract 1 for consistency (Ex. player 1 is controller index 0)
                controllerIndex = value - 1;
                //Console.WriteLine($"Arg val set to {controllerIndex}");
            }
            else
            {
                //Console.WriteLine("No arg found");
            }

            //Console.WriteLine("CONTROLLER INDEX: " + controllerIndex);

            //Check if the controller port is out of range
            if (controllerIndex < 0 || controllerIndex >= InputGlobals.ControllerMngr.ControllerCount)
            {
                BotProgram.MsgHandler.QueueMessage($"controller port is out of the 1 to {InputGlobals.ControllerMngr.ControllerCount} range.");
                return;
            }

            //Get the controller
            IVirtualController controller = InputGlobals.ControllerMngr.GetController(controllerIndex);

            if (controller.IsAcquired == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Controller at index {controllerIndex} is not acquired.");
                return;
            }

            //Console.WriteLine("Found controller and acquired");

            StringBuilder stringBuilder = new StringBuilder(500);
            string        startString   = $"Pressed inputs for controller {controllerIndex + 1}: ";

            stringBuilder.Append(startString);

            //Check which inputs are pressed
            string[] validInputs = InputGlobals.ValidInputs;
            for (int i = 0; i < validInputs.Length; i++)
            {
                string       inputName = validInputs[i];
                ButtonStates btnState  = controller.GetInputState(inputName);
                if (btnState == ButtonStates.Pressed)
                {
                    stringBuilder.Append(inputName).Append(',').Append(' ');
                }
            }

            //If the controller doesn't have any pressed inputs, mention it
            if (stringBuilder.Length == startString.Length)
            {
                stringBuilder.Append("None!");
            }
            else
            {
                stringBuilder.Remove(stringBuilder.Length - 2, 2);
            }

            string finalStr = stringBuilder.ToString();

            BotProgram.MsgHandler.QueueMessage(finalStr);
        }
Пример #5
0
 public virtual void SetVirtualController(IVirtualController virtualController)
 {
     // do nothing
 }
Пример #6
0
        private static void ExecuteInput(object obj)
        {
            /*************************************************************
            * PERFORMANCE CRITICAL CODE                                  *
            * Even the smallest change must be thoroughly tested         *
            *************************************************************/

            //Increment running threads
            Interlocked.Increment(ref RunningInputThreads);

            //Get the input list - this should have been validated beforehand
            InputWrapper inputWrapper = (InputWrapper)obj;

            ParsedInput[][] inputArray = inputWrapper.InputArray;

            Stopwatch sw = new Stopwatch();

            List <int> indices = new List <int>(16);
            IVirtualControllerManager vcMngr = inputWrapper.VCManager;

            int controllerCount = vcMngr.ControllerCount;

            //Use Span with stack memory to avoid allocations and improve speed
            Span <int> nonWaits = stackalloc int[controllerCount];

            nonWaits.Clear();

            //This is used to track which controller ports were used across all inputs
            //This helps prevent updating controllers that weren't used at the end
            Span <int> usedControllerPorts = stackalloc int[controllerCount];

            usedControllerPorts.Clear();

            GameConsole curConsole = inputWrapper.Console;

            //Don't check for overflow to improve performance
            unchecked
            {
                for (int i = 0; i < inputArray.Length; i++)
                {
                    ref ParsedInput[] inputs = ref inputArray[i];

                    indices.Clear();

                    //Press all buttons unless it's a release input
                    for (int j = 0; j < inputs.Length; j++)
                    {
                        indices.Add(j);

                        //Get a reference to avoid copying the struct
                        ref ParsedInput input = ref inputs[j];

                        //Don't do anything for a blank input
                        if (curConsole.IsBlankInput(input) == true)
                        {
                            continue;
                        }

                        int port = input.controllerPort;

                        //Get the controller we're using
                        IVirtualController controller = vcMngr.GetController(port);

                        //These are set to 1 instead of incremented to prevent any chance of overflow
                        nonWaits[port]            = 1;
                        usedControllerPorts[port] = 1;

                        if (input.release == true)
                        {
                            InputHelper.ReleaseInput(input, curConsole, controller);
                        }
                        else
                        {
                            InputHelper.PressInput(input, curConsole, controller);
                        }
                    }

                    //Update the controllers if there are non-wait inputs
                    for (int waitIdx = 0; waitIdx < nonWaits.Length; waitIdx++)
                    {
                        //Store by ref and change directly to avoid calling the indexer twice
                        ref int nonWaitVal = ref nonWaits[waitIdx];

                        if (nonWaitVal > 0)
                        {
                            IVirtualController controller = vcMngr.GetController(waitIdx);
                            controller.UpdateController();
                            nonWaitVal = 0;
                        }
                    }
Пример #7
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count != 1)
            {
                BotProgram.MsgHandler.QueueMessage("Usage: state #");
                return;
            }

            string stateNumStr = args[0];

            if (int.TryParse(stateNumStr, out int stateNum) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Invalid state number.");
                return;
            }

            string loadStateStr = $"ls{stateNum}";

            if (InputGlobals.CurrentConsole.ButtonInputMap.ContainsKey(loadStateStr) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Invalid state number.");
                return;
            }

            User user = BotProgram.GetOrAddUser(e.Command.ChatMessage.Username, false);

            //Check if the user can perform this input
            ParserPostProcess.InputValidation inputValidation = ParserPostProcess.CheckInputPermissions(user.Level, loadStateStr, BotProgram.BotData.InputAccess.InputAccessDict);

            //If the input isn't valid, exit
            if (inputValidation.IsValid == false)
            {
                if (string.IsNullOrEmpty(inputValidation.Message) == false)
                {
                    BotProgram.MsgHandler.QueueMessage(inputValidation.Message);
                }

                return;
            }

            //Load states are always performed on the first controller
            IVirtualController joystick = InputGlobals.ControllerMngr.GetController(0);

            joystick.PressButton(InputGlobals.CurrentConsole.ButtonInputMap[loadStateStr]);
            joystick.UpdateController();

            BotProgram.MsgHandler.QueueMessage($"Loaded state {stateNum}!");

            //Wait a bit before releasing the input
            const float wait = 50f;
            Stopwatch   sw   = Stopwatch.StartNew();

            while (sw.ElapsedMilliseconds < wait)
            {
            }

            joystick.ReleaseButton(InputGlobals.CurrentConsole.ButtonInputMap[loadStateStr]);
            joystick.UpdateController();
        }