/// <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); }
/// <summary> /// Returns the target associated to a spell. /// </summary> private string GetTargetAssociatedTo(BSpell spell) { int id = spells[spell]; if (id == -1) { return(""); } foreach (KeyValuePair <string, int> pair in targets) { if (pair.Value == id) { return(pair.Key); } } return(""); }
/// <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 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> /// 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; }
/// <summary> /// Parse a line and fill the differents fields /// </summary> private void ParseLine(string line) { int i = -1; try { line = line.Trim(); switch (m_flag) { case "<Spells>": i = line.IndexOf('='); if (i != -1) { string[] splitted = line.Split('='); i = Int32.Parse(splitted[1]); line = splitted[0]; } BSpell spell = new BSpell(GetSpellIdFromName(line), line); spells.Add(spell, i); SpellsCondition.Add(spell, m_cond); break; case "<Targets>": i = line.IndexOf('='); if (i != -1) { string[] splitted = line.Split('='); i = Int32.Parse(splitted[1]); line = splitted[0]; } targets.Add(line, i); TargetsCondition.Add(line, m_cond); break; case "<Strategy>": i = line.IndexOf('='); if (i != -1) { string[] splitted = line.Split('='); i = Int32.Parse(splitted[1]); line = splitted[0]; } TacticEnum tactic = (TacticEnum)Enum.Parse(typeof(TacticEnum), line); if (Enum.IsDefined(typeof(TacticEnum), tactic) | tactic.ToString().Contains(",")) { strategy.Add(tactic, i); } else { throw new Exception("AI Script : Invalid strategy at line : " + line); } break; case "<Position>": PlacementEnum position = (PlacementEnum)Enum.Parse(typeof(PlacementEnum), line); if (Enum.IsDefined(typeof(PlacementEnum), position) | position.ToString().Contains(",")) { positions.Add(position); } else { throw new Exception("AI Script : Invalid position at line : " + line); } break; case "<Challenges>": ChallengeEnum challenge = (ChallengeEnum)Enum.Parse(typeof(ChallengeEnum), line); if (Enum.IsDefined(typeof(ChallengeEnum), challenge) | challenge.ToString().Contains(",")) { challenges.Add(challenge); } else { throw new Exception("AI Script : Invalid challenge at line : " + line); } break; } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
/// <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 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> /// Parse a line and fill the differents fields /// </summary> private void ParseLine(string line) { int i = -1; try { line = line.Trim(); switch (m_flag) { case "<Spells>": i = line.IndexOf('='); if (i != -1) { string[] splitted = line.Split('='); i = Int32.Parse(splitted[1]); line = splitted[0]; } BSpell spell = new BSpell(GetSpellIdFromName(line), line); spells.Add(spell, i); SpellsCondition.Add(spell, m_cond); break; case "<Targets>": i = line.IndexOf('='); if (i != -1) { string[] splitted = line.Split('='); i = Int32.Parse(splitted[1]); line = splitted[0]; } targets.Add(line, i); TargetsCondition.Add(line, m_cond); break; case "<Strategy>": i = line.IndexOf('='); if (i != -1) { string[] splitted = line.Split('='); i = Int32.Parse(splitted[1]); line = splitted[0]; } TacticEnum tactic = (TacticEnum)Enum.Parse(typeof(TacticEnum), line); if (Enum.IsDefined(typeof(TacticEnum), tactic) | tactic.ToString().Contains(",")) strategy.Add(tactic, i); else throw new Exception("AI Script : Invalid strategy at line : " + line); break; case "<Position>": PlacementEnum position = (PlacementEnum)Enum.Parse(typeof(PlacementEnum), line); if (Enum.IsDefined(typeof(PlacementEnum), position) | position.ToString().Contains(",")) positions.Add(position); else throw new Exception("AI Script : Invalid position at line : " + line); break; case "<Challenges>": ChallengeEnum challenge = (ChallengeEnum)Enum.Parse(typeof(ChallengeEnum), line); if (Enum.IsDefined(typeof(ChallengeEnum), challenge) | challenge.ToString().Contains(",")) challenges.Add(challenge); else throw new Exception("AI Script : Invalid challenge at line : " + line); break; } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
/// <summary> /// Returns the target associated to a spell. /// </summary> private string GetTargetAssociatedTo(BSpell spell) { int id = spells[spell]; if (id == -1) return ""; foreach (KeyValuePair<string,int> pair in targets) { if (pair.Value == id) return pair.Key; } return ""; }