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 override bool Apply() { EffectInteger effectInteger = this.GenerateEffect(); bool flag; if (effectInteger == null) { flag = false; } else { foreach (FightActor target in this.GetAffectedActors()) { if (target.CanBeMove()) { MapPoint point1 = this.TargetedCell.Id != target.Cell.Id ? this.TargetedPoint : new MapPoint(this.CastCell); if (point1.CellId != target.Position.Cell.Id) { DirectionsEnum direction = target.Position.Point.OrientationTo(point1, false); MapPoint point2 = target.Position.Point; MapPoint mapPoint1 = point2; for (int index = 0; index < effectInteger.Value; ++index) { MapPoint nearestCellInDirection = mapPoint1.GetNearestCellInDirection(direction); if (nearestCellInDirection != null) { if (!this.Fight.ShouldTriggerOnMove(this.Fight.Map.Cells[nearestCellInDirection.CellId])) { if (this.Fight.IsCellFree(this.Map.Cells[nearestCellInDirection.CellId])) { mapPoint1 = nearestCellInDirection; } else { break; } } else { mapPoint1 = nearestCellInDirection; break; } } else break; } MapPoint mapPoint2 = mapPoint1; target.Position.Cell = this.Map.Cells[(int)mapPoint2.CellId]; ActionsHandler.SendGameActionFightSlideMessage((IPacketReceiver)this.Fight.Clients, this.Caster, target, point2.CellId, mapPoint2.CellId); } } } flag = true; } return flag; }
public override bool Apply() { EffectInteger integer = base.GenerateEffect(); if (integer == null) { return(false); } foreach (FightActor actor in base.GetAffectedActors()) { if (actor.CanBeMove()) { MapPoint startCell; MapPoint endCell; FightActor actorCopy; MapPoint point = (base.TargetedCell.Id == actor.Cell.Id) ? new MapPoint(base.CastCell) : base.TargetedPoint; if (point.CellId != actor.Position.Cell.Id) { DirectionsEnum direction = point.OrientationTo(actor.Position.Point, false); startCell = actor.Position.Point; MapPoint point2 = startCell; for (int i = 0; i < integer.Value; i++) { MapPoint nearestCellInDirection = point2.GetNearestCellInDirection(direction); if (nearestCellInDirection == null) { break; } if (base.Fight.ShouldTriggerOnMove(base.Fight.Map.Cells[nearestCellInDirection.CellId])) { point2 = nearestCellInDirection; break; } if ((nearestCellInDirection == null) || !base.Fight.IsCellFree(base.Map.Cells[nearestCellInDirection.CellId])) { int damage = (8 + (new AsyncRandom().Next(1, 8) * (base.Caster.Level / 50))) * (integer.Value - i); actor.InflictDirectDamage(damage, base.Caster); break; } point2 = nearestCellInDirection; } endCell = point2; actorCopy = actor; base.Fight.ForEach(delegate(Character entry) { ActionsHandler.SendGameActionFightSlideMessage(entry.Client, this.Caster, actorCopy, startCell.CellId, endCell.CellId); }); actor.Position.Cell = base.Map.Cells[endCell.CellId]; } } } return(true); }
public void PushCaster(Fighter source, short delta, MapPoint castPoint) { MapPoint startCell; MapPoint endCell; Fighter FighterCopy; MapPoint point = (castPoint.CellId == Fighter.CellId) ? new MapPoint(source.CellId) : castPoint; if (point.CellId != Fighter.CellId) { DirectionsEnum direction = Fighter.Point.OrientationTo(point, false); startCell = source.Point; MapPoint point2 = startCell; for (int i = 0; i < delta; i++) { MapPoint nearestCellInDirection = point2.GetNearestCellInDirection(direction); if (nearestCellInDirection == null) { break; } if (Fight.ShouldTriggerOnMove(nearestCellInDirection.CellId)) { point2 = nearestCellInDirection; break; } if ((nearestCellInDirection == null) || !Fight.IsCellFree(nearestCellInDirection.CellId)) { source.InflictPushDamages(source, (sbyte)(delta - i), true); MapPoint nextNearest = nearestCellInDirection.GetNearestCellInDirection(direction); Fighter nextFighter = Fight.GetFighter(nearestCellInDirection.CellId); if (nextFighter != null) { nextFighter.InflictPushDamages(source, (sbyte)(delta - i), false); } break; } point2 = nearestCellInDirection; } endCell = point2; FighterCopy = Fighter; if (startCell != endCell) { source.Slide(source, endCell.CellId); } } }
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)); }
internal List <MapPoint> method_0(bool bool_0) { var list = new List <MapPoint>(); var num = bool_0 ? 2 : 1; var i = bool_0 ? 1 : 0; while (((num >> 31) ^ i) <= ((num >> 31) ^ 7)) { var nearestCellInDirection = v_OriginPoint.GetNearestCellInDirection(i, 1); if (nearestCellInDirection.IsInMap() && nearestCellInDirection.CellId < 560 && nearestCellInDirection.CellId > 0) { list.Add(nearestCellInDirection); } i = i + num; } return(list); }
private Cell[] BuildCompletePath() { System.Collections.Generic.List <Cell> list = new System.Collections.Generic.List <Cell>(); for (int i = 0; i < this.m_compressedPath.Length - 1; i++) { list.Add(this.m_compressedPath[i].Cell); int num = 0; MapPoint mapPoint = this.m_compressedPath[i].Point; while ((mapPoint = mapPoint.GetNearestCellInDirection(this.m_compressedPath[i].Direction)) != null && mapPoint.CellId != this.m_compressedPath[i + 1].Cell.Id) { if ((long)num > 54L) { throw new System.Exception("Path too long. Maybe an orientation problem ?"); } list.Add(this.Map.Cells[(int)mapPoint.CellId]); num++; } } list.Add(this.m_compressedPath[this.m_compressedPath.Length - 1].Cell); return(list.ToArray()); }
public void PullForward(Fighter source, short delta, MapPoint castPoint) { MapPoint point1 = (int)castPoint.CellId != (int)Fighter.CellId ? castPoint : source.Point; if ((int)point1.CellId != (int)Fighter.CellId) { DirectionsEnum direction = Fighter.Point.OrientationTo(point1, true); MapPoint point2 = Fighter.Point; MapPoint mapPoint1 = point2; for (int index = 0; index < (int)delta; ++index) { MapPoint nearestCellInDirection = mapPoint1.GetNearestCellInDirection(direction); if (nearestCellInDirection != null) { if (!Fight.ShouldTriggerOnMove(nearestCellInDirection.CellId)) { if (Fight.IsCellFree(nearestCellInDirection.CellId)) { mapPoint1 = nearestCellInDirection; } else { break; } } else { mapPoint1 = nearestCellInDirection; break; } } else { break; } } Fighter.Slide(source, mapPoint1.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); } } }
public Path FindPath(MapPoint startPoint, MapPoint endPoint, bool diagonal, int movementPoints = (short)-1) { var success = false; var matrix = new PathNode[MapPoint.MapSize + 1]; var openList = new PriorityQueueB <short>(new ComparePfNodeMatrix(matrix)); var closedList = new List <PathNode>(); var location = startPoint.CellId; var counter = 0; if (movementPoints == 0) { return(Path.GetEmptyPath(CellsInformationProvider.Map, CellsInformationProvider.Map.Cells[startPoint.CellId])); } matrix[location].Cell = location; matrix[location].Parent = -1; matrix[location].G = 0; matrix[location].F = EstimateHeuristic; matrix[location].Status = NodeState.Open; openList.Push(location); while (openList.Count > 0) { location = openList.Pop(); var locationPoint = new MapPoint(location); if (matrix[location].Status == NodeState.Closed) { continue; } if (location == endPoint.CellId) { matrix[location].Status = NodeState.Closed; success = true; break; } if (counter > SearchLimit) { return(Path.GetEmptyPath(CellsInformationProvider.Map, CellsInformationProvider.Map.Cells[startPoint.CellId])); } for (int i = 0; i < (diagonal ? 8 : 4); i++) { var newLocationPoint = locationPoint.GetNearestCellInDirection(Directions[i]); if (newLocationPoint == null) { continue; } var newLocation = newLocationPoint.CellId; if (newLocation < 0 || newLocation >= MapPoint.MapSize) { continue; } if (!MapPoint.IsInMap(newLocationPoint.X, newLocationPoint.Y)) { continue; } if (!CellsInformationProvider.IsCellWalkable(newLocation)) { continue; } double newG = matrix[location].G + 1; if ((matrix[newLocation].Status == NodeState.Open || matrix[newLocation].Status == NodeState.Closed) && matrix[newLocation].G <= newG) { continue; } matrix[newLocation].Cell = newLocation; matrix[newLocation].Parent = location; matrix[newLocation].G = newG; matrix[newLocation].H = GetHeuristic(newLocationPoint, endPoint); matrix[newLocation].F = newG + matrix[newLocation].H; openList.Push(newLocation); matrix[newLocation].Status = NodeState.Open; } counter++; matrix[location].Status = NodeState.Closed; } if (success) { var node = matrix[endPoint.CellId]; while (node.Parent != -1) { closedList.Add(node); node = matrix[node.Parent]; } closedList.Add(node); } closedList.Reverse(); if (movementPoints > 0 && closedList.Count + 1 > movementPoints) { return(new Path(CellsInformationProvider.Map, closedList.Take(movementPoints + 1).Select(entry => CellsInformationProvider.Map.Cells[entry.Cell]))); } return(new Path(CellsInformationProvider.Map, closedList.Select(entry => CellsInformationProvider.Map.Cells[entry.Cell]))); }
public MapPoint[] FindReachableCells(MapPoint from, int distance) { var result = new List <MapPoint>(); var matrix = new PathNode[MapPoint.MapSize + 1]; var openList = new PriorityQueueB <short>(new ComparePfNodeMatrix(matrix)); var location = from.CellId; var counter = 0; if (distance == 0) { return new [] { new MapPoint(from.CellId) } } ; matrix[location].Cell = location; matrix[location].Parent = -1; matrix[location].G = 0; matrix[location].F = 0; matrix[location].Status = NodeState.Open; openList.Push(location); while (openList.Count > 0) { location = openList.Pop(); var locationPoint = new MapPoint(location); if (matrix[location].Status == NodeState.Closed) { continue; } if (counter > SearchLimit) { break; } for (int i = 0; i < 4; i++) { var newLocationPoint = locationPoint.GetNearestCellInDirection(Directions[i]); if (newLocationPoint == null) { continue; } var newLocation = newLocationPoint.CellId; if (newLocation < 0 || newLocation >= MapPoint.MapSize) { continue; } if (!MapPoint.IsInMap(newLocationPoint.X, newLocationPoint.Y)) { continue; } if (!CellsInformationProvider.IsCellWalkable(newLocation)) { continue; } double newG = matrix[location].G + 1; if ((matrix[newLocation].Status == NodeState.Open || matrix[newLocation].Status == NodeState.Closed) && matrix[newLocation].G <= newG) { continue; } matrix[newLocation].Cell = newLocation; matrix[newLocation].Parent = location; matrix[newLocation].G = newG; matrix[newLocation].H = 0; matrix[newLocation].F = newG + matrix[newLocation].H; if (newG <= distance) { result.Add(newLocationPoint); openList.Push(newLocation); matrix[newLocation].Status = NodeState.Open; } } counter++; matrix[location].Status = NodeState.Closed; } return(result.ToArray()); }
public Path FindPath(short startCell, short endCell, bool diagonal, int movementPoints = -1) { bool flag = false; PathNode[] matrix = new PathNode[561]; PriorityQueueB <short> priorityQueueB = new PriorityQueueB <short>((IComparer <short>) new Pathfinder.ComparePfNodeMatrix(matrix)); List <PathNode> list = new List <PathNode>(); MapPoint mapPoint1 = new MapPoint(startCell); MapPoint pointB = new MapPoint(endCell); short num1 = startCell; int num2 = 0; Path path; if (movementPoints == 0) { path = Path.GetEmptyPath(this.CellsInformationProvider.Map, this.CellsInformationProvider.Map.Cells[(int)startCell]); } else { matrix[(int)num1].Cell = num1; matrix[(int)num1].Parent = (short)-1; matrix[(int)num1].G = 0.0; matrix[(int)num1].F = (double)Pathfinder.EstimateHeuristic; matrix[(int)num1].Status = NodeState.Open; priorityQueueB.Push(num1); while (priorityQueueB.Count > 0) { short cellId1 = priorityQueueB.Pop(); MapPoint mapPoint2 = new MapPoint(cellId1); if (matrix[(int)cellId1].Status != NodeState.Closed) { if ((int)cellId1 != (int)endCell) { if (num2 <= Pathfinder.SearchLimit) { for (int index = 0; index < (!diagonal ? 4 : 8); ++index) { MapPoint nearestCellInDirection = mapPoint2.GetNearestCellInDirection(Pathfinder.Directions[index]); if (nearestCellInDirection != null) { short cellId2 = nearestCellInDirection.CellId; if (((int)cellId2 < 0 ? 0 : ((long)cellId2 < 560L ? 1 : 0)) != 0 && MapPoint.IsInMap(nearestCellInDirection.X, nearestCellInDirection.Y) && this.CellsInformationProvider.IsCellWalkable(cellId2)) { double num3 = matrix[(int)cellId1].G + 1.0; if ((matrix[(int)cellId2].Status == NodeState.Open || matrix[(int)cellId2].Status == NodeState.Closed ? (matrix[(int)cellId2].G > num3 ? 1 : 0) : 1) != 0) { matrix[(int)cellId2].Cell = cellId2; matrix[(int)cellId2].Parent = cellId1; matrix[(int)cellId2].G = num3; matrix[(int)cellId2].H = Pathfinder.GetHeuristic(nearestCellInDirection, pointB); matrix[(int)cellId2].F = num3 + matrix[(int)cellId2].H; priorityQueueB.Push(cellId2); matrix[(int)cellId2].Status = NodeState.Open; } } } } ++num2; matrix[(int)cellId1].Status = NodeState.Closed; } else { path = Path.GetEmptyPath(this.CellsInformationProvider.Map, this.CellsInformationProvider.Map.Cells[(int)startCell]); goto label_23; } } else { matrix[(int)cellId1].Status = NodeState.Closed; flag = true; break; } } } if (flag) { PathNode pathNode; for (pathNode = matrix[(int)endCell]; (int)pathNode.Parent != -1; pathNode = matrix[(int)pathNode.Parent]) { list.Add(pathNode); } list.Add(pathNode); } list.Reverse(); path = (movementPoints <= 0 ? 1 : (list.Count + 1 <= movementPoints ? 1 : 0)) != 0 ? new Path(this.CellsInformationProvider.Map, Enumerable.Select <PathNode, Cell>((IEnumerable <PathNode>)list, (Func <PathNode, Cell>)(entry => this.CellsInformationProvider.Map.Cells[(int)entry.Cell]))) : new Path(this.CellsInformationProvider.Map, Enumerable.Select <PathNode, Cell>(Enumerable.Take <PathNode>((IEnumerable <PathNode>)list, movementPoints + 1), (Func <PathNode, Cell>)(entry => this.CellsInformationProvider.Map.Cells[(int)entry.Cell]))); } label_23: return(path); }