Esempio n. 1
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;
                }
            }
        }
Esempio n. 2
0
        protected virtual NetPlayerInfo GetOpponentNetworkState(PlayerInfo player)
        {
            var netOpponent = new NetPlayerInfo();

            netOpponent.id    = player.id;
            netOpponent.netId = player.netId;

            // Copy player stats.
            var stats = new NetStat[player.stats.Count];
            var idx   = 0;

            foreach (var entry in player.stats)
            {
                var stat = entry.Value;
                stats[idx++] = NetworkingUtils.GetNetStat(stat);
            }
            netOpponent.stats = stats;

            // Copy player zones.
            var gameConfig   = GameManager.Instance.config;
            var staticZones  = new List <NetStaticZone>();
            var dynamicZones = new List <NetDynamicZone>();

            foreach (var zonePair in player.zones)
            {
                var zone           = zonePair.Value;
                var zoneDefinition = gameConfig.gameZones.Find(x => x.id == zone.zoneId);
                if (zoneDefinition.type == ZoneType.Static)
                {
                    var staticZone = new NetStaticZone();
                    staticZone.zoneId = zone.zoneId;
                    if (zoneDefinition.opponentVisibility == ZoneOpponentVisibility.Visible)
                    {
                        staticZone.cards = new NetStaticCard[zone.cards.Count];
                        var i = 0;
                        foreach (var card in zone.cards)
                        {
                            var netCard = new NetStaticCard();
                            netCard.cardId        = card.cardId;
                            netCard.instanceId    = card.instanceId;
                            staticZone.cards[i++] = netCard;
                        }
                    }
                    staticZone.numCards = zone.cards.Count;
                    staticZones.Add(staticZone);
                }
                else if (zoneDefinition.type == ZoneType.Dynamic)
                {
                    var dynamicZone = new NetDynamicZone();
                    dynamicZone.zoneId = zone.zoneId;
                    if (zoneDefinition.opponentVisibility == ZoneOpponentVisibility.Visible)
                    {
                        dynamicZone.cards = new NetCard[zone.cards.Count];
                        for (var j = 0; j < zone.cards.Count; j++)
                        {
                            var card    = zone.cards[j];
                            var netCard = new NetCard();
                            netCard.cardId     = card.cardId;
                            netCard.instanceId = card.instanceId;
                            netCard.stats      = new NetStat[card.stats.Count];
                            idx = 0;
                            foreach (var entry in card.stats)
                            {
                                netCard.stats[idx++] = NetworkingUtils.GetNetStat(entry.Value);
                            }
                            netCard.keywords = new NetKeyword[card.keywords.Count];
                            idx = 0;
                            foreach (var entry in card.keywords)
                            {
                                netCard.keywords[idx++] = NetworkingUtils.GetNetKeyword(entry);
                            }
                            dynamicZone.cards[j] = netCard;
                        }
                    }
                    dynamicZone.numCards = zone.cards.Count;
                    dynamicZones.Add(dynamicZone);
                }
            }
            netOpponent.staticZones  = staticZones.ToArray();
            netOpponent.dynamicZones = dynamicZones.ToArray();

            return(netOpponent);
        }