public bool ThrowItem(GameObject objectThrown, entityDirection directionThrown)
    {
        GameObject thrownItem = Instantiate(objectThrown, transform.position, Quaternion.identity);

        thrownItem.GetComponent <WeaponHandler>().parentObject = this.gameObject;
        thrownItem.GetComponent <Rigidbody2D>().velocity       = GlobalFunc.entityDirectionToVector2(directionThrown).normalized * 5;
        if (thrownItem.GetComponent <WeaponHandler>().NeedsRotate)
        {
            switch (directionThrown)
            {
            case entityDirection.N:
                thrownItem.transform.eulerAngles = new Vector3(0, 0, 90);
                break;

            case entityDirection.E:
                break;

            case entityDirection.S:
                thrownItem.transform.eulerAngles = new Vector3(0, 0, -90);
                break;

            case entityDirection.W:
                thrownItem.transform.eulerAngles = new Vector3(0, 0, 180);
                break;
            }
        }
        return(true);
    }
    public bool ThrowItem(int itemIndex, entityDirection directionThrown)
    {
        Item itemToThrow = inventory.Inventory[itemIndex];

        if (inventory.RemoveItem(itemIndex, 1))
        {
            GameObject thrownItem = Instantiate(itemToThrow.weaponPrefab, transform.position, Quaternion.identity);
            thrownItem.GetComponent <WeaponHandler>().parentObject = this.gameObject;
            thrownItem.GetComponent <Rigidbody2D>().velocity       = GlobalFunc.entityDirectionToVector2(directionThrown).normalized * 5;
            if (thrownItem.GetComponent <WeaponHandler>().NeedsRotate)
            {
                switch (directionThrown)
                {
                case entityDirection.N:
                    thrownItem.transform.eulerAngles = new Vector3(0, 0, 90);
                    break;

                case entityDirection.E:
                    break;

                case entityDirection.S:
                    thrownItem.transform.eulerAngles = new Vector3(0, 0, -90);
                    break;

                case entityDirection.W:
                    thrownItem.transform.eulerAngles = new Vector3(0, 0, 180);
                    break;
                }
            }

            return(true);
        }

        return(false);
    }
Esempio n. 3
0
    //Get Direction From Vector2 Inputs && Returns Original Direction if no input
    static public entityDirection GetDirection(Vector2 direction, entityDirection curDir)
    {
        string dirReturn = "";

        if (direction.y != 0)
        {
            dirReturn += direction.y > 0 ? "N" : "S";
        }
        if (direction.x != 0)
        {
            dirReturn += direction.x > 0 ? "W" : "E";
        }

        return(dirReturn != "" ? (entityDirection)Enum.Parse(typeof(entityDirection), dirReturn) : curDir);
    }
Esempio n. 4
0
    //Get Direction From Joystick Inputs && Returns Original Direction if no input
    static public entityDirection GetDirection(float horzInput, float vertInput, entityDirection curDir)
    {
        string dirReturn = "";

        if (vertInput != 0)
        {
            dirReturn += vertInput > 0 ? "N" : "S";
        }
        if (horzInput != 0)
        {
            dirReturn += horzInput > 0 ? "E" : "W";
        }

        return(dirReturn != "" ?  (entityDirection)Enum.Parse(typeof(entityDirection), dirReturn):curDir);
    }
Esempio n. 5
0
 void UpdateAnimationVariables()
 {
     if (curTurn)
     {
         if (playerControlled)
         {
             curDir = !isMoving?GlobalFunc.GetDirection(Mathf.Round(Input.GetAxisRaw("Horizontal")), Mathf.Round(Input.GetAxisRaw("Vertical")), curDir) : curDir; GetComponent <EntityAnimation>().prevDir = curDir;
         }
         else
         {
             GetComponent <EntityAnimation>().prevDir = curDir;
         }
     }
     GetComponent <EntityAnimation>().isMoving   = isMoving;
     GetComponent <EntityAnimation>().isSleeping = isSleeping;
 }
Esempio n. 6
0
    public void MoveOffScreen()
    {
        curPos = (Vector2)thisEntity.position;
        if (agroObj != null)
        {
            PathRequestManager.RequestPath(transform.position, agroObj.position, OnPathFound);
        }
        if (path.Length != 0)
        {
            curDir = GlobalFunc.GetDirection(path[0] - curPos);
            MoveTargetPos(path[0] - curPos);
        }
        else
        {
            curDir = GlobalFunc.getRandDirection();
            MoveTargetPos(GlobalFunc.entityDirectionToVector2(curDir));
        }

        thisEntity.position = targetPos;
    }
Esempio n. 7
0
    static public Vector2 entityDirectionToVector2(entityDirection entityDir)
    {
        switch (entityDir)
        {
        case entityDirection.E: return(Vector2.right);

        case entityDirection.N: return(Vector2.up);

        case entityDirection.S: return(Vector2.down);

        case entityDirection.W: return(Vector2.left);

        case entityDirection.NE: return(Vector2.right + Vector2.up);

        case entityDirection.NW: return(Vector2.left + Vector2.up);

        case entityDirection.SE: return(Vector2.right + Vector2.down);

        case entityDirection.SW: return(Vector2.left + Vector2.down);

        default: return(Vector2.zero);
        }
    }
    public bool UseSMove(int moveIndex, entityDirection moveDir)
    {
        if (moveIndex < specialMoves.Count && moveIndex >= 0)
        {
            if (specialMoves[moveIndex] != null)
            {
                if (specialMoves[moveIndex].GetComponent <WeaponHandler>().IsThrown)
                {
                    ThrowItem(specialMoves[moveIndex], moveDir);
                    return(true);
                }
                GameObject newAttack;
                switch (moveDir)
                {
                case entityDirection.N:
                    newAttack = Instantiate(specialMoves[moveIndex], (Vector2)transform.position + specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetVert, Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, 90);
                    }
                    break;

                case entityDirection.NE:
                    newAttack = Instantiate(specialMoves[moveIndex], ((Vector2)transform.position +
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetVert +
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetHorz), Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, 45);
                    }
                    break;

                case entityDirection.E:
                    newAttack = Instantiate(specialMoves[moveIndex], (Vector2)transform.position + specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetHorz, Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    break;

                case entityDirection.SE:
                    newAttack = Instantiate(specialMoves[moveIndex], ((Vector2)transform.position -
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetVert +
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetHorz), Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, -45);
                    }
                    break;

                case entityDirection.S:
                    newAttack = Instantiate(specialMoves[moveIndex], (Vector2)transform.position - specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetVert, Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, -90);
                    }
                    break;

                case entityDirection.SW:
                    newAttack = Instantiate(specialMoves[moveIndex], ((Vector2)transform.position -
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetVert -
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetHorz), Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, -135);
                    }
                    break;

                case entityDirection.W:
                    newAttack = Instantiate(specialMoves[moveIndex], (Vector2)transform.position - specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetHorz, Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, 180);
                    }
                    break;

                case entityDirection.NW:
                    newAttack = Instantiate(specialMoves[moveIndex], ((Vector2)transform.position +
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetVert -
                                                                      specialMoves[moveIndex].GetComponent <WeaponHandler>().WeaponOffsetHorz), Quaternion.identity);
                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                    {
                        newAttack.transform.eulerAngles = new Vector3(0, 0, 135);
                    }
                    break;

                default:
                    break;
                }
                if (playerControlled)
                {
                    curBelly--;
                    curBelly = Mathf.Clamp(curBelly, 0, maxBelly);
                }


                return(true);
            }
        }

        return(false);
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        curPos = (Vector2)thisEntity.position;

        if (!playerControlled)
        {
            if (agroObj == null && Vector2.Distance(GameObject.Find("objPlayer").transform.position, transform.position) < 8f && !isSleeping)  //Agro on Player if line of site
            {
                Debug.DrawRay(transform.position, (GameObject.Find("objPlayer").transform.position - transform.position));
                if (agroObj == null && Physics2D.CircleCast(transform.position, .45f, (GameObject.Find("objPlayer").transform.position - transform.position)) == GameObject.Find("objPlayer").transform)
                {
                    agroObj = GameObject.Find("objPlayer").transform;
                }
            }
            if (agroObj != null && Physics2D.CircleCast(transform.position, .45f, (GameObject.Find("objPlayer").transform.position - transform.position)).transform != GameObject.Find("objPlayer").transform &&
                Vector2.Distance(transform.position, GameObject.Find("objPlayer").transform.position) > 5)
            {
                agroObj = null;
                path    = new Vector2[0];
            }
        }



        if (!amh.IsPaused)
        {
            UpdateAnimationVariables();
            if (isMoving)
            {
                if (GetComponent <SpriteRenderer>().isVisible)
                {
                    thisEntity.position = Vector2.MoveTowards((Vector2)thisEntity.position, targetPos, Time.deltaTime * moveSpeed);
                }
                else
                {
                    thisEntity.position = targetPos; EndTurn(); return;
                }
                if (curPos == targetPos)
                {
                    EndTurn();
                }
                return;
            }
            else
            {
                if (canMove)
                {
                    //PC Movement
                    if (playerControlled)
                    {
                        MoveTargetPos(new Vector2(Mathf.Round(Input.GetAxisRaw("Horizontal")), Mathf.Round(Input.GetAxisRaw("Vertical"))));
                        if (Input.GetButtonDown("RightButton") && !isMoving && canMove)
                        {
                            canMove = false;
                            Debug.Log("ATTACK!");
                            if (!(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab).GetComponent <WeaponHandler>().IsThrown)
                            {
                                GameObject newAttack;
                                switch (curDir)
                                {
                                case entityDirection.N:

                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position +
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetVert)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                                    {
                                        newAttack.transform.eulerAngles = new Vector3(0, 0, 90);
                                    }
                                    break;

                                case entityDirection.NE:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position +
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetVert) +
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetHorz)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                                    {
                                        newAttack.transform.eulerAngles = new Vector3(0, 0, 45);
                                    }
                                    break;

                                case entityDirection.E:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position +
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetHorz)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    break;

                                case entityDirection.SE:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position -
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetVert) +
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetHorz)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                                    {
                                        newAttack.transform.eulerAngles = new Vector3(0, 0, -45);
                                    }
                                    break;

                                case entityDirection.S:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position -
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetVert)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                                    {
                                        newAttack.transform.eulerAngles = new Vector3(0, 0, -90);
                                    }
                                    break;

                                case entityDirection.SW:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position -
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetVert) -
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetHorz)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                                    {
                                        newAttack.transform.eulerAngles = new Vector3(0, 0, -135);
                                    }
                                    break;

                                case entityDirection.W:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position -
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetHorz)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    break;

                                case entityDirection.NW:
                                    newAttack = Instantiate(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, ((Vector2)transform.position +
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetVert) -
                                                                                                                                                     (eManager.EntityArmor[7] == null ? unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz : eManager.EntityArmor[7].weaponPrefab.GetComponent <WeaponHandler>().WeaponOffsetHorz)), Quaternion.identity);
                                    newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                    if (newAttack.GetComponent <WeaponHandler>().NeedsRotate)
                                    {
                                        newAttack.transform.eulerAngles = new Vector3(0, 0, 135);
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                            else
                            {
                                eManager.ThrowItem(eManager.EntityArmor[7] == null ? unarmedAttack : eManager.EntityArmor[7].weaponPrefab, CurDirection);
                            }
                        }
                    }
                    //NPC Movement
                    else
                    {
                        if (agroObj == null && Vector2.Distance(GameObject.Find("objPlayer").transform.position, transform.position) < 1.5f || isSleeping && Vector2.Distance(GameObject.Find("objPlayer").transform.position, transform.position) < 1.5f)
                        {
                            agroObj    = GameObject.Find("objPlayer").transform;
                            isSleeping = false;
                            EndTurn();
                            return;
                        }
                        if (isSleeping)
                        {
                            EndTurn();
                            return;
                        }
                        if (agroObj != null)
                        {
                            PathRequestManager.RequestPath(transform.position, agroObj.position, OnPathFound);
                        }

                        //aDebug.Log(path.Length);
                        if (path.Length == 1 || agroObj != null && Vector2.Distance(transform.position, agroObj.position) <= attackRange && GlobalFunc.HasLineOfSight(this.gameObject, agroObj.gameObject, attackRange, GlobalFunc.entityDirectionToVector2(curDir)))
                        {
                            if (!isMoving && canMove)
                            {
                                canMove = false;
                                curDir  = GlobalFunc.GetDirection(path[0] - curPos);
                                Debug.Log("ATTACK!");
                                if (!unarmedAttack.GetComponent <WeaponHandler>().IsThrown)
                                {
                                    GameObject newAttack;

                                    switch (curDir)
                                    {
                                    case entityDirection.N:
                                        newAttack = Instantiate(unarmedAttack, ((Vector2)transform.position + unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert), Quaternion.identity);
                                        newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                        break;

                                    case entityDirection.E:
                                        newAttack = Instantiate(unarmedAttack, ((Vector2)transform.position + unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz), Quaternion.identity);
                                        newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                        break;

                                    case entityDirection.S:
                                        newAttack = Instantiate(unarmedAttack, ((Vector2)transform.position - unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetVert), Quaternion.identity);
                                        newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                        break;

                                    case entityDirection.W:
                                        newAttack = Instantiate(unarmedAttack, ((Vector2)transform.position - unarmedAttack.GetComponent <WeaponHandler>().WeaponOffsetHorz), Quaternion.identity);
                                        newAttack.GetComponent <WeaponHandler>().parentObject = this.gameObject;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                else
                                {
                                    eManager.ThrowItem(unarmedAttack, curDir);
                                }
                            }
                            return;
                        }
                        else if (path.Length != 0)
                        {
                            curDir = GlobalFunc.GetDirection(path[0] - curPos);
                            MoveTargetPos(path[0] - curPos);
                        }
                        else
                        {
                            curDir = GlobalFunc.getRandDirection();
                            MoveTargetPos(GlobalFunc.entityDirectionToVector2(curDir));
                            isMoving = true;
                        }
                    }
                }
            }
        }
    }