Esempio n. 1
0
        public void Run()
        {
            GameDataLists gameDataLists = new GameDataLists();

            gameDataLists.Load(@"..\..\..\datasource\export\exd-all\");

            bool result = true;

            result = result && ValidateCardIds(gameDataLists);
            result = result && ValidateNpcIds(gameDataLists);
            result = result && gameDataLists.Link();
            if (result)
            {
                var mapRuleByCodeName     = BuildRuleNameMap();
                var mapCardTypeByCodeName = BuildCardTypes();

                result = result && ExportRuleNames(gameDataLists.rules, mapRuleByCodeName);
                result = result && ExportCardTypes(gameDataLists.cardTypes, mapCardTypeByCodeName);
                result = result && UpdateCards(gameDataLists, mapCardTypeByCodeName);
                result = result && UpdateNpcs(gameDataLists, mapRuleByCodeName);
                result = result && UpdateTournaments(gameDataLists, mapRuleByCodeName);
            }

            if (result)
            {
                LocalizationDB.Get().Save();
                TriadCardDB.Get().Save();
                TriadNpcDB.Get().Save();
                TriadTournamentDB.Get().Save();
            }

            Logger.WriteLine(result ? "Done." : "Aborted");
        }
Esempio n. 2
0
        private bool ValidateNpcIds(GameDataLists gameDataLists)
        {
            foreach (var npcData in gameDataLists.npcs)
            {
                if (npcData.locCards.Count > 0)
                {
                    foreach (var kvp in npcData.locCards)
                    {
                        bool isMatch = npcData.HasMatchingCards(kvp.Value);
                        if (!isMatch)
                        {
                            Logger.WriteLine("FAILED to validate npc - Id:{0} [{1}] + [{2}] vs {3}:[{4}]",
                                             npcData.Id, string.Join(", ", npcData.CardsFixed), string.Join(", ", npcData.CardsVariable),
                                             kvp.Key, string.Join(", ", kvp.Value));

                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 3
0
        private bool ValidateCardIds(GameDataLists gameDataLists)
        {
            foreach (var cardData in gameDataLists.cards)
            {
                if (cardData.locSides.Count > 0)
                {
                    foreach (var kvp in cardData.locSides)
                    {
                        bool isMatch = cardData.HasMatchingLocSide(kvp.Value);
                        if (!isMatch)
                        {
                            Logger.WriteLine("FAILED to validate card - Id:{0} [{1}, {2}, {3}, {4}] vs {5}:[{6}, {7}, {8}, {9}]",
                                             cardData.Id, cardData.sideTop, cardData.sideLeft, cardData.sideBottom, cardData.sideRight,
                                             kvp.Key, kvp.Value[0], kvp.Value[1], kvp.Value[2], kvp.Value[3]);

                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 4
0
        private bool UpdateTournaments(GameDataLists gameDataLists, Dictionary <string, TriadGameModifier> mapRuleNames)
        {
            Logger.WriteLine("Updating tournament list...");

            // TODO: not sure how to find it in .csv data,
            // hardcode entries + rules for now
            // alert new new unique entry appears

            var uniqueTournamentNames    = new List <string>();
            var uniqueTournamentLocNames = new List <LocString>();

            foreach (var tourData in gameDataLists.tournamentNames)
            {
                var codeName = tourData.Name.GetCodeName();
                if (!string.IsNullOrEmpty(codeName))
                {
                    if (!uniqueTournamentNames.Contains(codeName))
                    {
                        uniqueTournamentNames.Add(codeName);
                        uniqueTournamentLocNames.Add(tourData.Name);
                    }
                }
            }

            string[] hardcodedNames = { "the Manderville Tournament of Champions", "the Spinner's Pull", "the Durai Memorial", "the Rowena Cup Classic" };
            string[] hardcodedRules =
            {
                "All Open",   "Plus",
                "Three Open", "Swap",
                "Order",      "Same",
                "Roulette",   "Roulette",
            };

            if (uniqueTournamentNames.Count != hardcodedNames.Length)
            {
                Logger.WriteLine("FAILED tournament update, hardcoded list diff! [{0}]", string.Join(", ", uniqueTournamentNames));
                return(false);
            }

            TriadTournamentDB tournamentDB = TriadTournamentDB.Get();

            for (int idx = 0; idx < uniqueTournamentNames.Count; idx++)
            {
                if (uniqueTournamentNames[idx] != hardcodedNames[idx])
                {
                    Logger.WriteLine("FAILED tournament update, id:{0} mismatch!", idx);
                    return(false);
                }

                TriadTournament tourOb = (idx < tournamentDB.tournaments.Count) ? tournamentDB.tournaments[idx] : null;
                if (tourOb == null)
                {
                    while (tournamentDB.tournaments.Count <= idx)
                    {
                        tournamentDB.tournaments.Add(new TriadTournament(idx, new List <TriadGameModifier>()));
                    }

                    tourOb = tournamentDB.tournaments[idx];
                }

                tourOb.Name.Text = uniqueTournamentLocNames[idx].Text;

                tourOb.Rules.Clear();
                int ruleStartIdx = idx * 2;
                for (int ruleIdx = 0; ruleIdx < 2; ruleIdx++)
                {
                    tourOb.Rules.Add(mapRuleNames[hardcodedRules[ruleIdx + ruleStartIdx]]);
                }
            }

            return(true);
        }
Esempio n. 5
0
        private bool UpdateNpcs(GameDataLists gameDataLists, Dictionary <string, TriadGameModifier> mapRuleNames)
        {
            Logger.WriteLine("Updating npc list...");

            TriadCardDB cardDB       = TriadCardDB.Get();
            TriadNpcDB  npcDB        = TriadNpcDB.Get();
            var         validDeckIds = new List <string>();

            foreach (var npcData in gameDataLists.npcs)
            {
                if (npcData.LinkedNpcId == null)
                {
                    continue;
                }

                if (npcData.LinkedNpcId.LinkedName == null || npcData.LinkedNpcId.LinkedLocation == null)
                {
                    continue;
                }

                TriadDeck npcDataDeck = new TriadDeck();
                foreach (var cardData in npcData.LinkedCardsFixed)
                {
                    npcDataDeck.knownCards.Add(cardDB.cards[cardData.Id]);
                }
                foreach (var cardData in npcData.LinkedCardsVariable)
                {
                    npcDataDeck.unknownCardPool.Add(cardDB.cards[cardData.Id]);
                }
                npcDataDeck.UpdateDeckId();
                validDeckIds.Add(npcDataDeck.deckId);

                // mistakes were made...
                TriadNpc npcOb = npcDB.FindByDeckId(npcDataDeck.deckId);
                int      npcId = (npcOb == null) ? npcDB.npcs.Count : npcOb.Id;

                if (npcOb != null)
                {
                    // ensure decks are the same
                    if (!npcOb.Deck.Equals(npcDataDeck))
                    {
                        Logger.WriteLine("FAILED npc update, id:{0} name:{1} is not matching cards!", npcId, npcData.LinkedNpcId.LinkedName.Name.GetCodeName());
                        return(false);
                    }
                }
                else
                {
                    while (npcDB.npcs.Count <= npcId)
                    {
                        npcDB.npcs.Add(null);
                    }

                    var listMods = new List <TriadGameModifier>();
                    foreach (var ruleData in npcData.LinkedRules)
                    {
                        listMods.Add(mapRuleNames[ruleData.Name.GetCodeName()]);
                    }

                    var listRewards = new List <TriadCard>();
                    foreach (var rewardData in npcData.LinkedRewards)
                    {
                        listRewards.Add(cardDB.cards[rewardData.LinkedCard.Id]);
                    }

                    npcOb = new TriadNpc(npcId, listMods, listRewards, npcDataDeck);

                    Logger.WriteLine(">> adding new npc: " + npcOb.ToString());
                    npcDB.npcs[npcId] = npcOb;
                }

                var linkedLoc = npcData.LinkedNpcId.LinkedLocation;
                linkedLoc.LinkedMap.GetCoords(linkedLoc.ScaledPosX, linkedLoc.ScaledPosZ, out npcOb.LocationX, out npcOb.LocationY);

                npcOb.Name.Text        = npcData.LinkedNpcId.LinkedName.Name.Text;
                npcOb.LocationMap.Text = npcData.LinkedNpcId.LinkedLocation.LinkedMap.LinkedPlace.Name.Text;
            }

            for (int idx = 0; idx < npcDB.npcs.Count; idx++)
            {
                TriadNpc npcOb = npcDB.npcs[idx];
                if (npcOb != null)
                {
                    if (!validDeckIds.Contains(npcOb.Deck.deckId))
                    {
                        Logger.WriteLine(">> removing npc: " + npcOb.ToString() + ", deck:" + npcOb.Deck.ToString());
                        npcDB.npcs[idx] = null;
                        continue;
                    }

                    if (npcOb.Id != idx)
                    {
                        Logger.WriteLine("FAILED npc update, index mismatch for npc[{0}].Id:{1}, Name:{2}", idx, npcOb.Id, npcOb.Name.GetCodeName());
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 6
0
        private bool UpdateCards(GameDataLists gameDataLists, Dictionary <string, ETriadCardType> mapCardTypes)
        {
            Logger.WriteLine("Updating card list...");

            TriadCardDB cardDB = TriadCardDB.Get();

            foreach (var cardData in gameDataLists.cards)
            {
                TriadCard cardOb = (cardData.Id < cardDB.cards.Count) ? cardDB.cards[cardData.Id] : null;
                if (cardOb != null)
                {
                    // ensure side numbers are the same
                    if (cardOb.Sides[0] != cardData.sideTop ||
                        cardOb.Sides[1] != cardData.sideLeft ||
                        cardOb.Sides[2] != cardData.sideBottom ||
                        cardOb.Sides[3] != cardData.sideRight)
                    {
                        Logger.WriteLine("FAILED card update, id:{0} name:{1} is not matching side numbers!", cardData.Id, cardData.LinkedName.Name.GetCodeName());
                        return(false);
                    }
                }
                else
                {
                    while (cardDB.cards.Count <= cardData.Id)
                    {
                        cardDB.cards.Add(null);
                    }

                    int    iconId   = 82500 + cardData.Id;
                    string iconPath = iconId.ToString("000000") + ".png";

                    cardOb = new TriadCard(cardData.Id,
                                           iconPath,
                                           (ETriadCardRarity)(cardData.rarityIdx - 1),
                                           mapCardTypes[cardData.LinkedType == null ? "" : cardData.LinkedType.Type.GetCodeName()],
                                           cardData.sideTop,
                                           cardData.sideBottom,
                                           cardData.sideLeft,
                                           cardData.sideRight,
                                           cardData.sortOrder,
                                           cardData.uiGroup);

                    Logger.WriteLine(">> adding new card: " + cardOb.ToString());
                    cardDB.cards[cardData.Id] = cardOb;
                }

                cardOb.Name.Text = cardData.LinkedName.Name.Text;
            }

            for (int idx = 0; idx < cardDB.cards.Count; idx++)
            {
                TriadCard cardOb = cardDB.cards[idx];
                if (cardOb != null)
                {
                    var matchingCardData = gameDataLists.cards.Find(x => (x.Id == cardOb.Id));
                    if (matchingCardData == null)
                    {
                        Logger.WriteLine(">> removing card: " + cardOb.ToString());
                        cardDB.cards[idx] = null;
                        continue;
                    }

                    if (cardOb.Id != idx)
                    {
                        Logger.WriteLine("FAILED card update, index mismatch for card[{0}].Id:{1}, Name:{2}", idx, cardOb.Id, cardOb.Name.GetCodeName());
                        return(false);
                    }
                }
            }

            return(true);
        }