public override void Use(Player player) { Mob target = player.Champion.Target; if (target == null) { Output.WriteGenericText(Output.NoTarget); } else { if (GenericOperations.FetchRandomPercentage() <= (CalculateChance(target))) { target.ResetMob(); Output.WriteGenericText(GetItemUsedMessage()); Deplete(player); player.OwnedMobs.Add(Mob.InstantiateMob(target, false)); if (player.CurrentLocation is Encounter e) { e.FinishCombat(player, Output.ComposeGenericText(new string[] { target.Name, Output.CapturedLabel }), true); return; } target = null; Controls.GoBackAction(player); } else { Output.WriteCleanPause(Output.CaptureFailureSentence); } } }
public static void ScaleLevels() { Settings.MinLevel = Mobs.Aggregate((m1, m2) => m1.Level < m2.Level ? m1 : m2).Level; Settings.MaxLevel = Mobs.Aggregate((m1, m2) => m1.Level > m2.Level ? m1 : m2).Level; foreach (Town t in Towns) { t.Level = (float)GenericOperations.GetProportion(Settings.MinLevel, Settings.MaxLevel, t.LevelRatio); t.InitializeEstablishments(); } }
public Wilderness(Town start, Town finish) //parameters are not in a form of a collection for better usability and readability { endpoints[0] = start; endpoints[1] = finish; level = CalculateLevel(endpoints[0], endpoints[1]); title = $"{Output.LoadingLabel} {Output.TownToFilename(finish)}..."; encountersAt = CalculateLoadingEvents(CalculateEncounterAmount()); loadingStuckAt = CalculateLoadingEvents(GenericOperations.GetRandom().Next(0, Settings.MaxStuckTimes)); description = $"{Output.DidYouKnowSentence} {Output.ProTips[GenericOperations.GetRandom().Next(0, Output.ProTips.Count)]}"; screen = ScreenType.wilderness; }
private double CalculateChance(Mob target) { Stat health = target.Stats[StatType.health]; Stat defence = target.Stats[StatType.defence]; float coeficient = -2; double lifeRatio = GenericOperations.GetRatio(health.MinValue, health.MaxValue, health.Value); double baseChance = lifeRatio * (lifeRatio + coeficient) + 1; double defenceRatio = GenericOperations.GetRatio(defence.DefaultValue * .75, defence.MaxValue, defence.Value); double result = baseChance - defenceRatio; if (result < 0) { result = 0; } return(result); }
public static void FleeAction(Player p) { if (GenericOperations.FetchRandomPercentage() < Settings.FleeChance) { Console.Clear(); if (p.CurrentLocation is Encounter e) { e.FinishCombat(p, Output.FleeSuccessSentence); } } else { Output.WriteCleanPause(Output.FleeFailureSentence); p.Champion.ActionsLeft--; } }
private int[] CalculateLoadingEvents(int amount) { int [] result = new int[amount]; for (int i = 0; i < amount; i++) { while (true) //ensure there are no duplicate values { int encIndex = GenericOperations.GetRandom().Next(0, Settings.DefaultWildernessGoal); if (!result.Contains(encIndex)) { result[i] = encIndex; break; } } } Array.Sort(result); return(result); }
private Mob SelectEncounterMob() { float percentage = GenericOperations.FetchRandomPercentage(); List <Mob> encounterable; if (percentage < Settings.NativeWildlifeChance / 2f) { encounterable = Data.Mobs.Where(t => t.Type == endpoints[0].TownType).ToList(); } else if (percentage < Settings.NativeWildlifeChance) { encounterable = Data.Mobs.Where(t => t.Type == endpoints[1].TownType).ToList(); } else { encounterable = Data.Mobs; } return(PickMob(encounterable)); }
public void Explore(Player player) { Output.InitializeLoadingScreen(exploredCurrent, ""); int loadingDelay = GenericOperations.GetRandom().Next(Settings.MinLoadingDelay, Settings.MaxLoadingDelay); int nextStuck = 0; int nextEncounter = (encounterIndex < encountersAt.Length) ? encountersAt[encounterIndex] : 0; if (loadingStuckAt.Length > 0) { nextStuck = loadingStuckAt[0]; } while (exploredCurrent <= Settings.DefaultWildernessGoal) { Output.AnimateLoadingBar(exploredCurrent); Thread.Sleep(loadingDelay); exploredCurrent++; if (nextEncounter == exploredCurrent) { EncounterIndex++; GenerateEncounter(player); return; } if (exploredCurrent == nextStuck) { Thread.Sleep(Settings.LoadingStuckDelay); loadingDelay = GenericOperations.GetRandom().Next(Settings.MinLoadingDelay, Settings.MaxLoadingDelay); loadingStuckAt = loadingStuckAt.Skip(1).ToArray(); if (loadingStuckAt.Length > 0) { nextStuck = loadingStuckAt[0]; } } } player.ChangeLocation(endpoints[1]); }
//Combat related stuff #region Combat public void Attack() { int damage = Stats[StatType.attack].Value - target.Stats[StatType.defence].Value; bool strong = GenericOperations.CalculateTypeAdvantage(Type, Target.Type); Output.WritelineUsedAction(this, Output.AttackLabel); if (strong) { Output.WritelineColor(Output.StrongAttackSentence, Settings.DefaultStrongColor); } double randomizedDamage = new Normal(damage, Settings.DamageDeviation).Sample(); damage = (int)Math.Round(randomizedDamage); if (damage < Settings.MinDamage) { damage = Settings.MinDamage; } int targetHealth = target.Stats[StatType.health].Value; if (damage > targetHealth) { damage = targetHealth; } if (strong) { damage *= (int)Math.Ceiling(Settings.StrongMP); } target.ModifyStat(StatType.health, -damage); actionsLeft--; }
public static void WriteBinary() { Console.Write(GenericOperations.GetRandom().Next(0, 2)); Thread.Sleep(10); }
private double CalculateMean() { double levelRatio = GenericOperations.GetRatio(Settings.MinLevel, Settings.MaxLevel, Level); return(GenericOperations.GetProportion(Settings.MinEncounters, Settings.MaxEncounters, levelRatio)); }