Beispiel #1
0
    void Update()
    {
        if (!DieOnce && StartAgentBool)
        {
            AmIBurning();
            AmISlowed();
            agent.speed = MovementSpeed;



            if (Input.GetKey((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveLeftKey)))
            {
                HorMov = -1;
            }
            else
            {
                HorMov = 0;
            }
            if (Input.GetKey((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveRightKey)))
            {
                HorMov2 = 1;
            }
            else
            {
                HorMov2 = 0;
            }

            if (Input.GetKey((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveDownKey)))
            {
                VerMov = -1;
            }
            else
            {
                VerMov = 0;
            }
            if (Input.GetKey((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveUpKey)))
            {
                VerMov2 = 1;
            }
            else
            {
                VerMov2 = 0;
            }

            inputY = VerMov + VerMov2;
            inputX = HorMov + HorMov2;


            MoveCD_ -= Time.deltaTime;

            if (inputX != 0 || inputY != 0)
            {
                Vector3 moveDir = new Vector3(inputX, 0, inputY).normalized;
                targetPosition = transform.position + moveDir;
                if (BlobArmorBool)
                {
                    agent.destination = targetPosition;
                }
                move                   = true;
                rightclick             = false;
                agent.stoppingDistance = 0f;
            }

            if (LeaveFireTrail)
            {
                LeaveFireTrailFunc();
            }


            if (ChannelingCount > 0)  //channelingNow == true)
            {
                anim.PlayerAttack();
                if (Input.GetKeyDown((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.CastSpellLoc)) && curSpellProjectile.Count > 0 && !BlobArmorBool)
                {
                    foreach (var item in curSpellProjectile)
                    {
                        if (item != null)
                        {
                            item.GetComponent <SpellProjectile>().Stop();
                            curSpellProjectile_.Add(item);
                        }
                    }
                    foreach (var item in curSpellProjectile_)
                    {
                        curSpellProjectile.Remove(item);
                    }
                }
            }
            if (((Input.GetKeyDown((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveLoc)) && !BlobArmorBool) || ((inputX != 0 || inputY != 0) && !BlobArmorBool)) && ChannelingCount > 0 && curSpellProjectile.Count > 0)
            {
                foreach (var item in curSpellProjectile)
                {
                    if (item != null)
                    {
                        item.GetComponent <SpellProjectile>().Stop();
                        curSpellProjectile_.Add(item);
                    }
                }
                foreach (var item in curSpellProjectile_)
                {
                    curSpellProjectile.Remove(item);
                }
            }

            if (Input.GetKey((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveLoc)) && !EventSystem.current.IsPointerOverGameObject() && (ChannelingCount == 0 || BlobArmorBool))
            {
                rightclick = false;
                //  BlobArmorAttackOnceBool = false;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Raycast things, checks where mouse clicks
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    Vector3 HitGroundlevel = new Vector3(hit.point.x, 1, hit.point.z);
                    float   dist           = Vector3.Distance(HitGroundlevel, transform.position); // distance between click point and PC
                    if (Input.GetKeyDown((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.MoveLoc)) && (hit.collider.tag == "Floor" || hit.collider.tag == "Door" || hit.collider.tag == "Wall" || hit.collider.tag == "MageBossDeadGolem" || hit.collider.tag == "Shop" || hit.collider.tag == "Chest"))
                    {
                        Vector3 DaPoint = new Vector3(hit.point.x, hit.point.y + 0.1f, hit.point.z);
                        Instantiate(MousePing, DaPoint, Quaternion.Euler(0, 0, 0));
                    }

                    if (dist > 0.1f && hit.collider.tag != "ObstacleCourseClickLayer")
                    {
                        targetPosition         = HitGroundlevel;
                        move                   = true; // when move true, character moves unless rightclick is true.
                        agent.stoppingDistance = 0f;
                        if (BlobArmorBool)
                        {
                            agent.destination = targetPosition;
                        }
                    }



                    if (hit.collider.gameObject.tag == "Token") // if mouse clicks on a object with the tag Monster, PC will start tracking it and following it.
                    {
                        activeToken = hit.collider.gameObject;
                    }
                    else if (activeToken != null)
                    {
                        activeToken.GetComponent <TokenScript>().ClickedElsewhere();
                        activeToken = null;
                    }

                    if (hit.collider.gameObject.tag == "Door") // if mouse clicks on a object with the tag Monster, PC will start tracking it and following it.
                    {
                        activeDoor = hit.collider.gameObject;
                    }
                    else if (activeDoor != null)
                    {
                        activeDoor.GetComponent <OneWayDoor>().ClickedElsewhere();
                        activeDoor = null;
                    }
                    if (hit.collider.gameObject.tag == "EventTag") // if mouse clicks on a object with the tag Monster, PC will start tracking it and following it.
                    {
                        activeEvent = hit.collider.gameObject;
                    }
                    else if (activeEvent != null)
                    {
                        activeEvent.GetComponent <EventStart>().ClickedElsewhere();
                        activeEvent = null;
                    }
                    if (hit.collider.gameObject.tag == "Shop") // if mouse clicks on a object with the tag Monster, PC will start tracking it and following it.
                    {
                        targetPosition = new Vector3(hit.collider.transform.position.x - 4, hit.collider.transform.position.y, hit.collider.transform.position.z);
                        activeShop     = hit.collider.gameObject;
                    }
                    else if (activeShop != null)
                    {
                        activeShop.GetComponent <Shop>().ClickedElsewhere();
                        activeShop = null;
                    }
                    if (hit.collider.gameObject.tag == "Chest") // if mouse clicks on a object with the tag Monster, PC will start tracking it and following it.
                    {
                        activeChest    = hit.collider.gameObject;
                        targetPosition = new Vector3(hit.collider.transform.position.x, hit.collider.transform.position.y, hit.collider.transform.position.z - 3);
                    }
                    else if (activeChest != null)
                    {
                        activeChest.GetComponent <AmazingChestHead>().ClickedElsewhere();
                        activeChest = null;
                    }
                }
            }
            // right click spell cast input

            if (Input.GetKey((KeyCode)System.Enum.Parse(typeof(KeyCode), MenuScript.CastSpellLoc)) && !EventSystem.current.IsPointerOverGameObject())
            {
                //  BlobArmorAttackOnceBool = false;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    CS.spellCastLocation   = hit.point;
                    SpellcastPosition      = hit.point;
                    agent.stoppingDistance = 0f;
                    move = true;
                    if (!rightclick)
                    {
                        RotateAfterCastingTimer = 0.5f;
                    }

                    rightclick = true;
                }
            }

            RotateAfterCastingTimer -= Time.deltaTime;

            if (move)
            {
                if (rightclick == true || RotateAfterCastingTimer > 0)
                {
                    bool asd = CS.IsCurrentSpellSlotReady();
                    if (asd || agent.velocity.magnitude == 0f || BlobArmorBool)
                    {
                        Vector3    direction = (new Vector3(SpellcastPosition.x, transform.position.y, SpellcastPosition.z) - transform.position).normalized;
                        Quaternion rotation  = Quaternion.LookRotation(direction);
                        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 25);
                        float angle = Quaternion.Angle(transform.rotation, rotation);
                        if (ChannelingCount == 0 && angle <= 35f || BlobArmorBool)
                        {
                            RotateAfterCastingTimer = 0;
                            transform.rotation      = rotation;
                            SendSpellCast();
                            rightclick = false;
                        }
                    }
                    else
                    {
                        rightclick = false;
                    }
                }
                if ((MoveCD_ <= 0 && !attackingRightNow && !rightclick) || BlobArmorBool)
                {
                    agent.isStopped = false;
                    if (Vector3.Distance(agent.destination, targetPosition) > 1 || (inputX != 0 || inputY != 0))
                    {
                        agent.destination = targetPosition;
                    }
                    float distanceToTarget = Vector3.Distance(transform.position, agent.destination);
                    float velocity         = agent.velocity.magnitude / agent.speed;
                    if ((distanceToTarget > 0.75f || velocity > 0.9f) && !attackingRightNow)
                    {
                        anim.PlayerMove();
                    }
                }
                else
                {
                    agent.isStopped = true;
                }
            }
            else if (!attackingRightNow)
            {
                PlayerIsIdle();
            }

            if (attackingRightNow)
            {
                if (attackingDuration <= 0f)
                {
                    if (ChannelingCount == 0)
                    {
                        attackingRightNow = false;
                    }
                    attackingDuration = 0.25f;
                }
                attackingDuration -= Time.deltaTime;
            }
            InternalSpellCastCD_ -= Time.deltaTime;
            CheckDestinationReached();
        }
        else
        {
            DieSoundOff(Time.deltaTime * 10);
        }
        if (Immortal)
        {
            DieSoundOff(Time.deltaTime * 4);
        }
    }