public static Stat GetRuntimeStat(NetStat netStat)
        {
            var stat = new Stat();

            stat.statId        = netStat.statId;
            stat.originalValue = netStat.originalValue;
            stat.baseValue     = netStat.baseValue;
            stat.minValue      = netStat.minValue;
            stat.maxValue      = netStat.maxValue;
            stat.modifiers     = new List <Modifier>();
            foreach (var netModifier in netStat.modifiers)
            {
                var modifier = new Modifier(netModifier.value, netModifier.duration);
                stat.modifiers.Add(modifier);
            }
            return(stat);
        }
        public static NetStat GetNetStat(Stat stat)
        {
            var netStat = new NetStat();

            netStat.statId        = stat.statId;
            netStat.originalValue = stat.originalValue;
            netStat.baseValue     = stat.baseValue;
            netStat.minValue      = stat.minValue;
            netStat.maxValue      = stat.maxValue;
            var modifiers = new NetModifier[stat.modifiers.Count];

            for (var i = 0; i < stat.modifiers.Count; i++)
            {
                var netModifier = new NetModifier();
                netModifier.value    = stat.modifiers[i].value;
                netModifier.duration = stat.modifiers[i].duration;
                modifiers[i]         = netModifier;
            }
            netStat.modifiers = modifiers;
            return(netStat);
        }
Beispiel #3
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);
        }