public string CreateStarterBlossom() { string name = GetRandomBlossomName(); string newBlossom = CreateRandomBlossom(name, BlossomData.BlossomGrowth.Baby, 20, 20, 0.5f, 0.5f, 0, 1, 2, string.Empty, new Vector2(0, 0), false); Dictionary <string, int> colorPool = new Dictionary <string, int>(); BlossomColor blue = Resources.Load <BlossomColor>("BlossomColors/Blue"); colorPool.Add(blue.Name, blue.Probability); BlossomColor red = Resources.Load <BlossomColor>("BlossomColors/Red"); colorPool.Add(red.Name, red.Probability); BlossomColor yellow = Resources.Load <BlossomColor>("BlossomColors/Yellow"); colorPool.Add(yellow.Name, yellow.Probability); BlossomColor green = Resources.Load <BlossomColor>("BlossomColors/Green"); colorPool.Add(green.Name, green.Probability); string color = WeightedRandomizer.From(colorPool).TakeOne(); DialogueLua.SetVariable(newBlossom + "Color", color); //STAT POTENTIAL BONUS DISTRIBUTION for (int potentialBonus = 30; potentialBonus > 0; potentialBonus--) { List <string> availableStats = new List <string>(); if (DialogueLua.GetVariable(newBlossom + "AgilityPotential").asFloat < 40) { availableStats.Add("AgilityPotential"); } if (DialogueLua.GetVariable(newBlossom + "StrengthPotential").asFloat < 40) { availableStats.Add("StrengthPotential"); } if (DialogueLua.GetVariable(newBlossom + "IntellectPotential").asFloat < 40) { availableStats.Add("IntellectPotential"); } if (DialogueLua.GetVariable(newBlossom + "CharmPotential").asFloat < 40) { availableStats.Add("CharmPotential"); } if (availableStats.Count > 0) { int rand = Random.Range(0, availableStats.Count); float currentVal = DialogueLua.GetVariable(newBlossom + availableStats[rand]).asFloat; DialogueLua.SetVariable(newBlossom + availableStats[rand], currentVal + 1); } else { break; } } //STAT LEARNING SPEED BONUS DISTRIBUTION for (int learningSpeedBonus = 5; learningSpeedBonus > 0; learningSpeedBonus--) { List <string> availableStats = new List <string>(); availableStats.Add("AgilityLearningSpeed"); availableStats.Add("StrengthLearningSpeed"); availableStats.Add("IntellectLearningSpeed"); availableStats.Add("CharmLearningSpeed"); if (availableStats.Count > 0) { int rand = Random.Range(0, availableStats.Count); float currentVal = DialogueLua.GetVariable(newBlossom + availableStats[rand]).asFloat; DialogueLua.SetVariable(newBlossom + availableStats[rand], currentVal + 0.1f); } else { break; } } return(newBlossom); }
public string CreateChildBlossom(string pParent1, string pParent2) { //CREATE BLOSSOM BlossomData newBlossom = Instantiate(BlossomPrefab, transform); newBlossom.ID = "Blossom" + CurrentBlossomID.ToString(); string ID = newBlossom.ID; CurrentBlossomID += 1; newBlossom.Age = 0; newBlossom.Name = GetRandomBlossomName(); newBlossom.Parent1 = pParent1; newBlossom.Parent2 = pParent2; newBlossom.Energy = 2; //STATS //Agility newBlossom.Agility.Value = 0; newBlossom.Agility.Potential = SetChildStat(pParent1, pParent2, "AgilityPotential"); newBlossom.Agility.LearningSpeed = SetChildStat(pParent1, pParent2, "AgilityLearningSpeed"); //Strength newBlossom.Strength.Value = 0; newBlossom.Strength.Potential = SetChildStat(pParent1, pParent2, "StrengthPotential"); newBlossom.Strength.LearningSpeed = SetChildStat(pParent1, pParent2, "StrengthLearningSpeed"); //Intellect newBlossom.Intellect.Value = 0; newBlossom.Intellect.Potential = SetChildStat(pParent1, pParent2, "IntellectPotential"); newBlossom.Intellect.LearningSpeed = SetChildStat(pParent1, pParent2, "IntellectLearningSpeed"); //Charm newBlossom.Charm.Value = 0; newBlossom.Charm.Potential = SetChildStat(pParent1, pParent2, "CharmPotential"); newBlossom.Charm.LearningSpeed = SetChildStat(pParent1, pParent2, "CharmLearningSpeed"); //TRAITS string dominantParent; int rand = Random.Range(0, 100); if (rand <= 50) { dominantParent = pParent2; } else { dominantParent = pParent1; } Dictionary <Trait, int> parentTraits = new Dictionary <Trait, int>(); List <Trait> parent1Traits = new List <Trait>(); int parent1TraitAmount = DialogueLua.GetVariable(pParent1 + "TraitAmount").asInt; for (int i = 0; i < parent1TraitAmount; i++) { string traitName = DialogueLua.GetVariable(pParent1 + "Trait" + i).asString; parent1Traits.Add(Resources.Load <Trait>("BlossomTraits/" + traitName)); } List <Trait> parent2Traits = new List <Trait>(); int parent2TraitAmount = DialogueLua.GetVariable(pParent2 + "TraitAmount").asInt; for (int i = 0; i < parent1TraitAmount; i++) { string traitName = DialogueLua.GetVariable(pParent2 + "Trait" + i).asString; parent1Traits.Add(Resources.Load <Trait>("BlossomTraits/" + traitName)); } List <Trait> dominantTraits = new List <Trait>(); List <Trait> nonDominantTraits = new List <Trait>(); if (dominantParent == pParent1) { dominantTraits = parent1Traits; nonDominantTraits = parent2Traits; } else { dominantTraits = parent2Traits; nonDominantTraits = parent1Traits; } foreach (Trait trait in dominantTraits) { if (!parentTraits.ContainsKey(trait)) { parentTraits.Add(trait, trait.Probabilty * 2); } } foreach (Trait trait in nonDominantTraits) { if (!parentTraits.ContainsKey(trait)) { parentTraits.Add(trait, trait.Probabilty); } else { parentTraits[trait] += trait.Probabilty; } } rand = Random.Range(1, 2); for (int i = 0; i < rand; i++) { Trait trait = WeightedRandomizer.From(parentTraits).TakeOne(); if (!newBlossom.Traits.Contains(trait)) { newBlossom.Traits.Add(trait); } } //STAT POTENTIAL BONUS DISTRIBUTION for (int potentialBonus = 10; potentialBonus > 0; potentialBonus--) { List <string> availableStats = new List <string>(); availableStats.Add("AgilityPotential"); availableStats.Add("StrengthPotential"); availableStats.Add("IntellectPotential"); availableStats.Add("CharmPotential"); if (availableStats.Count > 0) { rand = Random.Range(0, availableStats.Count); float currentVal = DialogueLua.GetVariable(newBlossom + availableStats[rand]).asFloat; DialogueLua.SetVariable(newBlossom + availableStats[rand], currentVal + 1); } else { break; } } //STAT LEARNING SPEED BONUS DISTRIBUTION for (int learningSpeedBonus = 2; learningSpeedBonus > 0; learningSpeedBonus--) { List <string> availableStats = new List <string>(); availableStats.Add("AgilityLearningSpeed"); availableStats.Add("StrengthLearningSpeed"); availableStats.Add("IntellectLearningSpeed"); availableStats.Add("CharmLearningSpeed"); if (availableStats.Count > 0) { rand = Random.Range(0, availableStats.Count); float currentVal = DialogueLua.GetVariable(newBlossom + availableStats[rand]).asFloat; DialogueLua.SetVariable(newBlossom + availableStats[rand], currentVal + 0.1f); } else { break; } } string parent1Color = DialogueLua.GetVariable(pParent1 + "Color").asString; string parent2Color = DialogueLua.GetVariable(pParent2 + "Color").asString; BlossomColorMix[] allMixes = Resources.LoadAll <BlossomColorMix>("BlossomColorMixes"); BlossomColorMix matchingMix = null; foreach (BlossomColorMix mix in allMixes) { if ((mix.Input1.Name == parent1Color && mix.Input2.Name == parent2Color) || (mix.Input1.Name == parent2Color && mix.Input2.Name == parent1Color)) { matchingMix = mix; } } if (matchingMix != null) { Dictionary <string, int> outputs = new Dictionary <string, int>(); foreach (ColorOutput output in matchingMix.Outputs) { outputs.Add(output.Output.Name, output.Output.Probability); } string color = WeightedRandomizer.From(outputs).TakeOne(); newBlossom.Color = color; } else { Dictionary <string, int> parentColors = new Dictionary <string, int>(); BlossomColor color1 = Resources.Load <BlossomColor>("BlossomColors/" + parent1Color); BlossomColor color2 = Resources.Load <BlossomColor>("BlossomColors/" + parent2Color); parentColors.Add(color1.Name, color1.Probability); if (!parentColors.ContainsKey(color2.Name)) { parentColors.Add(color2.Name, color2.Probability); } string color = WeightedRandomizer.From(parentColors).TakeOne(); newBlossom.Color = color; } //DESTROY OBJECT Destroy(newBlossom.gameObject); return(ID); }