public static NetCard GetNetCard(RuntimeCard card) { var netCard = new NetCard(); netCard.cardId = card.cardId; netCard.instanceId = card.instanceId; var netStats = new List <NetStat>(card.stats.Count); foreach (var stat in card.stats) { netStats.Add(GetNetStat(stat.Value)); } netCard.stats = netStats.ToArray(); var netKeywords = new List <NetKeyword>(card.keywords.Count); foreach (var keyword in card.keywords) { netKeywords.Add(GetNetKeyword(keyword)); } netCard.keywords = netKeywords.ToArray(); return(netCard); }
public static RuntimeCard GetRuntimeCard(NetCard netCard) { var runtimeCard = new RuntimeCard(); runtimeCard.cardId = netCard.cardId; runtimeCard.instanceId = netCard.instanceId; foreach (var stat in netCard.stats) { var runtimeStat = GetRuntimeStat(stat); runtimeCard.stats[stat.statId] = runtimeStat; var libraryCard = GameManager.Instance.config.GetCard(netCard.cardId); var statName = libraryCard.stats.Find(x => x.statId == stat.statId).name; runtimeCard.namedStats[statName] = runtimeStat; } var keywords = new List <RuntimeKeyword>(); foreach (var keyword in netCard.keywords) { keywords.Add(GetRuntimeKeyword(keyword)); } runtimeCard.keywords = keywords; return(runtimeCard); }
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); }