public void Initialize(TPSC_RPG1 controller, RPG3_Ability ability)
    {
        GameObject o = Instantiate(buttonObj, buttonParent.transform);

        UnityAction action = delegate {
            RPG3_AbilitySettings settings = RPG3_AbilitySettings.Initialize(controller, controller.GetCurrentTarget());
            ability.Activate(settings);
        };

        o.GetComponentInChildren <Button>().onClick.AddListener(action);
        o.GetComponentInChildren <RPG3_ButtonHandler>().ability = ability;

        o.GetComponentsInChildren <Image>()[1].sprite = ability.GetIcon();
    }
Example #2
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 #3
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);
                        }
                    }
                }
            }
        }
    }