public FighterEntry GetNearestAlly(Func <FighterEntry, bool> filter = null) { MapPoint charMp = MapPoint.FromCellId(PlayedFighter.CellId), allyMp; int distance = -1, tempDistance; FighterEntry ally = null; foreach (var allyEntry in filter == null ? Allies : Allies.Where(f => filter(f))) { if (!allyEntry.Alive) { continue; } allyMp = MapPoint.FromCellId(allyEntry.CellId); tempDistance = charMp.DistanceToCell(allyMp); if (distance == -1 || tempDistance < distance) { distance = tempDistance; ally = allyEntry; } } return(ally); }
public FighterEntry GetNearestEnnemy(short cellId = -1, Func <FighterEntry, bool> filter = null) { MapPoint charMp = MapPoint.FromCellId(cellId == -1 ? PlayedFighter.CellId : cellId), ennemyMp; int distance = -1, tempDistance; FighterEntry ennemy = null; foreach (var ennemyEntry in filter == null ? Ennemies : Ennemies.Where(f => filter(f))) { if (!ennemyEntry.Alive) { continue; } ennemyMp = MapPoint.FromCellId(ennemyEntry.CellId); tempDistance = charMp.DistanceToCell(ennemyMp); if (distance == -1 || tempDistance < distance) { distance = tempDistance; ennemy = ennemyEntry; } } return(ennemy); }
private static double GetTackleRatio(FighterEntry actor, FighterEntry tackler) { var evade = Math.Max(0, actor.Stats.TackleEvade); var block = Math.Max(0, tackler.Stats.TackleBlock); return(((double)evade + 2) / ((double)block + 2) / 2); }
private static bool CanBeTackled(FightGame fight, FighterEntry actor) { if (actor.Stats.InvisibilityState != 3) { return(false); } // TODO: Add carried condition if (fight.HasState(96) || fight.HasState(6)) { return(false); } return(true); }
private async Task <SpellCastingResults> MoveToCastSimpleSpell(Spell spell, FighterEntry target) { // We'll move to cast the spell (if we can) with the least number of MP possible KeyValuePair <short, MoveNode>?node = null; int pmUsed = 99; foreach (var kvp in FightsPathfinder.GetReachableZone(_account.Game.Fight, _account.Game.Map.Data, _account.Game.Fight.PlayedFighter.CellId)) { if (!kvp.Value.Reachable) { continue; } // Only choose the safe paths // TODO: Maybe in the futur try to cast the spell even with tackle cost, in a LanguageManager.Translate("66") way of course if (kvp.Value.Path.Ap > 0 || kvp.Value.Path.Mp > 0) { continue; } if (spell.HandToHand && !_account.Game.Fight.IsHandToHandWithAnEnnemy(kvp.Key)) { continue; } if (_account.Game.Fight.CanLaunchSpell(spell.SpellId, kvp.Key, target.CellId) != SpellInabilityReasons.NONE) { continue; } if (kvp.Value.Path.Reachable.Count <= pmUsed) { node = kvp; pmUsed = kvp.Value.Path.Reachable.Count; } } if (node != null) { _account.Logger.LogDebug(LanguageManager.Translate("52"), LanguageManager.Translate("63", node.Value.Key, spell.SpellName)); await _account.Game.Managers.Movements.MoveToCellInFight(node); return(SpellCastingResults.MOVED); } return(SpellCastingResults.NOT_CASTED); }
private static bool CanBeTackler(FighterEntry tackler, FighterEntry actor) { if (tackler == null || actor == null) { return(false); } if (!tackler.Alive || tackler.Stats.InvisibilityState != 3) { return(false); } if (tackler.Team == actor.Team) { return(false); } return(true); }
private bool IsResistanceGood(Spell spell, FighterEntry fighter) { switch (spell.Resistance) { case SpellResistances.NEUTRAL: return(fighter.Stats.NeutralElementResistPercent <= spell.ResistanceValue); case SpellResistances.EARTH: return(fighter.Stats.EarthElementResistPercent <= spell.ResistanceValue); case SpellResistances.FIRE: return(fighter.Stats.FireElementResistPercent <= spell.ResistanceValue); case SpellResistances.WIND: return(fighter.Stats.AirElementResistPercent <= spell.ResistanceValue); default: // Water return(fighter.Stats.WaterElementResistPercent <= spell.ResistanceValue); } }
public FighterEntry GetWeakestAlly() { int lp = -1; FighterEntry ally = null; foreach (var allyEntry in Allies) { if (!allyEntry.Alive) { continue; } if (lp == -1 || allyEntry.LifePercent < lp) { lp = allyEntry.LifePercent; ally = allyEntry; } } return(ally); }
public FighterEntry GetWeakestEnnemy() { int lp = -1; FighterEntry ennemy = null; foreach (var ennemyEntry in Ennemies) { if (!ennemyEntry.Alive) { continue; } if (lp == -1 || ennemyEntry.LifePercent < lp) { lp = ennemyEntry.LifePercent; ennemy = ennemyEntry; } } return(ennemy); }