Ejemplo n.º 1
0
    static private CardDescription GenerateTrapCard(System.Random random, IHistogram model, ImageGlossary images, CreatureModelIndex creatureModels, NameModel nameModel, CardGenerationFlags flags)
    {
        CardDescription card = ScriptableObject.CreateInstance(typeof(CardDescription)) as CardDescription;

        card.cardType = CardType.TRAP;
        card.manaCost = (int)ProceduralUtils.GetRandomValue <ManaCost>(random, model);

        double powerBudget = PowerBudget.ManaPowerBudgets[card.manaCost];
        double powerMargin = PowerBudget.ManaPowerMargin[card.manaCost];
        double powerLimit  = PowerBudget.ManaPowerLimit[card.manaCost];

        card.cardName = "A trap card";
        //card.name += "(" + powerBudget.ToString() + ")";

        GenerateCardEffects(random, model, creatureModels, card, powerBudget, powerMargin, powerLimit);

        // Revise the mana cost based on what effects we actually did generate
        int revisedMana = PowerBudget.PowerLevelToMana(card.PowerLevel());

        if (revisedMana != card.manaCost)
        {
            Debug.Log("Had to revise the mana cost from " + card.manaCost.ToString() + " to " + revisedMana.ToString());
            card.manaCost = revisedMana;
        }
        card.image = ProceduralUtils.GetRandomTexture(random, images.GetTrapImages());

        CardTags tags = CardTagging.GetCardTags(card);

        card.cardName = nameModel.GenerateName(random, tags);

        return(card);
    }
Ejemplo n.º 2
0
    static private CardDescription GenerateCreatureCard(System.Random random, IHistogram model, ImageGlossary images, CreatureModelIndex creatureModels, NameModel nameModel, CardGenerationFlags flags)
    {
        CreatureCardDescription card = ScriptableObject.CreateInstance(typeof(CreatureCardDescription)) as CreatureCardDescription;

        card.creatureType = ProceduralUtils.GetRandomValue <CreatureType>(random, model);

        if ((flags & CardGenerationFlags.HUMAN) == CardGenerationFlags.HUMAN)
        {
            card.creatureType = CreatureType.HUMAN;
        }
        else if ((flags & CardGenerationFlags.GOBLIN) == CardGenerationFlags.GOBLIN)
        {
            card.creatureType = CreatureType.GOBLIN;
        }
        else if ((flags & CardGenerationFlags.FAERIE) == CardGenerationFlags.FAERIE)
        {
            card.creatureType = CreatureType.FAERIE;
        }

        MultiCardHistogram combinedModel = ScriptableObject.CreateInstance(typeof(MultiCardHistogram)) as MultiCardHistogram;

        combinedModel.Init(new IHistogram[] { model, creatureModels.GetModel(card.creatureType) });

        card.manaCost = (int)ProceduralUtils.GetRandomValue <ManaCost>(random, model);

        // Potentially generate a stronger body, but with a drawback
        double bodyManaCost = GetCreatureBodyBudget(creatureModels.GetBodyLambda(card.creatureType), random.Next(), card.manaCost + 1);
        int    maxStats     = PowerBudget.StatBudget(bodyManaCost);

        // Decide on stats
        card.health = GetHealth(random, creatureModels.GetStatProbability(card.creatureType, (int)Math.Round(bodyManaCost, MidpointRounding.AwayFromZero)), maxStats);
        card.attack = maxStats - card.health;

        // Decide on power budget
        double powerBudget = PowerBudget.ManaPowerBudgets[card.manaCost];
        double powerMargin = PowerBudget.ManaPowerMargin[card.manaCost];
        double powerLimit  = PowerBudget.ManaPowerLimit[card.manaCost];

        card.cardName = "A creature card";
        //card.name += "(" + powerBudget.ToString() + ")";

        // Decide on keyword attributes
        int maxKeywords = 3;

        for (int i = 0; i < maxKeywords; i++)
        {
            double keywordPowerLimit = powerLimit - card.PowerLevel();
            if (keywordPowerLimit < 0)
            {
                keywordPowerLimit = 0;
            }
            KeywordAttribute keyword = ProceduralUtils.GetRandomValue(random, combinedModel, ProceduralUtils.GetKeywordsWithinBudget(keywordPowerLimit, card.attack, card.health));
            if (keyword == KeywordAttribute.NONE)
            {
                break;
            }
            card.AddAttribute(keyword);
        }

        // Decide on effects
        GenerateCardEffects(random, combinedModel, creatureModels, card, powerBudget, powerMargin, powerLimit);

        // Revise the mana cost based on what effects we actually did generate
        int revisedMana = PowerBudget.PowerLevelToMana(card.PowerLevel());

        if (revisedMana != card.manaCost)
        {
            Debug.Log("Had to revise the mana cost from " + card.manaCost.ToString() + " to " + revisedMana.ToString());
            card.manaCost = revisedMana;
        }
        card.image = ProceduralUtils.GetRandomTexture(random, images.GetCreatureImages(card.creatureType));

        CardTags tags = CardTagging.GetCardTags(card);

        card.cardName = nameModel.GenerateName(random, tags);

        return(card);
    }