public static Item GenerateRandom(Pg.Level level) { Item item = null; var type = typeof(Item); var itemClasses = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => type.IsAssignableFrom(p)).ToArray(); var ix = 0; // TODO: Random index generation --> i.e. The type of item var luck = Dice.Throws(new Dice(20)); var actualLevel = level; if (luck < 3) { actualLevel = actualLevel.Previous(); } if (luck > 18) { actualLevel = actualLevel.Next(); } var method = itemClasses[ix].GetMethods().Where(m => m.GetCustomAttributes(typeof(Generator), false).Length > 0).FirstOrDefault(); if (method == null) { throw new Exception("Unexpected null method"); } return((Item)method.Invoke(null, new object[] { actualLevel })); }
public static Item GenerateByBuilderType(Type type, Pg.Level level = Pg.Level.Novice, Coord position = new Coord()) { return(Generators.ContainsKey(type) ? Generators[type].GenerateRandom(level, position) : null); }
protected override AICharacter RandomBuild(Pg.Level level) { var lvl = ((int)level); Name = Name.ValueIfNotNullOrElse("Orc"); // God - can be null Stats = Stats.ValueIfNotNullOrElse(new GodsWill_ASCIIRPG.Stats( StatsBuilder.RandomStats( new Dictionary <StatsType, int>() { { StatsType.Strength, 2 }, { StatsType.Toughness, 2 }, { StatsType.Mental, -2 }, { StatsType.InnatePower, -2 }, }))); var toughMod = ((Stats)Stats)[StatsType.Toughness].ModifierOfStat(); MaximumPf = CurrentPf.ValueIfNotNullOrElse(Orc.healthDice.Max + Dice.Throws(Orc.healthDice, lvl) + lvl * toughMod); CurrentPf = MaximumPf.ValueIfNotNullOrElse((int)MaximumPf); Hunger = Hunger.ValueIfNotNullOrElse((Orc.hungerDice.Max + Dice.Throws(Orc.hungerDice, lvl)) * toughMod); MyAI = MyAI.ValueIfNotNullOrElse(new SimpleAI()); MySensingMethod = MySensingMethod.ValueIfNotNullOrElse(AI.SensingAlgorythms.AllAround); PerceptionDistance = PerceptionDistance.ValueIfNotNullOrElse(5); //WornArmor - Can be null //EmbracedShield - Can be null //HandledWeapon - Can be null Backpack = Backpack.ValueIfNotNullOrElse(new Backpack()); Symbol = Symbol.ValueIfNotNullOrElse("o"); Color = Color.ValueIfNotNullOrElse(System.Drawing.Color.DarkOliveGreen); Description = Description.ValueIfNotNullOrElse("A greenish, smelly human-like creature. Strong, but usually not very smart."); Position = Position.ValueIfNotNullOrElse(new Coord()); AlliedTo = AlliedTo.ValueIfNotNullOrElse(Allied.Enemy); var orc = new Orc(Name, (int)CurrentPf, (int)MaximumPf, (int)Hunger, MyAI, MySensingMethod, (int)PerceptionDistance, (Stats)Stats, WornArmor, EmbracedShield, HandledWeapon, Backpack, God, Symbol, (System.Drawing.Color)Color, Description, (Coord)Position, (Allied)AlliedTo); return(orc); }
public void NotifyLevel(Pg.Level level, God god) { setTextAndRefresh(tblPanelNameAndLevel.Controls[_lblLevel], String.Format("[{0}{1}]", level.ToString(), god != null ? String.Format(" of {0}", god.Name) : "")); }
public static Pg.Level Next(this Pg.Level level) { var levels = (Pg.Level[])Enum.GetValues(typeof(Pg.Level)); // Last level available if (levels.Length == 1 + (int)level) { return(level); } else { return(level + 1); } }
public static Weapon RandomWeapon(Pg.Level level) { var weaponsType = typeof(Weapon); var weapons = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(w => weaponsType.IsAssignableFrom(w)) .Where(w => { var attribute = w.GetCustomAttributes(typeof(Prerequisite), false).FirstOrDefault(); return(attribute != null && ((Prerequisite)attribute).MinimumLevel == level); }) .ToArray(); if (weapons.Length == 0) { throw new Exception("Unexpected No Weapon"); } var ix = Dice.Throws(new Dice(weapons.Length)) - 1; return((Weapon)Activator.CreateInstance(weapons[ix])); }
public static Pg.Level Previous(this Pg.Level level) { return((Pg.Level)Math.Max(0, (int)level - 1)); }
public OnPrayResult(Pg.Level forLevel) { ForLevel = forLevel; }
public virtual AICharacter Build(Pg.Level level = Pg.Level.Novice) { var aiChar = RandomBuild(level); return(aiChar); }
protected abstract AICharacter RandomBuild(Pg.Level level);
public OnVeryGoodPrayResult(Pg.Level forLevel) : base(forLevel) { }
public OnBadPrayResult(Pg.Level forLevel) : base(forLevel) { }
public EquivalentLevel(Pg.Level level) { Level = level; }
public Prerequisite(Pg.Level minimumLevel) { MinimumLevel = minimumLevel; }
public override PrayerBook GenerateTypedRandom(Pg.Level casterLevel, Coord position) { var allSpells = Spell.All; var spellsWithPrerequisite = from spell in allSpells let attributes = spell.GetCustomAttributes(typeof(Prerequisite), false) where attributes != null && attributes.Length > 0 let prerequisite = ((Prerequisite)attributes[0]) group spell by prerequisite.MinimumLevel into newGroup select newGroup; #region PERC_LEVEL // Perc -> Level Dictionary <int, Pg.Level> percSpellLevel = null; switch (casterLevel) { case Pg.Level.Novice: percSpellLevel = new Dictionary <int, Pg.Level>() { { 80, Pg.Level.Novice }, { 100, Pg.Level.Cleric }, }; break; case Pg.Level.Cleric: percSpellLevel = new Dictionary <int, Pg.Level>() { { 60, Pg.Level.Novice }, { 85, Pg.Level.Cleric }, { 100, Pg.Level.Master }, }; break; case Pg.Level.Master: percSpellLevel = new Dictionary <int, Pg.Level>() { { 50, Pg.Level.Novice }, { 80, Pg.Level.Cleric }, { 95, Pg.Level.Master }, { 100, Pg.Level.GrandMaster }, }; break; case Pg.Level.GrandMaster: percSpellLevel = new Dictionary <int, Pg.Level>() { { 35, Pg.Level.Novice }, { 65, Pg.Level.Cleric }, { 85, Pg.Level.Master }, { 100, Pg.Level.GrandMaster }, }; break; } #endregion #region LEVEL_EMPTY // Level -> Perc Empty Book Dictionary <Pg.Level, int> spellLevelPercEmpty = new Dictionary <Pg.Level, int>() { { Pg.Level.Novice, 15 }, { Pg.Level.Cleric, 10 }, { Pg.Level.Master, 5 }, { Pg.Level.GrandMaster, 1 }, }; #endregion var diceResult = Dice.Throws(new Dice(nFaces: 100)); var spellLevel = percSpellLevel.Where(p => diceResult < p.Key).Select(p => p.Value).First(); List <Type> spellSetFromWhichToChoose = null; foreach (var spellGroup in spellsWithPrerequisite) { if (spellGroup.Key == spellLevel) { spellSetFromWhichToChoose = spellGroup.ToList <Type>(); break; } } if (spellLevel == Pg.Level.Novice) { var spellsWithNoPrerequisite = from spell in allSpells let attributes = spell.GetCustomAttributes(typeof(Prerequisite), false) where attributes == null || attributes.Length == 0 select spell; if (spellSetFromWhichToChoose == null) { spellSetFromWhichToChoose = spellsWithNoPrerequisite.ToList <Type>(); } else { spellSetFromWhichToChoose.AddRange(spellsWithNoPrerequisite); } } // If spell of Novice, there's a chance book is empty var voidBook = Dice.Throws(new Dice(100)) <= spellLevelPercEmpty[casterLevel]; if (voidBook || spellSetFromWhichToChoose == null || spellSetFromWhichToChoose.Count == 0) { return(new VoidPrayerBook(position)); } var ix = Dice.Throws(spellSetFromWhichToChoose.Count) - 1; var spellB = (SpellBuilder)Activator.CreateInstance(spellSetFromWhichToChoose[ix]); var pl = spellSetFromWhichToChoose[ix].GetCustomAttributes(typeof(PercentageOfSuccess), false); var percentageOfSuccess = pl.Length == 0 ? 100 : ((PercentageOfSuccess)pl[0]).Percentage; return(new PrayerBook(spellB, cost: spellB.MoneyValue, percOfSuccess: percentageOfSuccess, position: position)); }
public abstract Item GenerateRandom(Pg.Level level, Coord position);