Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (GameManagerScript.instance.getHoveredUnit () != null) {
            unit = GameManagerScript.instance.getHoveredUnit ();
            health.text = "" + unit.getHealth ();
            attack.text = "" + unit.getAttack ();
            defense.text = "" + unit.getDefense ();
            range.text = "" + unit.getRange();
            movement.text = "" + unit.getMovement ();
            if (unitName != null) {
                string unitText = unit.unitType ().ToString();
                unitText = unitText.Substring (2);
                unitName.text = unitText;
            }
            if (unitSprite != null) {
                unitSprite.sprite = unit.gameObject.GetComponent<SpriteRenderer>().sprite;
            }
        }
        else if (GameManagerScript.instance.getFocusedUnit () != null) {
            unit = GameManagerScript.instance.getFocusedUnit ();
            health.text = "" + unit.getHealth ();
            attack.text = "" + unit.getAttack ();
            defense.text = "" + unit.getDefense ();
            range.text = "" + unit.getRange();
            movement.text = "" + unit.getMovement ();
            if (unitName != null) {
                string unitText = unit.unitType ().ToString();
                unitText = unitText.Substring (2);
                unitName.text = unitText;
            }
            if (unitSprite != null) {
                unitSprite.sprite = unit.gameObject.GetComponent<SpriteRenderer>().sprite;
            }
        }

        currency.text = "" + GameManagerScript.instance.getPlayer().getCurrency();
        deckCount.text = "" + GameManagerScript.instance.getDeckCount ();
        discardCount.text = "" + GameManagerScript.instance.getDiscardCount ();
    }
Beispiel #2
0
    // Attacks another unit. This is currently extremely primitive.
    public void attack(UnitScript unit)
    {
        if (!paused) {
            if (focusedUnit != null && focusedUnit.getAttack() > 0 && focusedUnit.getState() < 2) {//!focusedUnit.hasAttacked) {
                bool inRange = false;
                List<HexScript> focMapRow = Map.map [(int)focusedUnit.getPosition ().x];
                HexScript focHex = focMapRow [(int)focusedUnit.getPosition ().y];

                List<HexScript> curMapRow = Map.map [(int)(unit.getPosition ().x)];
                HexScript curHex = curMapRow [(int)unit.getPosition ().y];

                HashSet<HexScript> tempRange = findAdj(curHex);
                HashSet<HexScript> totalRange = new HashSet<HexScript>();
                int range = focusedUnit.getRange();
                //Debug.Log("attack " + range);
                if (range != 1)
                {
                    attackRange(range - 1, tempRange, totalRange);
                }
                else
                {
                    totalRange = findAdj(curHex);
                }
                foreach (HexScript hex in totalRange)
                {
                    if (hex == focHex)
                    {
                        inRange = true;
                    }
                }

                if (inRange) {
                    //Debug.Log (focusedUnit.getPosition () + " attacked " + unit.getPosition ());

                    int h = unit.getHealth ();
                    focusedUnit.attackEnemy ();
                    // Reduces the attacked units health by the attacking units attack
                    // dmg = 2 (P / A ) - 2 ( A / P ) + 3P - 2A + 38
                    var dmg = 2 * ( (float)focusedUnit.getAttack() / unit.getDefense() ) - 2 * ( (float)unit.getDefense() / focusedUnit.getAttack() ) +
                              3 * focusedUnit.getAttack() - 2 * unit.getDefense() + 38;
                    // damage randomness
                    dmg *= ( 100 + UnityEngine.Random.Range(-8, 8) ) / 100.0f;
                    unit.setHealth(h - (int)dmg);
                    //unit.setHealth ((int)(unit.getHealth () - (focusedUnit.getAttack () * (1 - unit.getDefense () / 100))));

                    focusedUnit.setState(2);
                    /*Debug.Log ("Attack: " + focusedUnit.getAttack () +
                        "\nDefense: " + unit.getDefense () +
                        "\nPrevious health: " + h +
                        "\nResulting health lost: " + (focusedUnit.getAttack () * (1 - unit.getDefense () / 100)));*/

                    // If the unit is out of health, destroy it
                    if (unit.getHealth () <= 0) {
                        unit.destroyUnit ();
                        units.Remove (unit);
                        Map.hex_of(unit).setOccupied(0);
                        Destroy (unit);
                    }

                    focusedUnit = null;
                }
            } else {
                //Debug.Log ("No unit currently focused...");
            }
            if (p1Base.getHealth () <= 0 || p2Base.getHealth () <= 0) {
                Invoke ("endGame", 2.0f);
            }

            updateHexes();
        }
    }