/// <summary> /// Returns the cells reachable by the player. /// </summary> private List <int> GetReachableCells() { // TODO : Manage challenge (zombie) List <int> listWalkableCells = new List <int>(); MapPoint point = new MapPoint(Fighter.CellId); int movementPoints = Fighter.MovementPoints; for (int i = 0; i < 600; i++) { if (IsCellWalkable(i)) { MapPoint cellPoint = new MapPoint(i); if (cellPoint.DistanceToCell(point) <= movementPoints) { listWalkableCells.Add(i); } } } if (listWalkableCells.Contains(point.CellId)) { listWalkableCells.Add(point.CellId); } return(listWalkableCells); }
internal SimpleCellInfo(MapData MapData, MapPoint OriginPoint, SimpleCellInfo class13_1, MapPoint mapPoint_2) { this.int_0 = 0; this.int_1 = 0; this.v_OriginPoint = OriginPoint; this.class13_0 = class13_1; this.int_1 = (mapPoint_2.DistanceToCell(OriginPoint) * 5); this.int_0 = (class13_1.int_0 + 10); if (((class13_1.class13_0 != null))) { int num2 = class13_1.class13_0.v_OriginPoint.OrientationTo(class13_1.v_OriginPoint); int num3 = class13_1.v_OriginPoint.OrientationTo(OriginPoint); int num = Math.Abs(Convert.ToInt32((num2 - num3))); if ((num != 0)) { this.int_0 = (this.int_0 + 5); if (((num != 1) && (num != 7))) { this.int_0 = (this.int_0 + 50); } } if ((MapData.Data.Cells[OriginPoint.CellId].Speed == 2)) { this.int_0 = (this.int_0 - 8); } } }
private BFighter NearestMonster() { MapPoint CharacterPoint = new MapPoint(this.Fighter.CellId); BFighter Fighterr = null; int SavDistance = -1; foreach (BFighter TestFighter in Fighters) { if (TestFighter.TeamId == Fighter.TeamId || TestFighter.IsAlive == false) { continue; } MapPoint TestFighterPoint = new MapPoint(TestFighter.CellId); int dist = new SimplePathfinder(m_Account.Map.Data).FindPath(CharacterPoint.CellId, TestFighterPoint.CellId).Cells.Count(); dist += CharacterPoint.DistanceToCell(TestFighterPoint); if (((dist < SavDistance) || (SavDistance == -1)) && TestFighter != this.Fighter) { SavDistance = dist; Fighterr = TestFighter; } } if (Fighterr == null) { return(null); } return(Fighterr); }
public List <int> GetReachableCells() { var listWalkableCells = new List <int>(); var point = new MapPoint(Fighter.CellId); int movementPoints = Fighter.MovementPoints; for (var i = 0; i < 600; i++) { if (IsCellWalkable(i)) { var cellPoint = new MapPoint(i); if (cellPoint.DistanceToCell(point) <= movementPoints) { listWalkableCells.Add(i); } } } if (listWalkableCells.Contains(point.CellId)) { listWalkableCells.Add(point.CellId); } return(listWalkableCells); }
public int CanUseSpell(int spellId, IFighter target) { if (CanLaunchSpell(spellId) != SpellInabilityReason.None) { return(-1); } if (CanLaunchSpellOn(spellId, Fighter.CellId, target.CellId) == SpellInabilityReason.None) { return(0); } var moveCell = -1; var distance = -1; foreach (var cell in GetReachableCells()) { if (CanLaunchSpellOn(spellId, cell, target.CellId, true) != SpellInabilityReason.None) { continue; } var characterPoint = new MapPoint(cell); var tempDistance = characterPoint.DistanceToCell(new MapPoint(target.CellId)); if (tempDistance <= distance && distance != -1) { continue; } distance = tempDistance; moveCell = cell; } return(moveCell); }
public bool IsHandToHand() { var characterPoint = new MapPoint(Fighter.CellId); var targetPoint = new MapPoint(NearestMonster().CellId); return(characterPoint.DistanceToCell(targetPoint) <= 1); }
internal SimpleCellInfo(Gamedata.D2p.Map MapData, MapPoint OriginPoint, SimpleCellInfo class13_1, MapPoint mapPoint_2) { int_0 = 0; int_1 = 0; v_OriginPoint = OriginPoint; class13_0 = class13_1; int_1 = mapPoint_2.DistanceToCell(OriginPoint) * 5; int_0 = class13_1.int_0 + 10; if (class13_1.class13_0 != null) { var num2 = class13_1.class13_0.v_OriginPoint.OrientationTo(class13_1.v_OriginPoint); var num3 = class13_1.v_OriginPoint.OrientationTo(OriginPoint); var num = Math.Abs(Convert.ToInt32(num2 - num3)); if (num != 0) { int_0 = int_0 + 5; if (num != 1 && num != 7) { int_0 = int_0 + 50; } } if (MapData.Cells[OriginPoint.CellId].Speed == 2) { int_0 = int_0 - 8; } } }
private MapPoint getClosestPortal(MapPoint refMapPoint, List <MapPoint> portals) { uint dist = 0; List <MapPoint> closests = new List <MapPoint>(); uint bestDist = BEST_DIST; foreach (var portal in portals) { dist = refMapPoint.DistanceToCell(portal); if (dist < bestDist) { closests.Clear(); closests.Add(portal); bestDist = dist; } else if (dist == bestDist) { closests.Add(portal); } } if (closests.Count == 0) { return(null); } if (closests.Count == 1) { return(closests[0]); } return(getBestNextPortal(refMapPoint, closests)); }
/// <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); }
private List <MapPoint> GetListPointAtGoodDistance(MapPoint characterPoint, MapPoint elementPoint, int weaponRange) { List <MapPoint> list = new List <MapPoint>(); int num = -1; int direction = 1; while (true) { int i = 0; while (i < weaponRange) { i += 1; MapPoint nearestCellInDirection = elementPoint.GetNearestCellInDirection(direction, i); if (nearestCellInDirection.IsInMap() && m_Account.Map.Data.IsWalkable(nearestCellInDirection.CellId)) { int num4 = characterPoint.DistanceToCell(nearestCellInDirection); if ((num == -1) || (num >= num4)) { if (num4 < num) { list.Clear(); } num = num4; list.Add(nearestCellInDirection); } break; } } direction = (direction + 2); if (direction > 7) { return(list); } } }
private bool MoveToCell(int cellId) { if (cellId != Fighter.CellId) { if (!(IsCellWalkable(cellId))) { int num = -1; int num2 = 5000; MapPoint point = new MapPoint(Fighter.CellId); MapPoint point2 = new MapPoint(cellId); int direction = 1; while (true) { MapPoint nearestCellInDirection = point2.GetNearestCellInDirection(direction, 1); if (IsCellWalkable(nearestCellInDirection.CellId)) { int num4 = point.DistanceToCell(nearestCellInDirection); if (num4 < num2) { num2 = num4; num = nearestCellInDirection.CellId; } } direction = (direction + 2); if (direction > 7) { if (num == -1) { return(false); } cellId = num; break; } } } SimplePathfinder pathfinder = new SimplePathfinder((BlueSheep.Data.D2p.Map)m_Account.Map.Data); pathfinder.SetFight(Fighters, Fighter.MovementPoints); MovementPath path = pathfinder.FindPath(Fighter.CellId, cellId); if (path != null) { List <UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path); //Account.Network.SendToServer(new GameMapMovementRequestMessage(serverMovement.ToList().Select<uint, short>(ui => (short)ui).ToArray(), Account.Game.Map.Id)); using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.ToList().Select <uint, short>(ui => (short)ui).ToArray(), m_Account.Map.Id); msg.Serialize(writer); writer.Content = m_Account.HumanCheck.hash_function(writer.Content); MessagePackaging pack = new MessagePackaging(writer); pack.Pack((int)msg.ProtocolID); m_Account.SocketManager.Send(pack.Writer.Content); if (m_Account.DebugMode.Checked) { m_Account.Log(new BotTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0); } } return(true); } } return(false); }
public void StartPathfinding(MapPoint startP, MapPoint endP) { Start = startP; End = endP; StartX = startP.X; StartY = startP.Y; EndX = endP.X; EndY = endP.Y; StartPoint = new MapPoint(startP.X, startP.Y); EndPoint = new MapPoint(endP.X, endP.Y); AuxEndPoint = StartPoint; AuxEndX = StartPoint.X; AuxEndY = StartPoint.Y; DistanceToEnd = StartPoint.DistanceToCell(EndPoint); for (int y = -19; y <= MaxY; y++) { for (int x = 0; x <= MaxX; x++) { MapStatus.Add(new CellInfo(0, null, false, false, x, y)); } } OpenList = new List <OpenSquare>(); OpenSquare(StartY, StartX, null, 0, 0, false); }
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 List <int> GetReachableCells() { // TODO : Generate Losange form Fighter Point List <int> listCellulesMarchables = new List <int>(); MapPoint point = new MapPoint(Fighter.CellId); int movementPoints = Fighter.MovementPoints; for (int i = 0; i < 600; i++) { if (IsCellWalkable(i)) { MapPoint cellPoint = new MapPoint(i); if (cellPoint.DistanceToCell(point) <= movementPoints) { listCellulesMarchables.Add(i); } } } if (listCellulesMarchables.Contains(point.CellId)) { listCellulesMarchables.Add(point.CellId); } return(listCellulesMarchables); }
protected int DistanceFrom(IFighter fighter) { var characterPoint = new MapPoint(Fighter.CellId); var testFighterPoint = new MapPoint(fighter.CellId); var dist = new SimplePathfinder((API.Gamedata.D2p.Map)Account.Character.Map.Data) .FindPath(fighter.CellId, testFighterPoint.CellId).Cells.Count(); dist += characterPoint.DistanceToCell(testFighterPoint); return(dist); }
public IMonster NearestMonster() { var charMp = new MapPoint(Fighter.CellId); var distance = -1; IMonster rMonster = null; foreach (var monster in Monsters) { var monsterMp = new MapPoint(monster.CellId); if (distance != -1 && charMp.DistanceToCell(monsterMp) >= distance) { continue; } rMonster = monster; distance = charMp.DistanceToCell(monsterMp); } return(rMonster); }
/// <summary> /// Place the character according to the AI positioning. /// </summary> public void PlaceCharacter(List <int> PlacementCells) { m_error = 0; m_Account.Log(new BotTextInformation("Placement du personnage."), 5); try { PlacementEnum position = m_AI.GetPositioning(); int distance = -1; int cell = -1; Dictionary <int, int> cells = new Dictionary <int, int>(); foreach (int tempCell in PlacementCells) { int tempDistance = 0; MapPoint cellPoint = new MapPoint(Convert.ToInt32(tempCell)); foreach (BFighter fighter in m_Data.Fighters) { MapPoint fighterPoint = new MapPoint(fighter.CellId); tempDistance += cellPoint.DistanceToCell(fighterPoint); } switch (position) { case PlacementEnum.Eloigné: case PlacementEnum.Far: if (distance < tempDistance || distance == -1) { distance = tempDistance; cell = Convert.ToInt32(tempCell); } break; case PlacementEnum.Near: case PlacementEnum.Rapproché: if (distance > tempDistance || distance == -1 || tempDistance == 1) { distance = tempDistance; cell = Convert.ToInt32(tempCell); } break; } } if (cell != -1) { GameFightPlacementPositionRequestMessage msg = new GameFightPlacementPositionRequestMessage((ushort)cell); m_Account.SocketManager.Send(msg); } } catch (Exception ex) { m_Account.Log(new ErrorTextInformation(ex.Message), 0); } }
/// <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); }
public ICellMovement MoveToCellWithDistance(int cellId, int maxDistance, bool bool1) { MovementPath path = null; var savDistance = -1; var characterPoint = new MapPoint(_account.Character.CellId); var targetPoint = new MapPoint(cellId); foreach (var point in GetListPointAtGoodDistance(characterPoint, targetPoint, maxDistance)) { Pathfinder pathFinding = null; if (targetPoint.DistanceToCell(point) > maxDistance || targetPoint.X != point.X && targetPoint.Y != point.Y) { continue; } var distance = characterPoint.DistanceTo(point); if (savDistance != -1 && distance >= savDistance) { continue; } if (bool1) { if (Data.IsWalkable(point.CellId)) { goto Label_00A8; } continue; } if (!NothingOnCell(point.CellId)) { continue; } Label_00A8: pathFinding = new Pathfinder(_account.Character.Map); var path2 = pathFinding.FindPath(_account.Character.CellId, point.CellId); if (path2 == null) { continue; } path = path2; savDistance = distance; } if (path == null) { return(null); } var move = new CellMovement(_account, path); return(move); }
public bool CanUseWeapon(Cell cell, WeaponTemplate weapon) { bool result; if (!base.IsFighterTurn()) { result = false; } else { MapPoint mapPoint = new MapPoint(cell); result = ((ulong)mapPoint.DistanceToCell(this.Position.Point) <= (ulong)((long)weapon.WeaponRange) && (ulong)mapPoint.DistanceToCell(this.Position.Point) >= (ulong)((long)weapon.MinRange) && base.AP >= weapon.ApCost && base.Fight.CanBeSeen(cell, this.Position.Cell, false)); } return(result); }
public IMonster NearestMonster() { var charMp = new MapPoint(Fighter.CellId); var distance = -1; IMonster rMonster = null; foreach (var monster in Monsters.ToList()) { var monsterMp = new MapPoint(monster.CellId); if (monster.LifePoints == 0) { continue; } if (distance != -1 && charMp.DistanceToCell(monsterMp) >= distance) { continue; } rMonster = monster; distance = charMp.DistanceToCell(monsterMp); //Logger.Default.Log($"Closest Monster[{rMonster.Id}] has LifePoints[{rMonster.LifePoints}]"); } return(rMonster); }
public void PlaceCharacter() { m_Account.Log(new BotTextInformation("Placement du personnage"), 5); try { int distance = -1; int cell = -1; Dictionary <int, int> cells = new Dictionary <int, int>(); foreach (uint tempCell in PlacementCells) { int tempDistance = 0; MapPoint cellPoint = new MapPoint(Convert.ToInt32(tempCell)); foreach (BFighter fighter in Fighters) { MapPoint fighterPoint = new MapPoint(fighter.CellId); tempDistance += cellPoint.DistanceToCell(fighterPoint); } if (m_Conf.Placement == PlacementEnum.Eloigné) { if (distance < tempDistance || distance == -1) { distance = tempDistance; cell = Convert.ToInt32(tempCell); } } else if (m_Conf.Placement == PlacementEnum.Rapproché) { if (distance > tempDistance || distance == -1 || tempDistance == 1) { distance = tempDistance; cell = Convert.ToInt32(tempCell); } } } if (cell != -1) { GameFightPlacementPositionRequestMessage msg = new GameFightPlacementPositionRequestMessage((short)cell); m_Account.SocketManager.Send(msg); } } catch (Exception ex) { m_Account.Log(new ErrorTextInformation(ex.Message), 0); } }
public bool IsHandToHand(int cell = 0) { if (cell == 0) { cell = Fighter.CellId; } MapPoint characterPoint = new MapPoint(cell); MapPoint targetPoint = new MapPoint(NearestMonster().CellId); if (characterPoint.DistanceToCell(targetPoint) <= 1) { return(true); } return(false); }
public ICellMovement MoveToCell(int cellId) { if (cellId == Fighter.CellId) { return(null); } if (!IsCellWalkable(cellId)) { var num = -1; var num2 = 5000; var point = new MapPoint(Fighter.CellId); var point2 = new MapPoint(cellId); var direction = 1; while (true) { var nearestCellInDirection = point2.GetNearestCellInDirection(direction, 1); if (IsCellWalkable(nearestCellInDirection.CellId)) { var num4 = point.DistanceToCell(nearestCellInDirection); if (num4 < num2) { num2 = num4; num = nearestCellInDirection.CellId; } } direction += 2; if (direction <= 7) { continue; } if (num == -1) { return(null); } cellId = num; break; } } var pathfinder = new SimplePathfinder((API.Gamedata.D2p.Map)Account.Character.Map.Data); pathfinder.SetFight(Fighters, Fighter.MovementPoints); var path = pathfinder.FindPath(Fighter.CellId, cellId); return(path == null ? null : new CellMovement(Account, path)); }
/// <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); }
private int NearCell() { 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(NearMonster.CellId))); if (((SavDistance == -1) || (Distance < SavDistance))) { CellId = ReachableCell; SavDistance = Distance; } } return(CellId); }
private IEnumerable <MapPoint> GetListPointAtGoodDistance(MapPoint characterPoint, MapPoint elementPoint, int weaponRange) { var list = new List <MapPoint>(); var num = -1; var direction = 1; while (true) { var i = 0; while (i < weaponRange) { i += 1; var nearestCellInDirection = elementPoint.GetNearestCellInDirection(direction, i); if (!nearestCellInDirection.IsInMap() || !_account.Character.Map.Data.IsWalkable(nearestCellInDirection.CellId)) { continue; } var num4 = characterPoint.DistanceToCell(nearestCellInDirection); if (num == -1 || num >= num4) { if (num4 < num) { list.Clear(); } num = num4; list.Add(nearestCellInDirection); } break; } direction = direction + 2; if (direction > 7) { return(list); } } }
/// <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); }
private void MoveClose(IFighter target /*, EventHandler<CellMovementEventArgs> eventHandler*/) { var reachableCells = _account.Character.Fight.GetReachableCells(); var cellId = -1; var savDistance = -1; foreach (var cell in reachableCells) { var reachableCellPoint = new MapPoint(cell); var distance = 0; distance += reachableCellPoint.DistanceToCell(new MapPoint(target.CellId)); if (savDistance != -1 && distance >= savDistance) { continue; } cellId = cell; savDistance = distance; } var movement = _account.Character.Fight.MoveToCell(cellId); movement.MovementFinished += Movement_MovementFinished; movement.PerformMovement(); }