public static float BuffUpToThreshold(PawnKindDef def, float points, IEnumerable <BuffCat> strategyWeights, out Dictionary <BuffCat, float> buffMultipliers, int MaxBuffAttempts = 10000) { List <BuffCat> strategy = new List <BuffCat>(strategyWeights); Dictionary <BuffCat, float> buffs = new Dictionary <BuffCat, float> { //[BuffCat.Accuracy] = 1, [BuffCat.Cooldown] = 1 * BossFightSettings.CooldownInitialScalar, [BuffCat.Damage] = 1, [BuffCat.Health] = 1, // Set size multiplier to a random value in between 0.5 and SizeMultMax [BuffCat.Size] = 6,//Math.Max((FloatRange.ZeroToOne.RandomInRange * BossFightSettings.SizeMultMax), .5f), [BuffCat.Speed] = 1 }; float power = def.combatPower; float powerAfterBuff; int buffAttempts; // TODO: Make a binary search fn instead of linear to zoom for (buffAttempts = 0; buffAttempts < MaxBuffAttempts; buffAttempts++) { if (strategy.NullOrEmpty()) { break; } BuffCat buff = strategy.RandomElement(); Debug.Log(power + ": " + buffs.ToStringSafeEnumerable()); powerAfterBuff = PowerIfBuffed(def, buffs, buff); //Debug.Log("Chosen " + buff.ToString() + "Buff would increase power to " + powerAfterBuff + "," + (powerAfterBuff < points ? " applying buff..." : " breaking generation.")); if (powerAfterBuff == -1 || powerAfterBuff >= points) { Debug.Log("Buffing " + buff + " is too powerful, removing..."); strategy.RemoveAll(buffCat => buffCat == buff); continue; } else { power = powerAfterBuff; IncrementBuff(ref buffs, buff); } } if (buffAttempts >= MaxBuffAttempts) { Log.Warning("Took too long generating a powerful enough boss. Buff attempts capped at " + MaxBuffAttempts); } buffMultipliers = buffs; Debug.Log("Took " + buffAttempts + " buffs to create a " + power + " Boss " + def.label); return(power); }
private static bool IncrementBuff(ref Dictionary <BuffCat, float> buffs, BuffCat buff) { switch (buff) { // reduce by 15% every time without hitting 0. case BuffCat.Cooldown: if (buffs[buff] * (1 - BossFightSettings.BuffIncrements[buff]) <= BossFightSettings.CooldownMin) { return(false); } break; // limit to a max size case BuffCat.Size: Log.Warning("Caught an attempted Size buff after initial size determination. This should not happen."); return(false); } Buff(ref buffs, buff); return(true); }
private static void Buff(ref Dictionary <BuffCat, float> buffs, BuffCat buff) { buffs[buff] = (buff == BuffCat.Cooldown) ? buffs[buff] * (1 - BossFightSettings.BuffIncrements[buff]) : buffs[buff] + BossFightSettings.BuffIncrements[buff]; }
private static float PowerIfBuffed(PawnKindDef def, Dictionary <BuffCat, float> buffMultipliers, BuffCat buff) { Dictionary <BuffCat, float> buffs = new Dictionary <BuffCat, float>(buffMultipliers); return(IncrementBuff(ref buffs, buff) ? CombatPower(def.race, buffs) : -1); }