コード例 #1
0
        public void Attack(AsyncUserToken userToken, int?attackingUnit, int targetPlayer, int?targetUnit)
        {
            var identity    = (ServerSideTokenIdentity)userToken.info;
            var gameWrapper = identity.GameWrapper;

            if (gameWrapper == null || identity.MatchmakingStatus != UserMatchmakingStatus.GAME)
            {
                throw new LogicExecutionException("Korisnik nije u igri");
            }
            lock (gameWrapper.@lock)
            {
                var game = gameWrapper.Game;
                if (gameWrapper.Tokens[game.IndexOfPlayerWhoPlayTheTurn] != userToken)
                {
                    throw new LogicExecutionException("Igrač nije na potezu");
                }
                if (attackingUnit == null)
                {
                    throw new LogicExecutionException("Data opcija jos nije podrzana");
                }

                int attackerRemainingHealth, targetRemainingHealth;
                if (targetUnit == null)
                {
                    executionEngine.AttackPlayer(game, game.IndexOfPlayerWhoPlayTheTurn, (int)attackingUnit, targetPlayer,
                                                 out attackerRemainingHealth, out targetRemainingHealth);
                }
                else
                {
                    executionEngine.AttackCard(game, game.IndexOfPlayerWhoPlayTheTurn, (int)attackingUnit, targetPlayer, (int)targetUnit,
                                               out attackerRemainingHealth, out targetRemainingHealth);
                }

                AttackNotification attackNotification = new AttackNotification
                {
                    AttackingPlayer         = game.IndexOfPlayerWhoPlayTheTurn,
                    AttackingUnit           = attackingUnit,
                    TargetPlayer            = targetPlayer,
                    TargetUnit              = targetUnit,
                    AttackerRemainingHealth = attackerRemainingHealth,
                    TargetRemainingHealth   = targetRemainingHealth
                };

                foreach (var token in gameWrapper.Tokens)
                {
                    Config.GameServer.Send(token, attackNotification);
                }

                CheckIfPlayerDied(gameWrapper);
            }
        }
コード例 #2
0
    private void HandleAttackNotification(AttackNotification attackNotification)
    {
        int attackingPlayer = attackNotification.AttackingPlayer;
        int targetPlayer    = attackNotification.TargetPlayer;

        var attackedPlayerControllers = playersControllers[targetPlayer];

        if (attackNotification.TargetUnit == null)
        {
            attackedPlayerControllers.dataController.Health = attackNotification.TargetRemainingHealth;
        }
        else
        {
            int targetUnit = (int)attackNotification.TargetUnit;

            CardController cardController = attackedPlayerControllers.boardSideController.GetCardsController(targetUnit);

            cardController.Health = attackNotification.TargetRemainingHealth;

            if (cardController.Health <= 0)
            {
                attackedPlayerControllers.boardSideController.RemoveCard(targetUnit);
            }
        }

        if (attackNotification.AttackingUnit == null)
        {
            throw new InvalidOperationException("Opcija da igrac napada jos nije podrzana");
        }

        int            attackingUnit = (int)attackNotification.AttackingUnit;
        var            attackerBoardSideController = playersControllers[attackingPlayer].boardSideController;
        CardController attackingCardController     = attackerBoardSideController.GetCardsController(attackingUnit);

        attackingCardController.Health = attackNotification.AttackerRemainingHealth;

        attackingCardController.LastAttackingTurn = AcccumulativeTurn;

        if (attackingCardController.Health <= 0)
        {
            attackerBoardSideController.RemoveCard(attackingUnit);
        }

        Debug.Log("Attack Notification: \n" +
                  $"Attacker: {attackNotification.AttackingPlayer} ({attackNotification.AttackingUnit}) - remaining HP {attackNotification.AttackerRemainingHealth}\n" +
                  $"Attacker: {attackNotification.TargetPlayer} ({attackNotification.TargetUnit}) - remaining HP {attackNotification.TargetRemainingHealth}");

        UpdateHighlightedCards();
    }