Пример #1
0
 /// <summary>
 /// Removes given unit from dictionary
 /// </summary>
 /// <param name="unit"></param>
 public void RemoveUnit(Unit unit)
 {
     _units[unit.OwnerColor].Remove(unit.Id);
 }
Пример #2
0
        /// <summary>
        /// Builds forts at the start of the game
        /// </summary>
        /// <param name="userId"></param>
        public void BuildStartingStructures(string userId)
        {
            if (MatchCommunicationManager.Instance.IsHost == false)
            {
                Debug.Log("Only host can spawn starting structures.");
                return;
            }

            Card fortCard = new Card()
            {
                cardType = CardType.Fort,
                level    = 1
            };
            Card mainFortCard = new Card()
            {
                cardType = CardType.MainFort,
                level    = 1
            };

            if (userId == MatchCommunicationManager.Instance.HostId)
            {
                MatchMessageUnitSpawned fortTop = new MatchMessageUnitSpawned(
                    userId, PlayerColor.Black, _nextId++, fortCard, 4, 10);
                MatchMessageUnitSpawned fortBot = new MatchMessageUnitSpawned(
                    userId, PlayerColor.Black, _nextId++, fortCard, 4, 2);
                MatchMessageUnitSpawned fortMain = new MatchMessageUnitSpawned(
                    userId, PlayerColor.Black, _nextId++, mainFortCard, 2, 6);

                MatchCommunicationManager.Instance.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortTop);
                MatchCommunicationManager.Instance.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortBot);
                MatchCommunicationManager.Instance.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortMain);
                MatchCommunicationManager.Instance.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortTop);
                MatchCommunicationManager.Instance.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortBot);
                MatchCommunicationManager.Instance.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortMain);

                Unit tower2 = _units[PlayerColor.Black][_nextId - 3];
                Unit tower1 = _units[PlayerColor.Black][_nextId - 2];
                Unit castle = _units[PlayerColor.Black][_nextId - 1];
                GameManager.Instance.SetTowers(PlayerColor.Black, castle, tower1, tower2);
            }
            else
            {
                MatchMessageUnitSpawned fortTop = new MatchMessageUnitSpawned(
                    userId, PlayerColor.Red, _nextId++, fortCard, 10, 10);
                MatchMessageUnitSpawned fortBot = new MatchMessageUnitSpawned(
                    userId, PlayerColor.Red, _nextId++, fortCard, 10, 2);
                MatchMessageUnitSpawned fortMain = new MatchMessageUnitSpawned(
                    userId, PlayerColor.Red, _nextId++, mainFortCard, 12, 6);

                MatchCommunicationManager.Instance.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortTop);
                MatchCommunicationManager.Instance.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortBot);
                MatchCommunicationManager.Instance.SendMatchStateMessage(MatchMessageType.UnitSpawned, fortMain);
                MatchCommunicationManager.Instance.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortTop);
                MatchCommunicationManager.Instance.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortBot);
                MatchCommunicationManager.Instance.SendMatchStateMessageSelf(MatchMessageType.UnitSpawned, fortMain);

                Unit tower2 = _units[PlayerColor.Red][_nextId - 3];
                Unit tower1 = _units[PlayerColor.Red][_nextId - 2];
                Unit castle = _units[PlayerColor.Red][_nextId - 1];
                GameManager.Instance.SetTowers(PlayerColor.Red, castle, tower1, tower2);
            }
        }