public void Validate() { int statBudget = PowerBudget.StatBudget(mana); while (statModels.Count > statBudget) { statModels.RemoveAt(statModels.Count - 1); } while (statModels.Count < statBudget) { int i = statModels.Count; statModels.Add(new StatModelEntry()); statModels[i].value = 1; statModels[i].health = i + 1; statModels[i].mana = mana; } int total = 0; foreach (StatModelEntry statModel in statModels) { total += statModel.value; } foreach (StatModelEntry statModel in statModels) { statModel.total = total; } }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property != null) { // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); // Draw label position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); // Don't make child fields be indented var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // Calculate rects var rect1 = new Rect(position.x, position.y, 50, position.height); var rect2 = new Rect(position.x + 55, position.y, 50, position.height); var rect3 = new Rect(position.x + 110, position.y, 200, position.height); var rect4 = new Rect(position.x + 315, position.y, 50, position.height); var rect5 = new Rect(position.x + 370, position.y, position.width - 370, position.height); SerializedProperty health = property.FindPropertyRelative("health"); SerializedProperty mana = property.FindPropertyRelative("mana"); SerializedProperty value = property.FindPropertyRelative("value"); SerializedProperty total = property.FindPropertyRelative("total"); // Draw fields - pass GUIContent.none to each so they are drawn without labels EditorGUI.LabelField(rect1, "Atk: " + (PowerBudget.StatBudget(mana.intValue) - health.intValue).ToString()); EditorGUI.LabelField(rect2, "Hp: " + health.intValue.ToString()); EditorGUI.PropertyField(rect3, value, GUIContent.none, true); float percent = 0; if (total.intValue > 0) { percent = (value.intValue / (float)total.intValue); } string percentText = (percent * 100).ToString("0.00") + "%"; EditorGUI.LabelField(rect4, percentText); EditorGUI.ProgressBar(rect5, percent, ""); // Set indent back to what it was EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); } }
public StatProbability(int manaCost) { statModels = new List <StatModelEntry>(); mana = manaCost; int statBudget = PowerBudget.StatBudget(mana); for (int i = 0; i < statBudget; i++) { statModels.Add(new StatModelEntry()); statModels[i].value = 1; statModels[i].health = i + 1; statModels[i].total = statBudget; statModels[i].mana = mana; } }
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); }