You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
8.7 KiB
253 lines
8.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Game
|
|
{
|
|
public static class MoveSvc
|
|
{
|
|
public static void OnMoveWalk(PlayerOnGame player, ref CSMoveWalk req)
|
|
{
|
|
TraceLog.Trace("MoveSvc.OnMoveWalk player {0} map {1}", player.UserID, req.Mapid);
|
|
|
|
if(req.Points.Count == 0)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveWalk player {0} in map {1}, req no any point!"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
if(req.Mapid != player.m_actor.mapDescId)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveWalk player {0} in map {1}, but move req map {2}, drop it"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
MapDesc mapDesc = MapDescMgr.Instance.GetConfig(req.Mapid);
|
|
if(mapDesc == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveWalk player {0} in map {1}, no desc"
|
|
, player.UserID, player.m_actor.mapDescId);
|
|
return;
|
|
}
|
|
|
|
if(mapDesc.serverMode == 0)
|
|
{
|
|
//保存坐标
|
|
SavePositionOnClientMod(player, ref req.Points, ref req.Dir);
|
|
return;
|
|
}
|
|
|
|
MapInstance instance = MapInstanceOp.GetInstanceById(player.m_actor.instanceId);
|
|
if (instance == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveWalk player {0} instance {1} not object"
|
|
, player.UserID, player.m_actor.instanceId);
|
|
return;
|
|
}
|
|
|
|
Map map = MapSvc.GetMap(instance, req.Mapid);
|
|
if (map == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveWalk player {0} no map {1}"
|
|
, player.UserID, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
int iRet = MoveCheckSvc.CheckMoveWalk(player, ref req, map);
|
|
if(iRet != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//服务器端先什么都不处理,只是改变一下坐标
|
|
DBPosition lastPos = req.Points[req.Points.Count - 1];
|
|
|
|
MapSvc.ChangePosition(player.m_actor, map, player.m_actor.position, lastPos, req.Dir, true);
|
|
|
|
req.ActorId = player.m_actor.actorId;
|
|
|
|
//广播移动消息
|
|
MapViewSvc.BroadCastToPlayerInView(player.m_actor, (int)CSGameMsgID.MoveWalk, ref req);
|
|
|
|
}
|
|
|
|
public static void OnMoveTurn(PlayerOnGame player, ref CSMoveTurn req)
|
|
{
|
|
TraceLog.Trace("MoveSvc.OnMoveTurn player {0} map {1}", player.UserID, req.Mapid);
|
|
|
|
if (req.Points.Count != 1)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveWalk player {0} in map {1}, req must 1 point!"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
if (req.Mapid != player.m_actor.mapDescId)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveTurn player {0} in map {1}, but move req map {2}, drop it"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
MapDesc mapDesc = MapDescMgr.Instance.GetConfig(req.Mapid);
|
|
if (mapDesc == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveTurn player {0} in map {1}, no desc"
|
|
, player.UserID, player.m_actor.mapDescId);
|
|
return;
|
|
}
|
|
|
|
if (mapDesc.serverMode == 0)
|
|
{
|
|
//保存坐标
|
|
SavePositionOnClientMod(player, ref req.Points, ref req.Dir);
|
|
return;
|
|
}
|
|
|
|
MapInstance instance = MapInstanceOp.GetInstanceById(player.m_actor.instanceId);
|
|
if (instance == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveTurn player {0} instance {1} not object"
|
|
, player.UserID, player.m_actor.instanceId);
|
|
return;
|
|
}
|
|
|
|
Map map = MapSvc.GetMap(instance, req.Mapid);
|
|
if (map == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveTurn player {0} no map {1}"
|
|
, player.UserID, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
int iRet = MoveCheckSvc.CheckMoveTurn(player, ref req, map);
|
|
if (iRet != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//服务器端先什么都不处理,只是改变一下坐标
|
|
DBPosition lastPos = req.Points[req.Points.Count - 1];
|
|
|
|
MapSvc.ChangePosition(player.m_actor, map, player.m_actor.position, lastPos, req.Dir, true);
|
|
|
|
req.ActorId = player.m_actor.actorId;
|
|
|
|
//广播移动消息
|
|
MapViewSvc.BroadCastToPlayerInView(player.m_actor, (int)CSGameMsgID.MoveTurn, ref req);
|
|
|
|
}
|
|
|
|
public static void OnMoveStop(PlayerOnGame player, ref CSMoveStop req)
|
|
{
|
|
TraceLog.Trace("MoveSvc.OnMoveStop player {0} map {1}", player.UserID, req.Mapid);
|
|
|
|
if (req.Points.Count == 0)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveStop player {0} in map {1}, req no any point!"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
if (req.Mapid != player.m_actor.mapDescId)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveStop player {0} in map {1}, but move req map {2}, drop it"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
MapDesc mapDesc = MapDescMgr.Instance.GetConfig(req.Mapid);
|
|
if (mapDesc == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveTurn player {0} in map {1}, no desc"
|
|
, player.UserID, player.m_actor.mapDescId);
|
|
return;
|
|
}
|
|
|
|
if (mapDesc.serverMode == 0)
|
|
{
|
|
//保存坐标
|
|
SavePositionOnClientMod(player, ref req.Points, ref req.Dir);
|
|
return;
|
|
}
|
|
|
|
MapInstance instance = MapInstanceOp.GetInstanceById(player.m_actor.instanceId);
|
|
if (instance == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveStop player {0} instance {1} not object"
|
|
, player.UserID, player.m_actor.instanceId);
|
|
return;
|
|
}
|
|
|
|
Map map = MapSvc.GetMap(instance, req.Mapid);
|
|
if (map == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveStop player {0} no map {1}"
|
|
, player.UserID, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
int iRet = MoveCheckSvc.CheckMoveStop(player, ref req, map);
|
|
if (iRet != 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//服务器端先什么都不处理,只是改变一下坐标
|
|
DBPosition lastPos = req.Points[req.Points.Count - 1];
|
|
|
|
MapSvc.ChangePosition(player.m_actor, map, player.m_actor.position, lastPos, req.Dir, true);
|
|
|
|
req.ActorId = player.m_actor.actorId;
|
|
|
|
//广播移动消息
|
|
MapViewSvc.BroadCastToPlayerInView(player.m_actor, (int)CSGameMsgID.MoveStop, ref req);
|
|
|
|
}
|
|
|
|
public static void OnMoveCameraChange(PlayerOnGame player, ref CSMoveCameraChange req)
|
|
{
|
|
TraceLog.Trace("MoveSvc.OnMoveCameraChange player {0} map {1}", player.UserID, req.Mapid);
|
|
|
|
if (req.Mapid != player.m_actor.mapDescId)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveCameraChange player {0} in map {1}, but move req map {2}, drop it"
|
|
, player.UserID, player.m_actor.mapDescId, req.Mapid);
|
|
return;
|
|
}
|
|
|
|
MapDesc mapDesc = MapDescMgr.Instance.GetConfig(req.Mapid);
|
|
if (mapDesc == null)
|
|
{
|
|
TraceLog.Error("MoveSvc.OnMoveCameraChange player {0} in map {1}, no desc"
|
|
, player.UserID, player.m_actor.mapDescId);
|
|
return;
|
|
}
|
|
|
|
player.m_actor.camera = req.Camera;
|
|
|
|
MapInstanceUtils.SavePlayerMapPosToDBData(player);
|
|
}
|
|
|
|
//客户端模式直接保存客户端发上来的坐标
|
|
public static void SavePositionOnClientMod(PlayerOnGame player, ref RepeatedDBPosition_16 points, ref DBPosition dir)
|
|
{
|
|
if(points.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
player.m_actor.instanceId = 0;
|
|
player.m_actor.position = points[points.Count - 1];
|
|
player.m_actor.direction = dir;
|
|
|
|
MapInstanceUtils.SavePlayerMapPosToDBData(player);
|
|
}
|
|
}
|
|
}
|
|
|