コード例 #1
0
ファイル: Player.cs プロジェクト: trustieee/UnicornFrenzy
    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;
        }
    }