Beispiel #1
0
    // Run only when Mouse click on the unit
    void OnMouseDown()
    {
        // Return if AI is blocked by UI elements
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        // if unit can attack
        if (PlayerManager.Instance.GetAbleToAttack())
        {
            // If the AI is an ally, cannot attack
            if (this.Stats.Side == FACTION.ALLY)
            {
                return;
            }
            // Get information from Units class
            Players selectedUnitObject = PlayerManager.Instance.GetSelectedUnit().GetComponent <Players> ();
            for (int i = 1; i <= selectedUnitObject.GetStats()._weapon.Range; ++i)
            {
                if ((selectedUnitObject.GetCurrNode().GetXIndex() + i == currNode.GetXIndex() &&
                     selectedUnitObject.GetCurrNode().GetZIndex() == currNode.GetZIndex()) ||
                    (selectedUnitObject.GetCurrNode().GetXIndex() - i == currNode.GetXIndex() &&
                     selectedUnitObject.GetCurrNode().GetZIndex() == currNode.GetZIndex()) ||
                    (selectedUnitObject.GetCurrNode().GetZIndex() + i == currNode.GetZIndex() &&
                     selectedUnitObject.GetCurrNode().GetXIndex() == currNode.GetXIndex()) ||
                    (selectedUnitObject.GetCurrNode().GetZIndex() - i == currNode.GetZIndex() &&
                     selectedUnitObject.GetCurrNode().GetXIndex() == currNode.GetXIndex()))
                {
                    // Update Opponent Unit Info
                    selectedUnitObject.GetStats().UpdateOpponentUnitInfo(this.Stats);

                    int damageDeal = turnManager.CalculateDamage(selectedUnitObject.gameObject, this.gameObject);

                    Stats.HP -= damageDeal;
                    if (Stats.HP <= 0)
                    {
                        Destroy(this);
                    }
                    PlayerManager.Instance.SetAbleToAttack(false);
                    // End the turn of the player node
                    selectedUnitObject.TurnEnd();
                    // Change unit back to no unit
                    PlayerManager.Instance.ChangeUnit(null);

                    // De-Spawn Opponent Unit Info Window
                    selectedUnitObject.GetStats().SetOpponentUnitInfoWindow(false);

                    break;
                }
            }
        }
    }