コード例 #1
0
        public virtual void OnCardMoved(CardMovedMessage msg)
        {
            var runtimeCard = CreateRuntimeCard();

            runtimeCard.cardId      = msg.card.cardId;
            runtimeCard.instanceId  = msg.card.instanceId;
            runtimeCard.ownerPlayer = playerInfo.netId == msg.playerNetId ? playerInfo : opponentInfo;
            foreach (var stat in msg.card.stats)
            {
                var runtimeStat = NetworkingUtils.GetRuntimeStat(stat);
                runtimeCard.stats[stat.statId] = runtimeStat;
                var libraryCard = GameManager.Instance.config.GetCard(msg.card.cardId);
                var statName    = libraryCard.stats.Find(x => x.statId == stat.statId).name;
                runtimeCard.namedStats[statName] = runtimeStat;
            }
            opponentInfo.zones[msg.originZoneId].RemoveCard(runtimeCard);
            opponentInfo.zones[msg.destinationZoneId].AddCard(runtimeCard);
        }
コード例 #2
0
        public void LoadPlayerStates(NetPlayerInfo playerState, NetPlayerInfo opponentState)
        {
            var players = new Dictionary <NetPlayerInfo, PlayerInfo>();

            players.Add(playerState, playerInfo);
            players.Add(opponentState, opponentInfo);
            foreach (var player in players)
            {
                player.Value.netId = player.Key.netId;

                foreach (var stat in player.Key.stats)
                {
                    var playerStat = player.Value.stats[stat.statId];
                    var oldValue   = playerStat.effectiveValue;
                    playerStat.originalValue = stat.originalValue;
                    playerStat.baseValue     = stat.baseValue;
                    playerStat.minValue      = stat.minValue;
                    playerStat.maxValue      = stat.maxValue;
                    playerStat.modifiers     = new List <Modifier>();
                    foreach (var netModifier in stat.modifiers)
                    {
                        var modifier = new Modifier(netModifier.value, netModifier.duration);
                        playerStat.modifiers.Add(modifier);
                    }
                    if (playerStat.onValueChanged != null)
                    {
                        playerStat.onValueChanged(oldValue, playerStat.effectiveValue);
                    }
                }

                foreach (var zone in player.Key.staticZones)
                {
                    // Remove obsolete entries.
                    var obsoleteCards = new List <RuntimeCard>(player.Value.zones[zone.zoneId].cards.Count);
                    foreach (var card in player.Value.zones[zone.zoneId].cards)
                    {
                        if (System.Array.FindIndex(zone.cards, x => x.instanceId == card.instanceId) == -1)
                        {
                            obsoleteCards.Add(card);
                        }
                    }
                    foreach (var card in obsoleteCards)
                    {
                        player.Value.zones[zone.zoneId].RemoveCard(card);
                    }

                    // Add new entries.
                    foreach (var card in zone.cards)
                    {
                        var runtimeCard = player.Value.zones[zone.zoneId].cards.Find(x => x.instanceId == card.instanceId);
                        if (runtimeCard == null)
                        {
                            runtimeCard             = CreateRuntimeCard();
                            runtimeCard.cardId      = card.cardId;
                            runtimeCard.instanceId  = card.instanceId;
                            runtimeCard.ownerPlayer = player.Value;
                            player.Value.zones[zone.zoneId].AddCard(runtimeCard);
                        }
                    }

                    player.Value.zones[zone.zoneId].numCards = zone.numCards;
                }

                foreach (var zone in player.Key.dynamicZones)
                {
                    // Remove obsolete entries.
                    var obsoleteCards = new List <RuntimeCard>(player.Value.zones[zone.zoneId].cards.Count);
                    foreach (var card in player.Value.zones[zone.zoneId].cards)
                    {
                        if (System.Array.FindIndex(zone.cards, x => x.instanceId == card.instanceId) == -1)
                        {
                            obsoleteCards.Add(card);
                        }
                    }
                    foreach (var card in obsoleteCards)
                    {
                        player.Value.zones[zone.zoneId].RemoveCard(card);
                    }

                    foreach (var card in zone.cards)
                    {
                        var runtimeCard = player.Value.zones[zone.zoneId].cards.Find(x => x.instanceId == card.instanceId);
                        if (runtimeCard != null)
                        {
                            foreach (var stat in card.stats)
                            {
                                runtimeCard.stats[stat.statId].originalValue = stat.originalValue;
                                runtimeCard.stats[stat.statId].baseValue     = stat.baseValue;
                                runtimeCard.stats[stat.statId].minValue      = stat.minValue;
                                runtimeCard.stats[stat.statId].maxValue      = stat.maxValue;
                                runtimeCard.stats[stat.statId].modifiers     = new List <Modifier>();
                                foreach (var netModifier in stat.modifiers)
                                {
                                    var modifier = new Modifier(netModifier.value, netModifier.duration);
                                    runtimeCard.stats[stat.statId].modifiers.Add(modifier);
                                }
                            }
                            runtimeCard.keywords.Clear();
                            foreach (var keyword in card.keywords)
                            {
                                runtimeCard.AddKeyword(keyword.keywordId, keyword.valueId);
                            }
                        }
                        else
                        {
                            runtimeCard             = CreateRuntimeCard();
                            runtimeCard.cardId      = card.cardId;
                            runtimeCard.instanceId  = card.instanceId;
                            runtimeCard.ownerPlayer = player.Value;
                            foreach (var stat in card.stats)
                            {
                                var runtimeStat = NetworkingUtils.GetRuntimeStat(stat);
                                runtimeCard.stats[stat.statId] = runtimeStat;
                                var libraryCard = GameManager.Instance.config.GetCard(card.cardId);
                                var statName    = libraryCard.stats.Find(x => x.statId == stat.statId).name;
                                runtimeCard.namedStats[statName] = runtimeStat;
                            }
                            foreach (var keyword in card.keywords)
                            {
                                runtimeCard.AddKeyword(keyword.keywordId, keyword.valueId);
                            }
                            player.Value.zones[zone.zoneId].AddCard(runtimeCard);
                            effectSolver.SetDestroyConditions(runtimeCard);
                            effectSolver.SetTriggers(runtimeCard);
                        }
                    }

                    player.Value.zones[zone.zoneId].numCards = zone.numCards;
                }
            }
        }