public AnalyticModule(Bot m, IWebDriver b) : base(m,b) { format = "ou"; myTeam = new List<BattlePokemon>(); enemyTeam = new List<BattlePokemon>(); errormon = new BattlePokemon(Global.lookup("error")); currentActive = errormon; turnsSpentSleepTalking = 0; // lastMove = moveLookup("error"); }
public static IEnumerable<BattlePokemon> GetTargetablePokemon(IEnumerable<BattlePokemon> allPokemon, BattlePokemon user, TargetType target) { if (target == TargetType.SingleTarget || target == TargetType.MultiTarget) throw new InvalidOperationException("Collection target types cannot be used as a target description."); var userPos = user.Position; switch (target) { case TargetType.Self: return allPokemon.Where(p => p.Position == userPos); case TargetType.OneAdjacentTarget: case TargetType.AllAdjacentTargets: return allPokemon.Where(p => p.Position != userPos && Abs(p.Position.X - userPos.X) == 1); case TargetType.OneAdjacentFoe: case TargetType.AllAdjacentFoes: return allPokemon.Where(p => p.Position != userPos && Abs(p.Position.X - userPos.X) == 1 && p.Position.Y != userPos.Y); case TargetType.OneAdjacentAlly: case TargetType.AllAdjacentAllies: return allPokemon.Where(p => p.Position != userPos && Abs(p.Position.X - userPos.X) == 1 && p.Position.Y == userPos.Y); case TargetType.OneTarget: case TargetType.AllTargets: return allPokemon.Where(p => p.Position != userPos); case TargetType.OneFoe: case TargetType.AllFoes: return allPokemon.Where(p => p.Position.Y != userPos.Y); case TargetType.OneAlly: case TargetType.AllAllies: return allPokemon.Where(p => p.Position != userPos && p.Position.Y == userPos.Y); case TargetType.AllOwn: return allPokemon.Where(p => p.Position.Y == userPos.Y); case TargetType.All: default: return allPokemon; } }
public override bool ExecuteSecondaryEffect(BattlePokemon user, BattlePokemon target) { return(Battle.ActiveBattle.ChangeStat(target, PokemonStat.Speed, PokemonStatChange.Decrease)); }
public HornAttackAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public override void ShowAnimation(BattlePokemon user, BattlePokemon target) { // TODO: animation }
public BellyDrumAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
protected bool HasNoEffect(BattlePokemon defender) { return(GetTypeMatchupMultiplier(defender) == 0f); }
public FurySwipesAnimation(BattlePokemon user, BattlePokemon target, int hitAmount) : base(user, target) { _hitAmount = hitAmount; }
public override void ShowAnimation(BattlePokemon user, BattlePokemon target) { var animation = new FlyAnimation(user, target); Battle.ActiveBattle.AnimationController.ShowAnimationAndWait(animation); }
private bool battleAnalytic(ref BattlePokemon active, BattlePokemon enemy, ref int turn) { //Extra check to make sure we pick a lead. //Possibly redundant if (enemy == null) { if (checkSwitch()) { browser.FindElement(By.CssSelector ("button[value='" + pickPokeRandomly().ToString() + "'][name='chooseSwitch']")); //todo change this to analytic pick } else return false; } if (checkBattleEnd()) { return true; } //Switch if fainted else if (checkSwitch()) { active = pickPokeAnalytic(enemy,true); if (active == null) { cwrite("Can't find new pokemon, unable to continue.", "[ERROR]", COLOR_ERR); return true; } return false; } //Preemptively switch out of bad situations else if (needSwitch(active, enemy)) { cwrite("I'm switching out.", "Turn " + turn.ToString(), COLOR_BOT); wait(); BattlePokemon temp = pickPokeAnalytic(enemy,false); if (temp == null) { cwrite("Couldn't pick a pokemon. Going with moves instead.", "[!]", COLOR_WARN); pickMoveAnalytic(active, enemy); } else { active = temp; } turn++; return false; } else if (checkMove()) { //for now, automatically activate mega if (elementExists(By.Name("megaevo"))) browser.FindElement(By.Name("megaevo")).Click(); //pick moves string mv = pickMoveAnalytic(active, enemy); //if we can't reasonably defeat the opponent, switch. if (mv == "needswitch") { cwrite("Unable to do enough damage this turn, switching out.", COLOR_BOT); BattlePokemon temp = pickPokeAnalytic(enemy, false); if (temp == null) { cwrite("Couldn't pick a pokemon.", "[!]", COLOR_WARN); } else { active = temp; turn++; } } else { cwrite("I'm picking move " + mv, "Turn " + turn.ToString(), COLOR_BOT); cwrite("Last Move: " + lastAction.ToString(), "DEBUG", COLOR_OK); turn++; } } else wait(); return false; }
/// <summary> /// Updates various information about the two active pokemon including status and health percentage. /// </summary> /// <param name="you"></param> /// <param name="opponent"></param> private void updateActiveStatuses (ref BattlePokemon you, ref BattlePokemon opponent) { var yourStats = waitFind(By.CssSelector("div[class='statbar rstatbar']"),1); if (yourStats == null) return; if (findWithin(yourStats, By.ClassName("par")) != null) you.status = Status.STATE_PAR; else if (findWithin(yourStats, By.ClassName("psn")) != null) you.status = Status.STATE_TOX; else if (findWithin(yourStats, By.ClassName("brn")) != null) you.status = Status.STATE_BRN; else if (findWithin(yourStats, By.ClassName("slp")) != null) you.status = Status.STATE_SLP; else if (findWithin(yourStats, By.ClassName("frz")) != null) you.status = Status.STATE_FRZ; else you.status = Status.STATE_HEALTHY; updateHealth(yourStats, ref you); updateModifiers(yourStats, ref you); var oppStats = waitFind(By.CssSelector("div[class='statbar lstatbar']")); if (oppStats == null) return; if (findWithin(oppStats, By.ClassName("par")) != null) opponent.status = Status.STATE_PAR; else if (findWithin(oppStats, By.ClassName("psn")) != null) opponent.status = Status.STATE_TOX; else if (findWithin(oppStats, By.ClassName("brn")) != null) opponent.status = Status.STATE_BRN; else if (findWithin(oppStats, By.ClassName("slp")) != null) opponent.status = Status.STATE_SLP; else if (findWithin(oppStats, By.ClassName("frz")) != null) opponent.status = Status.STATE_FRZ; else opponent.status = Status.STATE_HEALTHY; updateHealth(oppStats, ref opponent); updateModifiers(oppStats, ref opponent); }
private void updateModifiers(IWebElement statbar, ref BattlePokemon p) { IList<IWebElement> elems; try { elems = browser.FindElements(By.ClassName("good")); //for some stupid reason, the x isn't an 'x' but an '×' foreach (IWebElement e in elems) { if (e.Text.Contains("×")) p.updateBoosts(e.Text); } elems = browser.FindElements(By.ClassName("bad")); foreach (IWebElement e in elems) { if (e.Text.Contains("×")) p.updateBoosts(e.Text); } } catch { return; } }
private void updateHealth(IWebElement statbar, ref BattlePokemon p) { var elem = findWithin(statbar, By.ClassName("hptext")); if (elem != null) { string txt = elem.Text; int pct = 100; txt = txt.Trim('%'); int.TryParse(txt, out pct); p.setHealth(pct); } }
// don't request the user here cause the animation needs to be used where only the target is available public BindAnimation(BattlePokemon target) : base(null, target) { }
public FlashAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public override MoveCategory GetCategory(BattlePokemon user) => MoveCategory.Status;
protected float CalcDamage( BattlePokemon user, BattlePokemon defender) { float relativeLevel = CritFlag == true ? user.Level * 2f : user.Level; //checks for light screen float relativeDefenderSpecial = defender.Special; if (defender.IsLightScreenActive() && CritFlag == false) { relativeDefenderSpecial *= 2f; if (relativeDefenderSpecial > 1024f) { relativeDefenderSpecial = 1024f; } } //checks for reflect float relativeDefenderDefense = defender.Defense; if (defender.IsReflectActive() && CritFlag == false) { relativeDefenderDefense *= 2f; if (relativeDefenderDefense > 1024f) { relativeDefenderDefense = 1024f; } } //if crit on transformed pokemon, defender uses original stats in damage calculation if (defender.IsTransformActive() && CritFlag == true) { if (Category == Category.PHYSICAL) { return(DamageFormula(relativeLevel, user.Attack, defender.PokemonsDefenseStatWithModifiers, Power, getStab(user), EffectivenessMultiplier)); } else { return(DamageFormula(relativeLevel, user.Special, defender.PokemonsSpecialStatWithModifiers, Power, getStab(user), EffectivenessMultiplier)); } } else if (Category == Category.PHYSICAL) { return(DamageFormula(relativeLevel, user.Attack, relativeDefenderDefense, Power, getStab(user), EffectivenessMultiplier)); } else { return(DamageFormula(relativeLevel, user.Special, relativeDefenderSpecial, Power, getStab(user), EffectivenessMultiplier)); } }
//TODO: add moves to each BattlePokemon as they're encountered so that its not dependent on the web elements. private BattlePokemon pickPokeAnalytic(BattlePokemon enemy,bool offense) { //Loop over all pokemon int bestChoice = 1000; float highestdamage = (offense)? 0 : 5000f; for (int i = 1; i <= 5; i++) { if (!elementExists(By.CssSelector("button[value='" + i.ToString() + "'][name='chooseSwitch']"))) continue; BattlePokemon p = getPokemon(Global.lookup(PERSONAL_PRE+waitFind(By.CssSelector("button[value='" + i.ToString() + "'][name='chooseSwitch']"),1).Text),myTeam); if (bestChoice == 1000) bestChoice = i; //set a default value that can be accessed. float temp = 0; /* Depending if we are switching offensively or defensively compare either the potential * new mon's aptitude to KO the opponent (offensive) or the opponent's to KO ours (defensive). */ if (offense) { temp = enemy.matchup(p); temp += p.checkKOChance(enemy); if (temp > highestdamage) { highestdamage = temp; bestChoice = i; } } else { temp = p.matchup(enemy); temp += enemy.checkKOChance(p); if (temp < highestdamage) { highestdamage = temp; bestChoice = i; } } cwrite(p.mon.name + " value:" + temp, "[DEBUG]", COLOR_OK); } var b = waitFind(By.CssSelector("button[value='" + bestChoice.ToString() + "'][name=chooseSwitch]")); if (b != null) { BattlePokemon nextPoke = getPokemon(Global.lookup(b.Text), myTeam); b.Click(); return nextPoke; } return null; }
public override bool ShouldShowUsedText(BattlePokemon user) => user.IsFlying;
private string pickMoveAnalytic(BattlePokemon you, BattlePokemon enemy) { float[] rankings = new float[4]; //ranking of each move float bestMove = 0f; int choice = 1; const int MIN_RANK_OR_SWITCH = 10; //if no move ranks above this, consider switching. float risk = you.matchup(enemy); Move[] moves = getMoves(); for (int i = 0; i < 4; i++) { //Sleep talk if asleep, but never more than twice in a row. //Must use name.contains due to the way normal moves are added ( with (type) appended). if (moves[i].name.Contains("Sleep Talk") && you.status == Status.STATE_SLP && turnsSpentSleepTalking < 2) rankings[i] = MAX_MOVE_RANK; else rankings[i] = you.rankMove(moves[i], enemy, enemyTeam, lastAction); cwrite(moves[i].name + "'s rank: " + rankings[i].ToString(), "[DEBUG]", COLOR_OK); } for (int i = 0; i < 4; i++) { if (rankings[i] > bestMove) { bestMove = rankings[i]; choice = i + 1; } } //TODO: maybe make this chance based, increasing the chance if drops exist. if (bestMove < MIN_RANK_OR_SWITCH) return "needswitch"; //break any ties if (hasTies(rankings, bestMove)) choice = breakTies(moves, rankings, bestMove); //figure out what move we've chosen Move chosenMove = moves[choice - 1]; setLastBattleAction(chosenMove); if (chosenMove.name.Contains("Sleep Talk")) turnsSpentSleepTalking++; else turnsSpentSleepTalking = 0; if (elementExists(By.CssSelector("button[value='" + choice.ToString() + "'][name='chooseMove']"))) { browser.FindElement(By.CssSelector("button[value='" + choice.ToString() + "'][name='chooseMove']")).Click(); return chosenMove.name; } else return "no move"; }
protected void SetLastMoveAndMirrorMove(BattlePokemon user, BattlePokemon defender) { user.LastMoveUsed = this; defender.MirrorMove = this; }
private bool needSwitch(BattlePokemon you, BattlePokemon enemy) { if (isLastMon()) return false; //If the cancel button exists, we have either already made our switch, or have made a move this turn. if (elementExists(By.Name("undoChoice"))) return false; //if the pokemon is at low health, don't bother if (you.getHPPercentage() <= 25) return false; float tolerance = 2.5f; //Default tolerance based on type matchups. if (you.currentBoosts.total() > 0) tolerance += 1.5f; //enemy must be much more dangerous to consider switching with boosts. else if (you.currentBoosts.total() < 0) tolerance -= 1f; //more likely to switch if drops are present. if (you.matchup(enemy) > tolerance) return true; else return false; }
protected float GetTypeMatchupMultiplier(BattlePokemon defender) { return(TypeEffectiveness(Type, defender.Type1) * TypeEffectiveness(Type, defender.Type2)); }
public override void battle() { int turn = 1; wait(5000); //give battle time to load if (format == "randombattle") buildOwnTeam(); buildTeams(); //Select lead pickLead(); BattlePokemon active = null;//Global.lookup(lead); BattlePokemon enemy = null; do { wait(); if(format == "randombattle") buildTeams(); //if randombattle, check to see if any new pokemon have been revealed. enemy = getPokemon(getActivePokemon(),enemyTeam); active = getPokemon(updateYourPokemon(),myTeam); updateActiveStatuses(ref active,ref enemy); currentActive = active; battleAnalytic(ref active, enemy, ref turn); } while (activeState == State.BATTLE); myTeam.Clear(); enemyTeam.Clear(); }
public HydroPumpAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public override bool ExecuteSecondaryEffect(BattlePokemon user, BattlePokemon target) { return(Battle.ActiveBattle.ChangeStat(user, PokemonStat.Defense, PokemonStatChange.SharpIncrease)); }
public sealed override void ExecuteAndUpdate(BattlePokemon user, BattlePokemon defender) { Move move1 = defender.Move1; Move move2 = defender.Move2; Move move3 = defender.Move3; Move move4 = defender.Move4; OnUsed(); if (HasNoEffect(defender)) { OnNoEffect(); } else if (IsAMiss(user, defender)) { OnMissed(); defender.CheckForRageAndUpdateAttackStatStageIfNecessary(); } //success condition: else if (!defender.IsDisabled() && ( (move1 != null && move1.CurrentPP > 0) || (move2 != null && move2.CurrentPP > 0) || (move3 != null && move3.CurrentPP > 0) || (move4 != null && move4.CurrentPP > 0) ) ) { bool disabled = false; while (!disabled) { Random rng = new Random(); int rando = rng.Next(1, 5); if (rando == 1 && move1 != null && move1.CurrentPP > 0) { defender.ActivateDisable(move1, rng.Next(0, 7)); disabled = true; } else if (rando == 2 && move2 != null && move2.CurrentPP > 0) { defender.ActivateDisable(move2, rng.Next(0, 7)); disabled = true; } else if (rando == 3 && move3 != null && move3.CurrentPP > 0) { defender.ActivateDisable(move3, rng.Next(0, 7)); disabled = true; } else if (rando == 4 && move4 != null && move4.CurrentPP > 0) { defender.ActivateDisable(move4, rng.Next(0, 7)); disabled = true; } } } else { OnFailed(); defender.CheckForRageAndUpdateAttackStatStageIfNecessary(); } SetLastMoveAndMirrorMove(user, defender); SubtractPP(1); }
public override bool StatusMoveCheck(BattlePokemon user, BattlePokemon target) { return(MoveHelper.CheckStatChange(user, PokemonStat.Defense, PokemonStatChange.SharpIncrease)); }
public override bool ExecuteSecondaryEffect(BattlePokemon user, BattlePokemon target) { return(Battle.ActiveBattle.TryInflictConfusion(target)); }
public ReflectAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public override bool StatusMoveCheck(BattlePokemon user, BattlePokemon target) { return(MoveHelper.CheckStatChange(target, PokemonStat.Speed, PokemonStatChange.Decrease)); }
protected sealed override void Execute(BattlePokemon user) { OnUsed(); user.ActivateFocusEnergy(); SetLastMoveAndSubtractPP(user); }
protected void UpdateEffectivenessUpdateCritFlagAndDoDamage(BattlePokemon user, BattlePokemon defender) { UpdateEffectiveness(defender); UpdateCritFlag(user); float damageAmount = CalcDamage(user, defender); defender.Damage(damageAmount, Type); }
protected sealed override void Execute(BattlePokemon user) { OnUsed(); OnNoEffect(); SetLastMoveAndSubtractPP(user); }
public override bool HasAccuracyCheck(BattlePokemon user) => user.IsFlying;
public TackleAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public override bool ShouldConsumePP(BattlePokemon user) => user.IsFlying;
public SurfAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public ConfusionAnimation(BattlePokemon user, BattlePokemon target) : base(user, target) { }
public BattlePosition() { index = 0; trainer = null; pokemon = null; }