Ejemplo n.º 1
0
 void ProcessAbility()
 {
     if (CurrentAbility != null)
     {
         CurrentAbility.UpdateAbility();
         if (_controls.GetButtonDown(ActionNames.Ability))
         {
             CurrentAbility.UseAbility();
         }
     }
 }
Ejemplo n.º 2
0
    public void AbilityHandler(PlayerAbility ability)
    {
        switch (ability.Type)
        {
        case PlayerAbility.AbilityType.EnemyTarget:
            mTargetAbility = ability;
            ARangeDisplay.transform.localScale = new Vector3(ability.Range * 2, 0, ability.Range * 2);
            ARangeDisplay.enabled = true;
            mETargetSelect        = true;
            AttackAble            = false;
            break;

        case PlayerAbility.AbilityType.AllyTarget:
            mTargetAbility = ability;
            ARangeDisplay.transform.localScale = new Vector3(ability.Range * 2, 0, ability.Range * 2);
            ARangeDisplay.enabled = true;
            mFTargetSelect        = true;
            AttackAble            = false;
            break;

        case PlayerAbility.AbilityType.Self:

            ability.UseAbility(this, PrimaryStat, SecondaryStat, mGameController);
            AttackAble = false;

            break;

        case PlayerAbility.AbilityType.WorldTarget:

            mWorldAbility = ability;
            ARangeDisplay.transform.localScale = new Vector3(ability.Range * 2, 0, ability.Range * 2);
            ARangeDisplay.enabled = true;
            mSelectLocation       = true;
            AttackAble            = false;

            break;
        }
    }
Ejemplo n.º 3
0
    public virtual void Update()
    {
        if (Health <= 0)
        {
            Death();
        }

        if (ActionPoints > MaxActionPoints)
        {
            ActionPoints = MaxActionPoints;
        }

        if (EndingTurn)
        {
            if (FinishedMoving)
            {
                EndTurn();
            }
        }

        if (TurnActive || TurnPaused)
        {
            if (!mSelectLocation && !mFTargetSelect && !mETargetSelect && !MoveAble && !AttackAble && !mMoving && FinishedMoving)
            {
                EndTurn();
            }
        }

        if (TurnActive)
        {
            if (Health > MaxHealth)
            {
                Health = MaxHealth;
            }

            if (Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0 && TurnActive)
            {
                var        playerPlane = new Plane(Vector3.up, transform.position);
                Ray        ray         = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                float      hitdist = 0.0f;

                if (mETargetSelect)
                {
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.gameObject.tag == "Enemy" && Vector3.Distance(hit.transform.position, transform.position) <= mTargetAbility.Range)
                        {
                            mEnemyTarget = hit.collider.gameObject.GetComponent <Enemy> ();
                            print("enemy target aquired!");
                            mTargetAbility.UseAbility(this, mEnemyTarget, PrimaryStat, SecondaryStat);
                            ARangeDisplay.enabled = false;
                            mETargetSelect        = false;
                            mTargetAbility        = null;
                        }
                    }
                }
                else if (mFTargetSelect)
                {
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.gameObject.tag == "Player" && Vector3.Distance(hit.transform.position, transform.position) <= mTargetAbility.Range)
                        {
                            mFriendlyTarget = hit.collider.gameObject.GetComponent <Player> ();
                            print("friendly target aquired!");
                            mTargetAbility.UseAbility(this, mFriendlyTarget, PrimaryStat, SecondaryStat);
                            ARangeDisplay.enabled = false;
                            mFTargetSelect        = false;
                            mTargetAbility        = null;
                        }
                    }
                }
                else if (MovePhase)
                {
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.tag == "Ground")
                        {
                            if (playerPlane.Raycast(ray, out hitdist))
                            {
                                Vector3 targetPoint = ray.GetPoint(hitdist);
                                TargetNode = mAstarPath.astarData.gridGraph.GetNearest(targetPoint).node;
                                if (TargetNode != null)
                                {
                                    GraphNode match = MoveableNodes.FirstOrDefault(x => x.position == TargetNode.position);
                                    if (match != null)
                                    {
                                        MoveCharacter(targetPoint);
                                        ClearRender();
                                        MoveAble = false;
                                        SelectionIndicator.SetActive(true);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (mSelectLocation)
                {
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.tag == "Ground")
                        {
                            if (playerPlane.Raycast(ray, out hitdist))
                            {
                                Vector3 targetPoint = ray.GetPoint(hitdist);

                                if (Vector3.Distance(transform.position, targetPoint) <= mWorldAbility.Range)
                                {
                                    mWorldAbility.UseAbility(this, targetPoint, PrimaryStat, SecondaryStat, mGameController);
                                    ARangeDisplay.enabled = false;
                                    mWorldAbility         = null;
                                    mSelectLocation       = false;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.gameObject.tag == "Item" && Vector3.Distance(hit.transform.position, transform.position) <= 8)
                        {
                            ItemPickup hitItem = hit.collider.gameObject.GetComponent <ItemPickup>();
                            Inventory.AddItem(hitItem.ItemID, hitItem.ItemQuantity);
                            hitItem.RemoveObject();
                        }
                        else if (hit.collider.gameObject.tag == "Interactable" && Vector3.Distance(hit.transform.position, transform.position) <= 8)
                        {
                            Debug.Log("Using Object!");
                            hit.collider.gameObject.GetComponent <InteractiveObject>().UseObject();
                        }
                        else if (hit.collider.gameObject.tag == "Player")
                        {
                            Player SelectedPlayer = hit.collider.gameObject.GetComponent <Player>();

                            if (mGameController.PlayerInActiveList(SelectedPlayer))
                            {
                                PauseTurn();
                                if (SelectedPlayer.TurnPaused)
                                {
                                    SelectedPlayer.ResumeTurn();
                                }
                                else
                                {
                                    SelectedPlayer.StartTurn();
                                }
                            }
                        }
                    }
                }
            }



            if (Input.GetMouseButtonDown(1) && TurnActive)
            {
                if (mSelectLocation || mETargetSelect || mFTargetSelect)
                {
                    mSelectLocation       = false;
                    mETargetSelect        = false;
                    mFTargetSelect        = false;
                    mWorldAbility         = null;
                    mTargetAbility        = null;
                    ARangeDisplay.enabled = false;
                    AttackAble            = true;
                }

                if (MovePhase && MoveAble)
                {
                    MovePhase = false;
                    SelectionIndicator.SetActive(true);
                    ClearRender();
                }
            }
        }
        else
        {
            ARangeDisplay.enabled = false;
        }
    }