Beispiel #1
0
    public void Fight(ICombatable attacker, ICombatable defender)
    {
        int damage = CalculateAttackerDamage(attacker, defender);

        attacker.OnAttack(defender);
        attacker.CurrentActionPoints -= attacker.AttackActionPointCost;
        defender.CurrentHealth       -= damage;

        if (defender.CurrentHealth <= 0)
        {
            defender.OnDeath();
        }
        else if (defender.CanRetaliate())
        {
            int dist = HexHeuristic.MinDistTile(defender.Tile, attacker.Tile);
            if (dist > defender.Range)
            {
                return;
            }

            damage = CalculateDefenderDamage(defender);
            defender.OnAttack(attacker);
            attacker.CurrentHealth -= damage;
            if (attacker.CurrentHealth <= 0)
            {
                attacker.OnDeath();
            }
        }
    }
Beispiel #2
0
        private IEnumerator Controller()
        {
            while (hasControl)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    RaycastHit unitHit;

                    Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),
                                    out unitHit, 200.0f, LayerMask.GetMask("Unit"));

                    if (unitHit.collider != null &&
                        unitHit.collider.GetComponent <Unit>().Controller.Team != unit.Controller.Team)
                    {
                        if (unit.CurrentActionPoints >= unit.AttackActionPointCost)
                        {
                            Unit other = unitHit.collider.gameObject.GetComponent <Unit>();

                            int dist = HexHeuristic.MinDistTile(unit.Tile, other.Tile);
                            if (dist <= unit.Range)
                            {
                                IFireFight fireFight = new FireFightNoRetaliation();
                                fireFight.Fight(unit, other);

                                yield return(new WaitForEndOfFrame());

                                hasControl = false;
                                UnitController.Singleton.StopAction();
                                break;
                            }
                        }
                    }
                }

                yield return(new WaitForFixedUpdate());
            }
        }