Example #1
0
    private void Update()
    {
        if (activeController != null && !gm.isPaused)
        {
            activeController.Tick();
        }

        if (Input.GetKeyDown(KeyCode.Mouse4))
        {
            //Debug.Log("Attempting to Possess");

            Vector3    rayOrigin = activeController.cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            // Check if there's an interactable target in range.
            if (Physics.Raycast(rayOrigin, activeController.cam.transform.forward, out hit, 5.0f))
            {
                // Declare Target;
                GameObject targetHit = hit.transform.gameObject;
                //Debug.Log(targetHit.name);

                if (targetHit.GetComponentInParent <TPS_Controller>() != null)
                {
                    activeController.Eject();
                    activeController = targetHit.GetComponentInParent <TPS_Controller>().Possess(this);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Mouse3))
        {
            activeController.Eject();
            activeController = defaultController.Possess(this);
        }
    }
    public static RPG3_AbilitySettings Initialize(TPS_Controller owner, Vector3 targetPosition)
    {
        RPG3_AbilitySettings result = new RPG3_AbilitySettings();

        result.owner          = owner;
        result.targetPosition = targetPosition;

        return(result);
    }
Example #3
0
    private void Start()
    {
        if (activeController != null)
        {
            activeController.Possess(this);
        }

        else
        {
            activeController = defaultController.Possess(this);
        }
    }
    public static RPG3_AbilitySettings Initialize(TPS_Controller owner, TPS_Controller target)
    {
        RPG3_AbilitySettings result = new RPG3_AbilitySettings();

        result.owner  = owner;
        result.target = target;

        if (target != null)
        {
            result.targetEntity = target.GetComponent <TPS_Entity>();
        }

        return(result);
    }
Example #5
0
    // #########################################################
    // # --------------------- CONTROLS ---------------------- #
    // #########################################################

    // Player Movement Controls
    private void Motion()
    {
        if (isChanneling)
        {
            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
            {
                Debug.Log("Cancel Channeling");
                isChanneling      = false;
                channelledAbility = null;

                channelTarget          = null;
                channelingText.enabled = false;
                channelingBar.enabled  = false;
            }
        }


        // X/Y Motion
        m_xForce = Input.GetAxis("Horizontal") * m_Speed * speedMultiplier;
        m_yForce = Input.GetAxis("Vertical") * m_Speed * speedMultiplier;

        // Z Motion
        //if (Input.GetKeyDown(KeyCode.Space) && m_Jump)
        //{
        //    m_zForce += m_JumpForce;
        //    m_Jump = false;

        //}

        if (!controller.isGrounded && isFalling)
        {
            m_zForce += (-0.15f) * Time.deltaTime;
        }
        else
        {
            m_zForce = 0;
            //m_Jump = true;
        }

        // Calculate Motion
        Vector3 motion = new Vector3(m_xForce, m_zForce, m_yForce);

        motion = transform.rotation * motion;
        controller.Move(motion);
    }
Example #6
0
    // #########################################################
    // # ---------------------- UPDATE ----------------------- #
    // #########################################################

    public override void Tick()
    {
        base.Tick();

        if (owner != null)
        {
            if (!owner.gm.isPaused)
            {
                if (!disableControls)
                {
                    Motion();
                }


                // TARGETING SYSTEM
                if (activeTargetIndicator != null)
                {
                    Ray ray = cam.ScreenPointToRay(Input.mousePosition);

                    RaycastHit hitInfo;
                    if (Physics.Raycast(ray, out hitInfo))
                    {
                        // Get Collision Data
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        activeTargetIndicator.transform.position = hitInfo.point + hitInfo.normal * 0.1f;
                    }
                }

                // CHANNELLING
                if (channelledAbility != null)
                {
                    channelingBar.enabled  = true;
                    channelingText.enabled = true;

                    if (channelTimer > 0)
                    {
                        channelTimer -= Time.deltaTime;
                        isChanneling  = true;

                        channelingText.text      = channelledAbility.GetName() + " : " + Mathf.Round(channelTimer * 100) / 100;
                        channelingBar.fillAmount = (channelTimer / 2.5f);
                    }

                    if (channelTimer <= 0)
                    {
                        RPG3_AbilitySettings settings = new RPG3_AbilitySettings();
                        switch (channelledAbility.GetAbilityMode())
                        {
                        case RPG3_AbilityMode.Targeted:
                            settings = RPG3_AbilitySettings.Initialize(this, channelTarget);
                            break;

                        case RPG3_AbilityMode.Positional:
                            settings = RPG3_AbilitySettings.Initialize(this, abilityTargetPoint);
                            break;

                        case RPG3_AbilityMode.Self:
                            settings = RPG3_AbilitySettings.Initialize(this, channelTarget);
                            break;
                        }

                        channelledAbility.Effect(settings);

                        channelledAbility      = null;
                        channelTarget          = null;
                        channelingBar.enabled  = false;
                        channelingText.enabled = false;
                    }
                }

                hotbar.HotkeyTracker();

                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    // If a UI element was pressed, break out.
                    if (uiRaycaster.Raycast().Count > 0)
                    {
                        return;
                    }

                    if (abilityBeingTargeted == null)
                    {
                        // Clear the active target if worldspace was clicked
                        if (targetController != null || targetEntity != null)
                        {
                            targetController = null;
                            targetEntity     = null;
                        }
                    }


                    // if the UI was not pressed, raycast to world position
                    Ray ray = cam.ScreenPointToRay(Input.mousePosition);

                    RaycastHit hitInfo;
                    if (Physics.Raycast(ray, out hitInfo))
                    {
                        // Get Collision Data
                        ///////////////////////////////////////////////////////////////////////////////////////////////

                        GameObject targetHit = hitInfo.collider.gameObject;
                        Debug.Log(targetHit);

                        // Activate an ability that's being targeted
                        if (abilityBeingTargeted != null)
                        {
                            if (activeTargetIndicator != null)
                            {
                                Destroy(activeTargetIndicator);
                                activeTargetIndicator = null;
                            }

                            RPG3_AbilitySettings settings = RPG3_AbilitySettings.Initialize(this, hitInfo.point);
                            abilityBeingTargeted.Activate(settings);

                            abilityTargetPoint = hitInfo.point;
                            abilityBeingTargeted.isTargeting = false;
                            abilityBeingTargeted             = null;
                        }


                        // Selection Command
                        if (targetHit.GetComponentInParent <TPS_Controller>() != null)
                        {
                            targetController = targetHit.GetComponentInParent <TPS_Controller>();
                        }

                        if (targetHit.GetComponentInParent <TPS_Entity>() != null)
                        {
                            //Debug.Log(hitInfo.collider.gameObject.name + " selected");

                            targetEntity = targetHit.GetComponentInParent <TPS_Entity>();

                            ///////////////////////////////////////////////////////////////////////////////////////////////
                        }
                    }
                }

                if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    // Activate an ability that's being targeted
                    if (abilityBeingTargeted != null)
                    {
                        if (!isChanneling)
                        {
                            if (activeTargetIndicator != null)
                            {
                                Destroy(activeTargetIndicator);
                                activeTargetIndicator = null;
                            }

                            abilityTargetPoint = Vector3.zero;
                            abilityBeingTargeted.isTargeting = false;
                            abilityBeingTargeted             = null;
                        }
                    }
                }

                // Update Canvas
                if (guiCanvas.enabled)
                {
                    // Health
                    healthText.text = entity.GetCurrentHealth() + " / " + entity.GetMaxHealth();

                    float currentHealth = entity.GetCurrentHealth();
                    float maxHealth     = entity.GetMaxHealth();
                    healthBar.fillAmount = currentHealth / maxHealth;

                    // Resource
                    resourceText.text = entity.GetCurrentResource() + " / " + entity.GetMaxResource();

                    float currentResource = entity.GetCurrentResource();
                    float maxResource     = entity.GetMaxResource();
                    resourceBar.fillAmount = currentResource / maxResource;

                    // Target System
                    if (targetEntity != null)
                    {
                        if (!targetInfoDisplay.activeInHierarchy)
                        {
                            targetInfoDisplay.SetActive(true);
                        }

                        // Health
                        targetHealthText.text = targetEntity.GetCurrentHealth() + " / " + targetEntity.GetMaxHealth();

                        float currentTargetHealth = targetEntity.GetCurrentHealth();
                        float maxTargetHealth     = targetEntity.GetMaxHealth();
                        targetHealthBar.fillAmount = currentTargetHealth / maxTargetHealth;

                        // Resource
                        targetResourceText.text = targetEntity.GetCurrentResource() + " / " + targetEntity.GetMaxResource();

                        float currentTargetResource = targetEntity.GetCurrentResource();
                        float maxTargetResource     = targetEntity.GetMaxResource();
                        targetResourceBar.fillAmount = currentTargetResource / maxTargetResource;
                    }

                    else
                    {
                        if (targetInfoDisplay.activeInHierarchy)
                        {
                            targetInfoDisplay.SetActive(false);
                        }
                    }
                }
            }
        }
    }