Exemplo n.º 1
0
    /// <summary>
    /// Notify this controller than the current unit has finished its current attack order.
    /// </summary>
    protected override void UnitDoneAttacking(UnitAttackResponse response)
    {
        string debugString =
            string.Format ("{0} received a report that {1} finished attacking.", this.name, currentUnit.name);
        Debug.Log(debugString);

        if (response.validAttack) {
            hasAlreadyAttacked = true;
        } else {
            // TODO Report to user that the attack was illegal
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Called when the unit has finished its attack.
 /// </summary>
 public void DoneAttacking(UnitAttackResponse response)
 {
     if (currentState == State.Attacking) {
         string LogMsg = "{0} is done attacking.";
         Debug.Log (string.Format(LogMsg, this.name));
         currentState = State.WaitingOrders;
         response.caller.SendMessage("UnitDoneAttacking", response, SendMessageOptions.RequireReceiver);
         playerController.SendMessage("ChangeGUIState", "StartTurn");
         BroadcastMessage("HideAttackRadius", SendMessageOptions.RequireReceiver);
     } else {
         string LogMsg = "DoneAttacking unexpectedly called on {0} while it is in state \"{1}\"";
         Debug.LogWarning(string.Format(LogMsg, this.name, currentState.ToString()));
     }
 }
Exemplo n.º 3
0
    public void ExecuteAttack(UnitAttackRequest request)
    {
        attackRequest = request;
        if (request.target.GetComponent<UnitInfo>() == null) {
            BroadcastMessage("DoneAttacking", NotAUnitResponse(), SendMessageOptions.RequireReceiver);
        } else if (request.target.GetComponent<UnitInfo>().controller
            == gameObject.GetComponent<UnitInfo>().controller) {

            string debugString = string.Format
                    ("Attack target is on the same team as attacker!");
            Debug.Log(debugString);
            BroadcastMessage("DoneAttacking", TeammateResponse(), SendMessageOptions.RequireReceiver);

        } else if (!withinRange(request.target)) {
            string debugString = string.Format
                    ("Attack target was distance {0}, but unit's max attack range is {1}",
                        (this.transform.position - request.target.transform.position).magnitude,
                        unitInfo.CalculateAttackRange());
            Debug.Log(debugString);
            BroadcastMessage("DoneAttacking", OutOfRangeResponse(), SendMessageOptions.RequireReceiver);
        } else {
            transform.LookAt(
                new Vector3(
                attackRequest.target.transform.position.x,
                transform.position.y,
                attackRequest.target.transform.position.z));

            animation.Play("Attack");

            float damage = unitInfo.attackDamage;

            damage += Random.Range(-damage / 2, damage / 2);

            attackRequest.target.BroadcastMessage("TakeDamage", damage, SendMessageOptions.RequireReceiver);

            UnitAttackResponse response = new UnitAttackResponse(request.caller, false, damage);
            BroadcastMessage("DoneAttacking", response);
        }
    }
Exemplo n.º 4
0
 /// <summary>
 /// Notify this controller than the current unit has finished its current attack order.
 /// </summary>
 protected abstract void UnitDoneAttacking(UnitAttackResponse response);