Ejemplo n.º 1
0
    Dictionary <string, Species> ImportMonsterSpecies(ExcelImporter excel, Dictionary <string, Element> elements, Dictionary <string, Ability> abilities)
    {
        if (!excel.TryGetTable("Monsters", out ExcelImporter.Table table))
        {
            throw new System.IO.InvalidDataException($"No Monsters table was found!");
        }

        var assets        = GetAllAssetsOfType <Species>();
        int originalCount = assets.Count;

        int nonBlankCount = 0;

        for (int row = 1; row <= table.RowCount; row++)
        {
            string name = table.GetValue <string>(row, "Name");
            if (string.IsNullOrWhiteSpace(name))
            {
                continue;
            }

            nonBlankCount++;

            var monster = GetOrCreateAsset(name, assets, "Monsters/Species");

            string rarityName = table.GetValue <string>(row, "Rarity");
            if (!System.Enum.TryParse(rarityName, out monster.rarity))
            {
                Debug.LogError($"Unknown rarity {rarityName} used by monster species {name}.");
            }

            string elementName = table.GetValue <string>(row, "Element");
            if (!elements.TryGetValue(elementName, out monster.element))
            {
                Debug.LogError($"Element {elementName} used by monster {name} was not found.");
            }

            monster.baseStats.health  = table.GetValue <int>(row, "Health");
            monster.baseStats.stamina = table.GetValue <int>(row, "Stamina");
            monster.baseStats.attack  = table.GetValue <int>(row, "Attack");
            monster.baseStats.defense = table.GetValue <int>(row, "Defense");
            monster.baseStats.luck    = table.GetValue <int>(row, "Luck");

            monster.abilities[0] = SetAbility(row, 1, table, abilities);
            monster.abilities[1] = SetAbility(row, 2, table, abilities);

            monster.OnValidate();
        }

        MarkChangesForSaving(speciesCollection);
        speciesCollection.species.Clear();
        foreach (var monster in assets.Values)
        {
            speciesCollection.species.Add(monster);
        }
        speciesCollection.OnEnable();

        Debug.Log($"Successfully imported {nonBlankCount} monsters " +
                  $"({assets.Count - originalCount} new, {assets.Count - nonBlankCount} unused).");
        return(assets);
    }
Ejemplo n.º 2
0
    Dictionary <string, Ability> ImportAbilities(ExcelImporter excel, Dictionary <string, Element> elements)
    {
        if (!excel.TryGetTable("Abilities", out ExcelImporter.Table table))
        {
            throw new System.IO.InvalidDataException($"No Abilities table was found!");
        }

        var specials = GetAllAssetsOfType <SpecialEffect>();

        var assets        = GetAllAssetsOfType <Ability>();
        int originalCount = assets.Count;

        int nonBlankCount = 0;

        for (int row = 1; row <= table.RowCount; row++)
        {
            string name = table.GetValue <string>(row, "Name");
            if (string.IsNullOrWhiteSpace(name))
            {
                continue;
            }

            nonBlankCount++;

            var ability = GetOrCreateAsset(name, assets, "Abilities");

            string elementName = table.GetValue <string>(row, "Element");
            if (!elements.TryGetValue(elementName, out ability.element))
            {
                Debug.LogError($"Element {elementName} used by ability {name} was not found.");
            }

            ability.staminaCost = table.GetValue <int>(row, "Stamina Cost");
            ability.minDamage   = table.GetValue <int>(row, "Min Damage");
            ability.maxDamage   = table.GetValue <int>(row, "Max Damage");

            string specialName = table.GetValue <string>(row, "Special Effect");
            if (string.IsNullOrWhiteSpace(specialName) || !specials.TryGetValue(specialName, out SpecialEffect special))
            {
                if (!string.IsNullOrWhiteSpace(specialName))
                {
                    Debug.LogError($"Special effect {specialName} used by ability {name} was not found.");
                }

                ability.special       = null;
                ability.specialChance = 0;
            }
            else
            {
                ability.special       = special;
                ability.specialChance = table.GetValue <float>(row, "Effect Chance");
            }
        }

        Debug.Log($"Successfully imported {nonBlankCount} abilities " +
                  $"({assets.Count - originalCount} new, {assets.Count - nonBlankCount} unused).");
        return(assets);
    }