/// <summary> /// Returns the distance between our player and the specified fighter. Default is the nearest monster. /// </summary> public int DistanceFrom(BFighter fighter = null) { if (fighter == null) fighter = NearestMonster(); MapPoint CharacterPoint = new MapPoint(Fighter.CellId); MapPoint TestFighterPoint = new MapPoint(fighter.CellId); int dist = new SimplePathfinder(m_Account.MapData).FindPath(fighter.CellId, TestFighterPoint.CellId).Cells.Count(); dist += CharacterPoint.DistanceToCell(TestFighterPoint); return dist; }
/// <summary> /// Returns the nearest cell from the specified fighter. Default is the nearest monster. /// </summary> public int NearestCellFrom(BFighter fighter = null) { if (fighter == null) fighter = NearestMonster(); List<int> ReachableCells = GetReachableCells(); int CellId = -1; int SavDistance = -1; foreach (int ReachableCell in ReachableCells) { MapPoint ReachableCellPoint = new MapPoint(ReachableCell); int Distance = 0; Distance = (Distance + ReachableCellPoint.DistanceToCell(new MapPoint(fighter.CellId))); if (((SavDistance == -1) || (Distance < SavDistance))) { CellId = ReachableCell; SavDistance = Distance; } } return CellId; }
/// <summary> /// Add the summoner and its summon. /// </summary> public void AddSummon(int sourceId, BFighter summon) { Fighters.Add(summon); List<BFighter> summoned = new List<BFighter>(); if (m_Summons.ContainsKey(sourceId)) { m_Summons.TryGetValue(sourceId, out summoned); summoned.Add(summon); m_Summons.Remove(sourceId); m_Summons.Add(sourceId, summoned); } else { summoned.Add(summon); m_Summons.Add(sourceId, summoned); } }
/// <summary> /// Check if the target is targetable by the specified spell (with and without moving). /// </summary> /// <param name="spell">Spell to launch</param> /// <param name="target">Target</param> /// <returns>The cellId we need to move to. -1 if we can't use. 0 if we don't need to move.</returns> public int CanUseSpell(BSpell spell, BFighter target) { if (CanLaunchSpell(spell.SpellId) != SpellInabilityReason.None) { return -1; } // Use without move if (CanLaunchSpellOn(spell.SpellId, Fighter.CellId, target.CellId) == SpellInabilityReason.None) { return 0; } // Try with move int moveCell = -1; int distance = -1; foreach (int cell in GetReachableCells()) { if (CanLaunchSpellOn(spell.SpellId, cell, target.CellId, true) == SpellInabilityReason.None) { MapPoint characterPoint = new MapPoint(cell); int tempDistance = characterPoint.DistanceToCell(new MapPoint(target.CellId)); if (tempDistance > distance || distance == -1) { distance = tempDistance; moveCell = cell; } } } return moveCell; }
public BFighter GetTarget(TeamEnum teamEnum__1) { BFighter target = null; switch (teamEnum__1) { case TeamEnum.Ally: target = null; break; case TeamEnum.EmptyCase: target = new BFighter(0,NearCell(),0,null,false,0,0,0,0,0); break; case TeamEnum.Enemy: target = NearestMonster(); break; case TeamEnum.Self: target = Fighter; break; } return target; }
/// <summary> /// CanUseSpell() vérifie si le sort peut être utilisé. /// </summary> /// <param name="spell">Sort à lancé</param> /// <param name="target">Cible</param> /// <returns>False si non, true si oui. </returns> public bool CanUseSpell(BSpell spell, BFighter target) { // Principally AP if (CanLaunchSpell(spell.SpellId) != SpellInabilityReason.None) { return false; } // Use without move if (CanLaunchSpell(spell.SpellId, Fighter.CellId, target.CellId) == SpellInabilityReason.None) { Account.Log(new BotTextInformation("No need to move maggle"), 5); return true; } // Try with move int moveCell = -1; int distance = -1; foreach (int cell in GetReachableCells()) { if (CanLaunchSpell(spell.SpellId, cell, target.CellId) == SpellInabilityReason.None) { MapPoint characterPoint = new MapPoint(cell); int tempDistance = characterPoint.DistanceToCell(new MapPoint(target.CellId)); if (tempDistance > distance || distance == -1) { distance = tempDistance; moveCell = cell; } } } if (moveCell != -1 && moveCell != Fighter.CellId) { MoveToCell(moveCell); Account.Log(new BotTextInformation("CanUseSpellWithMove!"), 5); return true; } // Can't use Account.Log(new ErrorTextInformation("CantUseSpell"), 5); return false; }
public void FightTurn() { m_Account.Log(new BotTextInformation("FightTurn"),5); try { if (GetFighters(true).Count > 0) { // Spells foreach (BSpell spell in m_Spells) { if (spell.Turns != TurnId & spell.Turns != -1) { continue; } m_Account.Log(new BotTextInformation("Sort validé"),5); //Relaunch for (int i = 0; i <= spell.Relaunch - 1; i++) { if (GetFighters(true).Count > 0) { if (DeadEnnemiInTurn > 0) { m_Account.Wait(Convert.ToInt32((DeadEnnemiInTurn + 1.5) * 1000), (DeadEnnemiInTurn + 2) * 1000); DeadEnnemiInTurn = 0; } BFighter target = null; if (spell.TargetName == "Nom du monstre") { target = GetTarget(spell.Target); } else { target = GetTarget(spell.TargetName); } m_Account.Log(new BotTextInformation("Cible en vue à la cellule " + target.CellId + " !"),5); //target = GetTarget(spell.Target); if (spell.SpellId == 413 ) { if (target.LifePoints / target.MaxLifePoints * 100 <= spell.TargetLife && GetFighters(true).Count() < 2) { m_Account.Log(new BotTextInformation("It's time to capture ! POKEBALL GOOOOOOOOOO"),5); LaunchSpell(spell.SpellId, Fighter.CellId); spell.LastTurn = TurnId; PerformAutoTimeoutFight(1000); EndTurn(); return; } else break; } if (target.LifePoints / target.MaxLifePoints * 100 <= spell.TargetLife) { if (m_Conf.Tactic == TacticEnum.Immobile) { if (CanLaunchSpell(spell.SpellId) == SpellInabilityReason.None && CanLaunchSpell(spell.SpellId, Fighter.CellId, target.CellId) == SpellInabilityReason.None) { m_Account.Log(new BotTextInformation("CanLaunchSpell ! "),5); LaunchSpell(spell.SpellId, target.CellId); spell.LastTurn = TurnId; } else { break; } } else if (CanUseSpell(spell, target)) { m_Account.Log(new BotTextInformation("CanUseSpell ! "),5); LaunchSpell(spell.SpellId, target.CellId); spell.LastTurn = TurnId; } else { break; } PerformAutoTimeoutFight(700); } } } } NearMonster = NearestMonster(); if (NearMonster == null) { return; } // EndMove if (Fighter.MovementPoints > 0 && m_Conf.Tactic != TacticEnum.Immobile) { int distance = new MapPoint(Fighter.CellId).DistanceToCell(new MapPoint(NearMonster.CellId)); if (m_Conf.Tactic == TacticEnum.Fuyard) { if (distance > m_Conf.FarCells) { MoveToCell(NearCell()); } else { MoveToCell(FarCell()); } } else if (m_Conf.Tactic == TacticEnum.Barbare && !IsHandToHand()) MoveToCell(NearCell()); m_Account.Log(new BotTextInformation("EndMove"),5); //else if (!IsHandToHand()) //{ // Account.Game.Fight.MoveToCell(NearCell()); //} } PerformAutoTimeoutFight(700); EndTurn(); } } catch (Exception ex) { m_Account.Log(new ErrorTextInformation(ex.Message),0); } }
public bool CanUseSpell(BSpell spell, BFighter target) { // Principally AP if (CanLaunchSpell(spell.SpellId) != SpellInabilityReason.None) { return false; } // Use without move if (CanLaunchSpell(spell.SpellId, Fighter.CellId, target.CellId) == SpellInabilityReason.None) { //if (spell.IsHandToHand && !IsHandToHand()) //{ // MapPoint characterPoint = new MapPoint(Account.Game.Fight.Fighter.CellId); // int tempDistance = characterPoint.DistanceToCell(new MapPoint(NearestMonster().CellId)); // if (tempDistance - 1 > Account.Game.Fight.Fighter.MovementPoints) // { // return false; // } //} //else if (spell.IsHandToHand && IsHandToHand()) //{ // Account.Log("No need to move maggle", LogType.DEBUG); // return true; //} //else if (!spell.IsHandToHand) //{ m_Account.Log(new BotTextInformation("No need to move maggle"),5); return true; //} } // Try with move int moveCell = -1; int distance = -1; foreach (int cell in GetReachableCells()) { //if (spell.IsHandToHand) //{ // MapPoint characterPoint = new MapPoint(cell); // int tempDistance = characterPoint.DistanceToCell(new MapPoint(target.CellId)); // if (IsHandToHand(cell) && (tempDistance < distance || distance == -1)) // { // distance = tempDistance; // moveCell = cell; // } //} if (CanLaunchSpell(spell.SpellId, cell, target.CellId) == SpellInabilityReason.None) { MapPoint characterPoint = new MapPoint(cell); int tempDistance = characterPoint.DistanceToCell(new MapPoint(target.CellId)); if (tempDistance > distance || distance == -1) { distance = tempDistance; moveCell = cell; } } } if (moveCell != -1 && moveCell != Fighter.CellId) { MoveToCell(moveCell); m_Account.Log(new BotTextInformation("CanUseSpellWithMove!"),5); return true; } // Can't use m_Account.Log(new ErrorTextInformation("CantUseSpell"),5); return false; }
/// <summary> /// Get the spell to launch and the associated target. /// </summary> public Dictionary<BSpell, BFighter> GetPlan() { Dictionary<BSpell, BFighter> result = new Dictionary<BSpell, BFighter>(); foreach (KeyValuePair<BSpell,int> pair in spells) { string t = GetTargetAssociatedTo(pair.Key); if (t.StartsWith("#")) target = GetSpecialTarget(t); else if (t != "") target = GetTargetFromName(t); else target = GetTarget(); List<FightCondition> cond = SpellsCondition[pair.Key]; if (CheckConditions(cond)) { result.Add(pair.Key, target); } else continue; } return result; }
/// <summary> /// Returns the target. /// </summary> private BFighter GetTarget() { BFighter target = null; foreach (KeyValuePair<string, int> pair in targets) { List<FightCondition> cond = TargetsCondition[pair.Key]; if (!CheckConditions(cond)) continue; else { if (pair.Key.StartsWith("#")) target = GetSpecialTarget(pair.Key); else if (pair.Key != "") target = GetTargetFromName(pair.Key); } } if (target == null) target = m_Account.FightData.NearestMonster(); return target; }
/// <summary> /// Convert a special target to a fighter. /// </summary> private BFighter GetSpecialTarget(string target) { target = target.Replace("#", "").Replace(" ", "").Trim(); switch (target) { case "NearestMonster": return m_Account.FightData.NearestMonster(); case "WeakestMonster": return m_Account.FightData.WeakestMonster(); case "Self": return m_Account.FightData.Fighter; case "FreeCell": return new BFighter(0, m_Account.FightData.NearestCellFrom(), 0, null, false, 0, 0, 0, 0, 0); case "NearestAlly": return m_Account.FightData.NearestAlly(); case "WeakestAlly": return m_Account.FightData.WeakestAlly(); case "Summon": return new BFighter(0, m_Account.FightData.NearestCellFrom(m_Account.FightData.Fighter), 0, null, false, 0, 0, 0, 0, 0); } return null; }