public static HashSet <CutBase> TestDamageForDataFight(Data.Fight fight, double threshold) { HashSet <CutBase> ret = new HashSet <Model.CutBase>(); fight.SetCuts(); FighterStats stats1 = new FighterStats(fight.Fighter1); FighterStats stats2 = new FighterStats(fight.Fighter2); foreach (Data.Round round in fight.Rounds) { if (RoundMatchesExpectations(round, stats1, stats2, true, threshold)) { foreach (var c in GetCutsForDataRound(round.First)) { if (!ret.Contains(c)) { ret.Add(c); } } foreach (var c in GetCutsForDataRound(round.Second)) { if (!ret.Contains(c)) { ret.Add(c); } } } } return(ret); }
public void NextTurn() { battleText.gameObject.SetActive(false); FighterStats currentFighterStats = fighterStats[0]; fighterStats.Remove(currentFighterStats); if (!currentFighterStats.GetDead()) { GameObject currentUnit = currentFighterStats.gameObject; currentFighterStats.CalculateNextTurn(currentFighterStats.nextActTurn); fighterStats.Add(currentFighterStats); fighterStats.Sort(); if (currentUnit.tag == "Hero") { this.battleMenu.SetActive(true); } else { this.battleMenu.SetActive(false); string attackType = Random.Range(0, 2) == 1 ? "Melee" : "Magic"; currentUnit.GetComponent <FighterAction>().SelectAttack(attackType); } } else { NextTurn(); } }
public void AdjustCounter_NegativeTest() { FighterStats f1 = GetFighterStats(); FighterStats f2 = GetFighterStats(); f2.Height = 15; f2.Speed = 15; FighterRoundStats frs1 = GetFighterRoundStats(f1, FightingStyle.Counter); FighterRoundStats frs2 = GetFighterRoundStats(f2, FightingStyle.Counter); FighterStats expected = f1.Copy(); expected.Strength++; expected.Agility -= 2; frs1.AdjustCounter(frs2); Assert.AreEqual(expected, frs1.AdjustedStats); FighterTactics tactics = frs1.Plan.Copy(); tactics.Aggressiveness = 3.4; Assert.AreEqual(tactics, frs1.AdjustedTactics); expected = f2.Copy(); expected.Agility = 14; Assert.AreEqual(expected, frs2.AdjustedStats); }
public void Attack(GameObject victim) { attackerStats = owner.GetComponent <FighterStats>(); targetStats = victim.GetComponent <FighterStats>(); if (attackerStats.magic >= magicCost) { float multiplier = Random.Range(minAttackMultiplier, maxAttackMultiplier); damage = multiplier * attackerStats.melee; if (magicAttack) { damage = multiplier * attackerStats.magicRange; } float defenseMultiplier = Random.Range(minDefenseMultiplier, maxDefenseMultiplier); damage = Mathf.Max(0, damage - (defenseMultiplier * targetStats.defense)); owner.GetComponent <Animator>().Play(animationName); targetStats.ReceiveDamage(Mathf.CeilToInt(damage)); attackerStats.UpdateMagicFill(magicCost); } else { Task.Delay(2000); Debug.Log("Turn skipped"); attackerStats.ContinueGame(); } }
public static void Part2(FighterStats boss, List <Spell> spells) { var player = new FighterStats(50, 0, 0, 500); var data = new Data { Spells = spells, MinManaUsed = Int32.MaxValue, HardMode = true }; var state = new StateNode { Player = player, Boss = boss, ActiveEffects = new List <Effect>(), }; Func <Data, StateNode, bool> reject = (Data data, StateNode state) => { if (state.Player.Hp <= 0 || state.Player.Mana <= 0 || state.ManaSpent > data.MinManaUsed) { return(true); } return(false); }; Func <Data, StateNode, bool> accept = (Data data, StateNode state) => { if (state.Boss.Hp <= 0) { data.MinManaUsed = Math.Min(data.MinManaUsed, state.ManaSpent); return(true); } return(false); }; Console.WriteLine(AOC.Backtrack(data, state, reject, accept, TrySpells).Select(s => s.ManaSpent).Min()); }
public CheckableDataItem(Data.Fighter fighter) : this(fighter, fighter.Name, fighter.FighterId) { WeightClass weightClass = FighterStats.GetWeightClass(fighter.Weight, fighter.Conditioning); string name = Enum.GetName(typeof(WeightClass), weightClass); this.Name = String.Format("{0} ({1})", fighter.Name, name); }
public void Attack(GameObject victim) { attackerStats = owner.GetComponent <FighterStats>(); targetStats = victim.GetComponent <FighterStats>(); if (magicAttack && attackerStats.magic < magicCost) { Invoke("SkipTurnContinueGame", 2); } else { float multiplier = Random.Range(minAttackMultiplier, maxAttackMultiplier); if (attackerStats.magic >= magicCost && magicAttack) { if (magicCost > 0) { attackerStats.updateMagicFill(magicCost); } damage = multiplier * attackerStats.magicRange; } else { damage = multiplier * attackerStats.melee; } float defenseMultiplier = Random.Range(minDefenseMultiplier, maxDefenseMultiplier); damage = Mathf.Max(0, damage - (defenseMultiplier * targetStats.defense)); owner.GetComponent <Animator>().Play(animationName); targetStats.ReceiveDamage(Mathf.CeilToInt(damage)); } }
public void Attack(GameObject victim) { attackerStats = owner.GetComponent <FighterStats>(); targetStats = victim.GetComponent <FighterStats>(); if (attackerStats.magic >= magicCost) { float multiplier = Random.Range(minAttackMultiplier, maxAttackMultiplier); damage = multiplier * attackerStats.attack; if (magicAttack) { damage = multiplier * attackerStats.intelligence; } float defenseMultiplier = Random.Range(minDefenseMultiplier, maxDefenseMultiplier); damage = targetStats.block - Mathf.Max(0, damage - (defenseMultiplier * targetStats.defense)); if (damage < 0) { damage = 0; } owner.GetComponent <Animator>().Play(animationName); targetStats.ReceiveDamage(Mathf.CeilToInt(damage)); attackerStats.UpdateMagicFill(magicCost); } else { Invoke("SkipTurnContinueGame", 2); } }
public void AdjustClinchTest() { FighterStats fst = GetFighterStats(); fst.Strength = 18; FighterStats other = GetFighterStats(); FighterRoundStats frs = new FighterRoundStats(fst, new FighterRoundPlan(4, 8, 8)); FighterRoundStats otherRs = new FighterRoundStats(other, new FighterRoundPlan(4, 8, 8)); frs.AdjustClinch(otherRs); FighterStats expected = fst.Copy(); expected.Agility = 16; Assert.AreEqual(expected, frs.AdjustedStats); FighterTactics tactics = frs.Plan.Copy(); tactics.Aggressiveness = 3.4; tactics.Rest = 0.6; Assert.AreEqual(tactics, frs.AdjustedTactics); }
public void FightAllTest() { List <int> fpList = new List <int>() { 8, 9, 14, 15, 16 }; var listOne = new List <PivotFighter>(); var listTwo = new List <PivotFighter>(); int fighter1Id = 5; int fighter2Id = 5; FightOptions options = new FightOptions() { JudgeLuck = 0.05, LuckAmount = 0.05 }; Data.Fighter f1 = DataHelpers.Entities.Fighters.First(f => f.FighterId == fighter1Id); FighterStats f1Stats = new FighterStats(f1); Data.Fighter f2 = DataHelpers.Entities.Fighters.First(f => f.FighterId == fighter2Id); FighterStats f2Stats = new FighterStats(f2); Fighter f1Fighter = new Fighter() { Stats = f1Stats }; Fighter f2Fighter = new Fighter() { Stats = f2Stats }; foreach (int i in fpList) { Data.FightPlan dfp = DataHelpers.Entities.FightPlans.First(fp => fp.PlanId == i); Model.FightPlan mFp = new FightPlan() { FightPlanText = dfp.PlanData }; string name = String.Format("{0}, {1}", f1.Name, dfp.PlanName); listOne.Add(new PivotFighter(f1Stats, mFp, name, TrainingStat.None)); name = String.Format("{0}, {1}", f2.Name, dfp.PlanName); listTwo.Add(new PivotFighter(f2Stats, mFp, name, TrainingStat.None)); } PivotFightSimulator simmer = new PivotFightSimulator(listOne, listTwo, 100, options); Stopwatch sw = new Stopwatch(); sw.Start(); simmer.FightAll(); Debug.Print("Done in " + sw.ElapsedMilliseconds); simmer.PrintAll(); }
public override void RefreshStats() { this.FighterInformations = new GameFightCharacterInformations(ContextualId, FighterLook, new EntityDispositionInformations(CellId, Direction), (sbyte)Team.TeamColor, 0, !Dead, FighterStats.GetMinimalStats(), new ushort[0], Client.Character.Record.Name, new PlayerStatus(0), Client.Character.Record.Level, Client.Character.GetActorAlignement(), Client.Character.Record.Breed, Client.Character.Record.Sex); Client.Send(new FighterStatsListMessage(FighterStats.GetCharacterCharacteristics(Client.Character))); }
public void TestAgain() { DataHelpers.Entities.Fights.Load(); HashSet <CutBase> doNothingCuts = new HashSet <CutBase>(); var something = DataHelpers.Entities.Fights.Where(f => f.FightId >= 19 && !f.BadResult); foreach (Fight fight in something) { fight.SetCuts(); FighterStats stats1 = new FighterStats(fight.Fighter1); FighterStats stats2 = new FighterStats(fight.Fighter2); foreach (Data.Round round in fight.Rounds) { List <CutBase> cuts1 = FightHelpers.GetCutsForDataRound(round.First); List <CutBase> cuts2 = FightHelpers.GetCutsForDataRound(round.Second); CutPenalty cp1 = CutBase.CalculatePenaltyForCuts(FightHelpers.GetCutsForDataRound(round.First)); CutPenalty cp2 = CutBase.CalculatePenaltyForCuts(FightHelpers.GetCutsForDataRound(round.Second)); if (round.First.Tactic.Aggressiveness == 1) { continue; } if (FightHelpers.RoundMatchesExpectations(round, stats1, stats2, true, 0)) { if (!cp1.HasNone || !cp2.HasNone) { Debug.Print("HMMM"); } if (cuts1.Count > 0 || cuts2.Count > 0) { doNothingCuts.UnionWith(cuts1); doNothingCuts.UnionWith(cuts2); } } else { if (cp1.HasNone && cp2.HasNone) { Debug.Print("uh oh?"); if (FightHelpers.RoundMatchesExpectations(round, stats1, stats2, true, 0.1)) { Debug.Print("Looks like, just a rounding thing"); } else { Debug.Print("No it's worse"); } } } } } foreach (CutBase cb in doNothingCuts) { Debug.Print(cb.ToString() + " does nothing!"); } }
public void FatigueStats_StunDefenseTest() { FighterStats fStats = new FighterStats(height: 10, speed: 10, agility: 15, strength: 10, knockoutPunch: 1, conditioning: 10, chin: 15, cutResistance: 1, weight: 150, numberOfFights: 0, rating: 0); FighterStats fatigued = FighterStats.FatigueStats(fStats, 90); const double expected = 18; double actual = fatigued.StunDefense; Assert.AreEqual(expected, actual); }
public void AdjustAlloutTest() { FighterStats fst = GetFighterStats(); FighterStats other = GetFighterStats(); FighterRoundStats frs = new FighterRoundStats(fst, new FighterRoundPlan(4, 8, 8)); FighterRoundStats otherFrs = new FighterRoundStats(other, new FighterRoundPlan(4, 8, 8)); frs.AdjustAllout(otherFrs); Assert.AreEqual(2.0, frs.DamageAdjustment); Assert.AreEqual(4.0, otherFrs.DamageAdjustment); }
public override void Initialize() { base.Initialize(); ContextualId = Client.Character.Id; FighterLook = Client.Character.Look.CloneContextActorLook(); RealFighterLook = FighterLook.CloneContextActorLook(); FighterStats = new FighterStats(Client.Character.StatsRecord); FighterInformations = new GameFightCharacterInformations(ContextualId, FighterLook.ToEntityLook(), new EntityDispositionInformations(CellId, Direction), (sbyte)Team.TeamColor, 0, true, FighterStats.GetMinimalStats(), new ushort[0], Client.Character.Record.Name, new PlayerStatus(0), Client.Character.Record.Level, Client.Character.GetActorAlignement(), Client.Character.Record.Breed, Client.Character.Record.Sex); }
public static FighterStats GetFighterStats() { FighterStats fst = new FighterStats( height: 12, speed: 12, agility: 12, strength: 12, knockoutPunch: 0, conditioning: 12, chin: 12, cutResistance: 1, weight: 150, numberOfFights: 1, rating: 0); return(fst); }
public void FatigueStatsTest() { FighterStats fStats = new FighterStats(height: 10, speed: 10, agility: 15, strength: 10, knockoutPunch: 1, conditioning: 10, chin: 15, cutResistance: 1, weight: 150, numberOfFights: 0, rating: 0); FighterStats fatigued = FighterStats.FatigueStats(fStats, 90); FighterStats expected = new FighterStats(height: 10, speed: 9, agility: 13.5, strength: 9, knockoutPunch: 1, conditioning: 10, chin: 15, cutResistance: 1, weight: 150, numberOfFights: 0, rating: 0) { FatiguePercent = 0.9 }; Assert.AreEqual(expected, fatigued); }
public virtual void EndTurn() { if (Fight.Ended) { return; } ApplyFighterEvent(FighterEventType.ON_TURN_ENDED, null); Fight.Send(new GameFightTurnEndMessage(ContextualId)); IsPlaying = false; m_turnEngine.EndTurn(); FighterStats.OnTurnEnded(); SpellHistory.OnTurnEnded(); RefreshStats(); Fight.Synchronizer.Start(Fight.NewTurn); }
public static RoundDamage CalculateDamageForDataRound(Data.Round round, FighterStats fStats, FighterStats oStats, List <CutBase> cuts, bool isFirst) { Data.FighterRound round1 = (isFirst) ? round.First : round.Second; Data.FighterRound round2 = (isFirst) ? round.Second : round.First; FighterStats adjusted1 = FighterStats.FatigueStats(fStats, round1.Endurance_Start); FighterStats adjusted2 = FighterStats.FatigueStats(oStats, round2.Endurance_Start); FighterRoundPlan fp1 = new FighterRoundPlan(round1.Tactic); FighterRoundPlan fp2 = new FighterRoundPlan(round2.Tactic); if (cuts != null) { adjusted1.AdjustCutStats(cuts); } RoundDamage ret = RoundDamage.CalculateRoundDamage(adjusted1, fp1, adjusted2, fp2, fp1.TargetArea); return(ret); }
public void Damage(GameObject target) { attackerStats = owner.GetComponent <FighterStats>(); targetStats = target.GetComponent <FighterStats>(); owner.GetComponent <Animator>().Play(weaponName); if (Random.Range(0, 10) <= dodge) { damage = 3; dodged = "\nShe DODGED it like a champ!"; } else if (multiplier == "Dexterity") { damage = (int)(baseDamage * (double)(attackerStats.Dexterity / 100.00)); } else if (multiplier == "Strength") { damage = (int)(baseDamage * (double)(attackerStats.Strength / 100.00)); } else { Debug.Log("Something went wrong..."); } target.GetComponent <Animator>().Play("damage"); targetStats.Health -= damage; targetStats.UpdateHealthBar(); GameControllerObj.GetComponent <GameController>().battleText.gameObject.SetActive(true); GameControllerObj.GetComponent <GameController>().battleText.text = damage.ToString(); string playerName = target.name == "Kristen" ? "Kristen the Samurai" : "Kim the Viking"; GameControllerObj.GetComponent <GameController>().narration_text.gameObject.SetActive(true); GameControllerObj.GetComponent <GameController>().narration_text.text = $"{playerName} was attacked with the {weaponName}.{dodged}"; if (weaponName == "Bow") { Invoke("ContinueGame", 1f); } else { Invoke("ContinueGame", 2f); } }
private List <PivotFighter> GetPivotFighterList(IEnumerable <CheckableDataItem> fighterList, IEnumerable <CheckableDataItem> planList, IEnumerable <CheckableDataItem> trainingList) { var ret = new List <PivotFighter>(); List <Data.Fighter> fighters = fighterList.Where(f => f.IsChecked).Select(f => f.DataObject).OfType <Data.Fighter>().ToList(); List <Data.FightPlan> fightPlans = planList.Where(f => f.IsChecked).Select(f => f.DataObject).OfType <Data.FightPlan>().ToList(); List <TrainingStat> trainings = trainingList.Where(f => f.IsChecked).Select(f => f.DataObject).OfType <TrainingStat>().ToList(); bool includeFighterInName = fighterList.Count() > 1; bool includeFPInName = planList.Count() > 1; bool includeStatInName = planList.Count() > 1; foreach (Data.Fighter fighter in fighters) { FighterStats fStats = new FighterStats(fighter); Weebul.Core.Model.Fighter mFighter = new Core.Model.Fighter() { Stats = fStats }; foreach (Data.FightPlan fp in fightPlans) { Core.Model.FightPlan mfp = new Core.Model.FightPlan() { FightPlanText = fp.PlanData }; foreach (TrainingStat stat in trainings) { string statName = Enum.GetName(typeof(TrainingStat), stat); string name = String.Format("{0}/{1}/{2}", fighter.Name, fp.PlanName, statName); PivotFighter pivotFighter = new PivotFighter(fStats, mfp, name, stat); string shortName = (includeFighterInName) ? fighter.Name : null; if (includeFPInName) { shortName = shortName == null ? fp.PlanName : shortName + "/" + fp.PlanName; } if (includeStatInName) { shortName = shortName == null ? statName : shortName + "/" + statName; } pivotFighter.ShortName = shortName; ret.Add(pivotFighter); } } } return(ret); }
public void AdjustRingTest() { FighterStats f1 = GetFighterStats(); f1.Agility = 18; FighterStats f2 = GetFighterStats(); FighterRoundStats frs1 = GetFighterRoundStats(f1, FightingStyle.Ring); FighterRoundStats frs2 = GetFighterRoundStats(f2, FightingStyle.None); frs1.AdjustRing(frs2); FighterStats expected = f1.Copy(); expected.Agility = 22; Assert.AreEqual(expected, frs1.AdjustedStats); Assert.AreEqual(1, frs1.AdditionalFatigue); }
public void AdjustFeintTest() { FighterStats f1 = GetFighterStats(); f1.Speed = 20; FighterStats f2 = GetFighterStats(); FighterRoundStats frs1 = GetFighterRoundStats(f1, FightingStyle.Feint); FighterRoundStats frs2 = GetFighterRoundStats(f2, FightingStyle.None); frs1.AdjustFeint(frs2); FighterStats expected = f1.Copy(); expected.Speed = 25; Assert.AreEqual(expected, frs1.AdjustedStats); Assert.AreEqual(1, frs1.AdditionalFatigue); }
public void AdjustInsideTest() { FighterStats f1 = GetFighterStats(); f1.Strength = 20; FighterStats f2 = GetFighterStats(); FighterRoundStats frs1 = GetFighterRoundStats(f1, FightingStyle.Inside); FighterRoundStats frs2 = GetFighterRoundStats(f2, FightingStyle.None); frs1.AdjustInside(frs2); FighterStats expected = f1.Copy(); expected.Strength = 25; Assert.AreEqual(expected, frs1.AdjustedStats); Assert.AreEqual(1.1, frs2.DamageAdjustment); }
public static bool RoundMatchesExpectations(Data.Round round, FighterStats f1Stats, FighterStats f2Stats, bool skipCuts, double threshold = 0) { List <CutBase> cuts1 = skipCuts ? new List <CutBase>() : round.First.GetCutsForDataRound(); List <CutBase> cuts2 = skipCuts ? new List <CutBase>() : round.Second.GetCutsForDataRound(); RoundDamage rd = CalculateDamageForDataRound(round, f1Stats, f2Stats, cuts1, true); if (!IsDamageEqual(round.First, rd, threshold)) { return(false); } RoundDamage rd2 = CalculateDamageForDataRound(round, f2Stats, f1Stats, cuts2, false); if (!IsDamageEqual(round.Second, rd2, threshold)) { return(false); } return(true); }
public static void ApplyEffects(FighterStats boss, FighterStats player, List <Effect> activeEffects) { for (int i = 0; i < activeEffects.Count; i++) { var effect = activeEffects[i]; boss.Hp -= effect.Damage; player.Mana += effect.Mana; effect.Duration--; if (effect.Duration == 0) { // Spell has expired player.Armor -= effect.Armor; activeEffects.RemoveAt(i); i--; } } }
void Start() { fighterStats = new List <FighterStats>(); GameObject hero = GameObject.FindGameObjectWithTag("Hero"); FighterStats currentHeroStats = hero.GetComponent <FighterStats>(); currentHeroStats.CalculateNextTurn(0); fighterStats.Add(currentHeroStats); GameObject enemy = GameObject.FindGameObjectWithTag("Enemy"); FighterStats currentEnemyStats = enemy.GetComponent <FighterStats>(); currentEnemyStats.CalculateNextTurn(0); fighterStats.Add(currentEnemyStats); fighterStats.Sort(); NextTurn(); }
public void AdjustRopesBelow8Test() { FighterStats f1 = GetFighterStats(); f1.Agility = 24; FighterStats f2 = GetFighterStats(); FighterRoundStats frs1 = GetFighterRoundStats(f1, FightingStyle.Ropes); FighterRoundStats frs2 = GetFighterRoundStats(f2, FightingStyle.Ropes); FighterStats expected = f1.Copy(); expected.Agility = 23; frs1.AdjustRopes(frs2); Assert.AreEqual(expected, frs1.AdjustedStats); expected = f2.Copy(); expected.Agility = 8; Assert.AreEqual(expected, frs2.AdjustedStats); }
public static void Main() { var nums = AOC.ParseInts(File.ReadAllText(@"..\..\inputs\22.txt")); // var bossStats = new FighterStats(14, 8, 0, 0); var bossStats = new FighterStats(nums[0], nums[1], 0, 0); var spells = new List <Spell> { new Spell("Magic missile", 53, 4, 0, null), // Magic missile new Spell("Drain", 73, 2, 2, null), // Drain new Spell("Shield", 113, 0, 0, new Effect { ID = 1, Duration = 6, Armor = 7 }), // Shield new Spell("Poison", 173, 0, 0, new Effect { ID = 2, Duration = 6, Damage = 3 }), // Poison new Spell("Recharge", 229, 0, 0, new Effect { ID = 3, Duration = 5, Mana = 101 }), // Recharge }; Part1(bossStats, spells); Part2(bossStats, spells); }
public void AdjustOutsideTest() { FighterStats f1 = GetFighterStats(); f1.Height = 18; FighterStats f2 = GetFighterStats(); FighterRoundStats frs1 = GetFighterRoundStats(f1, FightingStyle.Outside); FighterRoundStats frs2 = GetFighterRoundStats(f2, FightingStyle.None); frs1.AdjustOutside(frs2); FighterStats expected = f1.Copy(); expected.Agility = 12.5; expected.Speed = 12.5; expected.Height = 21; Assert.AreEqual(expected, frs1.AdjustedStats); FighterTactics tactics = frs1.Plan.Copy(); tactics.Power = 6.8; Assert.AreEqual(tactics, frs1.AdjustedTactics); }