Ejemplo n.º 1
0
    // Update is called once per frame
    private void Update()
    {
        //if it is this character's turn, they have not attack, they have a target and the 1 key is pressed
        if (turnIsActive && target != null && !hasAttacked && Input.GetKeyDown(KeyCode.Alpha1))
        {
            if (!character.GetAbilities()[0].GetLineOfSight() || pathGrid.checkLineOfSight(transform.position, target.transform.position, character.GetAbilities()[0].GetRange()))
            {
                //attack with ability 1
                character.UseAbility(character.GetAbilities()[0], pathGrid.GetCoverValue(transform.position, target.transform.position), new CharacterTargetInfo(character, target.character));
                hasAttacked = true;
            }
            else
            {
                Debug.Log("No LoS");
            }
        }
        else if (turnIsActive && target != null && !hasAttacked && Input.GetKeyDown(KeyCode.Alpha2))
        {
            if (!character.GetAbilities()[1].GetLineOfSight() || pathGrid.checkLineOfSight(transform.position, target.transform.position, character.GetAbilities()[1].GetRange()))
            {
                //if the 2 key is pressed attack with ability two
                character.UseAbility(character.GetAbilities()[1], pathGrid.GetCoverValue(transform.position, target.transform.position), new CharacterTargetInfo(character, target.character));
                hasAttacked = true;
            }
            else
            {
                Debug.Log("No LoS");
            }
        }
        //else if (turnIsActive && target != null && !hasAttacked && Input.GetKeyDown(KeyCode.Alpha3))
        //{
        //    //if the 3 key is pressed attack with ability three
        //    character.UseAbility(character.abilities[2], new CharacterTargetInfo(character, target.character));
        //    hasAttacked = true;
        //}
        //if the character has not mvoed yet and the right mouse buttonis clicked, move
        else if (turnIsActive && !hasMoved && Input.GetMouseButtonDown(1) && !isMoving)
        {
            StartCoroutine(MoveToPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition)));
        }

        //if the character is slain, destroy this object
        if (character.GetAttribute(CharacterAttributes.Health) <= 0)
        {
            //remove turn from the turn list
            GameObject.Find("TurnManager").GetComponent <TurnManager>().RemoveTurn(this);
            //unobstruct the pathing node at the current position
            pathGrid.WorldToNode(transform.position).isMoveObstructed = false;
            //destroy self
            GameObject.Destroy(this.gameObject);
        }
    }