Example #1
0
        public static XDocument BuildXml(BattleDataOptions battleData, FighterDataOptions fighterData)
        {
            var type = fighterData.GetFighters().GetType().Name.ToLower();

            type = type.Remove(type.Length - 2);

            XDocument doc =
                new XDocument(new XDeclaration("1.0", "utf-8", null),
                              new XElement("struct",
                                           // <list hash="battle_data_tbl">	// <*DataList.Type* hash="*DataTbl.Type*">
                                           new XElement(type,
                                                        new XAttribute("hash", battleData.GetXmlName()),
                                                        //<struct index="0">	// <struct index="*DataListItem.GetIndex*">
                                                        battleData.GetBattles().Select(battle =>
                                                                                       battle.GetAsXElement(battleData.GetBattleIndex(battle)
                                                                                                            )
                                                                                       )
                                                        ),
                                           // <list hash="fighter_data_tbl">	// <*DataList.Type* hash="*DataTbl.Type*">
                                           new XElement(type,
                                                        new XAttribute("hash", fighterData.GetXmlName()),
                                                        //<struct index="0">	// <struct index="*DataListItem.GetIndex*">
                                                        fighterData.GetFighters().Select(fighter =>
                                                                                         fighter.GetAsXElement(fighterData.GetFighterIndex(fighter)
                                                                                                               )
                                                                                         )
                                                        )
                                           )
                              );

            return(doc);
        }
Example #2
0
        public void EmptySpiritData()
        {
            var options = dataOptions.OfType <BattleDataOptions>();

            battleData  = new BattleDataOptions();
            fighterData = new FighterDataOptions();
        }
Example #3
0
        // Replace Save calls to calls here.
        public static void SaveUnencrypted(BattleDataOptions battleData, FighterDataOptions fighterData, string fileLocation, string fileName)
        {
            fileLocation = FixFolderEndPath(fileLocation);

            // Save the version for local editing.
            Directory.CreateDirectory(fileLocation);

            SaveToFile(ConvertDataToXDocument(battleData, fighterData), fileLocation + fileName);
        }
Example #4
0
        public static void SaveEncrypted(BattleDataOptions battleData, FighterDataOptions fighterData, string fileLocation, string fileName, bool useFolderStructure = false)
        {
            fileLocation = FixFolderEndPath(fileLocation);

            // Save an encrypted version for direct placement on SD card.
            if (useFolderStructure)
            {
                fileLocation += GetFilePath(fileName);
            }
            Directory.CreateDirectory(fileLocation);
            SaveToEncryptedFile(ConvertDataToXDocument(battleData, fighterData), fileLocation + fileName);
        }
Example #5
0
        public static void SaveRandomized(BattleDataOptions battleData, FighterDataOptions fighterData, int seed = -1, int iteration = 0)
        {
            // Do multiple randomizers, in case an impossible battle happens.
            var fileName         = config.file_name_encr;
            var randomizerString = iteration > 0 ? ".Randomizer " : "Randomizer ";
            var directory        = config.file_directory_randomized + randomizerString + seed + " " + iteration; // Randomizer ### 1

            Save(battleData, fighterData, directory, fileName, unencrypted: false, useFolderStructure: true, saveSpiritTitles: false);

            CopyPreloadFiles(directory);
            CopySpiritImages(directory);
        }
Example #6
0
        public static void Save(BattleDataOptions battleData, FighterDataOptions fighterData, string fileLocation, string fileName, SpiritDataOptions spiritData = null, bool unencrypted = true, bool encrypted = true, bool useFolderStructure = false, bool saveSpiritTitles = true)
        {
            fileLocation += @"\";

            if (unencrypted)
            {
                var pathMod = useFolderStructure ? "" : config.unencr_sub;
                SaveUnencrypted(battleData, fighterData, fileLocation + pathMod, fileName);
            }
            if (encrypted)
            {
                SaveEncrypted(battleData, fighterData, fileLocation, fileName, useFolderStructure);
                if (spiritData?.HasData() ?? false)
                {
                    var loc = MiscDbsToSave();
                    SaveEncrypted(spiritData, Path.GetDirectoryName(loc), Path.GetFileName(loc));
                }
            }

            if (saveSpiritTitles)
            {
                SaveSpiritTitles(battleData.GetBattles(), config.file_directory_preload);
            }
        }
Example #7
0
        public async Task <List <IDataOptions> > RandomizeAll(ProgressBar progressBar, int seed, int characterUnlockSeed, int iteration = 0)
        {
            Random rnd = new Random(seed);
            Random unlockableRnd;


            BattleDataOptions  randomizedBattleData;
            FighterDataOptions randomizedFighters;
            Fighter            randomizedFighter;
            int fighterCount;

            unlockableRnd        = new Random(characterUnlockSeed);
            randomizedFighters   = new FighterDataOptions();
            randomizedBattleData = this.battleData.Copy();
            List <string> unlockableFighters = this.spiritFighterData.unlockable_fighters_string;

            foreach (Battle battle in randomizedBattleData.GetBattles())
            {
                battle.Randomize(ref rnd, this);
                // If lose escort, need at least 2 fighters.
                fighterCount = battle.IsLoseEscort() ?
                               RandomizerHelper.fighterLoseEscortDistribution[rnd.Next(RandomizerHelper.fighterLoseEscortDistribution.Count)]
                    :
                               RandomizerHelper.fighterDistribution[rnd.Next(RandomizerHelper.fighterDistribution.Count)];

                // Save after randomizing, as cleanup will modify it.
                var isUnlockableFighterType = this.spiritFighterData.IsUnlockableFighter(battle.battle_id);
                var isBossType   = battle.IsBossType();
                var isLoseEscort = battle.IsLoseEscort();

                battle.Cleanup(ref rnd, fighterCount, this, isUnlockableFighterType);

                var fighterSum = 0;
                for (int i = 0; i < fighterCount; i++)
                {
                    string unlockableFighter = null;

                    var isMain = i == 0;                                         // Set first fighter to main.
                    var isUnlockableFighter = isMain && isUnlockableFighterType; // If unlockable fighter, we will explicitly set a fighter to match the spirit.
                    var isBoss   = isMain && isBossType;                         // Set first fighter to main.
                    var isEscort = i == 1 && battle.IsLoseEscort();              // Set second fighter to ally, if Lose Escort result type.

                    randomizedFighter = battle.GetNewFighter();
                    randomizedFighter.Randomize(ref rnd, this);

                    if (isUnlockableFighter)
                    {
                        int fighterIndex = unlockableRnd.Next(unlockableFighters.Count);
                        unlockableFighter = unlockableFighters[fighterIndex];
                        unlockableFighters.RemoveAt(fighterIndex);
                    }

                    randomizedFighter.Cleanup(ref rnd, isMain, isEscort, this.fighterData.Fighters, isBoss, unlockableFighter);
                    fighterSum += randomizedFighter.stock == 0 ? 1 : randomizedFighter.stock;

                    randomizedFighters.AddFighter(randomizedFighter);
                }
                // Do a total fighter check, and adjust stock accordingly.
                if (fighterSum > Defs.FIGHTER_COUNT_STOCK_CUTOFF)
                {
                    for (int i = randomizedFighters.GetCount() - fighterCount; i < randomizedFighters.GetCount(); i++)
                    {
                        randomizedFighters.GetFighterAtIndex(i).StockCheck(fighterSum);
                    }
                }

                progressBar.PerformStep();
            }

            return(new List <IDataOptions>()
            {
                randomizedBattleData, randomizedFighters
            });
        }
Example #8
0
 public void ImportBattle(BattleDataOptions battles, FighterDataOptions fighters)
 {
     battleData.ReplaceBattles(battles);
     fighterData.ReplaceFighters(fighters);
 }
Example #9
0
 public static XDocument ConvertDataToXDocument(BattleDataOptions battleData, FighterDataOptions fighterData)
 {
     return(XmlHelper.BuildXml(battleData, fighterData));
 }