Пример #1
0
    private void attack(Card attacker)
    {
        Control       control       = server.control;
        BattleControl battleControl = control.getBattleControl();
        int           opponent_id   = control.getOpponentId();

        if (gameObject.tag == "enemy")
        {
            if (battleControl.canAttackPlayer(attacker) &&
                server.tryAttackPlayer(attacker.getID(), attacker.getPosition()))
            {
                battleControl.directAttack(attacker, opponent_id);
            }
        }
        else
        {
            Card target = transform.GetComponent <CardGOInstance>().card;
            if (target == null)
            {
                return;
            }

            if (battleControl.canAttackCharacter(attacker, target) == false)
            {
                return;
            }

            bool can_attack_target = server.tryAttackCharacter(attacker.getID(), target.getID(), attacker.getPosition(), target.getPosition());
            if (can_attack_target)
            {
                battleControl.cardAttackCard(attacker, target);
            }
        }
    }
Пример #2
0
    private void enemyAttack(JSONObject json)
    {
        int        target_id         = (int)json.GetField("target_id").n;
        JSONObject position          = json.GetField("attacker_position");
        Position   attacker_position = JSONReader.getPositionInstance(position);

        Card          attacker_card = control.getField().getCardByPosition(attacker_position);
        BattleControl battleControl = control.getBattleControl();

        //atacou direto
        if (target_id == -1)
        {
            battleControl.directAttack(attacker_card, control.getPlayerId());
        }
        else
        {
            JSONObject target_positionJSON = json.GetField("target_position");
            Position   target_position     = JSONReader.getPositionInstance(target_positionJSON);

            Card target_card = control.getField().getCardByPosition(target_position);
            battleControl.cardAttackCard(attacker_card, target_card);
        }
    }