// Methods public static MovementPath GetClientMovement(List<UInt32> Keys) { MovementPath path = new MovementPath(); PathElement element = null; int num = 0; int num2 = 0; foreach (int num2_loopVariable in Keys) { num2 = num2_loopVariable; MapPoint point = new MapPoint((num2 & 4095)); PathElement item = new PathElement { Cell = point }; if ((num == 0)) { path.CellStart = point; } else { element.Orientation = element.Cell.OrientationTo(item.Cell); } if ((num == (Keys.Count - 1))) { path.CellEnd = point; } path.Cells.Add(item); element = item; num += 1; } return path; }
public MovementPath FindPath(int FromCell, int ToCell) { SimpleCellInfo class3 = null; this.MapPoint_FromCell = new MapPoint(FromCell); this.MapPoint_ToCell = new MapPoint(ToCell); SimpleCellInfo item = new SimpleCellInfo(this.MapPoint_FromCell); this.list_0.Add(item); Label_00BF: class3 = this.method_0(); if (class3 != null) { this.list_0.Remove(class3); this.list_1.Add(class3); if (class3.v_OriginPoint.CellId == ToCell) { return this.method_3(class3); } //INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#: // MapPoint point = null; foreach (MapPoint point in class3.method_0(this.IsInFight)) { if (Convert.ToBoolean(this.method_2(point.CellId))) { this.method_1(new SimpleCellInfo(this.MapData, point, class3, this.MapPoint_ToCell)); } } goto Label_00BF; } return null; }
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); } } }
// Methods internal SimpleCellInfo(MapPoint OriginPoint) { this.int_0 = 0; this.int_1 = 0; this.v_OriginPoint = OriginPoint; this.class13_0 = null; this.int_0 = 0; }
public int AdvancedOrientationTo(MapPoint point, bool b) { int num = (point.X - this.X); int num2 = (this.Y - point.Y); int num3 = Convert.ToInt32(Math.Round(Convert.ToDouble((Math.Floor(Convert.ToDouble(((Math.Acos((Convert.ToDouble(num) / Math.Sqrt((Math.Pow(Convert.ToDouble(num), 2) + Math.Pow(Convert.ToDouble(num2), 2))))) * 180) / 3.14159265358979))) * ((point.Y > this.Y) ? Convert.ToDouble(-1) : Convert.ToDouble(1)))))); if (b) { num3 = Convert.ToInt32(Math.Round(Convert.ToDouble(((Math.Round(Math.Floor(Convert.ToDouble((Convert.ToDouble(num3) / 90)))) * 2) + 1)))); } else { num3 = Convert.ToInt32(Math.Round(Convert.ToDouble((Math.Round(Math.Floor(Convert.ToDouble((Convert.ToDouble(num3) / 45)))) + 1)))); } if ((num3 < 0)) { num3 = (num3 + 8); } return num3; }
/// <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; }
/// <summary> /// Place the character according to the AI positioning. /// </summary> public void PlaceCharacter(List<short> 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 (short 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((short)cell); m_Account.SocketManager.Send(msg); } } catch (Exception ex) { m_Account.Log(new ErrorTextInformation(ex.Message),0); } }
public void ProcessPathfinding() { int actualX = 0; int actualY = 0; int speed = 0; int moveCost = 0; bool isDownRightEnd = false; bool isDownRightStart = false; bool isTopRightEnd = false; bool isTopRightStart = false; MapPoint actualPoint = null; int actualDistanceToEnd = 0; double heuristic = 0; uint square = 0; if (this.OpenList.Count > 0 && !(IsClosed(this.EndY, this.EndX))) { square = NearerSquare(); this.NowY = this.OpenList[(int)square].Y; this.NowX = this.OpenList[(int)square].X; this.PreviousCellId = (new MapPoint(this.NowX, this.NowY)).CellId; CloseSquare(this.NowY, this.NowX); for (actualY = this.NowY - 1; actualY <= this.NowY + 1; actualY++) { for (actualX = this.NowX - 1; actualX <= this.NowX + 1; actualX++) { if ((new MapPoint(actualX, actualY)).IsInMap()) { if (actualY >= this.MinY && actualY < this.MaxY && actualX >= this.MinX && actualX < this.MaxX && !(actualY == this.NowY && actualX == this.NowX) && ((this.AllowDiag) || actualY == this.NowY || actualX == this.NowX && ((AllowDiagCornering) || actualY == this.NowY || actualX == this.NowX || (PointMov(this.NowX, this.NowY, this.PreviousCellId, this.AllowTroughEntity)) || (PointMov(actualX, this.NowY, this.PreviousCellId, this.AllowTroughEntity))))) { if (!(!(PointMov(this.NowX, actualY, this.PreviousCellId, this.AllowTroughEntity)) && !(PointMov(actualX, this.NowY, this.PreviousCellId, this.AllowTroughEntity)) && !this.IsFighting && (this.AllowDiag))) { if (PointMov(actualX, actualY, this.PreviousCellId, this.AllowTroughEntity)) { if (!(IsClosed(actualY, actualX))) { if (actualX == this.EndX && actualY == this.EndY) { speed = 1; } else { speed = (int)GetCellSpeed((new MapPoint(actualX, actualY)).CellId, AllowTroughEntity); } moveCost = this.GetCellInfo(this.NowY, this.NowX).MovementCost + ((actualY == this.NowY || actualX == this.NowX) ? this.HVCost : this.DCost) * speed; if (AllowTroughEntity) { isDownRightEnd = actualX + actualY == this.EndX + this.EndY; isDownRightStart = actualX + actualY == this.StartX + this.StartY; isTopRightEnd = actualX - actualY == this.EndX - this.EndY; isTopRightStart = actualX - actualY == this.StartX - this.StartY; actualPoint = new MapPoint(actualX, actualY); if (!isDownRightEnd && !isTopRightEnd || !isDownRightStart && !isTopRightStart) { moveCost = moveCost + actualPoint.DistanceToCell(this.EndPoint); moveCost = moveCost + actualPoint.DistanceToCell(this.StartPoint); } if (actualX == this.EndX || actualY == this.EndY) { moveCost = moveCost - 3; } if ((isDownRightEnd) || (isTopRightEnd) || actualX + actualY == this.NowX + this.NowY || actualX - actualY == this.NowX - this.NowY) { moveCost = moveCost - 2; } if (actualX == this.StartX || actualY == this.StartY) { moveCost = moveCost - 3; } if ((isDownRightStart) || (isTopRightStart)) { moveCost = moveCost - 2; } actualDistanceToEnd = actualPoint.DistanceToCell(this.EndPoint); if (actualDistanceToEnd < this.DistanceToEnd) { if (actualX == this.EndX || actualY == this.EndY || actualX + actualY == this.EndX + this.EndY || actualX - actualY == this.EndX - this.EndY) { this.AuxEndPoint = actualPoint; this.AuxEndX = actualX; this.AuxEndY = actualY; this.DistanceToEnd = actualDistanceToEnd; } } } if (IsOpened(actualY, actualX)) { if (moveCost < this.GetCellInfo(actualY, actualX).MovementCost) { this.OpenSquare(actualY, actualX, new[] { this.NowY, this.NowX }, moveCost, 0, true); } } else { heuristic = Convert.ToDouble(this.HeuristicCost) * Math.Sqrt((this.EndY - actualY) * (this.EndY - actualY) + (this.EndX - actualX) * (this.EndX - actualX)); OpenSquare(actualY, actualX, new[] { this.NowY, this.NowX }, moveCost, heuristic, false); } } } } } } } } ProcessPathfinding(); } else { EndPathfinding(); } }
private double GetCellSpeed(int cellId, bool throughEntities) { BlueSheep.Data.D2p.Map data = MapData.Data; var speed = data.Cells[cellId].Speed; MapPoint cell = new MapPoint(cellId); if (throughEntities) { if (!(MapData.NoEntitiesOnCell(cellId))) { return 20; } if (speed >= 0) { return 1 + (5 - speed); } return 1 + (11 + Math.Abs(speed)); } var cost = 1.0D; MapPoint adjCell = null; if (!(MapData.NoEntitiesOnCell(cellId))) { cost += 0.3; } adjCell = new MapPoint(cell.X + 1, cell.Y); if (adjCell != null && !(MapData.NoEntitiesOnCell(adjCell.CellId))) { cost += 0.3; } adjCell = new MapPoint(cell.X, cell.Y + 1); if (adjCell != null && !(MapData.NoEntitiesOnCell(adjCell.CellId))) { cost += 0.3; } adjCell = new MapPoint(cell.X - 1, cell.Y); if (adjCell != null && !(MapData.NoEntitiesOnCell(adjCell.CellId))) { cost += 0.3; } adjCell = new MapPoint(cell.X, cell.Y - 1); if (adjCell != null && !(MapData.NoEntitiesOnCell(adjCell.CellId))) { cost += 0.3; } // todo // if (m_context.IsCellMarked(cell)) // cost += 0.2; return cost; }
public 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() && Data.IsWalkable(nearestCellInDirection.CellId)) { int dist = characterPoint.DistanceToCell(nearestCellInDirection); if ((num == -1) || (num >= dist)) { if (dist < num) list.Clear(); num = dist; list.Add(nearestCellInDirection); } break; } } direction = (direction + 2); if (direction > 7) return list; } }
public void MovementPathFromArray(MapPoint[] squares) { PathElement path = null; for (var i = 0; i <= squares.Length - 2; i++) { path = new PathElement(); path.Cell = squares[i]; path.Orientation = squares[i].OrientationTo(squares[i + 1]); this.MovPath.Cells.Add(path); } this.MovPath.Compress(); }
public bool CanGatherElement(int id, int distance) { if (distance <= 1 && distance >= 0) return true; if (m_Account.Inventory.HasFishingRod) { MapPoint characterPoint = new MapPoint(Character.CellId); //Elements.StatedElement element = (Elements.StatedElement)StatedElements.GetValueOrNull(id); Elements.StatedElement element = null; if (StatedElements.ContainsKey(id)) { element = StatedElements[id]; } if (element != null) { //StatedElement selectedStatedElement = findValue(StatedElements, id); //if (selectedStatedElement != null) // element = (Elements.StatedElement)selectedStatedElement; MapPoint elementPoint = new MapPoint((int)element.CellId); List<MapPoint> goodPointsList = GetListPointAtGoodDistance(characterPoint, elementPoint, 1); //m_Account.Inventory.WeaponRange); var selectedPoint = goodPointsList.FirstOrDefault((point) => point.CellId == characterPoint.CellId); if (selectedPoint != null) return true; } } return false; }
public bool MoveToCellWithDistance(int cellId, int maxDistance, bool bool1) { MovementPath path = null; int savDistance = -1; MapPoint characterPoint = new MapPoint(m_Account.MapData.Character.disposition.cellId); MapPoint targetPoint = new MapPoint(cellId); foreach (MapPoint point in m_Account.MapData.GetListPointAtGoodDistance(characterPoint, targetPoint, maxDistance)) { Pathfinder pathFinding = null; if ((targetPoint.DistanceToCell(point) > maxDistance) || ((targetPoint.X != point.X) && (targetPoint.Y != point.Y))) continue; int distance = characterPoint.DistanceTo(point); if ((savDistance != -1) && (distance >= savDistance)) continue; if (bool1) { if (m_Account.MapData.Data.IsWalkable(point.CellId)) goto Label_00A8; continue; } if (!(m_Account.MapData.NothingOnCell(point.CellId))) continue; Label_00A8: pathFinding = new Pathfinder(m_Account.MapData); MovementPath path2 = pathFinding.FindPath(m_Account.MapData.Character.disposition.cellId, point.CellId); if (path2 != null) { path = path2; savDistance = distance; } } if (path == null) return false; List<UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path); if (serverMovement[serverMovement.Count - 1] == m_Account.MapData.Character.disposition.cellId) { Moving = false; ConfirmMove(); return true; } int timetowait; if (serverMovement.Count() < 3) timetowait = serverMovement.Count() * 514; else { timetowait = serverMovement.Count() * 320; } m_time = timetowait; using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.Select<uint, short>(ui => (short)ui).ToArray(), m_Account.MapData.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); m_Account.SetStatus(Status.Moving); Moving = true; if (m_Account.DebugMode.Checked) m_Account.Log(new DebugTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0); } return true; }
/// <summary>Obtient la distance entre ce point et le point donné</summary> /// <param name="Point">Point donc on veut connaître la distance par rapport à ce MapPoint</param> /// <returns>La distance entre les deux points</returns> public int DistanceTo(MapPoint Point) { return Convert.ToInt32(Math.Round(Math.Sqrt((Math.Pow(Convert.ToDouble((Point.X - this.X)), 2) + Math.Pow(Convert.ToDouble((Point.Y - this.Y)), 2))))); }
/// <summary>Obtient la distance entre ce point et le point donné</summary> /// <param name="Point">Point donc on veut connaître la distance par rapport à ce MapPoint</param> /// <returns>La distance entre les deux points</returns> public int DistanceToCell(MapPoint Point) { return (Math.Abs(Convert.ToInt32((this.X - Point.X))) + Math.Abs(Convert.ToInt32((this.Y - Point.Y)))); }
/// <summary>Obtient la distance entre ce point et le point donné</summary> /// <param name="Point">Point donc on veut connaître la distance par rapport à ce MapPoint</param> /// <returns>La distance entre les deux points</returns> public int DistanceToCell(MapPoint Point) { return(Math.Abs(Convert.ToInt32((this.X - Point.X))) + Math.Abs(Convert.ToInt32((this.Y - Point.Y)))); }
/// <summary>Obtient la distance entre ce point et le point donné</summary> /// <param name="Point">Point donc on veut connaître la distance par rapport à ce MapPoint</param> /// <returns>La distance entre les deux points</returns> public int DistanceTo(MapPoint Point) { return(Convert.ToInt32(Math.Round(Math.Sqrt((Math.Pow(Convert.ToDouble((Point.X - this.X)), 2) + Math.Pow(Convert.ToDouble((Point.Y - this.Y)), 2)))))); }
/// <summary> /// Get the distance between the character and the ressource. /// </summary> /// <param name="Id"> /// The id of the ressource. /// </param> public int GetRessourceDistance(int Id) { MapPoint CharacterMapPoint = new MapPoint(account.MapData.Character.disposition.cellId); StatedElement StatedRessource = account.MapData.StatedElements.FirstOrDefault((se) => se.Id == Id); if (StatedRessource != null) { MapPoint RessourceMapPoint = new MapPoint((int)StatedRessource.CellId); return CharacterMapPoint.DistanceTo(RessourceMapPoint); } return -1; }
public bool MoveToCellWithDistance(int cellId, int maxDistance, bool bool1) { m_Account.ModifBar(6, 0, 0, "Déplacement"); MovementPath path = null; int savDistance = -1; MapPoint characterPoint = new MapPoint(Character.CellId); MapPoint targetPoint = new MapPoint(cellId); foreach (MapPoint point in GetListPointAtGoodDistance(characterPoint, targetPoint, maxDistance)) { Pathfinder pathFinding = null; if ((targetPoint.DistanceToCell(point) > maxDistance) || ((targetPoint.X != point.X) && (targetPoint.Y != point.Y))) continue; int 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(m_Account.Map.Data, m_Account.Map); MovementPath path2 = pathFinding.FindPath(Character.CellId, point.CellId); if (path2 != null) { path = path2; savDistance = distance; } } if (path == null) return false; //if (AutoTimeout) // m_Account.Game.Character.State.SetTimeout(StateEnum.Moving, false, TimeoutMin, TimeoutMax); List<UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path); int timetowait; if (serverMovement.Count() < 3) timetowait = serverMovement.Count() * 500; else { timetowait = serverMovement.Count() * 300; } //m_Account.Network.SendToServer(new GameMapMovementRequestMessage(serverMovement.Select<uint, short>(ui => (short)ui).ToArray(), Id)); using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.Select<uint, short>(ui => (short)ui).ToArray(), 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); } m_Account.Wait(timetowait, timetowait + 100); using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementConfirmMessage newmsg = new GameMapMovementConfirmMessage(); newmsg.Serialize(writer); MessagePackaging pack = new MessagePackaging(writer); pack.Pack((int)newmsg.ProtocolID); if (m_Account.Fight != null && m_Account.Fight.IsFollowingGroup()) { m_Account.SocketManager.Send(pack.Writer.Content); m_Account.Fight.LaunchFight(m_Account.Fight.followinggroup.m_contextualId); //m_Account.Wait(3000, 4000); //if (m_Account.StatusLb.Text != "Combat") //{ // m_Account.Fight.SearchFight(); //} } else if (m_Account.Gather.Id != -1) { m_Account.SocketManager.Send(pack.Writer.Content); UseElement(m_Account.Gather.Id, m_Account.Gather.SkillInstanceUid); } else { m_Account.SocketManager.Send(pack.Writer.Content); } m_Account.ModifBar(6, 0, 0, "Connecté"); } return true; }
/// <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> /// Return whether or not we can gather an element at the specified distance. /// </summary> public bool CanGatherElement(int id, int distance) { if (distance <= 1 && distance >= 0) return true; if (m_Account.Inventory.HasFishingRod) { MapPoint characterPoint = new MapPoint(Character.disposition.cellId); Elements.StatedElement element = StatedElements.Find(s => s.Id == id); if (element != null) { MapPoint elementPoint = new MapPoint((int)element.CellId); List<MapPoint> goodPointsList = GetListPointAtGoodDistance(characterPoint, elementPoint, m_Account.Inventory.WeaponRange); foreach (MapPoint mp in goodPointsList) m_Account.Log(new DebugTextInformation("[CanGatherElement] GoodPoints -> " + mp.CellId), 0); m_Account.Log(new DebugTextInformation("[CanGatherElement] Player CellId ? " + characterPoint.CellId),0); var selectedPoint = goodPointsList.FirstOrDefault((point) => point.CellId == characterPoint.CellId); if (selectedPoint != null) return true; } } return false; }
/// <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; }
private int GetRessourceDistance(int Id) { MapPoint CharacterMapPoint = new MapPoint(account.Map.Character.CellId); StatedElement StatedRessource = account.Map.StatedElements.FirstOrDefault((se) => se.Value.Id == Id).Value; if (StatedRessource != null) { MapPoint RessourceMapPoint = new MapPoint((int)StatedRessource.CellId); return CharacterMapPoint.DistanceTo(RessourceMapPoint); } return -1; }
/// <summary> /// Returns if we are currently hand to hand with the nearest monster or not. /// </summary> 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 bool PointMov(int x, int y, int cellId, bool troughtEntities) { bool isNewSystem = MapData.Data.IsUsingNewMovementSystem; MapPoint actualPoint = new MapPoint(x, y); BlueSheep.Data.D2p.CellData fCellData = null; BlueSheep.Data.D2p.CellData sCellData = null; bool mov = false; int floor = 0; if (actualPoint.IsInMap()) { fCellData = MapData.Data.Cells[actualPoint.CellId]; mov = ((fCellData.Mov()) && (!this.IsFighting || !fCellData.NonWalkableDuringFight())); if (!((mov == false)) && isNewSystem && cellId != -1 && cellId != actualPoint.CellId) { sCellData = (MapData).Data.Cells[cellId]; floor = Math.Abs(Math.Abs(fCellData.Floor) - Math.Abs(sCellData.Floor)); if (!(sCellData.MoveZone == fCellData.MoveZone) && floor > 0 && sCellData.MoveZone == fCellData.MoveZone && fCellData.MoveZone == 0 && floor > 11) { mov = false; } if (!troughtEntities) { int count = 0; count += MapData.Monsters.Where((e) => e.m_cellId == actualPoint.CellId).ToList().Count; if (count > 0) { // //ToDo Voir à travers les entity return false; } } } } else { mov = false; } return mov; }
/// <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; }
public void StartPathfinding(MapPoint startP, MapPoint endP) { this.Start = startP; this.End = endP; this.StartX = startP.X; this.StartY = startP.Y; this.EndX = endP.X; this.EndY = endP.Y; this.StartPoint = new MapPoint(startP.X, startP.Y); this.EndPoint = new MapPoint(endP.X, endP.Y); this.AuxEndPoint = this.StartPoint; this.AuxEndX = this.StartPoint.X; this.AuxEndY = this.StartPoint.Y; this.DistanceToEnd = this.StartPoint.DistanceToCell(this.EndPoint); for (int y = -19; y <= this.MaxY; y++) { for (int x = 0; x <= this.MaxX; x++) { this.MapStatus.Add(new CellInfo(0, null, false, false, x, y)); } } OpenList = new List<OpenSquare>(); OpenSquare(this.StartY, this.StartX, null, 0, 0, false); }
/// <summary> /// Returns the nearest monster from our player, in the specified list. /// </summary> public BFighter NearestMonster(List<BFighter> LFighters) { MapPoint CharacterPoint = new MapPoint(this.Fighter.CellId); BFighter Fighterr = null; int SavDistance = -1; foreach (BFighter TestFighter in LFighters) { if (TestFighter.TeamId == Fighter.TeamId || TestFighter.IsAlive == false) continue; MapPoint TestFighterPoint = new MapPoint(TestFighter.CellId); int dist = new SimplePathfinder(m_Account.MapData).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 void EndPathfinding() { List<MapPoint> mapsArray = new List<MapPoint>(); int parentY = 0; int parentX = 0; MapPoint btwPoint = null; List<MapPoint> tempArray = new List<MapPoint>(); int i = 0; int actualX = 0; int actualY = 0; int thirdX = 0; int thirdY = 0; int btwX = 0; int btwY = 0; bool endPointClosed = IsClosed(this.EndY, this.EndX); if (!endPointClosed) { this.EndPoint = this.AuxEndPoint; this.EndX = this.AuxEndX; this.EndY = this.AuxEndY; endPointClosed = true; MovPath.CellEnd = this.EndPoint; } this.PreviousCellId = -1; if (endPointClosed) { this.NowX = this.EndX; this.NowY = this.EndY; while (!(this.NowX == this.StartX) || !(this.NowY == this.StartY)) { mapsArray.Add(new MapPoint(this.NowX, this.NowY)); parentY = this.GetCellInfo(this.NowY, this.NowX).Parent[0]; parentX = this.GetCellInfo(this.NowY, this.NowX).Parent[1]; this.NowX = parentX; this.NowY = parentY; } mapsArray.Add(this.StartPoint); if (AllowDiag) { for (i = 0; i < mapsArray.Count; i++) { tempArray.Add(mapsArray[i]); this.PreviousCellId = mapsArray[i].CellId; if ((mapsArray.Count > i + 2 && !((mapsArray[i + 2] == null)) && (mapsArray[i].DistanceToCell(mapsArray[i + 2]) == 1)) && (!(IsChangeZone(mapsArray[i].CellId, mapsArray[i + 1].CellId))) && !(IsChangeZone(mapsArray[i + 1].CellId, mapsArray[i + 2].CellId))) { i += 1; } else { if ((mapsArray.Count > i + 3 && !((mapsArray[i + 3] == null))) && mapsArray[i].DistanceToCell(mapsArray[i + 3]) == 2) { actualX = mapsArray[i].X; actualY = mapsArray[i].Y; thirdX = mapsArray[i + 3].X; thirdY = mapsArray[i + 3].Y; btwX = actualX + (int)Math.Round((thirdX - actualX) / 2.0); btwY = actualY + (int)Math.Round((thirdY - actualY) / 2.0); btwPoint = new MapPoint(btwX, btwY); if ((PointMov(btwX, btwY, this.PreviousCellId, true)) && GetCellSpeed(btwPoint.CellId, this.AllowTroughEntity) < 2) { tempArray.Add(btwPoint); this.PreviousCellId = btwPoint.CellId; i += 2; } } else { if (mapsArray.Count > i + 2 && !((mapsArray[i + 2] == null)) && mapsArray[i].DistanceToCell(mapsArray[i + 2]) == 2) { actualX = mapsArray[i].X; actualY = mapsArray[i].Y; thirdX = mapsArray[i + 2].X; thirdY = mapsArray[i + 2].Y; btwX = mapsArray[i + 1].X; btwY = mapsArray[i + 1].Y; if (actualX + actualY == thirdX + thirdY && !(actualX - actualY == btwX - btwY) && !(IsChangeZone((new MapPoint(actualX, actualY)).CellId, (new MapPoint(btwX, btwY)).CellId)) && !(IsChangeZone((new MapPoint(btwX, btwY)).CellId, (new MapPoint(thirdX, thirdY)).CellId))) { i += 1; } else { if (actualX - actualY == thirdX - thirdY && !(actualX - actualY == btwX - btwY) && !(IsChangeZone((new MapPoint(actualX, actualY)).CellId, (new MapPoint(btwX, btwY)).CellId)) && !(IsChangeZone((new MapPoint(btwX, btwY)).CellId, (new MapPoint(thirdX, thirdY)).CellId))) { i += 1; } else { if (actualX == thirdX && !(actualX == btwX) && GetCellSpeed((new MapPoint(actualX, btwY)).CellId, this.AllowTroughEntity) < 2 && (PointMov(actualX, btwY, this.PreviousCellId, this.AllowTroughEntity))) { btwPoint = new MapPoint(actualX, btwY); tempArray.Add(btwPoint); this.PreviousCellId = btwPoint.CellId; i += 1; } else { if (actualY == thirdY && !(actualY == btwY) && GetCellSpeed((new MapPoint(btwX, actualY)).CellId, this.AllowTroughEntity) < 2 && (PointMov(btwX, actualY, this.PreviousCellId, this.AllowTroughEntity))) { btwPoint = new MapPoint(btwX, actualY); tempArray.Add(btwPoint); this.PreviousCellId = btwPoint.CellId; i += 1; } } } } } } } } mapsArray = tempArray; } if (mapsArray.Count == 1) { mapsArray = new List<MapPoint>(); } mapsArray.Reverse(); MovementPathFromArray(mapsArray.ToArray()); } }
/// <summary> /// Returns if a spell is launchable on a specified spellId or not. /// </summary> /// <param name="spellId">ID du sort</param> /// <param name="characterCellId">CellId du personnage</param> /// <param name="cellId">CellId cible</param> /// <returns>SpellInabilityReasons: Unknown, ActionPoints, TooManyLaunch, Cooldown, TooManyInvocations, None </returns> private SpellInabilityReason CanLaunchSpellOn(int spellId, int characterCellId, int cellId, bool withMove = false) { if (!withMove) { SpellInabilityReason canLaunchSpell = CanLaunchSpell(spellId); if (canLaunchSpell != SpellInabilityReason.None) return canLaunchSpell; } Inventory.Item weapon = m_Account.Inventory.Weapon; DataClass weaponData = null; DataClass spellData = GameData.GetDataObject(D2oFileEnum.Spells, spellId); ArrayList ids = (ArrayList)spellData.Fields["spellLevels"]; int level = m_Account.Spells.FirstOrDefault(Spell => Spell.Id == spellId).Level; int id = Convert.ToInt32(ids[level - 1]); DataClass spellLevelsData = GameData.GetDataObject(D2oFileEnum.SpellLevels, id); if (spellLevelsData == null && spellId != -1) // spellId = -1 -> Use weapon. return SpellInabilityReason.Unknown; if (spellId == 0 && weapon != null) weaponData = GameData.GetDataObject(D2oFileEnum.Items, weapon.GID); MapPoint characterPoint = new MapPoint(characterCellId); MapPoint targetPoint = new MapPoint(cellId); int distanceToTarget = characterPoint.DistanceToCell(targetPoint); int minRange = (spellId != -1) ? (int)spellLevelsData.Fields["minRange"] : (int)weaponData.Fields["minRange"]; if ((spellId != 0 && (bool)spellLevelsData.Fields["castInDiagonal"]) || (weaponData != null && !(bool)weaponData.Fields["castInLine"])) minRange = (minRange * 2); if (minRange < 0) minRange = 0; int maxRange = (spellId != 0) ? (int)((int)spellLevelsData.Fields["range"] + ((bool)spellLevelsData.Fields["rangeCanBeBoosted"] ? (m_Account.CharacterStats.range.objectsAndMountBonus + m_Account.CharacterStats.range.contextModif) : 0)) : (int)spellLevelsData.Fields["range"]; if ((spellId != 0 && (bool)spellLevelsData.Fields["castInDiagonal"]) || (weaponData != null && !(bool)weaponData.Fields["castInLine"])) maxRange = (maxRange * 2); if (maxRange < 0) maxRange = 0; if (distanceToTarget < minRange && distanceToTarget > 0) return SpellInabilityReason.MinRange; if (distanceToTarget > maxRange) return SpellInabilityReason.MaxRange; if (((spellId != 0 && (bool)spellLevelsData.Fields["castInLine"]) || (weaponData != null && (bool)weaponData.Fields["castInLine"])) && characterPoint.X != targetPoint.X && characterPoint.Y != targetPoint.Y) return SpellInabilityReason.NotInLine; if ((spellId != 0 && (bool)spellLevelsData.Fields["castInDiagonal"]) || (weaponData != null && !(bool)weaponData.Fields["castInLine"])) { ArrayList list = Dofus1Line.GetLine(characterPoint.X, characterPoint.Y, targetPoint.X, targetPoint.Y); int i = 0; while (i < list.Count - 1) { Dofus1Line.Point actualPoint = (Dofus1Line.Point)list[i]; Dofus1Line.Point nextPoint = (Dofus1Line.Point)list[i + 1]; i += 1; if (actualPoint.X == nextPoint.X + 1 && actualPoint.Y == nextPoint.Y + 1) continue; else if (actualPoint.X == nextPoint.X - 1 && actualPoint.Y == nextPoint.Y - 1) continue; else if (actualPoint.X == nextPoint.X + 1 && actualPoint.Y == nextPoint.Y - 1) continue; else if (actualPoint.X == nextPoint.X - 1 && actualPoint.Y == nextPoint.Y + 1) continue; return SpellInabilityReason.NotInDiagonal; } } if (((spellId != 0 && (bool)spellLevelsData.Fields["castTestLos"] && distanceToTarget > 1)) || (weaponData != null && (bool)weaponData.Fields["castTestLos"]) && distanceToTarget > 1) { ArrayList list = Dofus1Line.GetLine(characterPoint.X, characterPoint.Y, targetPoint.X, targetPoint.Y); int i = 0; while (i < list.Count - 1) { Dofus1Line.Point point3 = (Dofus1Line.Point)list[i]; MapPoint point4 = new MapPoint((int)Math.Round(Math.Floor(point3.X)), (int)Math.Round(Math.Floor(point3.Y))); if (!(IsFreeCell(point4.CellId)) || !(m_Account.MapData.Data.IsLineOfSight(point4.CellId))) return SpellInabilityReason.LineOfSight; i += 1; } } if ((TotalLaunchByCellBySpell.ContainsKey(spellId) && TotalLaunchByCellBySpell[spellId].ContainsKey(targetPoint.CellId)) && this.TotalLaunchByCellBySpell[spellId][targetPoint.CellId] >= (int)spellLevelsData.Fields["maxCastPerTarget"] && (int)spellLevelsData.Fields["maxCastPerTarget"] > 0) return SpellInabilityReason.TooManyLaunchOnCell; if (IsFreeCell(cellId)) { if ((bool)spellLevelsData.Fields["needTakenCell"]) return SpellInabilityReason.NeedTakenCell; } else if ((bool)spellLevelsData.Fields["needFreeCell"]) return SpellInabilityReason.NeedFreeCell; return SpellInabilityReason.None; }
/// <summary> /// Move to the specified cell (Fight). /// </summary> private bool MoveToCell(int cellId) { if (cellId != m_Data.Fighter.CellId) { if (!(m_Data.IsCellWalkable(cellId))) { int num = -1; int num2 = 5000; MapPoint point = new MapPoint(m_Data.Fighter.CellId); MapPoint point2 = new MapPoint(cellId); int direction = 1; while (true) { MapPoint nearestCellInDirection = point2.GetNearestCellInDirection(direction, 1); if (m_Data.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(m_Account.MapData); pathfinder.SetFight(m_Data.Fighters, m_Data.Fighter.MovementPoints); MovementPath path = pathfinder.FindPath(m_Data.Fighter.CellId, cellId); if (path != null) { List<UInt32> serverMovement = MapMovementAdapter.GetServerMovement(path); using (BigEndianWriter writer = new BigEndianWriter()) { GameMapMovementRequestMessage msg = new GameMapMovementRequestMessage(serverMovement.ToList().Select<uint, short>(ui => (short)ui).ToArray(), m_Account.MapData.Id); msg.Serialize(writer); writer.Content = m_Account.HumanCheck.hash_function(writer.Content); MessagePackaging pack = new MessagePackaging(writer); pack.Pack((int)msg.ProtocolID); flag = 0; m_Account.SocketManager.Send(pack.Writer.Content); if (m_Account.DebugMode.Checked) m_Account.Log(new DebugTextInformation("[SND] 950 (GameMapMovementRequestMessage)"), 0); } return true; } } return false; }
/// <summary>Donne l'orientation du point vers le point donné</summary> /// <param name="Point">Point dont on veut connaitre l'orientation par rapport à ce MapPoint</param> /// <returns>La valeur de l'orientation vers le point donné</returns> public int OrientationTo(MapPoint Point) { int num = (Point.X > this.X) ? 1 : (Point.X < this.X) ? -1 : 0; int num2 = (Point.Y > this.Y) ? 1 : (Point.Y < this.Y) ? -1 : 0; if (((num == 1) && (num2 == 1))) { return 0; } if (((num == 1) && (num2 == 0))) { return 1; } if (((num == 1) && (num2 == -1))) { return 2; } if (((num == 0) && (num2 == -1))) { return 3; } if (((num == -1) && (num2 == -1))) { return 4; } if (((num == -1) && (num2 == 0))) { return 5; } if (((num == -1) && (num2 == 1))) { return 6; } if (((num == 0) && (num2 == 1))) { return 7; } return -1; }