Beispiel #1
0
        /// <summary>
        /// Sends move request to other players and self.
        /// Use only on host!
        /// </summary>
        /// <param name="node"></param>
        protected virtual void SendMoveRequest(Node node)
        {
            MatchMessageUnitMoved message = new MatchMessageUnitMoved(node.Position.x, node.Position.y, _unit.Id, _unit.OwnerId);

            _stateManager.SendMatchStateMessage(MatchMessageType.UnitMoved, message);
            _stateManager.SendMatchStateMessageSelf(MatchMessageType.UnitMoved, message);
        }
        /// <summary>
        /// Selects a number of cards equal to <see cref="Hand._cardIdsInHand"/> from players deck
        /// and sends them to that player.
        /// </summary>
        private void SendStartingHand(string userId)
        {
            Hand        hand  = userId == _connection.BattleConnection.HostId ? _localHand : _opponentHand;
            List <Card> cards = hand.DrawInitialCards();
            MatchMessageStartingHand message = new MatchMessageStartingHand(userId, cards);

            if (userId == _connection.BattleConnection.HostId)
            {
                _stateManager.SendMatchStateMessageSelf(MatchMessageType.StartingHand, message);
            }
            else
            {
                _stateManager.SendMatchStateMessage(MatchMessageType.StartingHand, message);
                _opponentGold.Restart();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sends information about fireball activation to other players through Nakama server.
        /// Use only on host!
        /// </summary>
        /// <param name="node"></param>
        /// <param name="impactedUnits"></param>
        /// <param name="playerId"></param>
        private void SendSpellActivatedRequest(Node node, List <Unit> impactedUnits, string playerId)
        {
            List <int> impactedUnitsIds        = impactedUnits.Select(u => u.Id).ToList();
            MatchMessageSpellActivated message = new MatchMessageSpellActivated(playerId, SpellType, node.Position.x, node.Position.y, impactedUnitsIds);

            _stateManager.SendMatchStateMessage(MatchMessageType.SpellActivated, message);
            _stateManager.SendMatchStateMessageSelf(MatchMessageType.SpellActivated, message);
        }
        /// <summary>
        /// Builds forts at the start of the game.
        /// </summary>
        /// <param name="userId"></param>
        public void BuildStartingStructures(string userId)
        {
            bool isHost = userId == _connection.BattleConnection.HostId;

            CardData fortCard = new CardData()
            {
                type  = CardType.Fort,
                level = 1
            };

            CardData mainFortCard = new CardData()
            {
                type  = CardType.MainFort,
                level = 1
            };

            int fortX     = isHost ? 4 : 10;
            int mainFortX = isHost ? 2 : 12;

            var playerColor = isHost ? PlayerColor.Black : PlayerColor.Red;

            MatchMessageUnitSpawned fortTop = new MatchMessageUnitSpawned(
                userId, playerColor, _nextId++, fortCard, fortX, 10);
            MatchMessageUnitSpawned fortBot = new MatchMessageUnitSpawned(
                userId, playerColor, _nextId++, fortCard, fortX, 2);
            MatchMessageUnitSpawned fortMain = new MatchMessageUnitSpawned(
                userId, playerColor, _nextId++, mainFortCard, mainFortX, 6);

            _stateManager.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortTop);
            _stateManager.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortBot);
            _stateManager.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortMain);

            _stateManager.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortTop);
            _stateManager.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortBot);
            _stateManager.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortMain);

            Unit tower2 = _units[playerColor][_nextId - 3];
            Unit tower1 = _units[playerColor][_nextId - 2];
            Unit castle = _units[playerColor][_nextId - 1];
        }