Пример #1
0
    public void LoadNetZone(RuntimeZone _localZone, NetZone _netZone, PlayerData _ownerPlayer)
    {
        //remove any illegal cards
        for (int i = 0; i < _localZone.cards.Count; i++)
        {
            RuntimeCard _card = _localZone.cards[i];
            if (Array.Exists(_netZone.cards, x => x.unique_cardId == _card.guid) == false)
            {
                //remove the card
                StartCoroutine(GameScene.Active.ShowPlayerMessage("Developer Warning:: The Server Reverted A Move"));
                _localZone.RemoveCard(_card.guid);
            }
        }

        //add any new cards
        for (int i = 0; i < _netZone.cards.Length; i++)
        {
            NetCard     _card      = _netZone.cards[i];
            RuntimeCard _localCard = _localZone.cards.Find(x => x.guid == _card.unique_cardId);
            if (_localCard == null)
            {
                //add the card
                _localZone.AddCard(NetworkUtilities.GetRuntimeCard(_card, _ownerPlayer));
            }
        }
    }
    public static void MoveCard(RuntimeZone _fromZone, RuntimeZone _toZone, int _unique_CardId)
    {
        RuntimeCard _card = _fromZone.cards.Find(x => x.guid == _unique_CardId);

        _fromZone.RemoveCard(_unique_CardId);
        _toZone.AddCard(_card);
    }
Пример #3
0
    private GameState CreateTestGameState()
    {
        var gameState = new GameState();

        gameState.players.Add(new PlayerInfo());
        gameState.players.Add(new PlayerInfo());
        gameState.currentPlayer   = gameState.players[0];
        gameState.currentOpponent = gameState.players[1];

        foreach (var player in gameState.players)
        {
            var life = new Stat();
            life.statId                  = 0;
            life.name                    = "Life";
            life.baseValue               = 20;
            life.originalValue           = 20;
            life.minValue                = 0;
            life.maxValue                = 99;
            player.stats[life.statId]    = life;
            player.namedStats[life.name] = life;
        }

        foreach (var player in gameState.players)
        {
            var zone = new RuntimeZone();
            zone.zoneId     = 0;
            zone.instanceId = 0;
            zone.name       = "Test zone";
            zone.maxCards   = 100;

            var life = new Stat();
            life.statId        = 0;
            life.name          = "Life";
            life.baseValue     = 2;
            life.originalValue = 2;
            life.minValue      = 0;
            life.maxValue      = 99;

            var card = new RuntimeCard();
            card.cardId                = 0;
            card.instanceId            = 0;
            card.stats[life.statId]    = life;
            card.namedStats[life.name] = life;

            zone.AddCard(card);

            player.zones[zone.zoneId]    = zone;
            player.namedZones[zone.name] = zone;
        }

        return(gameState);
    }
    public static NetZone GetNetZone(RuntimeZone _zone)
    {
        NetCard[]      _cards;
        List <NetCard> _tempCards = new List <NetCard>();

        for (int i = 0; i < _zone.cards.Count; i++)
        {
            _tempCards.Add(GetNetCard(_zone.cards[i]));
        }

        _cards = _tempCards.ToArray();


        return(new NetZone()
        {
            _zoneName = _zone.zoneName,
            cards = _cards
        });
    }
    public override void OnStartLocalPlayer()
    {
        base.OnStartLocalPlayer();

        gameUI = GameObject.Find("GameUI").GetComponent <GameUI>();
        Assert.IsNotNull(gameUI);

        foreach (var entry in playerInfo.stats)
        {
            if (entry.Value.name == "Life")
            {
                lifeStat = entry.Value;
            }
            else if (entry.Value.name == "Mana")
            {
                manaStat = entry.Value;
            }
        }
        foreach (var entry in opponentInfo.stats)
        {
            if (entry.Value.name == "Life")
            {
                opponentLifeStat = entry.Value;
            }
            else if (entry.Value.name == "Mana")
            {
                opponentManaStat = entry.Value;
            }
        }

        lifeStat.onValueChanged += (oldValue, newValue) =>
        {
            gameUI.SetPlayerHealth(lifeStat.effectiveValue);
        };
        manaStat.onValueChanged += (oldValue, newValue) =>
        {
            gameUI.SetPlayerMana(manaStat.effectiveValue);
            UpdateHandCardsHighlight();
        };

        opponentLifeStat.onValueChanged += (oldValue, newValue) =>
        {
            gameUI.SetOpponentHealth(opponentLifeStat.effectiveValue);
        };
        opponentManaStat.onValueChanged += (oldValue, newValue) =>
        {
            gameUI.SetOpponentMana(opponentManaStat.effectiveValue);
        };

        deckZone = playerInfo.namedZones["Deck"];
        deckZone.onZoneChanged += numCards =>
        {
            gameUI.SetPlayerDeckCards(numCards);
        };

        handZone = playerInfo.namedZones["Hand"];
        handZone.onZoneChanged += numCards =>
        {
            gameUI.SetPlayerHandCards(numCards);
        };
        handZone.onCardAdded += card =>
        {
            AddCardToHand(card);
            RearrangeHand();
        };
        handZone.onCardRemoved += card =>
        {
            var handCard = playerHandCards.Find(x => x.card == card);
            if (handCard != null)
            {
                playerHandCards.Remove(handCard);
                RearrangeHand();
            }
        };

        boardZone = playerInfo.namedZones["Board"];
        boardZone.onCardRemoved += card =>
        {
            var graveyardPos = GameObject.Find("GraveyardPlayer").transform.position + new Vector3(0.0f, -0.2f, 0.0f);
            var boardCard    = playerBoardCards.Find(x => x.card == card);
            if (boardCard != null)
            {
                playerGraveyardCards.Add(boardCard);
                playerBoardCards.Remove(boardCard);
                boardCard.transform.DOKill();
                boardCard.transform.DOMove(graveyardPos, 0.7f);
                boardCard.SetHighlightingEnabled(false);
                boardCard.StopSleepingParticles();
                RearrangeBottomBoard();
                boardCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards";
                boardCard.GetComponent <SortingGroup>().sortingOrder     = playerGraveyardCards.Count;
                Destroy(boardCard.GetComponent <BoxCollider2D>());
            }
            else if (currentSpellCard != null && card == currentSpellCard.card)
            {
                currentSpellCard.SetHighlightingEnabled(false);
                currentSpellCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards";
                currentSpellCard.GetComponent <SortingGroup>().sortingOrder     = playerGraveyardCards.Count;
                Destroy(currentSpellCard.GetComponent <BoxCollider2D>());
                currentSpellCard.transform.DOMove(graveyardPos, 0.5f);
                currentSpellCard.transform.DOScale(new Vector2(0.6f, 0.6f), 0.5f);
                currentSpellCard.GetComponent <HandCard>().enabled = false;
                currentSpellCard = null;
            }
        };

        graveyardZone = playerInfo.namedZones["Graveyard"];
        graveyardZone.onZoneChanged += numCards =>
        {
            gameUI.SetPlayerGraveyardCards(numCards);
        };

        opponentDeckZone = opponentInfo.namedZones["Deck"];
        opponentDeckZone.onZoneChanged += numCards =>
        {
            gameUI.SetOpponentDeckCards(numCards);
        };

        opponentHandZone = opponentInfo.namedZones["Hand"];
        opponentHandZone.onZoneChanged += numCards =>
        {
            gameUI.SetOpponentHandCards(numCards);
        };
        opponentHandZone.onCardRemoved += card =>
        {
            var randomIndex = UnityEngine.Random.Range(0, opponentHandCards.Count);
            var randomCard  = opponentHandCards[randomIndex];
            opponentHandCards.Remove(randomCard);
            Destroy(randomCard);
            RearrangeOpponentHand();
        };

        opponentBoardZone = opponentInfo.namedZones["Board"];
        opponentBoardZone.onCardRemoved += card =>
        {
            var graveyardPos = GameObject.Find("GraveyardOpponent").transform.position + new Vector3(0.0f, -0.2f, 0.0f);
            var boardCard    = opponentBoardCards.Find(x => x.card == card);
            if (boardCard != null)
            {
                opponentGraveyardCards.Add(boardCard);
                opponentBoardCards.Remove(boardCard);
                boardCard.transform.DOKill();
                boardCard.transform.DOMove(graveyardPos, 0.7f);
                boardCard.SetHighlightingEnabled(false);
                boardCard.StopSleepingParticles();
                RearrangeTopBoard();
                boardCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards";
                boardCard.GetComponent <SortingGroup>().sortingOrder     = opponentGraveyardCards.Count;
                Destroy(boardCard.GetComponent <BoxCollider2D>());
            }
            else if (currentSpellCard != null && card == currentSpellCard.card)
            {
                currentSpellCard.SetHighlightingEnabled(false);
                currentSpellCard.GetComponent <SortingGroup>().sortingLayerName = "BoardCards";
                currentSpellCard.GetComponent <SortingGroup>().sortingOrder     = opponentGraveyardCards.Count;
                Destroy(currentSpellCard.GetComponent <BoxCollider2D>());
                var sequence = DOTween.Sequence();
                sequence.PrependInterval(2.0f);
                sequence.Append(currentSpellCard.transform.DOMove(graveyardPos, 0.5f));
                sequence.Append(currentSpellCard.transform.DOScale(new Vector2(0.6f, 0.6f), 0.5f));
                sequence.OnComplete(() =>
                {
                    currentSpellCard = null;
                });
            }
        };

        opponentGraveyardZone = opponentInfo.namedZones["Graveyard"];
        opponentGraveyardZone.onZoneChanged += numCards =>
        {
            gameUI.SetOpponentGraveyardCards(numCards);
        };
    }