private bool StepMove(double toMoveDist, GameClient client) { StoryBoard4Client sb = StoryBoard4Client.FindStoryBoard(this._RoleID); bool result; if (null == sb) { result = false; } else { lock (this.mutex) { this._PathIndex = Math.Min(this._PathIndex, this._Path.Count - 1); if (!this.DetectNextGrid()) { result = true; } else { double targetX = this._Path[this._PathIndex].X * (double)this._CellSizeX + (double)this._CellSizeX / 2.0; double targetY = this._Path[this._PathIndex].Y * (double)this._CellSizeY + (double)this._CellSizeY / 2.0; int direction = (int)StoryBoard4Client.GetDirectionByTan(targetX, targetY, (double)this._LastTargetX, (double)this._LastTargetY); double dx = targetX - (double)this._LastTargetX; double dy = targetY - (double)this._LastTargetY; double thisGridStepDist = Math.Sqrt(dx * dx + dy * dy); bool needWalking = false; if (this._Path.Count <= 1) { needWalking = true; } if (null != client) { GameMap gameMap = GameManager.MapMgr.DictMaps[client.ClientData.MapCode]; if (gameMap.InSafeRegionList(this._Path[this._PathIndex])) { needWalking = true; } } int action = needWalking ? 1 : 2; if (needWalking) { toMoveDist *= 0.8; } double thisToMoveDist = (thisGridStepDist < toMoveDist) ? thisGridStepDist : toMoveDist; double angle = Math.Atan2(dy, dx); double speedX = thisToMoveDist * Math.Cos(angle); double speedY = thisToMoveDist * Math.Sin(angle); this._CurrentX += speedX; this._CurrentY += speedY; if (null != client) { client.ClientData.CurrentAction = action; if (direction != client.ClientData.RoleDirection) { client.ClientData.RoleDirection = direction; } } if (thisGridStepDist >= toMoveDist) { if (null != client) { GameMap gameMap = GameManager.MapMgr.DictMaps[client.ClientData.MapCode]; int oldGridX = client.ClientData.PosX / gameMap.MapGridWidth; int oldGridY = client.ClientData.PosY / gameMap.MapGridHeight; client.ClientData.PosX = (int)this._CurrentX; client.ClientData.PosY = (int)this._CurrentY; int newGridX = client.ClientData.PosX / gameMap.MapGridWidth; int newGridY = client.ClientData.PosY / gameMap.MapGridHeight; if (oldGridX != newGridX || oldGridY != newGridY) { MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[client.ClientData.MapCode]; mapGrid.MoveObjectEx(oldGridX, oldGridY, newGridX, newGridY, client); } } this._LastTargetX = (int)this._CurrentX; this._LastTargetY = (int)this._CurrentY; } else { this._PathIndex++; if (this._PathIndex >= this._Path.Count) { if (null != client) { client.ClientData.PosX = (int)targetX; client.ClientData.PosY = (int)targetY; } return(true); } this._LastTargetX = (int)targetX; this._LastTargetY = (int)targetY; toMoveDist -= thisGridStepDist; this.StepMove(toMoveDist, client); } result = false; } } } return(result); }