/// <summary> /// Sets up various parameters for the worlds for this game in the save file, such as randomization of some bosses. /// </summary> public void SetupWorlds() { //First assign the world-related arrays of the saved game an array of the proper size. SavedGame.SemibossGroupForEachMap = new int[Database.Worlds.Length]; bool[][] completedAreas = new bool[Database.Worlds.Length][]; for (int i = 0; i < completedAreas.Length; i++) { int areaCount = Database.Worlds[i].AreaCount; completedAreas[i] = new bool[areaCount]; } SavedGame.CompletedAreas = completedAreas; //Then fill in some data: string[][] assignedBosses = new string[Database.Worlds.Length][]; foreach (World w in Database.Worlds) { List <string> bosses = w.bosses.ToList(); int chosenSemibossGroup = Random.Range(0, w.SemibossGroupsCount ?? 0); if (w.semibossMode == SemibossMode.Fill) { foreach (string semiboss in w.semibosses[chosenSemibossGroup]) { bosses.Add(semiboss); } } else { SavedGame.SemibossGroupForEachMap[w.number] = chosenSemibossGroup; } if (w.removePlayer) { string playerSpirit = Database.PlayerSpirit[SavedGame.PlayerChar]; if (bosses.Remove(playerSpirit)) { VisualDebug.WriteLine($"Removed {playerSpirit} from the list of bosses."); } else { VisualDebug.WriteLine("No suitable Digimon was found to be removed from the first list of bosses. This should never happen."); } } if (w.shuffle) { bosses.Shuffle(); } assignedBosses[w.number] = bosses.ToArray(); VisualDebug.WriteLine($"Finished parsing world {w.number}"); } SavedGame.Bosses = assignedBosses; }
/// <summary> /// Gets a digimon at random from those in the database that can be chosen for a random battle. /// The level of the Digimon will be similar to the level of the player. /// </summary> /// <param name="playerLevel">The level of the player.</param> public static Digimon GetRandomDigimonForBattle(int playerLevel) { List <string> candidates = new List <string>(); List <float> weightList = new List <float>(); float totalWeight = 0f; int threshold; //The maximum level difference between the player and the chosen digimon. if (playerLevel <= 2) { threshold = 3; } else if (playerLevel <= 4) { threshold = 4; } else if (playerLevel <= 10) { threshold = 7; } else if (playerLevel <= 60) { threshold = 10; } else if (playerLevel <= 80) { threshold = 20; } else { threshold = 40; } //Populate the 'candidates' list with all eligible digimon, and store their individual weights and the total weight. foreach (DigimonRarity r in Rarities) { if (r.EligibleForBattle) { Digimon thisDigimon = GetDigimon(r.digimon); if (thisDigimon != null || thisDigimon.disabled) { if (thisDigimon.baseLevel > (playerLevel - threshold) && //The digimon's level is higher than the minimum. thisDigimon.baseLevel < (playerLevel + threshold)) //And lower than the maximum. { candidates.Add(r.digimon); float baseWeight = 0f; switch (r.Rarity) { case Rarity.Common: baseWeight = 10f; break; case Rarity.Rare: baseWeight = 6f; break; case Rarity.Epic: baseWeight = 3f; break; case Rarity.Legendary: baseWeight = 1f; break; } float thisWeight = (1.1f - (Mathf.Abs(playerLevel - thisDigimon.baseLevel) / (float)threshold)) * baseWeight; weightList.Add(thisWeight); totalWeight += thisWeight; } } } } float fChosen = Random.Range(0, totalWeight); float weightSum = 0f; VisualDebug.WriteLine($"Weighted Digimon: candidates found: {candidates.Count} fChosen: {fChosen}, totalWeight: {totalWeight}"); for (int i = 0; i < weightList.Count; i++) { weightSum += weightList[i]; if (weightSum > fChosen) { return(GetDigimon(candidates[i])); } } return(null); }