public void ChangeGrid() { if (this._ClientData.MapCode >= 0) { GameMap gameMap = GameManager.MapMgr.DictMaps[this._ClientData.MapCode]; int newGridX = this._ClientData.PosX / gameMap.MapGridWidth; int newGridY = this._ClientData.PosY / gameMap.MapGridHeight; if (this._OldGridPoint.X != (double)newGridX || this._OldGridPoint.Y != (double)newGridY) { this._OldGridPoint = new Point((double)newGridX, (double)newGridY); this.ProcessAreaLua(gameMap, this._OldGridPoint); if (!gameMap.InSafeRegionList(this.CurrentGrid)) { this.InSafeRegion = false; this.delayExecModule.SetDelayExecProc(new DelayExecProcIds[] { DelayExecProcIds.ProcessClickGoodsPack }); } else { this.InSafeRegion = true; } } } }
private void CheckSceneGameClients(KarenBattleScene karenBattleScene, long nowTicks) { List <GameClient> objsList = karenBattleScene.CopyMap.GetClientsList(); if (objsList != null && objsList.Count != 0) { GameMap gameMap = null; if (GameManager.MapMgr.DictMaps.TryGetValue(karenBattleScene.m_nMapCode, out gameMap)) { for (int i = 0; i < objsList.Count; i++) { GameClient c = objsList[i]; if (c != null) { if (gameMap.InSafeRegionList(c.CurrentGrid)) { if (c.SceneContextData != null) { this.RemoveBattleSceneBuffForRole(karenBattleScene, c); } } } } } } }
public void AutoGetThingsOnAutoFight(long ticks) { if (ticks - this.lastAutoGetthingsTicks >= 20000L) { this.lastAutoGetthingsTicks = ticks; if (this.ClientData.AutoFighting && this.ClientData.AutoFightGetThings != 0) { GameMap gameMap = GameManager.MapMgr.DictMaps[this._ClientData.MapCode]; if (!gameMap.InSafeRegionList(this.CurrentGrid)) { GameManager.GoodsPackMgr.ProcessClickGoodsPackWhenMovingToOtherGrid(this, 5); } } } }
/// <summary> /// 每隔20秒自动失去一次周围物品,范围为7个格子 /// </summary> /// <param name="ticks"></param> public void AutoGetThingsOnAutoFight(long ticks) { if (ticks - lastAutoGetthingsTicks < 20000) { return; } lastAutoGetthingsTicks = ticks; if (ClientData.AutoFighting && ClientData.AutoFightGetThings != 0) { //安全区不进行物品拾取检测 ChenXiaojun GameMap gameMap = GameManager.MapMgr.DictMaps[_ClientData.MapCode]; if (!gameMap.InSafeRegionList(CurrentGrid)) { GameManager.GoodsPackMgr.ProcessClickGoodsPackWhenMovingToOtherGrid(this, 5); } } }
/// <summary> /// 格子发生了变化 /// </summary> public void ChangeGrid() { //角色死亡,并且登出的时候,会被配置成 -1 if (_ClientData.MapCode < 0) { return; } GameMap gameMap = GameManager.MapMgr.DictMaps[_ClientData.MapCode]; int newGridX = _ClientData.PosX / gameMap.MapGridWidth; int newGridY = _ClientData.PosY / gameMap.MapGridHeight; if (_OldGridPoint.X != newGridX || _OldGridPoint.Y != newGridY) { _OldGridPoint = new Point(newGridX, newGridY); //触发动作 int areaLuaID = gameMap.GetAreaLuaID(_OldGridPoint); if (areaLuaID != _OldAreaLuaID) { if (_OldAreaLuaID > 0) { //执行区域脚本 RunAreaLuaFile(gameMap, _OldAreaLuaID, "leaveArea"); } _OldAreaLuaID = areaLuaID; if (areaLuaID > 0) { //执行区域脚本 RunAreaLuaFile(gameMap, areaLuaID, "enterArea"); } } //在这里移动中拾取物品? //安全区不进行物品拾取检测 ChenXiaojun if (!gameMap.InSafeRegionList(CurrentGrid)) { GameManager.GoodsPackMgr.ProcessClickGoodsPackWhenMovingToOtherGrid(this); } } }
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); }
//判断需要走路 //private bool NeedWalking(int currentGridX, int currentGridY) //{ // if (_PathIndex >= _Path.Count - 1) // { // _ActionIndex = _Path.Count - 1; // return true; // } // double targetX1 = _Path[_PathIndex ].X; // double targetY1 = _Path[_PathIndex ].Y; // double targetX2 = _Path[_PathIndex + 1].X; // double targetY2 = _Path[_PathIndex + 1].Y; // int dir1 = CalcDirection((int)currentGridX, (int)currentGridY, (int)targetX1, (int)targetY1); // int dir2 = CalcDirection((int)targetX1, (int)targetY1, (int)targetX2, (int)targetY2); // if (dir1 == dir2) // { // _ActionIndex = _PathIndex + 1; // return false; // } // _ActionIndex = _PathIndex; // return true; //} #if USE_FLOYD_PATH_NODES private bool StepMove(double toMoveDist, GameClient client) { //防止外部结束后,这里还在递归处理 StoryBoard4Client sb = FindStoryBoard(_RoleID); if (null == sb) { return(false); } lock (mutex) { //已到最后一个目的地,则停下 _PathIndex = Math.Min(_PathIndex, _Path.Count - 1); //探测下一个格子 if (!DetectNextGrid()) { return(true); } double targetX = _Path[_PathIndex].X * _CellSizeX + _CellSizeX / 2.0; //根据节点列号求得屏幕坐标 double targetY = _Path[_PathIndex].Y * _CellSizeY + _CellSizeY / 2.0; //根据节点行号求得屏幕坐标 int direction = (int)(GetDirectionByTan(targetX, targetY, _LastTargetX, _LastTargetY)); double dx = targetX - _LastTargetX; double dy = targetY - _LastTargetY; double thisGridStepDist = Math.Sqrt(dx * dx + dy * dy); //trace("_PathIndex=" + _PathIndex + ", " + "thisGridStepDist=" + thisGridStepDist); bool needWalking = false;// _LastNeedWalking; //if (_PathIndex > _ActionIndex) //{ // int currentGridX = (int)(_LastTargetX / _CellSizeX); // int currentGridY = (int)(_LastTargetY / _CellSizeY); // needWalking = NeedWalking(currentGridX, currentGridY); // _LastNeedWalking = needWalking; //} if (_Path.Count <= 1) { needWalking = true; } if (null != client) { GameMap gameMap = GameManager.MapMgr.DictMaps[client.ClientData.MapCode]; if (gameMap.InSafeRegionList(_Path[_PathIndex])) { needWalking = true; } } int action = needWalking ? (int)GActions.Walk : (int)GActions.Run; if (needWalking) { toMoveDist = toMoveDist * 0.80; } double thisToMoveDist = (thisGridStepDist < toMoveDist) ? thisGridStepDist : toMoveDist; double angle = Math.Atan2(dy, dx); double speedX = thisToMoveDist * Math.Cos(angle); double speedY = thisToMoveDist * Math.Sin(angle); _CurrentX = _CurrentX + speedX; _CurrentY = _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)_CurrentX; client.ClientData.PosY = (int)_CurrentY; //_MovingObj.Z = int(_MovingObj.Y); //此处应该非常消耗CPU //trace("_PathIndex=" + _PathIndex + ", " + "now_cx=" + _MovingObj.cx + ", now_cy=" + _MovingObj.cy); //System.Diagnostics.Debug.WriteLine(string.Format("StepMove, toX={0}, toY={1}", client.ClientData.PosX, client.ClientData.PosY)); 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); /// 玩家进行了移动 //Global.GameClientMoveGrid(client); } } _LastTargetX = (int)_CurrentX; _LastTargetY = (int)_CurrentY; } else //到达当前目的地 { //trace("_PathIndex=" + _PathIndex + ", " + "targetX=" + targetX + ", targetY=" + targetY + ", cx=" + _MovingObj.cx + ", cy=" + _MovingObj.cy ); //trace("_PathIndex=" + _PathIndex + ", " + "_LastUsedTicks=" + _LastUsedTicks + ", " + "_LastLostNumberX=" + _LastLostNumberX + ", _LastLostNumberY=" + _LastLostNumberY + ", _TotalMovePercent=" + _TotalMovePercent); //trace("_LastTargetX=" + _LastTargetX + ", " + "_LastTargetY=" + _LastTargetY + ", TargetX=" + targetX + ", " + "targetY=" + targetY + ", cx=" + _MovingObj.cx + ", cy=" + _MovingObj.cy ); //trace(_TotalTicksSlot); _PathIndex++; //已到最后一个目的地,则停下 if (_PathIndex >= _Path.Count) { if (null != client) { client.ClientData.PosX = (int)targetX; client.ClientData.PosY = (int)targetY; } return(true); } _LastTargetX = (int)targetX; _LastTargetY = (int)targetY; //_LastUsedTicks = 0; //_TotalTicksSlot = ""; toMoveDist = toMoveDist - thisGridStepDist; StepMove(toMoveDist, client); } return(false); } }